//<![CDATA[
//AUTHOR:JULLYCAT(XUFENGTIAN)

Namespace.register("Lb.util.setDiv");
Namespace.register("Lb.util.showDiv");
/**
 *应用类方法定义
 */

/*
 *重构DIV位置的静态类
 *@class setDiv
 */
(function(){
	var initheight,totalheight;
	Lb.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 = $1(arg[0] + j);
				hidBox = $1(arg[1] + j);
				tagBox.m = j;
				hidBox.m = j;
				tagBox.onmouseover=function(){Lb.util.showDiv.slideshow(arg,this.m);};
				tagBox.onmouseout=function(){Lb.util.showDiv.slideshow(arg,this.m);};
				hidBox.onmouseover=function(){Lb.util.showDiv.slideshow(arg,this.m);};
//				hidBox.onmouseout=function(){Lb.util.showDiv.slideshow(arg,this.m);};
			}
			Lb.util.showDiv.slideshow(arg,1);
		},
		/**
		 *构建移动DOM对象
		 *@method build
		 *@param (el,className,targetName) 父层对象，及移动对象使用的样式，移动对象的tagName
		 */
		build:function(el,className,targetName,cookiename,mspace){
			totalheight = 0;
			var ctrHeight;
			var mb_arr = new Array();
			var childtag = el.getElementsByTagName(targetName);
			for(i=0;i<childtag.length;i++){
				if(childtag[i].className==className){
					with(childtag[i].style){
						position = "absolute";
						top = totalheight + "px";
					}
					if(childtag[i].scrollHeight==0) ctrHeight = parseInt(childtag[i].style.height);
					else ctrHeight = childtag[i].scrollHeight;
					if(mspace!=null && mspace!="") totalheight = totalheight + ctrHeight + mspace;
					else totalheight = totalheight + ctrHeight;
					mb_arr[mb_arr.length] = childtag[i].id;
				}
			}
			el.style.height = totalheight + "px";
			Lb.util.move.init(el,mb_arr,cookiename);
		},
		/**
		 *获取cookie重置移动DOM对象
		 *@method rebuild
		 *@param (movebox,cookieValue) 父层对象，cookie截取后的字符
		 */
		rebuild:function(movebox,cookieValue,cookiename,mspace){
			var ctrHeight;
			var totalheight = 0;
			var mb_arr = cookieValue.split("&");
			for(var i=0;i<mb_arr.length;i++){
				$1(mb_arr[i]).style.position = "absolute";
				$1(mb_arr[i]).style.top = totalheight + "px";
				if(parseInt($1(mb_arr[i]).scrollHeight)==0) {ctrHeight = parseInt($1(mb_arr[i]).style.height);}
				else ctrHeight = $1(mb_arr[i]).scrollHeight;
				if(mspace!=null && mspace!="") totalheight = totalheight + ctrHeight + mspace;
				else totalheight = totalheight + ctrHeight;
			}
			movebox.style.height = totalheight + "px";
			Lb.util.move.init(movebox,mb_arr,cookiename);
		},

		/**
		 *tab效果DOM对象初始化
		 *@method tabDivinit
		 *@param (nums,tab,con,curClassName,speed,oEvent) tab个数，tab前缀，显示内容前缀，tab当前时的样式，切换速度，设置控制切换的事件，tab非当前样式
		 */
		tabDivinit:function(nums,tab,con,curClassName,speed,oEvent,outcname)
		{
			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 = $1(arg[1] + j);
				curtab.n = j;
				switch(t)
				{
					case 'click':
						curtab.onclick = function(){Lb.util.showDiv.show(arg,this.n);};
						break;
					default:
						curtab.onclick = function(){Lb.util.showDiv.show(arg,this.n);};
						break;
				}
			}
			return arg;
		}
	};
})();

/**
 *显示隐藏类
 *@class showDiv
 */
(function(){
	var pos;
	var showpos;
	Lb.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 = $1(useArg[1] +i);
				if(i==id){ 
					curtab.className = useArg[3];
					$1(useArg[2]+i).style.display = "block";
				}else{
					curtab.className = useArg[6];
					$1(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 = $1(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;
				}
				$1(useArg[2] +i).onmouseover = function(){clearInterval(time1);bpos++;}
				$1(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 = $1(curobj[0] + i);
					hidBox = $1(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];
//							}
//							$1(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";
					}
				}
			}
		}
		
	}
})();
//]]>


