var imgNames=new Array(18);
imgNames[0]="t1-1.jpg";
imgNames[1]="t1-2.jpg";
imgNames[2]="t2-1.jpg";
imgNames[3]="t2-2.jpg";
imgNames[4]="t2-3.jpg";
imgNames[5]="t3-1.jpg";
imgNames[6]="t3-2.jpg";
imgNames[7]="t3-3.jpg";
imgNames[8]="t3-4.jpg";
imgNames[9]="t3-5.jpg";
imgNames[10]="t3-6.jpg";
imgNames[11]="t3-7.jpg";
imgNames[12]="t4-1.jpg";
imgNames[13]="t5-1.jpg";
imgNames[14]="t5-2.jpg";
imgNames[15]="t5-3.jpg";
imgNames[16]="t6-1.jpg";
imgNames[17]="t7-1.jpg";
var imgLinks=new Array(18);
imgLinks[0]="1.php";
imgLinks[1]="1.php";
imgLinks[2]="2.php";
imgLinks[3]="2.php";
imgLinks[4]="2.php";
imgLinks[5]="3.php";
imgLinks[6]="3.php";
imgLinks[7]="3.php";
imgLinks[8]="3.php";
imgLinks[9]="3.php";
imgLinks[10]="3.php";
imgLinks[11]="3.php";
imgLinks[12]="4.php";
imgLinks[13]="5.php";
imgLinks[14]="5.php";
imgLinks[15]="5.php";
imgLinks[16]="6.php";
imgLinks[17]="7.php";var images=new Array();
var views=new Array();
var queue=new Array();

function swimg(imgSrc)
{
  document.getElementById("big").src=imgSrc;
}

function isUndefined(v) {
    var undef;
    return v===undef;
}

var loadtimeout;
var errid;

function start(id, num){
	var box=document.getElementById(id);
	box.innerHTML="<div style='color:white; font-family:sans-serif; width:105px; margin:auto auto;'>Loading...<div style='width:105px; height:10px; border:1px solid white; text-align:left;'><div id='rotate_progress_slider' style='background-color:white; height:10px; width:1px;'>&nbsp;</div></div></div>"
	var bar=document.getElementById('rotate_progress_slider')
	var perstep=90/imgNames.length
	var current=0
	
	loadfn=function(){
		clearTimeout(loadtimeout)
		loadtimeout=setTimeout("loaderror()", 15000)
		current=current+perstep
		bar.style.width=current+"px"
		if (current>88){
			clearTimeout(loadtimeout);
			start2(box, num);
		}
	}
	errid=id;
	loadtimeout=setTimeout("loaderror()", 15000)
	for (var i=0; i<imgNames.length; i++){
		images[i]=new Image()
		images[i].onload=loadfn;
		images[i].src=imgNames[i]
		images[i].link=imgLinks[i]
		images[i].num=i
		queue[i]=i	
	}

}

function loaderror(){
	var box=document.getElementById(errid);
	box.innerHTML="<div style='color:white; font-family:sans-serif; width:190px; margin:auto auto;'><b>An Error has occurred!</b><br/>Please click the <em>Refresh</em> button in your browser to try again.</div></div></div>"
}

function start2(box, num){
	box.innerHTML='';
	for (var i=0; i<num; i++){
		link=document.createElement('a')
		link.setAttribute('href', '#')
		img=document.createElement('img')
		img.setAttribute('width', 200)
		img.setAttribute('height', 200)
		link.appendChild(img)
		box.appendChild(link)
		views[i]=link;
	}
	for (var i=0; i<num; i++){
		rotate(i)
	}
	setInterval("rotate(-1)", 2000)
	
}

function rotate(n){
	if (n==-1) var view=views[get_random(views.length)]
	else var view=views[n]
	if (!isUndefined(view.num)) queue.push(view.num)
	var newimgnum=queue.shift()
	var newimg=images[newimgnum]
	
	view.num=newimgnum;
	view.setAttribute('href', newimg.link)
	view.childNodes[0].src=newimg.src;
}

function get_random(n)
{
    var ranNum= Math.floor(Math.random()*n);
    return ranNum;
}


