// JavaScript Document

//--Code for rolling of products to left or right on button click --//
//Specify the slider's height(This is set at thwe height of the image)
var sliderheight="161px";
//Specify the slider's slide speed (This is set at the width of the image)
var slidespeed=60;


var copyspeed=slidespeed;
//leftrightslide is the array of images rendered by the code behind.
leftrightslide='<nobr>'+leftrightslide.join("")+'</nobr>';
var iedom=document.all||document.getElementById;

if (iedom)
document.write('<span id="temp" style="visibility:hidden;position:absolute;top:-100px;left:-9000px">'+leftrightslide+'</span>')

var actualwidth='';
var cross_slide, ns_slide;

function init() 
{

	if (iedom||document.layers)
	{
		with (document)
		{			
			write('<table border="0" cellspacing="0" cellpadding="0"><tr><td>')
			if (iedom)
			{
				write('<div style="position:relative;width:'+sliderwidth+';height:'+sliderheight+';overflow:hidden;">')
				write('<div id="test2" align="right" style="position:relative;left:0px;top:0px;"></div>')
				write('</div>')
			}
			else if (document.layers)
			{
				write('<ilayer width='+sliderwidth+' height='+sliderheight+' name="ns_slidemenu" bgColor='+slidebgcolor+'>')
				write('<layer name="ns_slidemenu2" left=0 top=0></layer>')//onMouseover="copyspeed=0" onMouseout="copyspeed=slidespeed"
				write('</ilayer>')
			}
				write('</td></tr></table>')
		}
	}
}

function fillup(){
	if (iedom){
		var al = document.getElementById("ArrowLeft");
		var ar = document.getElementById("ArrowRight");
		var mt = document.getElementById("MoreText");	

		cross_slide=document.getElementById? document.getElementById("test2") : document.all.test2;
		cross_slide.innerHTML=leftrightslide;
		actualwidth=document.getElementById("temp").offsetWidth;
		
		var lowwidth = nlow*slidespeed;
		
		cross_slide.style.left = csleft == null || csleft == "" ? 0 : parseInt(csleft);
		
		if (pcount <= 7) {
			al.style.visibility = "hidden";
			ar.style.visibility = "hidden";
			mt.style.visibility = "hidden";
		} else {
			setMoreArrows();
		}
	
	}
	else if (document.layers){
		ns_slide=document.ns_slidemenu.document.ns_slidemenu2
		ns_slide.document.write(leftrightslide)
		ns_slide.document.close()
		actualwidth=ns_slide.document.width
	}
}
window.onload=fillup
document.hide

function slideleft()
{
	newwidth=(actualwidth - parseInt(sliderwidth))
	
	var low
	if (iedom)
	{
		if (parseInt(cross_slide.style.left)>(newwidth*(-1)+8)) 
			cross_slide.style.left=parseInt(cross_slide.style.left)-copyspeed+"px";
		
		low = (parseInt(cross_slide.style.left))*(-1)/slidespeed;
		var high = low +4;
		setlow(low);	
		setMoreArrows();
	} 
	else if (document.layers) 
	{
		if (ns_slide.left>(newwidth*(-1)+8))
			ns_slide.left-=copyspeed;
	}	
}


function slideright()
{
	if (iedom)
	{		
		if (parseInt(cross_slide.style.left)<0) 
		{
			//alert(parseInt(cross_slide.style.left))			
			cross_slide.style.left=parseInt(cross_slide.style.left)+copyspeed+"px";
			//al.style.visibility = "visible";			
		}		
		setMoreArrows();
	}
}

/* Only call if HTML DOM compliant */
function setMoreArrows() 
{
	var al = document.getElementById("ArrowLeft");
	var ar = document.getElementById("ArrowRight");
	var mt = document.getElementById("MoreText");	
	var cross_slide = document.getElementById("test2");
	
	// get thenumber of "invisible" products left and right
	var placesToLeft = Math.abs(parseInt(cross_slide.style.left))/slidespeed;
	var placesToRight = pcount-parseInt(sliderwidth)/slidespeed - placesToLeft;
	
	mt.style.visibility = "visible";
	
	switch (placesToLeft) 
	{
		case 0:
			al.style.visibility = "hidden";
			break;
		default:
			al.style.visibility = "visible";
	}
	
	switch (placesToRight) 
	{
		case 0:
			ar.style.visibility = "hidden";
			break;
		default:
			ar.style.visibility = "visible";
	}
}

function setlow(lowvalue)
{
	document.Form1.lowHidden.value = lowvalue;
}

