/**
 * @author wuchunlei
 */

 /*常用工具函数封装 === [//] >> begin === */
var edu = {
	$:function(id) { return document.getElementById(id);},
	addEvent:function(obj,eventType,func) {
		if(obj.attachEvent) {
			obj.attachEvent("on" + eventType,func);
		} else {
			obj.addEventListener(eventType,func,false);
		}
	},
	delEvent:function(obj,eventType,func) {
		if(obj.detachEvent) {
			obj.detachEvent("on" + eventType,func);
		} else {
			obj.removeEventListener(eventType,func,false);
		}
	},addClass:function(obj,className) {
		obj.className = className;
	},delClass:function(obj) {
		obj.className ="";
	},
	show:function(obj) {
		obj.style.display ="block";
	},
	hidden:function(id) {
		edu.$(id).style.display = "none";
	},
	loadAjax:function(ID,URL,para) {
		var req;
		try {
			req = new XMLHttpRequest();
		} catch(Error) {
			try{
				req = new ActiveXObject("Microsoft.XMLHTTP");
			} catch(Error) {
				req = null;
			}
		}
		req.open("POST",URL);
        req.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		req.send(para);
		req.onreadystatechange = function() {
			if (req.readyState != 4) {
				edu.$(ID).innerHTML ="<div style='padding:10px; text-align:center;'>加载中...</div>";
			} else {
				if(req.status == 200) {
					edu.$(ID).innerHTML =req.responseText;
				}
			}
		};
	}
};
 /*常用工具函数封装 === [//] >> end === */

/*弹出窗口对象 === [//] >> begin === */
function PopObj(ID,couNode,eventType,targetID,targetBgId,targetClose,AjaxToggle) {
	if(!ID || edu.$(ID) == null) {
		throw new Error("PopObj(ID)参数错误:没有传递ID参数或$(ID)对象为空");
	}
	this.parentobj = edu.$(ID);
	this.sourceobj = this.parentobj.getElementsByTagName(couNode);
	this.targetid = targetID;
	this.targetObj = edu.$(targetID);
	this.targetBgid = targetBgId;
	this.targetClose = edu.$(targetClose);
	this.AjaxToggle = AjaxToggle ? true : false ;
	this.AjaxID,this.URL,this.para;
	if(!PopObj.myself) {
		PopObj.myself = [];
	}
	this.ID = PopObj.myself.length;
	PopObj.myself.push(this);
	if(typeof eventType != "String") {
		eventType = "onmousedown";
	}
	eventType = eventType.toLowerCase();
	switch(eventType) {
		case "onclick" :
			this.eventType = "click";
			break;
		case "onmouseover" :
			this.eventType = "mouseover";
			break;
		case "onmouseout" :
			this.eventType = "mouseout"
			break;
		default:
			this.eventType = "mousedown";
	}
}
PopObj.prototype.init = function() {
	for(var i = 0; i<this.sourceobj.length; i++) {
		var showFunc = Function("PopObj.myself[" + this.ID + "].showTarget('"+ this.targetid +"','"+ i +"')");
		var showBgFunc = Function("PopObj.myself[" + this.ID + "].showTargetBg('"+ this.targetBgid + "')");
		edu.addEvent(this.sourceobj[i],this.eventType,showFunc);
		edu.addEvent(this.sourceobj[i],this.eventType,showBgFunc);
	}
}
PopObj.prototype.showTarget = function(ID,index) {
	edu.show(this.targetObj);
	this.targetObj.style.position = "absolute";
	this.targetObj.style.left = document.documentElement.clientWidth/2 - parseInt(this.targetObj.clientWidth)/2 + "px";
	this.targetObj.style.top = (document.documentElement.clientHeight/2 - parseInt(this.targetObj.clientHeight)/2) + document.documentElement.scrollTop  + "px";
	var closeFunc = Function("edu.hidden('"+ ID +"')");
	edu.addEvent(this.targetClose,this.eventType,closeFunc);
	if(this.AjaxToggle) {
		edu.loadAjax(this.AjaxID,this.URL,this.para[index]);
	}
}
PopObj.prototype.showTargetBg = function(ID) {
	var d = document.documentElement;
	edu.$(ID).style.display = "block";
	edu.$(ID).style.width = d.scrollWidth > d.clientWidth ? d.scrollWidth : d.clientWidth + "px";
	edu.$(ID).style.height = (d.scrollHeight > d.clientHeight ? d.scrollHeight : d.clientHeight) + "px";
	var closeFunc = Function("edu.hidden('"+ ID +"')");
	edu.addEvent(this.targetClose,this.eventType,closeFunc);
}
/*弹出窗口对象 === [//] >> end === */

/*鼠标划过显示效果 === [显示/隐藏] >> begin === */
function fadeIn(obj,targetNode,className) {
	var targetObj = obj.getElementsByTagName(targetNode);
	for(var i =0 ; i<targetObj.length; i++) {
		if(targetObj[i].className == className) {
			edu.show(targetObj[i]);
			obj.style.zIndex = "100";
		}
	}
}
function fadeOut(obj,targetNode,className) {
	var targetObj = obj.getElementsByTagName(targetNode);
	for(var i =0 ; i<targetObj.length; i++) {
		if(targetObj[i].className == className) {
			targetObj[i].style.display ="none";
			obj.style.zIndex = "50";
		}
	}
}
/*鼠标划过显示效果 === [显示/隐藏] >> end === */

/*鼠标点击下拉效果 === [显示/隐藏] >> begin === */
var toggle = "expand";
function drogFunc(ID,ID2) {
	var firstHeight = 1;
	var lastHeight = /*edu.$(ID).getElementsByTagName('ul')[0].clientHeight*/ 450;

	if(toggle == "expand") {
		toggle = "";
		edu.$(ID2).style.visibility = "visible";
		var t = setInterval(function() { firstHeight += 25;
			if(firstHeight > lastHeight) {
				firstHeight = lastHeight;
				clearInterval(t);
				edu.$(ID).style.backgroundPosition ="-150px -25px";
				 toggle = "collapse";
			}
			edu.$(ID2).style.height = firstHeight +"px";
		 },25);
	} else if( toggle == "collapse") {
		toggle = "";
		var t = setInterval(function() { lastHeight -= 25;
			if(lastHeight < firstHeight) {
				lastHeight = firstHeight;
				clearInterval(t);
				edu.$(ID2).style.visibility = "hidden";
				edu.$(ID).style.backgroundPosition ="-150px 0";
				toggle = "expand";
			}
			edu.$(ID2).style.height = lastHeight +"px";
		 },25);
	}
}
/*鼠标点击下拉效果 === [显示/隐藏] >> end === */
function stuCentMapClick() {
	if(edu.$('smContent').style.display == 'block') {
		stuCentMapClose();
	} else {
		edu.$('smContent').style.display = 'block';
		edu.addEvent(document.body,'mousedown',otherClick);
	}
}
function otherClick(e) {
	var	thisObj = e.target ? e.target : window.event.srcElement;
	do {
		if(thisObj.id  == 'stuCentMap' || thisObj.id  == 'popDiv' || thisObj.id  == 'popBg') {
			return;
		}
		if ( thisObj.tagName == 'BODY') {
			stuCentMapClose();
		}
		thisObj = thisObj.parentNode;
	}
	while (thisObj.parentNode);
}
function stuCentMapClose() {
	edu.$('smContent').style.display = 'none';
	edu.delEvent(document.body,'mousedown',otherClick);
}




