// JavaScript Document
document.onselectstart = function(){return false;};
O    = new Array();
box  = 0;
img  = 0;
txt  = 0;
W    = 0;
H    = 0;
nI   = 0;
sel  = 0;
si   = 0;
ZOOM = 0;
rImg = 0;
//////////////////
speed = 0.06; // animation speed
delay = 1; // 1 = no delay
//////////////////

function dText(){
	txt.style.textAlign =  (sel<nI/2)?"left":"right";
	txt.innerHTML = O[sel].tx;
}
//n 	数组下标
//s 	图片数量*100
//x 	x+=s
//tx 	image alt
//ti 	image title
function CObj(n, s, x, tx){
	this.n    = n;
	this.dim  = s;
	this.tx   = tx;
	this.is   = img[n];
	this.vz   = 0;
	this.sx   = 0;
	this.x0   = x;
	this.x1   = 0;
	this.zo   = 0;
	//鼠标滑过
	this.over = function() {
		with(this){
			//数组下标 不等于
			if(n!=sel){
				//
				O[sel].dim = 100;
				O[n].dim = ZOOM * 100;
				sel = n;
				var l = 0;
				for(k=0; k<nI; k++){
					O[k].x0 = l;
					l += O[k].dim;
				}
				txt.innerHTML = "";
				//setTimeout("dText()", 32);
				dText();
			}
		}
	}
	
	//动画
	this.anim = function () {
		with(this){
			//0.06*(0+(0-0)*1)=0
			vz  = speed*(vz+(x1-sx)*delay);
			//0-0=0
			x1 -= vz;
			//n==0=0:上一个元素x0+dim
			//0
			sx  = (n==0)?0:O[n-1].x0+O[n-1].dim;
			//zo-(zo-dim)*0.6
			zo -= (zo-dim)*speed;
			//(0*0)+6*(下一个元素下标)
			l   = (x1*si)+6*(n+1);
			//zo*si
			w   = zo*si;
			
			is.style.left   = Math.round(l)+'px';
			is.style.top    = Math.round((H-w*rImg)*.5)+'px';
			is.style.width  = Math.round(w)+'px';
			is.style.height = Math.round(w*rImg)+'px';
			if(sel == n){
				if(sel<nI*.5) {
					txt.style.left = Math.round(l+w+6)+'px';
				} else {
					txt.style.left = Math.round(l-(nx*.25)-6)+'px';
				}
				txt.style.top = Math.round(-(w*rImg)*.25)+'px';
			}
		}
	}
}

function run(){
	for(j in O)O[j].anim();
	setTimeout("run()", 20);
}

function doResize(){
	txt.style.width = Math.round(nx*.25)+'px';
	txt.style.fontSize = (nx/70)+'px';
	with(box.style){
		width  = Math.round(W)+'px';
		height = Math.round(H)+'px';
		left   = Math.round(nx/2-W/2)+'px';
		top    = Math.round(ny/2-H/2)+'px';
	}
	with(lleft.style){
		left   = Math.round((nx/2-W/2)/2-32.5)+'px';
		top    = Math.round(ny/2-32.5)+'px';
		visibility = "visible";
	}
	with(rright.style){
		left   = Math.round((W+(nx-W)*0.75-32.5))+'px';
		top    = Math.round(ny/2-32.5)+'px';
		visibility = "visible";
	}
	
	if(paged!=null){
		with(paged.style){
			left   = Math.round(nx*0.7)+'px';
			top    = Math.round(ny)+'px';
			width  = Math.round(nx*0.3)+'px';
			visibility = "visible";
		}
	}
}

