/* new scroller functions */
var gnet_timeLag = 5000;
var gnet_loopCount = 0;
var gnet_loopMax = 3;
var gnet_killAuto = false;
var gnet_currentSlot = 1;
if (pagePlatform == 'home' ) {
	var gnet_totalSlots = 7;
}else{
	var gnet_totalSlots = 3;
}
var featureXML = "";
swapLag = window.setTimeout(swapSlot, 100000000);
autoLag = window.setTimeout(swapSlot, 100000000);

function swapFake() {
	// do nothing
}

function featureRequest() {
	new Ajax.Request('/scripts/ajax/scroller_swap.cfm?section=' + pagePlatform, {onSuccess: processFeatureRequest});
}

function processFeatureRequest(t) {
	featureXML = t.responseXML;
	autoRun();
}

function swapSlot() {
	markButton(gnet_currentSlot);
	objName = 'fea_' + gnet_currentSlot;
	if($(objName)) {
		featureList = $A($('features').getElementsByTagName('div'));
		featureList.each(function(featAt){
			featAt.style.display = 'none';			   
		});
		if (navigator.userAgent.indexOf("Mac") != -1 && navigator.userAgent.indexOf("Firefox") != -1) {
			$(objName).style.display = 'block';
		} else if ( navigator.userAgent.indexOf("MSIE 6.0") != -1) {
			$(objName).style.display = 'block';
		} else {
			Effect.Appear(objName,{duration: 1});
		}
	} else{
		buildSlot();
		swapSlot();
	}
}

function autoRun () {
	if (gnet_killAuto) return;
	if (gnet_loopCount < gnet_loopMax) {
		if (gnet_currentSlot == gnet_totalSlots) {
			gnet_loopCount++;	
		}
	} else {
		return;	
	}
	if (gnet_currentSlot < gnet_totalSlots) {
		gnet_currentSlot++;
	} else { 
		gnet_currentSlot = 1;
	}
	swapLag = window.setTimeout(swapSlot, gnet_timeLag);
	autoLag = window.setTimeout(autoRun, gnet_timeLag);
}

function markButton (slotNum) {
	buttons = $A($('fea_nav').getElementsByTagName("a"));
	buttons.each(function(buttonAt){
		$(buttonAt.id).removeClassName("on");
	});
	$('fea_trigger_' + slotNum).addClassName("on");
}

function manualSwap (slotNum) {
	$('fea_trigger_' + slotNum).blur();
	window.clearTimeout(swapLag);
	window.clearTimeout(autoLag);
	gnet_killAuto = true;
	gnet_currentSlot = slotNum;
	swapSlot();
}

function buildSlot() {
	xmlSlot = gnet_currentSlot - 2;
	parentDiv = $('features');
	newDiv = doc.createElement("div");
	newID = "fea_" + gnet_currentSlot;
	newDiv.setAttribute("id",newID);
	newDiv.setAttribute("style","display: none;");
	newH3 = doc.createElement("h3");
	newH3Link = doc.createElement("a");
	newH3Link.setAttribute("href",featureXML.getElementsByTagName('url')[xmlSlot].firstChild.data);
	newH3Link.setAttribute("title",featureXML.getElementsByTagName('title')[xmlSlot].firstChild.data);
	newH3Link.appendChild(doc.createTextNode(featureXML.getElementsByTagName('title')[xmlSlot].firstChild.data));
	newH3.appendChild(newH3Link);
	newP = doc.createElement("p");
	newP.appendChild(doc.createTextNode(featureXML.getElementsByTagName('blurb')[xmlSlot].firstChild.data));
	newImgLink = doc.createElement("a");
	newImgLink.setAttribute("href",featureXML.getElementsByTagName('url')[xmlSlot].firstChild.data);
	newImgLink.setAttribute("title",featureXML.getElementsByTagName('title')[xmlSlot].firstChild.data);
	newImg = doc.createElement("img");
	imgName = featureXML.getElementsByTagName('art')[xmlSlot].firstChild.data;
	newImg.setAttribute("src",imgName);
	newImg.setAttribute("alt",featureXML.getElementsByTagName('title')[xmlSlot].firstChild.data);
	newImgLink.appendChild(newImg);
	newDiv.appendChild(newH3);
	newDiv.appendChild(newP);
	newDiv.appendChild(newImgLink);
	parentDiv.appendChild(newDiv);
}