﻿var move_to="left"; //移动方向
var move_to_old=move_to; //原始移动方向
var Move_Layer_left=0; //移动层坐标
var move_start=0; //移动单位临时指针
var move_time=0; //移动时间指针
var Move_Layer_width=0; //内容区总长

//生成移动内容
function move_load(div_obj,content_width,content_quantity){
	//主体DIV，单个内容宽，内容数量
	var move_content=div_obj.innerHTML;
	Move_Layer_width=content_width*content_quantity;
	//移动内容编排
	var move_new_content="";
	move_new_content+="<div id=\"Move_body\" style=\"position:absolute; z-index:1\">";
	move_new_content+="<div id=\"Move_body\" style=\"position:absolute; width:"+div_obj.style.width+"; height:"+div_obj.style.height+"; overflow:hidden; z-index:2\">";
	
	move_new_content+="<div id=\"Move_Layer\" style=\"position:absolute; left:"+Move_Layer_left+"px; top:0px; z-index:3\">";
	move_new_content+="<div id=\"Move_Content1\" style=\"position:absolute; left:0px; top:0px; width:"+Move_Layer_width+"px; z-index:4\">";
	move_new_content+=move_content;
	move_new_content+="</div>";
	move_new_content+="<div id=\"Move_Content2\" style=\"position:absolute; left:"+Move_Layer_width+"px; top:0px; width:"+Move_Layer_width+"px; z-index:4\">";
	move_new_content+=move_content;
	move_new_content+="</div>";
	move_new_content+="</div>";
	
	move_new_content+="</div>";
	move_new_content+="<div id=\"Move_body_left\" style=\"position:absolute; left:-10px; top:0px; width:10px; height:"+div_obj.style.height+"; z-index:2; cursor:hand;\" onMouseOver=\"this.style.background='#F9F9F9';\" onMouseOut=\"this.style.background='';\" onClick=\"if (move_to_old!='left') {move_to='left';} else {if (move_time>="+content_width+") move_time=0;}\"><table width=\"100%\" height=\"100%\"  border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr><td align=\"center\">&lt;</td></tr></table></div>";
	move_new_content+="<div id=\"Move_body_left\" style=\"position:absolute; left:"+div_obj.style.width+"; top:0px; width:10px; height:"+div_obj.style.height+"; z-index:2; cursor:hand;\" onMouseOver=\"this.style.background='#F9F9F9';\" onMouseOut=\"this.style.background='';\" onClick=\"if (move_to_old!='right') {move_to='right';} else {if (move_time>="+content_width+") move_time=0;}\"><table width=\"100%\" height=\"100%\"  border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr><td align=\"center\">&gt;</td></tr></table></div>";
	move_new_content+="</div>";	
	
	div_obj.innerHTML=move_new_content;
	setTimeout("move_action("+content_width+")",3000);
}

//控制移动
function move_action(content_width){
	if (move_to_old!=move_to) { //正在移动变换方向运算
		if (move_time<=content_width) {
			move_time=content_width-move_time;
		}else{
			move_time=0;
		}
		move_to_old=move_to;
	}
	move_time+=2;
	if (move_time<=content_width) {
		if (move_to_old=="left") { //向左
			Move_Layer_left-=2; //全局移动层坐标
			if (Move_Layer_width+Move_Layer_left==0) { //复原全局移动层坐标
				Move_Layer_left=0;
			}
			Move_Layer.style.left=Move_Layer_left+"px";
		}else{ //向右
			Move_Layer_left+=2; //全局移动层坐标
			if (Move_Layer_left>0) { //复原全局移动层坐标
				Move_Layer_left=Move_Layer_left-Move_Layer_width;
			}
			Move_Layer.style.left=Move_Layer_left+"px";
		}
	}
	if (move_time>=600) {
		move_time=0;
	}
	setTimeout("move_action("+content_width+")",10);
}
