var currentImgNum=0;
var preloader=new Array();
function preloadListingImages()
{
	if (photoArray.length>1)
    {
        for (var i=0;i<photoArray.length;i++)
        {
            preloader[i]=new Image();
            preloader[i].src=photoArray[i];
        }
    }
}
function addAnEvent(el, evname, func)
{
	if (el.attachEvent)
    { // IE
		el.attachEvent("on" + evname, func);
	} 
	else if (el.addEventListener) 
    { // Gecko / W3C
		el.addEventListener(evname, func, true);
	} 
	else
    {
		el["on" + evname] = func;
	}
}
//depends on addAnEvent function from main.js
addAnEvent(window,'load',preloadListingImages);

function swapNext()
{
	if (photoArray.length > 1) swapListingImage(1);
}
function swapPrev()
{
	if(photoArray.length>1) swapListingImage(-1);
}
function swapListingImage(dir)
{
	currentImgNum+= dir;
	currentImgNum %= numPhotos;
	if(currentImgNum < 0)
	{
		currentImgNum= numPhotos - 1;
	}
	else if (currentImgNum == numPhotos)
	{
		currentImgNum = 0;
	}
	//alert(photoArray[currentImgNum]);
	if(document.getElementById)
	{
		document.getElementById('homeImg').src = photoArray[currentImgNum];
		//document.getElementById('photonum').innerHTML=currentImgNum+1;
	}
	else
	{
		document.layers['homeImg'].src = photoArray[currentImgNum];
		//document.layers['photonum'].innerHTML=currentImgNum+1;
	}
}

function swapListingImageIndex(index)
{
	if (index<1) 
    {
		index = 1;
	} 
    else if (index > numPhotos) 
    {
		index = numPhotos;
	}
	if(document.getElementById)
    {
		document.getElementById('homeImg').src=photoArray[index];
	}
    else
    {
		document.layers['homeImg'].src=photoArray[index];
	}
}

function loadVideo(video_disp)
{
	//var video_str = "<object width=\"360\" height=\"265\"><param name=\"movie\" value=\"http://www.youtube.com/v/" + video_disp + "&rel=1\"></param><param name=\"wmode\" value=\"transparent\"></param><embed src=\"http://www.youtube.com/v/" + video_disp + "&rel=1\" type=\"application/x-shockwave-flash\" wmode=\"transparent\" width=\"360\" height=\"265\"></embed></object>";
	
	var video_str = "<object type=\"application/x-shockwave-flash\" width=\"360\" height=\"265\" data=\"http://www.youtube.com/v/" + video_disp + "&rel=0\"><param name=\"movie\" value=\"http://www.youtube.com/v/" + video_disp + "&rel=0\" /></object>";
	
	document.getElementById('image_html').innerHTML = video_str;
	if(photoArray.length > 1)
	{	
		document.getElementById('prev_src').removeAttribute("href");
		document.getElementById('next_src').removeAttribute("href");
		document.getElementById('prev_img').src = siteImageFolder + "/btn_previous_02.gif";
		document.getElementById('next_img').src = siteImageFolder + "/btn_next_02.gif";		
	}
}

function loadImage(image_disp)
{
	var image_str = "<img id=\"homeImg\" name=\"homeImg\" src=\"" + image_disp + "/no_image.jpg\" border=\"0\" vspace=\"3\" width=\"360\" height=\"265\" />";
	document.getElementById('image_html').innerHTML = image_str;
	if(photoArray.length > 1)
	{	
		previous_btn_img = "btn_previous_01.gif";
		next_btn_img = "btn_next_01.gif";			
		document.getElementById('prev_src').setAttribute('href', 'javascript:swapPrev()');
		document.getElementById('next_src').setAttribute('href', 'javascript:swapNext()');		
		document.getElementById('prev_img').src = siteImageFolder + "/" + previous_btn_img;
		document.getElementById('next_img').src = siteImageFolder + "/" + next_btn_img;
	}
}
