/*
	Jemison Demsey Metals JavaScript
	Created: 2004.07.11
	Modified: 2004.07.13

	functions that begin with a lowercase letter are meant to be used
	as supporting functions only and not called from the html page.
*/


var browser = navigator.userAgent;

var __isIE = (browser.indexOf("MSIE") >= 0);
var __isPC = (browser.indexOf("Windows") >= 0);

var transferPage = null;

function Init()
{
	setExternalLinks(false);
}





/*
	Used with the Cornerstone elements of the home page
*/

var __stones = new Array("service","quality","delivery","stock");
var __current = null;
var __index = -1;
var __interval = 5000;	// delay before switching.
var __timer;				// the timer

function Cornerstones(obj, cs)
{

	//if(__isPC)
		stopTimer();

	__current = cs;

	clearCS();

	setCS(obj);

}

function setCS(obj)
{



	obj.src = "images/" + __stones[__index] + "_over.jpg";

	document.getElementById("blank_lnk").style.display = "none";
	document.getElementById(__stones[__index] + "_lnk").style.display = "block";
}


function clearCS()
{

	__index = -1;

	for(i = __stones.length; i-- > 0;)
	{
		// set all of the cornerstones to their default state
		document.getElementById(__stones[i]).src = "images/" + __stones[i] + ".jpg";
		document.getElementById(__stones[i] + "_lnk").style.display = "none";

		// set the current index value
		if(__current == __stones[i]) __index = i;
	}
}



/*

	The following set of functions are used to rotate the selected
	CornerStone (on the home page) based on a timer.

*/



function CSInit()
{
	//if(__isPC)
		startTimer();
}

function startTimer()
{
	__timer = window.setInterval(function() { rotateCS(); }, __interval);

	//alert(__timer);
}

function clearImageTimer() {
	if(__timer)
	{
		window.clearInterval(__timer);
		__timer = null;
	}
	else
	{
		__timer = window.setInterval(function() { rotateCS(); }, __interval);
	}
}


function stopTimer() {
	if(__timer)
	{
		window.clearInterval(__timer);
		__timer = null;
	}
}

function rotateCS()
{

	clearCS();

	if( __index + 1 < __stones.length)
		__index ++;
	else
		__index = 0;

	obj = document.getElementById(__stones[__index]);
	__current = __stones[__index];

	//alert("current: " + __index + " : " + __stones[__index]);

	setCS(obj, __stones[__index]);


}



// preloads images
// just pass each image source in as an argument
function LoadImages()
{
	var img = new Image();

	var args = LoadImages.arguments;

	for(var x = 0; x < args.length - 1; x++)
		img.src = args[x];
}

// changes a given images source to the given image
var __oldSrc = null;
function ChangeImage(obj, src, ret)
{
	if(obj)
	{
		if(! ret)
		{
			__oldSrc = obj.src;
			obj.src = src;
		}
		else
		{
			obj.src = __oldSrc;
			__oldSrc = null;
		}
	}
}


// changes the innerHTML of an element with the given id
// with the given text
function ChangeDescription(elem, text)
{
	e = document.getElementById(elem);

	if(e) e.innerHTML = text;

}

// changes the cssClass of a given object to the given CssClass name
function ChangeCssClass(object, css)
{
	object.className = css;
}


// sets the active stylesheet to the stylesheet that has
// the given title attribute
function SetActiveStyleSheet(title)
{
	var i, a, main;

	// find an loop through all the <link> elements in the document
	for (i = 0; (a = document.getElementsByTagName("link")[i]); i++)
	{
		// disable all the stylesheet
		if (a.getAttribute("rel").indexOf("style") != -1
			&& a.getAttribute("title"))

			a.disabled = true;

		// if it is the stylesheet requested, then enable it
		if (a.getAttribute("title") == title)
			a.disabled = false;
	}
}



// looks through all of the <a> elements in the document
// and checks for a rel attribute. If the rel attribute is
// set to "ext", "external", "blank", "new" or "_blank"
// then it sets the target attribute to "_blank" so that the link
// will open in a new browser window.
function setExternalLinks(showTransferPage)
{
	lnkArr = document.getElementsByTagName("a");

	for(i = lnkArr.length; i-- > 0;)
	{
		if(lnkArr[i].rel == "ext"
			|| lnkArr[i].rel == "external"
			|| lnkArr[i].rel == "blank"
			|| lnkArr[i].rel == "new"
			|| lnkArr[i].rel == "_blank")
		{
			if(transferPage != null && showTransferPage)
				linkArr[i].href = transferPage + "?" + linkArr[i].href;

			lnkArr[i].target = "_blank";
		}
	}
}