// Rotate Sponsors

addLoadEvent(
	function()
	{
		//sponsorInit();
	}	
);

function sponsorInit()
{
	getSponsors("sponsors");
	getSponsorsHeader("header_sponsors");
	rotateSponsors();
	rotateSponsorsInterval = setInterval("rotateSponsors()",6000);
}

//Grab sponsor from the righ rail
function getSponsors(nodeID) 
{
	var sponsorNode, ulArray, ulNode, liArray, headNode, sponsorNode
	sponsorObjectArray = new Array();
	sponsorNode = getDOMbyID(nodeID);
	ulArray  = getDOMbyTag(sponsorNode, "ul")
	for(var i = 0; ulNode = ulArray[i]; i++)
	{
		liArray  = getDOMbyTag(ulNode, "li")
		headNode = liArray[0];
		for(var n = 1; sponsorNode = liArray[n]; n++)
		{
			sponsorObjectArray.push(new sponsorObject(headNode,sponsorNode));
		}
	}
}

function getSponsorsHeader(nodeID) 
{
	var sponsorHeaderNode;
	sponsorHeaderNode = getDOMbyID(nodeID);
	sponsorHeaderNode.className = "header_sponsors_background";
	ulNode = document.createElement('ul');
	ulHeadNode = sponsorHeaderNode.appendChild(ulNode);
	
}

function displaySponsors(count)
{
	var sponsorHead;
	ulNode.innerHTML="";
	delete sponsorLogo;
	sponsorHead = ulHeadNode.appendChild(sponsorObjectArray[count].headNode.cloneNode(true));
	//alert(sponsorHead.innerHTML)
	sponsorObjectArray[count].sponsorNode.style.marginTop = "218px"
	
	sponsorLogo = ulHeadNode.appendChild(sponsorObjectArray[count].sponsorNode.cloneNode(true));
	
	wipeUpInterval = setInterval("wipeUp()",55);
}

function wipeUp()
{
	//Static init
	try{
		wipeCount;
	}
	catch(e)
	{
		wipeCount = 218;
	}
	
	if(wipeCount < 0)
	{
	delete wipeCount;
	clearInterval(wipeUpInterval);
	}
	else
	{
	sponsorLogo.style.marginTop = wipeCount+"px"
	wipeCount-= 5;
	}	
}

function rotateSponsors()
{
	//Static init
	try{
		rotateCount;
	}
	catch(e)
	{
		rotateCount = 0;
	}
	if(rotateCount < sponsorObjectArray.length)
	{
		displaySponsors(rotateCount);
		rotateCount++;
		
	}
	else
	{
		rotateCount = 0;
		displaySponsors(rotateCount);
		rotateCount++;
	}
	//alert("rotateCount = "+rotateCount+" and sponsorObjectArray length: "+sponsorObjectArray.length);
}

//Hold sponsors info
function sponsorObject(headNode,sponsorNode)
{
	var imgArray, imgNode, imgSrc;
	this.headNode = headNode.cloneNode(true);
	this.sponsorNode = sponsorNode.cloneNode(true);
	imgArray  = getDOMbyTag(this.sponsorNode, "img");
	imgNode = imgArray[0];
	imgSrc = imgNode.getAttribute("src");
	//Change the path to header_sponsors
	imgSrc = imgSrc.replace(/images/i, "images/header_sponsors");
	imgNode.setAttribute("src", imgSrc);
	imgNode.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader("+imgSrc+")";
}

//Get HTML DOM from ID with validation
function getDOMbyID(tagId)
{
	if(!tagId){
		alert("Tag ID argument must be set");
		return;
	}
	//Make sure this ID exists.
	if(!document.getElementById(tagId))
	{
		alert("No ID matching \""+tagId+"\" has been found.");
		return;
	}
	return document.getElementById(tagId);
}

//Get HTML DOM from TAG with validation
function getDOMbyTag(node, tag)
{
	if(!node){
		alert("You must have a node");
		return;
	}
	if(!tag){
		alert("You must have a tag");
		return;
	}
	if(!node.getElementsByTagName(tag)){
		alert("There is an error with your DOM");
		return;
	}
	
	return node.getElementsByTagName(tag);
}
