// JavaScript Document

var rotate_delay = 10000; // delay in milliseconds (5000 = 5 secs)
current = 0;
var pdtids;
var links;

function next() 
{
	if (number_loaded < total_imgs) 
	{
		alert(number_loaded + " of " +total_imgs+ " images Loaded");
	}
	else
	{
		if (document.slideform.slide[current+1]) 
		{
		document.images.show.src = document.slideform.slide[current+1].value;	
		document.slideform.slide.selectedIndex = ++current;
		
		document.slideform.slide_product_links.selectedIndex = current;
		pdtids = document.slideform.slide_product_links[current].value ;
		links = 'http://www.norkalighting.com.au/gallery_products.php?pdtids=' + pdtids;
		document.getElementById('gallery_products').src = links;
//		document.gallery_products.location.href = links;
		//alert(links);
		
		//alert(document.slideform.slide.selectedIndex);
		//document.forms[1].loadUpdate.value = "Viewing " + (document.slideform.slide.selectedIndex+1) + " of " +total_imgs+ " images";
		document.getElementById("counter").childNodes[0].nodeValue = "Viewing " + (document.slideform.slide.selectedIndex+1) + " of " +total_imgs+ " images";
		}
		else first();
	}
}

function previous() 
{
	if (number_loaded < total_imgs) 
	{
		alert(number_loaded + " of " +total_imgs+ " images Loaded");
	}
	else
	{
		if (current-1 >= 0) 
		{
			document.images.show.src = document.slideform.slide[current-1].value;
			document.slideform.slide.selectedIndex = --current;
		
			document.slideform.slide_product_links.selectedIndex = current;
			pdtids = document.slideform.slide_product_links[current].value ;
			links = 'http://www.norkalighting.com.au/gallery_products.php?pdtids=' + pdtids;
			document.gallery_products.location = links;
			//alert(links);
			
			//alert(document.slideform.slide.selectedIndex);
			//document.forms[1].loadUpdate.value = "Viewing " + (document.slideform.slide.selectedIndex+1) + " of " +total_imgs+ " images";
			document.getElementById("counter").childNodes[0].nodeValue = "Viewing " + (document.slideform.slide.selectedIndex+1) + " of " +total_imgs+ " images";
		}
		else last();
	}
}

function first() 
{
	if (number_loaded < total_imgs) 
	{
		alert(number_loaded + " of " +total_imgs+ " images Loaded");
	}
	else
	{
		current = 0;
		document.images.show.src = document.slideform.slide[0].value;
		document.slideform.slide.selectedIndex = 0;
		
		document.slideform.slide_product_links.selectedIndex = 0;
		pdtids = document.slideform.slide_product_links[0].value ;
		links = 'http://www.norkalighting.com.au/gallery_products.php?pdtids=' + pdtids;
		document.gallery_products.location = links;
		//alert(links);
		
		//alert(document.slideform.slide.selectedIndex);
		//document.forms[1].loadUpdate.value = "Viewing " + (document.slideform.slide.selectedIndex+1) + " of " +total_imgs+ " images";
		document.getElementById("counter").childNodes[0].nodeValue = "Viewing " + (document.slideform.slide.selectedIndex+1) + " of " +total_imgs+ " images";
		
	}
}

function last() 
{
	if (number_loaded < total_imgs) 
	{
		alert(number_loaded + " of " +total_imgs+ " images Loaded");
	}
	else
	{
		current = document.slideform.slide.length-1;
		document.images.show.src = document.slideform.slide[current].value;
		document.slideform.slide.selectedIndex = current;
		
		document.slideform.slide_product_links.selectedIndex = current;
		pdtids = document.slideform.slide_product_links[current].value ;
		links = 'http://www.norkalighting.com.au/gallery_products.php?pdtids=' + pdtids;
		document.gallery_products.location = links;
		//alert(links);
		
		//alert(document.slideform.slide.selectedIndex);
		//document.forms[1].loadUpdate.value = "Viewing " + (document.slideform.slide.selectedIndex+1) + " of " +total_imgs+ " images";
		document.getElementById("counter").childNodes[0].nodeValue = "Viewing " + (document.slideform.slide.selectedIndex+1) + " of " +total_imgs+ " images";
		
	}
}

function ap(text) 
{
	if (number_loaded < total_imgs) 
	{
		alert(number_loaded + " of " +total_imgs+ " images Loaded");
	}
	else
	{
		document.slideform.slidebutton.value = (text == "Stop") ? "Start" : "Stop";
		rotate();
	}
}

function change() 
{
	if (number_loaded < total_imgs) 
	{
		alert(number_loaded + " of " +total_imgs+ " images Loaded");
	}
	else
	{
		current = document.slideform.slide.selectedIndex;
		document.images.show.src = document.slideform.slide[current].value;
	}
}

function rotate() 
{
	if (number_loaded < total_imgs) 
	{
		alert(number_loaded + " of " +total_imgs+ " images Loaded");
	}
	else
	{
		if (document.slideform.slidebutton.value == "Stop") 
		{
			current = (current == document.slideform.slide.length-1) ? 0 : current+1;
			document.images.show.src = document.slideform.slide[current].value;
			document.slideform.slide.selectedIndex = current;
			window.setTimeout("rotate()", rotate_delay);
			
			document.slideform.slide_product_links.selectedIndex = current;
			pdtids = document.slideform.slide_product_links[current].value ;
			links = 'http://www.norkalighting.com.au/gallery_products.php?pdtids=' + pdtids;
			document.gallery_products.location = links;
			//alert(links);
			
			//alert(document.slideform.slide.selectedIndex);
			//document.forms[1].loadUpdate.value = "Viewing " + (document.slideform.slide.selectedIndex+1) + " of " +total_imgs+ " images";
			document.getElementById("counter").childNodes[0].nodeValue = "Viewing " + (document.slideform.slide.selectedIndex+1) + " of " +total_imgs+ " images";
		}
	}
}



var number_loaded = 0;
function MM_preloadImagesT() 
{ //v3.0
	var d=document; 
	if(d.images)
	{ 
		if(!d.MM_p) 
			d.MM_p=new Array();
    	var i,j=d.MM_p.length,a=MM_preloadImagesT.arguments; 
		total_imgs =a.length; 
		for(i=0; i<a.length; i++)
    		if (a[i].indexOf("#")!=0)
			{ 
				d.MM_p[j]=new Image; 
				d.MM_p[j].onload = onload_image;
				d.MM_p[j++].src=a[i];
			}
	}
}

function onload_image() {
	number_loaded++;
		//document.forms[1].loadUpdate.value = "Loaded " + number_loaded + " of " +total_imgs+ " images";
		document.getElementById("counter").childNodes[0].nodeValue = "Loaded " + number_loaded + " of " +total_imgs+ " images";

	if(total_imgs == number_loaded)
		//document.forms[1].loadUpdate.value = 	"Viewing 1 of " +total_imgs+ " images";
		document.getElementById("counter").childNodes[0].nodeValue = "Viewing 1 of " +total_imgs+ " images";
};

function checkLoaded() {
 	if (number_loaded < total_imgs) {
    		alert(number_loaded + " of " +total_imgs+ " images Loaded");
	}
    else {
		alert(number_loaded + " images Loaded !");
	}
};