// vjc
// version: 0.0.1
// lewphee@gmail.com
// 2009-03-22 05:01
var _d = document;
var _w = window;
var $=function(){return _d.getElementById(arguments[0]);}
var loadedAr = _w.loadedAr || [];
var registerHook = _w.registerHook || function(){loadedAr.push(arguments[0]);}
var _http=function(){return window.ActiveXObject ? new ActiveXObject("Msxml2.XMLHTTP") :  new XMLHttpRequest();}
var isIE = ("\v"=="v" ? true : false);
window.onload=function(){
	_w.loadedAr = _w.loadedAr || loadedAr;
	_w.registerHook = _w.registerHook || registerHook;
	_runchain();
}

var _runchain = function(){
	var c = _w.loadedAr;
	for(var i=0; i < c.length; i++){
		if(typeof(c[i]) == 'function'){
			c[i] && c[i]();
		}else if(typeof([c[i]] == "string")){
			eval(c[i]);
		}
	}
}

var bc = new basicClass();
function basicClass(){}
basicClass.prototype.toURL = function(){window.location.href = arguments[0];}

function MultimediaClass(){
	this.baseDir = arguments[0];
	this.fileName = arguments[1];
	this.loop = -1;
	this.width = 280;
	this.height = 65;
	this.autoStart = 0;
	this.volumn = 0;
	switch(arguments[2]){
		case 0:
			this.fileExt = ".mp3";
			break;
		case 1:
			this.fileExt = ".wma";
			break;
		case 2:
			this.fileExt = ".rm";
			break;
	}
}

MultimediaClass.prototype.flushPlayer = function(){
	var str = '<embed style="filter:xray;" src="' +
	this.baseDir +
	this.fileName +
	this.fileExt +
	'" width="'+
	this.width+
	'" height="' +
	this.height +
	'" type="application/x-mplayer2" loop="' +
	this.loop +
	'" showcontrols="1" showdisplay="0" showstatusbar="1" autostart="0" volume="' +
	this.volumn +
	'"></embed>';

	document.write(str);
	//type can also use audio/mpeg
}

/*tabs*/
function TabClass(){
	this.curActObject	= null;
	this.property		= new Object();
	this.childTags		= arguments[0];
	this.parentObject	= arguments[1];
	this.clsName		= arguments[2];
	this.relatedChilds	= new Array();
	this.tabType		= "value";
	this.curValue		= 0;
}

TabClass.prototype.assign = function(){
	var es = this.parentObject.getElementsByTagName(this.childTags);
	for(var i = 0; i < es.length; i++){
		es[i].setAttribute("TABEXEC", this.clsName + ".setCurAct(" + i + ")");
		es[i].onclick = function(e){
			var event = e || window.event;
			var s = event.srcElement ? event.srcElement : event.target;
			var str = s.getAttribute("TABEXEC");
			eval(str);
		}
	}
}

TabClass.prototype.setCurAct = function(){
	var es = this.parentObject.getElementsByTagName(this.childTags);
	this.curValue = arguments[0];
	for(var i = 0; i < es.length; i++){
		if(i == arguments[0]){
			this.curActObject = es[i];
			es[i].className = 'act';

			if(this.tabType == "display"){
				this.relatedChilds[i].style.display = "";
			}
		}else{
			es[i].className = '';
			if(this.tabType == "display"){
				this.relatedChilds[i].style.display = "none";
			}
		}
	}
}

TabClass.prototype.setRelated = function(){
	this.relatedChilds = arguments[0];
}

TabClass.prototype.setType = function(){
	this.tabType = arguments[0];
}

/*XMLs*/
function XMLClass(){
	this.clsName = arguments[0] || 'undefined';
}

XMLClass.prototype.setDestined = function(){
	this.destined	= arguments[0];
}

XMLClass.prototype.loadURL = function(){
	var d = arguments[0];
	var http = _http();
	http.open(d.sMethod, d.sURL);
	http.send(null);
	http.onreadystatechange = function(){
		if(http.readyState == 4){
			if(http.status == 200 || http.status == 0){
				d.refObj.innerHTML = http.responseText;
			}else{
				alert(http.status);
			}
		}
	};
}

XMLClass.prototype.loadThisURL = function(){
	return this.loadURL("GET", arguments[0].href, arguments[1]);
}

XMLClass.prototype.openURLHTML = function(){
	var d = arguments[0];
	var http = _http();
	http.open(d.sMethod, d.sURL);
	http.send(null);
	http.onreadystatechange = function(){
		if(http.readyState == 4){
			if(http.status == 200 || http.status == 0){
				d.refObj.innerHTML = http.responseText;
				if(!d.bIsAjax)return;
				var hrf = window.location.href;
				hrf = hrf.replace('http://' + document.domain, '');
				var pos = hrf.indexOf("#");
				if(pos == -1){
					window.location.href = hrf + '#' + d.sURL;
				}else{
					window.location.href = hrf.substring(0, pos) + '#' + d.sURL;
				}
				window.oHistory.save();
			}else{
				alert(http.status);
			}
		}
	};
}

XMLClass.prototype.assignLinks2Ajax = function(){
	var iscls	= arguments[0] == "class" ? 1 : 0;
	var es		= arguments[1].getElementsByTagName("a");
	var hd		= arguments[2];

	for(var i = 0; i < es.length; i++){
		var pat = /logout/;
		if(pat.test(es[i].href))continue;
		es[i].setAttribute("XML", this.clsName);
		es[i].onclick = function(e){
			var event = e || window.event;
			var s = event.srcElement ? event.srcElement : event.target;
			var lnk = s.getAttribute("href");
			var cls = s.getAttribute("XML");
			eval(cls + '.openURLHTML({sMethod:"GET", sURL: "'+lnk+'", refObj: '+cls+'.destined, bIsAjax: true})');
			return false;
		}
	}
}

/*HashHistory*/
function HashHistory(){
	this.clsName	= arguments[0];
	this.hashTable	= new Array();
	this.curHash	= '';

	var hrf = window.location.href;
	var pos = hrf.indexOf("#");
	if(pos == -1){
		this.hashTable[0] = hrf;
	}else{
		this.hashTable[0] = hrf.substring(0, pos);
	}
}

HashHistory.prototype.setup = function(){
	setInterval(this.clsName + ".checkHash()", 100);
}

HashHistory.prototype.checkHash =function(){
	var hsh = window.location.hash;
	var ths = this.hashTable[this.hashTable.length-1];

	if(hsh == this.curHash)return;
	this.curHash = hsh;
	this.oHistory.load(this.curHash);
}

HashHistory.prototype.save = function(){

}

HashHistory.prototype.load = function(){
	for(var p in this.hashTable){
		if(p == this.curHash){
			eval(this.hashTable[p]);
			return;
		}
	}
}