function goToUrl(url)
{
	//location.href = url + "?low=" + document.Form1.lowHidden.value;
	location.href = url + "?low=" + document.Form1.lowHidden.value + "&index=" + index + "&csleft=" + cross_slide.style.left;
}


//code for move next and previous on the product detail template.
		
function nextclick(prodName)
{
	var nindex;	
	var vindex;
	var newurl;
	var nurl;
	var pwidth=slidespeed;
	
	var csLeft;
	var slideWidth = 7*pwidth;
	var indexOffsetFromCSLeft = parseInt(index)+1 - Math.abs((parseInt(cross_slide.style.left))/pwidth);
	//alert(indexOffsetFromCSLeft);

	
	if (indexOffsetFromCSLeft < 7 && indexOffsetFromCSLeft >= 1 ) 
	{
		csLeft = cross_slide.style.left;
	} 
	else if ( indexOffsetFromCSLeft <= 0) 
	{
		csLeft = parseInt(cross_slide.style.left)-(pwidth*indexOffsetFromCSLeft)+"px"
	} 
	else 
	{
		csLeft = parseInt(cross_slide.style.left)-pwidth+"px";
		//alert(csLeft);
	}
	
	vindex= parseInt(index);
	pwidth = (vindex+1)*pwidth;	
	pcount = pcount-1;
	if (index < pcount && index != "")
	{
		nindex = vindex+1;
		
		newurl = nextarray[nindex].split("')");
		newurl = newurl[0];
		nurl = newurl.split("'");		
		
		if(pwidth > 360) 
		{
			var low = (pwidth-360)/60;
		
			nurl = nurl[1] + "?low=" + low + "&csleft=" + csLeft;			
			location.href = nurl;
		} 
		else 
		{
			nurl = nurl[1] + "?low=" + nlow + "&csleft=" + csLeft;			
			location.href = nurl;
		}
	} 
	else 
	{
		nindex = 0;
		var low = ((pwidth-360)/60)-1;

		newurl = nextarray[nindex].split("')");
		newurl = newurl[0];
		nurl = newurl.split("'");
		csLeft = "0px";		
		location.href = nurl[1] + "?csleft=" + csLeft;
	}
		
}



function previousclick(prodName)
{

	var nindex;	
	var vindex;
	var newurl;
	var nurl;
	
	var indexOffsetFromCSLeft = parseInt(index)+1 - Math.abs((parseInt(cross_slide.style.left))/slidespeed);
	
	if (parseInt(index) == 0)	
	{			csLeft = "-"+((pcount * slidespeed) - (slidespeed * 7))+"px";
	}
	else if (indexOffsetFromCSLeft > 1 ) 
	{		
		if (indexOffsetFromCSLeft <= 8)
		{
			csLeft = cross_slide.style.left;
		}
		else
		{
			csLeft = parseInt(cross_slide.style.left) - (indexOffsetFromCSLeft-8)*slidespeed+"px";
		}
	} 
	else if (indexOffsetFromCSLeft == 1) 
	{
		if (parseInt(cross_slide.style.left) != 0)
		{	
			csLeft = parseInt(cross_slide.style.left)+(slidespeed)+"px"	
		}
		else
		{
			csLeft = "-"+((pcount * slidespeed) - (slidespeed * 7))+"px"; 
		}
		
	} 
	else 
	{
		csLeft = parseInt(cross_slide.style.left) - (indexOffsetFromCSLeft-2)*slidespeed+"px";
	}
	
	
	vindex = parseInt(index);
	if (index > 0 && index != "")
	{
		nindex = vindex-1;
		newurl = nextarray[nindex].split("')");
		newurl = newurl[0];
		nurl = newurl.split("'");
		if(vindex <= nlow) 
		{
			var low = nlow - 1;
			nurl = nurl[1] + "?low=" + low + "&csleft=" + csLeft;
			location.href = nurl;
			slideright();	
		}
		else
		{
			nurl = nurl[1] + "?low=" + nlow + "&csleft=" + csLeft;
			location.href = nurl;
		}
	} 
	else 
	{		
		nindex = pcount-1;
		var placesToLeft = Math.abs(parseInt(cross_slide.style.left))/slidespeed;
		var placesToRight = pcount-parseInt(sliderwidth)/slidespeed - placesToLeft;
		
		newurl = nextarray[nindex].split("')");
		newurl = newurl[0];
		nurl = newurl.split("'");
		nurl = nurl[1] + "?low=" + placesToRight + "&csleft=" + csLeft;
		
		location.href = nurl;
	}	
}		
