﻿//<![CDATA[
//AUTHOR:JULLYCAT(ZHANGYANJUN)
huadong=function(id){
	return document.getElementById(id);
}
/**自定义多重类对象
 * @param {Object} namespace 自定义类名
 */
Namespace = new Object();
Namespace.register = function(namespace){
	var nsArray = namespace.split('.');
	var sEval = "";
    var sNS = "";
	for (var i = 0; i < nsArray.length; i++){
        if (i != 0) sNS += ".";
        sNS += nsArray[i];
        sEval += "if (typeof(" + sNS + ") == 'undefined') " + sNS + " = new Object();"
    }
    if (sEval != "") eval(sEval);
}
Namespace.register("Qy.util.showDiv");

/*
 *重构DIV位置的静态类
 *@class setDiv
 */
(function(){
	var initheight,totalheight;
	Qy.util.setDiv = {
		/**
		 *初始化弹性显示DOM对象
		 *@method init
		 *@param (el,con,nums,overclassname,outclassname,speed,maxheight) tab前缀，显示内容前缀，tab个数，覆盖tab样式，离开tab样式，弹开速度，显示内容框高度
		 */
		init:function(el,con,nums,overclassname,outclassname,speed,maxheight){
			var arg = new Array();
			for(i=0;i<arguments.length;i++){
				arg[i] = arguments[i];
			}
			for(j=1;j<=parseInt(arg[2]);j++){
				tagBox = huadong(arg[0] + j);
				hidBox = huadong(arg[1] + j);
				tagBox.m = j;
				hidBox.m = j;
				tagBox.onmouseover=function(){Qy.util.showDiv.slideshow(arg,this.m);};
				tagBox.onmouseout=function(){Qy.util.showDiv.slideshow(arg,this.m);};
				hidBox.onmouseover=function(){Qy.util.showDiv.slideshow(arg,this.m);};
//				hidBox.onmouseout=function(){Qy.util.showDiv.slideshow(arg,this.m);};
			}
			Qy.util.showDiv.slideshow(arg,1);
		},
		/**
		 *tab效果DOM对象初始化
		 *@method tabDivinit
		 *@param (nums,tab,con,curClassName,speed,oEvent) tab个数，tab前缀，显示内容前缀，tab当前时的样式，切换速度，设置控制切换的事件
		 */
		tabDivinit:function(nums,tab,con,curClassName,speed,oEvent){
			var t = oEvent;
			var arg = new Array;
			for(i=0;i<arguments.length;i++){
				arg[i] = arguments[i];
			}
			for(var j=0;j<arg[0];j++){
				var curtab = huadong(arg[1] + j);
				curtab.n = j;
				switch(t){
					case 'click':
						curtab.onclick = function(){Qy.util.showDiv.show(arg,this.n);};
						break;
					default:
						curtab.onmouseover = function(){Qy.util.showDiv.show(arg,this.n);};
						break;
				}
			}
			return arg;
		}
	};
})();

/**
 *显示隐藏类
 *@class showDiv
 */
