var current = 1;
var last = 14;
var timerID;
var cycles = 0;
var prevThumb = last;
var slideObject;
var frontPagePic = new Array(1,2,3,4,5,6,7);
var myPops = new Array("lg1.jpg","lg2.jpg","lg3.jpg","lg4.jpg","lg5.jpg","lg6.jpg","lg7.jpg","lg8.jpg","lg9.jpg","lg10.jpg","lg11.jpg","lg12.jpg","lg13.jpg","lg14.jpg");
var myTbs = new Array("tb1.jpg","tb2.jpg","tb3.jpg","tb4.jpg","tb5.jpg","tb6.jpg","tb7.jpg","tb8.jpg","tb9.jpg","tb10.jpg","tb11.jpg","tb12.jpg","tb13.jpg","tb14.jpg");
var loadPops = new Array;
var loadTbs = new Array;


function pickImg()
{
	var dateObj = new Date ();
	var today = dateObj.getDay();	
	document.imgFront.src='images/real-estate-photo/int' + frontPagePic[today] + '.jpg';
}

function PopsLoader()
{
	var i = 0;
	for (i = 0; i < myPops.length; i++)
	{
		loadPops[i] = new Image(700,469);
		loadPops[i].src = "images/real-estate-photo/" + myPops[i];
	}
}

function TbsLoader()
{
	var i = 0;
	for (i = 0; i < myTbs.length; i++)
	{
		loadTbs[i] = new Image(60,40);
		loadTbs[i].src = "images/real-estate-photo/" + myTbs[i];
	}
}

function loader()
{
	PopsLoader();
	TbsLoader();
}


function startSlideshow()
{
	slideObject = document.getElementById('frontSlide');
	slideObject.style.backgroundImage = 'url(images/real-estate-photo/lg' + current + '.jpg)';
	imgCounter();
	timerID = setTimeout('playSlideshow()',3000);
}

function playSlideshow()
{
	current++;
	if (current > last)
	{
		current = 1;
		cycles++;
	}
	slideObject.style.backgroundImage = 'url(images/real-estate-photo/lg' + current + '.jpg)';
	imgCounter();
	if (cycles < 3)
	{
		timerID = setTimeout('playSlideshow()',3000);
	}
}

function imgCounter()
{
	if (document.getElementById)
	{
		document.getElementById('img-counter').innerHTML = current;
	}
	document.images["tb" + prevThumb].style.borderColor = "#424242";
	document.images["tb" + current].style.borderColor = "#09F";
	prevThumb = current;
}

function play_onclick()
{
	clearTimeout(timerID);
	cycles = 0;
	playSlideshow();
}
	

function stopSlideshow()
{
	clearTimeout(timerID);
	cycles = 0;
}

function nextPicture()
{
	clearTimeout(timerID);
	cycles = 0;
	current++;
	if (current > last)
	{
		current = 1;
	}
	slideObject.style.backgroundImage = 'url(images/real-estate-photo/lg' + current + '.jpg)';
	imgCounter();
}


function previousPicture()
{
	clearTimeout(timerID);
	cycles = 0;
	current--;
	if (current < 1)
	{
		current = last;
	}
	slideObject.style.backgroundImage = 'url(images/real-estate-photo/lg' + current + '.jpg)';
	imgCounter();
}

function selThumb_onclick(thumbNumb)
{
	clearTimeout(timerID);
	cycles = 0;
	current = thumbNumb;
	slideObject.style.backgroundImage = 'url(images/real-estate-photo/lg' + current + '.jpg)';
	imgCounter();
}


function kbd_nav(e)
{
	var code;
	if (!e)
	{
		e = window.event;
	}
	if (e.keyCode)
	{
		code = e.keyCode;
	}
	else if (e.which)
	{
		code = e.which;
	}
	switch (code)
	{
		case 37:
			previousPicture();
			break;
		case 39:
			nextPicture();
			break;
	}
}
	
	
document.onkeydown = kbd_nav;




	
	

