﻿//<![CDATA[

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);
}

/**
 * 对数组Array对象扩展unite方法；
 * @method unite 类似concat，但FF不支持concat；
 * @param (arg) arg是需要增加的数组对象；
 */
Array.prototype.unite = function(arg){
	var temparg = new Array();
	var len1 = this.length;
	var len2 = arg.length;
	for(var i=0;i<(len1+len2);i++){
		if(i<len1) this[i] = this[i];
		else this[i] = arg[i-len1];
	}
	return this;
}

/**
 * 给数组扩展add方法.
 * @method add 类似push,需要增加的元素同元数组进行比较，如果没有相同值则追加，如果有则不追加;
 * @param {Object} obj 需要add的对象.
 */
Array.prototype.add = function(obj){
	var add_flag = true;
	for(var i=0;i<this.length;i++){
		if(this[i]==obj){
			add_flag = false;
			break;
		}
	}
	if(add_flag==true){
		this[this.length] = obj;
	}
}

function getE(id){ return document.getElementById(id);}
Namespace.register("SX.util.setDiv");
/*
 *重构DIV位置的静态类
 *@class setDiv
 */
(function(){
	var initheight,totalheight;
	
	SX.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 = getE(arg[0] + j);
				hidBox = getE(arg[1] + j);
				tagBox.m = j;
				hidBox.m = j;
				tagBox.onmouseover=function(){SX.util.showDiv.slideshow(arg,this.m);};
				tagBox.onmouseout=function(){SX.util.showDiv.slideshow(arg,this.m);};
				hidBox.onmouseover=function(){SX.util.showDiv.slideshow(arg,this.m);};
//				hidBox.onmouseout=function(){SX.util.showDiv.slideshow(arg,this.m);};
			}
			SX.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";
			SX.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++){
				getE(mb_arr[i]).style.position = "absolute";
				getE(mb_arr[i]).style.top = totalheight + "px";
				if(parseInt(getE(mb_arr[i]).scrollHeight)==0) {ctrHeight = parseInt(getE(mb_arr[i]).style.height);}
				else ctrHeight = getE(mb_arr[i]).scrollHeight;
				if(mspace!=null && mspace!="") totalheight = totalheight + ctrHeight + mspace;
				else totalheight = totalheight + ctrHeight;
			}
			movebox.style.height = totalheight + "px";
			SX.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 = getE(arg[1] + j);
				curtab.n = j;
				switch(t){
					case 'click':
						curtab.onclick = function(){SX.util.showDiv.show(arg,this.n);};
						break;
					default:
						curtab.onmouseover = function(){SX.util.showDiv.show(arg,this.n);};
						break;
				}
			}
			return arg;
		}
	};
})();

/**
 *显示隐藏类
 *@class showDiv
 */
(function(){
	var pos;
	var showpos;
	SX.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 = getE(useArg[1] +i);
				if(i==id){ 
					curtab.className = useArg[3];
					getE(useArg[2]+i).style.display = "block";
				}else{
					curtab.className = useArg[6];
					getE(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 = getE(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;
				}
				getE(useArg[2] +i).onmouseover = function(){clearInterval(time1);bpos++;}
				getE(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 = getE(curobj[0] + i);
					hidBox = getE(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];
//							}
//							getE(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";
					}
				}
			}
		}
		
	}
})();




