// 一般标签类
function Tab(cname){
	
	var old_id = new Array();
	old_id[cname] = 0;
	
	this.$ = function(id){
		return (typeof(id)=='object') ? id : document.getElementById(id);
	}
	
	this.show = function(tabname,boxname,id){
		if (old_id[cname]!=id){
			if (old_id[cname]!=0){
				this.$(tabname+old_id[cname]).className=tabname+"1";
				this.$(boxname+old_id[cname]).className=boxname+"1";
			}
			this.$(tabname+id).className=tabname+"2";
			this.$(boxname+id).className=boxname+"2";
			old_id[cname] = id;
		}
	}
}

// 一般移动类（类名，对象容器，执行脚本，宽，高，停止时间（毫秒），移动方向）
function Move(cname, location, script, box_width, box_height, stoptime, direction){
	
	var the_imgs = new Array(); //移动对象总数
	the_imgs[cname] = 0;
	this.get_imgs = function(){return the_imgs[cname];}
	
	var the_imgstr = new Array(); //移动对象总数
	the_imgstr[cname] = new Array();
	this.the_imgstr = function(v){return the_imgstr[cname][v];}
	
	var the_img = new Array(); //当前停留位置
	the_img[cname] = 1;
	this.get_img = function(){return the_img[cname];}
	
	var the_setTimeout = new Array(); //计时间对象
	the_setTimeout[cname] = "";
	
	var move_setTimeout = new Array(); //正在移动计时间对象
	move_setTimeout[cname] = "";
	
	var the_cname = new Array(); //类名
	the_cname[cname] = cname;
	
	var the_name = new Array(); //对象名
	the_name[cname] = cname+"_box";
	
	var the_location = new Array(); //对象放置容器
	the_location[cname] = location;
	
	var the_script = new Array(); //执行脚本
	the_script[cname] = script;
	
	var the_box_width = new Array(); //对象宽度
	the_box_width[cname] = box_width;
	
	var the_box_height = new Array(); //对象高度
	the_box_height[cname] = box_height;
	
	var the_stoptime = new Array(); //自动移动停止时间，0不自动
	the_stoptime[cname] = (stoptime==undefined) ? 0 : stoptime;
	
	var the_direction = new Array(); //移动方向，0左右，1上下
	the_direction[cname] = (direction==undefined) ? 0 : direction;
	
	//指定对象
	this.$ = function(id){
		return (typeof(id)=='object') ? id : document.getElementById(id);
	}
	
	//创建主容器
	this.$(the_location[cname]).innerHTML = "<div style=\"position:absolute;z-index:1;width:"+the_box_width[cname]+"px; height:"+the_box_height[cname]+"px; overflow:hidden;\"><div id=\""+the_name[cname]+"\" style=\"position:absolute;z-index:1; top:0px; left:0px;\"></div></div>"
	
	//添加图片（图片地址，标题，信息，链接地址，打开窗口，停止时间）
	this.add = function(img_url, img_title, img_info, img_link, img_link_target, stoptime){
		the_imgs[cname] ++;
		img_link_target = (img_link_target==undefined)?"_blank":img_link_target;
		the_imgstr[cname][the_imgs[cname]] = new Array(img_url, img_title, img_info, img_link, img_link_target, stoptime);
		//按方向设置位置
		if (the_direction[cname]==0){
			//横向
			var t = 0;
			var l = the_box_width[cname] * (the_imgs[cname] - 1);
		}else{
			//纵向
			var t = the_box_height[cname] * (the_imgs[cname] - 1);
			var l = 0;
		}
		var add_str = "";
		add_str += "<div id=\""+the_name[cname]+the_imgs[cname]+"\" style=\"position:absolute;z-index:1; top:"+t+"px; left:"+l+"px;\">";
		if (img_url.lastIndexOf(".swf")+4==img_url.length){
			
		}else{
			if (img_link!=undefined&&img_link!="#") add_str += "<a href=\""+img_link+"\" target=\""+img_link_target+"\">"
			add_str += "<img src=\""+img_url+"\" width=\""+the_box_width[cname]+"\" height=\""+the_box_height[cname]+"\" border=\"0\" title=\""+img_title+"\" />";
			if (img_link!=undefined&&img_link!="#") add_str += "</a>"
		}
		add_str += "</div>";
		
		this.$(the_name[cname]).innerHTML += add_str;
	}
	
	//开始移动
	this.to = function(v){
		clearTimeout(move_setTimeout[cname]);
		clearTimeout(the_setTimeout[cname]);
		if (v == "next"){
			the_img[cname] = (the_img[cname]==the_imgs[cname]) ? 1 : the_img[cname]+1;
			if (the_direction[cname]==0){
				//横向
				var t = 0;
				var l = 0 - the_box_width[cname] * (the_img[cname] - 1);
			}else{
				//纵向
				var t = 0 - the_box_height[cname] * (the_img[cname] - 1);
				var l = 0;
			}
		}
		else if (v == "previous"){
			the_img[cname] = (the_img[cname]==1) ? the_imgs[cname] : the_img[cname]-1;
			if (the_direction[cname]==0){
				//横向
				var t = 0;
				var l = 0 - the_box_width[cname] * (the_img[cname] - 1);
			}else{
				//纵向
				var t = 0 - the_box_height[cname] * (the_img[cname] - 1);
				var l = 0;
			}
		}
		else {
			v = (v == undefined) ? 1 : parseInt (v);
			the_img[cname] = v;
			if (the_direction[cname]==0){
				//横向
				var t = 0;
				var l = 0 - the_box_width[cname] * (v - 1);
			}else{
				//纵向
				var t = 0 - the_box_height[cname] * (v - 1);
				var l = 0;
			}
		}
		if (the_script[cname]!=undefined&&the_script[cname]!="") the_script[cname](the_img[cname], the_imgstr[cname][the_img[cname]]);
		this.moveto(t, l);
	}
	this.moveto = function(to_t, to_l){
		window.Obj = this;
		//当前所处位置
		var the_top = parseInt (this.$(the_name[cname]).style.top, 0);
		var the_left = parseInt (this.$(the_name[cname]).style.left, 0);
		
		if (to_t!=the_top || to_l!=the_left){
			if (to_t<the_top || to_l<the_left){
				yOffset = Math.floor((to_t - the_top) / 4);
				xOffset = Math.floor((to_l - the_left) / 4);
			}else{
				yOffset = Math.ceil((to_t - the_top) / 4);
				xOffset = Math.ceil((to_l - the_left) / 4);
			}
			this.$(the_name[cname]).style.top = parseInt (this.$(the_name[cname]).style.top, 0) + yOffset +"px";
			this.$(the_name[cname]).style.left = parseInt (this.$(the_name[cname]).style.left, 0) + xOffset +"px";
			move_setTimeout[cname] = setTimeout("Obj.moveto("+to_t+","+to_l+")",10);
		}else{
			//开始自动计时
			stoptime = (the_imgstr[cname][the_img[cname]][5]==undefined)?the_stoptime[cname]:the_imgstr[cname][the_img[cname]][5];
			if (stoptime != 0) the_setTimeout[cname] = setTimeout("Obj.to('next')",stoptime);
		}
	}
}
