﻿// $Id: promobox.js 3125 2008-09-08 19:00:16Z bradh $
var tpromo;
var tpromo2;
var divID = "promo";
var max = 4;
//var max = eval("document.aspnetForm."+divID+"maxcont").value;
var current = 1;
var previous = max;
var next = 1;
var promoid = 'titlepromo';
var nexttitleid = 'titlepromo2';

setNextPromo(max);

	function promoTimeout() {
		tpromo = setTimeout("NextContent('promo')", 10000);
		tpromo2 = setTimeout("promoTimeout()", 10000);
	}
	
	//?
	//SetInitialContent('promo'); 
	//not included in email, but I guess it contain code to intialize first promo
	//
	promoTimeout();
	function NextContent(divID) {
		try {	
			var currcont = parseInt(eval("document.aspnetForm."+divID+"currcont").value);
			var maxcont = parseInt(eval("document.aspnetForm."+divID+"maxcont").value);

			if (currcont == 0) 
				currcont = 1;
			
			if (nextcont > maxcont)
				nextcont = 1;
				
		
			var nextcont = (currcont % maxcont) + 1
				
			eval("document.aspnetForm."+divID+"currcont").value = nextcont;
			
			target = divID+"Numbers";
			document.getElementById(target).innerHTML = "<strong>"+nextcont+"</strong> of "+maxcont+" ";
			
			try {
			setNextPromo(currcont);
			} catch (Exception) {
			//
			}
	//		target = divID+"Next";
	//		document.getElementById(target).innerHTML = eval("document.aspnetForm.title"+divID+nextcont).value;
			
			idcc = divID+currcont;
			idnc = divID+nextcont;
			for (i=1; i<=maxcont; i++) {
				idcc = divID+i;
				document.getElementById(idcc).style.display = 'none';
			}
			
			document.getElementById(idnc).style.display = 'block';
			
			//alert('ga tag here for ' + idnc);
			ga_taglinksForLPromo(idnc);
//			if (divID == "spot" ) {
//				addEventsToLinks2(idnc); 
//				setNextPromo(currcont);

//			} else {
//				addEventsToLinks(divID + (nextcont -1));
//			}
			
		} catch (err) {
		//	
		} // Ignore errors
	}

	function PrevContent(divID) {
		var currcont = parseInt(eval("document.aspnetForm."+divID+"currcont").value);
		var maxcont = parseInt(eval("document.aspnetForm."+divID+"maxcont").value);
		
		if(currcont == 0)
			currcont = 1;
		if (currcont > maxcont)
			currcont = maxcont;
			
		var nextcont = currcont;
		var prevcont = currcont -  1;
		if (prevcont < 1)
			prevcont = maxcont;
		
		setNextPromo(currcont);
		eval("document.aspnetForm."+divID+"currcont").value = prevcont;
		
		target = divID+"Numbers";
		document.getElementById(target).innerHTML = " <b>"+prevcont+"</b> of "+maxcont+" ";
		
		//target = divID+"Next";
		//document.getElementById(target).innerHTML = eval("document.aspnetForm.title"+divID+nextcont).value;
		
		idcc = divID+currcont;
		idnc = divID+prevcont;
		for (i=1; i<=maxcont; i++) {
			idcc = divID+i;
			document.getElementById(idcc).style.display = 'none';
		}
		document.getElementById(idnc).style.display = 'block';
		
		ga_taglinksForLPromo(idnc);
	}
	
	function setNextPromo(current) {
		// 1 = 3, 2 = 4, 3 = 1, 4 = 2
		// 1 = 3, 2 = 1, 3 = 2
		if ( max == 4 ) {
			if ( current == 1 || current == 2 ) {		
				next = current + 2;
			} else {
				next = current -2;
			}
		} else {
			if ( current == 1 ) {
				next = current + 2;
			} else {
				next = current - 1;
			}
		}
		try {
			nexttitleid = promoid + next;
			document.getElementById('promoNext').innerHTML = document.getElementById(nexttitleid).value;
			current = next;
		} catch(err) {
			// ignore error
		}
	}
	