(function(){
	var pos;
	var showpos;
	Qy.util.showDiv = {
		/**
		 *tab切换控制，切屏事件可设置
		 *@param arg是数组类,id为当前出发对象的编号
		 */
		show:function(arg,id){
			var curtab,curobj;
			curobj = this;
			var useArg = new Array;
			for(j=0;j<arg.length;j++){
				useArg[j] = arg[j];
			}
			for(var i=0;i<useArg[0];i++){
				curtab = huadong(useArg[1] +i);
				if(i==id){ 
					curtab.className = useArg[3];
					huadong(useArg[2]+i).style.display = "block";
				}else{
					curtab.className = '';
					huadong(useArg[2]+i).style.display = "none";
				}
			}	
		},

		/**
		 *tab自动切换控制，切屏事件自动设置
		 *@param arg是数组类
		 */
		autoshow:function(arg){
			var time1,curobj,curtab,curnum,bpos;
			curnum = 1;
			curobj = this;
			bpos = 0;
			var useArg = new Array;
			for(j=0;j<arg.length;j++){
				useArg[j] = arg[j];
			}
			this.show(useArg,0);
			function ctrl(){
				time1 = setInterval(function(){
					if(curnum>=useArg[0]) curnum=0;
					bpos = curnum;
					curobj.show(useArg,curnum);
					curnum++;
				},useArg[4])
			}
			ctrl();
			for(var i=0;i<useArg[0];i++){
				curtab = huadong(useArg[1] +i);
				switch(useArg[5]){
					case 'click':
						curtab.onclick = function(){curobj.show(useArg,this.n);};
						curtab.onmouseover = function(){clearInterval(time1);bpos=this.n;}
						break;
					default:
						curtab.onmouseover = function(){clearInterval(time1);curobj.show(useArg,this.n);bpos=this.n;};
						break;
				}
				huadong(useArg[2] +i).onmouseover = function(){clearInterval(time1);bpos++;}
				huadong(useArg[2] +i).onmouseout = function(){
//					bpos++;
//					if(bpos==useArg[0]) bpos=0;
//					curobj.show(useArg,bpos);
					curnum = bpos;
					ctrl();
				}
				curtab.onmouseout = function(){
//					if(bpos==useArg[0]) bpos=0;
//					curobj.show(useArg,bpos);
					curnum = bpos;
					ctrl();
				}
			}
		},
		/**
		 *由onmouseover和onmouseout事件触发，弹性显示
		 *@param arg是数组类，id是tab的后缀数字
		 */
		slideshow:function(arg,id){
			var curobj = new Array();
			for(j=0;j<arg.length;j++){
				curobj[j] = arg[j];
			}
			var tagBox,hidBox;
			var ctrl = 0;
			if((id!=pos)||(pos==null)){
				for(i=1;i<=parseInt(curobj[2]);i++){
					tagBox = huadong(curobj[0] + i);
					hidBox = huadong(curobj[1] + i);
					if(i==id){
						pos=id;
						tagBox.className = curobj[3];
						hidBox.style.display = "block";
	/*设置弹性效果
//						hidBox.style.overflow = "hidden";
//						hidBox.style.height = "0px";
//						var time1 = setInterval(function(){
//							var ids = id;
//							ctrl +=	curobj[5];
//							if(ctrl>curobj[6]) {
//								clearInterval(time1);
//								ctrl = curobj[6];
//							}
//							huadong(curobj[1] + ids).style.height = ctrl  + "px";
//						},30);
	*/
						hidBox.style.height = curobj[6] + "px";
					}else{
							hidBox.style.height = "0px";
							tagBox.className = curobj[4];
							hidBox.style.display = "none";
					}
				}
			}
		}
		
	}
})();

/**
 *移动类
 *@class move
 */
