var photos = new Array;
var urls = new Array;


// SLIDE SHOW CONFIG //
/* 
To add or remove photos, simply follow the pattern below - each set should be the next number up eg:
photos[0] = new Image();
photos[0].src = 'YOUR IMAGE HERE';
urls[0] = 'YOUR URL HERE';

photos[1] = new Image();
photos[1].src = 'YOUR IMAGE HERE';
urls[1] = 'YOUR URL HERE';

then 2, then 3 etc
*/

photos[0] = new Image();
photos[0].src = 'images/img1.jpg';
urls[0] = 'http://www.ltdonlinestores.com/asian-furniture/';

photos[1] = new Image();
photos[1].src = 'images/img.jpg';
urls[1] = 'http://www.ltdonlinestores.com/outdoor-furniture/';

photos[2] = new Image();
photos[2].src = 'images/img2.jpg';
urls[2] = 'http://www.ltdonlinestores.com/bathroom-vanities/';

photos[3] = new Image();
photos[3].src = 'images/img3.jpg';
urls[3] = 'http://www.ltdonlinestores.com/electric-fireplace/electric-fireplaces/';


maxwidth = 678 ; //Maximum image width 678
maxheight = 250 ; //Maxiumum image height 250

rotatetime = 3 ; //Time between rotations in seconds

fillerlink = 'javascript:;'; //The Link for the Space filler image
fillerimg = 'images/spacefiller.jpg'; //The Image for the space filler

///// END CONFIG - DO NOT EDIT BELOW THIS LINE!! /////

playbutton = new Image();
playbutton.src = 'images/play.png';

var x = 0;
var num = photos.length;
var y = num - 1;
var pause = 0;

function slideshowInit(){
buttonsize = (num * 43) + 43;
left = (maxwidth - buttonsize);
document.write("<div id='showcontainer' style='width:"+maxwidth+"px;height:"+(maxheight+30)+";'><div id='slideshow' style='width:"+maxwidth+"px;height:"+maxheight+";text-align:center;'>Loading Images...");
document.write("</div>");
document.write("<div id='playpause' style='float:right;width:43px;height:33px;text-align:center;cursor:pointer' onclick='stopstart()'><img src='images/pause.png' /></div>");
while (y >= 0){
document.write ("<div id='button"+y+"' style='float:right;font-weight:bold;width:43px;height:33px;text-align:center;cursor:pointer;background:url(images/background.png);' onclick='showimage("+y+")'><div style='margin-top:7px;font-size:13px;font-weight:bold;font-family:verdana'><b>"+(y+1)+"</b></div></div>");
y = y-1;
}
document.write ("<div style='float:left;width:"+left+"px;height:33px;overflow:hidden;text-align:left;'><a href='"+fillerlink+"'><img src='"+fillerimg+"' style='border:0px'/></a></div>");
document.write ("<div style='clear:all'></div>");

setTimeout("checkload()","1000");
}

function checkload(){
if (photos[0].width != 0){
shownext()
}else{
setTimeout("checkload()","1000");
}
}


function shownext(){
if (pause == 1){
return;
}
if (x >= num){
x = 0;

thiswidth = photos[x].width;
thisheight = photos[x].height;

if (thiswidth > maxwidth){
	ratio = maxwidth / thiswidth;
	thiswidth = Math.floor(thiswidth * ratio);
	thisheight = Math.floor(thisheight * ratio);
}

if (thisheight > maxheight){
	ratio = maxheight / thisheight;
	thiswidth = Math.floor(thiswidth * ratio);
	thisheight = Math.floor(thisheight * ratio);
}

document.getElementById('slideshow').innerHTML = "<a href='"+urls[x]+"'><img src='"+photos[x].src+"' style='border:0px;width:"+thiswidth+";height:"+thisheight+";margin-left:auto;margin-right:auto;' /></a>";

clearhighlight();
document.getElementById("button"+x).style.background = 'url(images/backgroundselected.png)';
stopstart();
return;
}

thiswidth = photos[x].width;
thisheight = photos[x].height;

if (thiswidth > maxwidth){
	ratio = maxwidth / thiswidth;
	thiswidth = Math.floor(thiswidth * ratio);
	thisheight = Math.floor(thisheight * ratio);
}

if (thisheight > maxheight){
	ratio = maxheight / thisheight;
	thiswidth = Math.floor(thiswidth * ratio);
	thisheight = Math.floor(thisheight * ratio);
}


document.getElementById('slideshow').innerHTML = "<a href='"+urls[x]+"'><img src='"+photos[x].src+"' style='border:0px;width:"+thiswidth+";height:"+thisheight+";margin-left:auto;margin-right:auto;' /></a>";

clearhighlight();
document.getElementById("button"+x).style.background = 'url(images/backgroundselected.png)';


x = x + 1;
setTimeout("shownext()",rotatetime * 1000);
}

function clearhighlight(){
y = 0;
while (y < num){
document.getElementById("button"+y).style.background = 'url(images/background.png)';
y = y+1;
}
}

function showimage(img){
if (pause != 1){
stopstart();
}
clearhighlight();
document.getElementById("button"+img).style.background = 'url(images/backgroundselected.png)';
thiswidth = photos[img].width;
thisheight = photos[img].height;

if (thiswidth > maxwidth){
	ratio = maxwidth / thiswidth;
	thiswidth = Math.floor(thiswidth * ratio);
	thisheight = Math.floor(thisheight * ratio);
}

if (thisheight > maxheight){
	ratio = maxheight / thisheight;
	thiswidth = Math.floor(thiswidth * ratio);
	thisheight = Math.floor(thisheight * ratio);
}

document.getElementById('slideshow').innerHTML = "<a href='"+urls[img]+"'><img src='"+photos[img].src+"' style='border:0px;width:"+thiswidth+";height:"+thisheight+";margin-left:auto;margin-right:auto;' /></a>";

}

function stopstart(){
if (pause == 1){
pause = 0;
document.getElementById("playpause").innerHTML = "<img src='images/pause.png' />";
shownext();
}else{
pause = 1;
document.getElementById("playpause").innerHTML = "<img src='images/play.png' />";
}

}