function resize(){
	//screen宽度偏移量
	nx = scr.offsetWidth;
	//screen高度偏移量
	ny = scr.offsetHeight;
	//宽度*0.9
	W  =  nx*0.85;
	//(W-（（图片数量+1）*6）)/（（图片数量*100）+（（图片数量-1）*100））
	//1254/1100=1.14
	if(nI<6)
		si = (W-((nI+1)*6))/((nI*100)+((nI-1)*100)+(6-nI)*100);
	else
		si = (W-((nI+1)*6))/((nI*100)+((nI-1)*100));
	//100*1.14*0.4+14
	H  = (100*si*rImg)+14;
	doResize();
}
onresize = resize;

onload = function(){
	scr = document.getElementById("screen");
	box = document.getElementById("box");
	txt = document.getElementById("txt");
	img = box.getElementsByTagName("img");
	lleft = document.getElementById("left1");
	rright = document.getElementById("right1");
	link = box.getElementsByTagName("a");
	paged = document.getElementById("pagediv");
	
	//图片数量
	nI  = img.length;
	//图片数量
	ZOOM = nI;
	//图片的高宽比
	rImg = img[0].height/img[0].width;
	resize();
	
	if(maxL>6){
		lleft.onmouseover = function(){bool=true;left_moving();};
		lleft.onmouseout = function(){stop_moving();};
		rright.onmouseover = function(){bool=true;right_moving();};
		rright.onmouseout = function(){stop_moving();};
	}
	
	s = ZOOM * 100;
	x = 0;
	txt.innerHTML = img[0].alt;
	for(i=0; i<nI; i++) {
		O[i] = new CObj(i, s, x, img[i].alt);
		img[i].alt = "";
		img[i].onmousedown = function(){return false;};		
		img[i].onmouseover = new Function('O['+i+'].over();');
		x += s;
		s = 100;
	}
	box.style.visibility = "visible";
	run();
}

var bool=true;
var numberL=-1;
var numberR=6;
var minL=0;
function left_moving(){
	if(numberL>=minL){
		var temp1;
		var temp2;
		var temp3;
		var temp4;
		var temp7;
		var temp8;
		temp1=img[0].src;
		temp3=O[0].tx;
		temp7=link[0].href;
		for(var i=1;i<img.length;i++){
			temp2=img[i].src;
			temp4=O[i].tx;
			temp8=link[i].href;
			img[i].src=temp1;
			O[i].tx=temp3;
			link[i].href=temp7;
			temp1=temp2;
			temp3=temp4;
			temp7=temp8;
		}
	
		img[0].src=jdata[numberL][2];
		O[0].tx=jdata[numberL][1];
		if(jdata[numberL][0]=='')
			link[0].href='javascript:building();';
		else if(linkstr)
			link[0].href=linkstr+jdata[numberL][0];
		else
			link[0].href='javascript:onsub('+jdata[numberL][0]+');';
		numberR--;
		numberL--;
		dText();
		if(bool){
			setTimeout("left_moving()", 150);
		}
	}
}

function right_moving(){
	if(numberR<maxL){
		var temp1;
		var temp2;
		var temp3;
		var temp4;
		var temp7;
		var temp8;
		temp1=img[img.length-1].src;
		temp3=O[img.length-1].tx;
		temp7=link[link.length-1].href;
		for(var i=img.length-2;i>=0;i--){
			temp2=img[i].src;
			temp4=O[i].tx;
			temp8=link[i].href;
			img[i].src=temp1;
			O[i].tx=temp3;
			link[i].href=temp7;
			temp1=temp2;
			temp3=temp4;
			temp7=temp8;
		}
		img[img.length-1].src=jdata[numberR][2];
		O[img.length-1].tx=jdata[numberR][1];
		if(jdata[numberR][0]=='')
			link[link.length-1].href='javascript:building();';
		else if(linkstr)
			link[link.length-1].href=linkstr+jdata[numberR][0];
		else
			link[link.length-1].href='javascript:onsub('+jdata[numberR][0]+');';
		numberR++;
		numberL++;
		dText();
		if(bool){
			setTimeout("right_moving()", 150);
		}
	}
}

function stop_moving(){
	bool=false;
}