(function(){
	var movebox = null;
	var moveboxs = new Array();
	var oStart,oEnd,oStartY,oEndY;
	var speed = 10;
	var mflag = true;
	Qy.util.move = {
		/**
		 *增加movebox对象
		 *@param id 移动层的父层
		 *@param 移动层id
		 */
		init:function(id,mb_arr,cookiename){
			
			var movebox = new Qy.widget.movebox(id);
			for(var i=0;i<mb_arr.length;i++){
				movebox.list.push(huadong(mb_arr[i]));
			}
			movebox.cookieid = cookiename;
			moveboxs.push(movebox);
		},

		/**
		 * 向上移动当前对象在整个对象中的位置，并交换互相的位置.
		 * @method moveUp 
		 * @param {Object} m_b movebox的DOM对象.
		 * @param {Object} now 当前准备移动的DOM对象,包含在m_b里面.
		 */
		moveUp:function(m_b,now){
			if(mflag){
			oStart=null;
			oEnd=null;
			oStartY=null;
			oEndY=null;
			var changepoint = new Array();
			movebox = this.isHave(m_b);
			if(this.getUp(now)!=null){
				changepoint = this.getUp(now);
				oStart = changepoint[0];
				oEnd = changepoint[1];
				oStartY = parseInt(oEnd.style.top);
				oEndY = parseInt(oStart.style.top);
				oStart.style.zIndex = "0";
				oEnd.style.zIndex = "360";
				oStart.style.filter="alpha(opacity=10)";
				this.startmoving();
				this.endmoving();
				oStart.style.filter="alpha(opacity=100)";
			}
			this.change(oEnd,oStart);
			Qy.widget.cookie.newAndModif(movebox.cookieid,this.toString(),30);
			}
			
		},
		/**
		 *向下移动当前对象在整个对象中的位置，并交换互相的位置.
		 *@method moveDown 
		 */
		moveDown:function(m_b,now){
		if(mflag){
			oStart=null;
			oEnd=null;
			oStartY=null;
			oEndY=null;
			var changepoint = new Array();
			movebox = this.isHave(m_b);
			if(this.getDown(now)!=null){
				changepoint = this.getDown(now);
				oStart = changepoint[0];
				oEnd = changepoint[1];
				oStartY = parseInt(oEnd.style.top);
				oEndY = parseInt(oStart.style.top);
				oStart.style.zIndex = "360";
				oEnd.style.zIndex = "0";
				oEnd.style.filter="alpha(opacity=10)";
				this.startmoving();
				this.endmoving();
				oEnd.style.filter="alpha(opacity=100)";
			}
			this.change(oEnd,oStart);
			Qy.widget.cookie.newAndModif(movebox.cookieid,this.toString(),30);
		}
			
		},
		/**
		 *上一层的移动定位
		 */
		startmoving:function(){
			var con = this;
			yStart = parseInt(oStart.style.top);
			yEnd = oStartY+(oEnd.scrollHeight-oStart.scrollHeight);
			if(yStart<yEnd){
				this.moveY(oStart,1,speed,yEnd);
				setTimeout(function(){con.startmoving()},1);
				mflag = false;
			}
			if(yStart>yEnd){
				this.moveY(oStart,2,speed,yEnd);
				setTimeout(function(){con.startmoving()},1);
				mflag = false;
			}
			if(yStart==yEnd){
				mflag = true;
			}
		},
		/**
		 *下一层移动定位
		 */
		endmoving:function(){
			yStart = parseInt(oEnd.style.top);
			yEnd = parseInt(oEndY);
			var con = this;
			if(yStart<yEnd){
				this.moveY(oEnd,1,speed,yEnd);
				setTimeout(function(){con.endmoving()},1);
				mflag = false;
			}
			if(yStart>yEnd){
				this.moveY(oEnd,2,speed,yEnd);
				setTimeout(function(){con.endmoving()},1);
				mflag = false;
			}
			if(yStart==yEnd){
				mflag = true;
			}
		},
		/**
		 *调整浮动层obj的top值
		 *@method moveY
		 */
		moveY:function(obj,ySpeenType,speed,yEnd){
			if(ySpeenType==1){
				if((parseInt(obj.style.top)+speed)>yEnd){
					obj.style.top = yEnd+"px";
				}else{
					obj.style.top = parseInt(obj.style.top)+speed+"px";
				}
			}
			if(ySpeenType==2){
				if((parseInt(obj.style.top)-speed)<yEnd){
					obj.style.top = yEnd+"px";
				}else{
					obj.style.top = parseInt(obj.style.top)-speed+"px";
				}
			}
		},
		/**
		 *获取移动对象在movebox对象list中的位置
		 *@method getIndex 
		 *@param 移动对象
		 */
		getIndex:function(moveObj){
			for(var i=0;i<movebox.list.length;i++){
				if(movebox.list[i]==moveObj){
					return i;
				}
			}
			return -1;
		},
		/**
		 *获取moveboxs中movebox对象
		 *@param m_b是移动层的父层
		 */
		isHave:function(m_b){
			for(var i=0;i<moveboxs.length;i++){
				if(moveboxs[i].name==huadong(m_b.id)){
					return moveboxs[i];
				}
			}
		},
		/**
		 * 向上获取当前对象的临近的对象.
		 * @method getUp 
		 * @param {Object} now 当前对象.
		 */
		getUp:function(now){
			var arrm = new Array();
			for(var i=0;i<movebox.list.length;i++){
				if(movebox.list[i]==now){
					if(i>0){
						arrm[0] = movebox.list[i-1];
						arrm[1] = movebox.list[i];
						return arrm;
					}else{
						return null;
					}
				}
			}
		},
		/**
		 * 向下获取当前对象的临近的对象.
		 * @method getDown 
		 * @param {Object} now 当前对象.
		 */
		getDown:function(now){
			var arrm = new Array();
			for(var i=0;i<movebox.list.length;i++){
				if(movebox.list[i]==now){
					if(i<movebox.list.length-1){
						arrm[0] = movebox.list[i];
						arrm[1] = movebox.list[i+1];
						return arrm;
					}else{
						return null;
					}
				}
			}
		},
		/**
		 *改变移动对象在movebox.list中的位置
		 *@method change
		 *@param (start,end)移动的两个对象
		 */
		change:function(start,end){
			var s_index = this.getIndex(start);
			var e_index = this.getIndex(end);
			if(s_index!=-1&&e_index!=-1){
				movebox.list[s_index] = end;
				movebox.list[e_index] = start;
				movebox.version++;
			}
		},
		/**
		 *将movebox对象中的list数组值用&连接返回字符串
		 *@method toString
		 */
		toString:function(){
			var tempStr = "";
			for(var i=0;i<movebox.list.length;i++){
				tempStr = tempStr + movebox.list[i].id + "&";
			}
			tempStr = tempStr.substring(0,tempStr.length-1);
			return tempStr;
		}
	};
})();
//]]>

