// configuration
iProductColumnWidth = 147;	// amount (in pixels) which scrolling moves
iSpeed 				= 1;	// scrolling speed (in ms, lower is faster)


//
//
//
// ------------------------------------------------------------------------------
// init internal vars
iContentScroll 	= 0;
iCurrentScroll 	= 0;
sDebug 			= "";
iTimer 			= -1;
iRotation 		= 90;
iRadius 		= iProductColumnWidth;
iSlideOffset	= 27;

function showNav()
{
	document.getElementById("nav").className = "visible";
	document.getElementById("divHomeNews").className = "visible";
}

function initSlide()
{
	iTimer = -1;
	iCurrentScroll = o.scrollLeft;
	iRotation = 90;
}

function slide(direction, iSlideWidth)
{
	iRadius = iSlideWidth + iSlideOffset;
	if (iTimer < 0)
	{
		iTimer = setInterval("doSlide(" + direction + ")", iSpeed);
	} 
}

function doSlide(direction)
{
	o = document.getElementById("contentMain");
	iRotation+=2;
	
	if (iRotation <= 180)
	{
		iContentScroll = Math.abs(Math.cos(iRotation * Math.PI/180) * iRadius) * direction; // make slide "natural"
		o.scrollLeft = iCurrentScroll + iContentScroll;
		sDebug += iContentScroll + " (" + iRotation + ")\n";
	}
	else
	{
		clearInterval(iTimer);
		initSlide();
	}
}

function thescroll(direction)
{
	scrollTimer = setInterval("doScroll(" + direction + ")", iSpeed);
}

function doScroll(direction)
{
	var o = document.getElementById("productData");
	o.scrollTop += 3 * direction;
	
	// hide scroll up if we're already at the top
	//scrUp = document.getElementById("scrollUp")
	//scrUp.className = (o.scrollTop > 0) ? "visible" : "hidden";
}

function killScroll()
{
	clearInterval(scrollTimer);
}

function highlight(o)
{
	o.origClass = o.className;
	o.className = "on";
}

function deHighlight(o)
{
	o.className = o.origClass;
}

function initXMLObj()
{
	var oXMLRequest = false;
	if (window.XMLHttpRequest)
	{
		try
		{
			oXMLRequest = new XMLHttpRequest();
		}
		catch(e)
		{
			oXMLRequest = false;
		}
	// branch for IE/Windows ActiveX version
	}
	else if(window.ActiveXObject)
	{
		try
		{
			oXMLRequest = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e)
		{
			try
			{
				oXMLRequest = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(e)
			{
				oXMLRequest = false;
			}
		}
	}
	return oXMLRequest;
}

var oXML;
function requestProduct(id)
{
	oXML = initXMLObj();
	if (oXML)
	{
		with (oXML)
		{
			onreadystatechange = getProduct;
			open("POST", "/lib/xmlrequest/product.asp", true);
			setRequestHeader('Content-Type','application/x-www-form-urlencoded');
			send("id=" + id);
		}
	}	
}

function getProduct()
{
	with (oXML)
	{
		if (readyState == 4)
		{
			if (status == 200)
			{
				var s = responseText;
				if (s.length)
				{
					updateProductDetails(s);
				}
			}
			else
			{
				alert("There was a problem retrieving the user XML data:\n" + statusText + "\n" + responseText);
			}
		}
	}
}

function updateProductDetails(s)
{
	var oDiv = document.getElementById("contentRight");
	oDiv.innerHTML = s;
	oDiv.className = "productDetails";
	
	showScrollers();
}

function showScrollers()
{
	var oScroll = document.getElementById("scroller");
	var oDetails = document.getElementById("productData");
	oScroll.className = "scrollerVisible";
	oScroll.parentNode.innerHTML = oScroll.parentNode.innerHTML;
	
	// 181 comes from css height property of #productData (height of productData div)
	if (oScroll.scrollHeight > 181)
	{
		
	}
}