// SCRIPT TO SWAP AROUND THE LEAD STORIES ON THE HOME PAGE
var timer2 = 5000; // milliseconds
var pos = 1;
var leadstot = 4;
leadstories = new Array();

function swap(foo) {
	for (i=0 ; i<leadstories.length ; i++) {
		if (leadstories[i].className === 'leadpic' || leadstories[i].className === 'leadstory') leadstories[i].style.display = 'none';
	}
	if (foo === 'next') {
		pos++;
		if (pos === leadstot+1) pos = 1;
	} else if (foo === 'prev') {
		pos--;
		if (pos === 0) pos = leadstot;
	}
	
	document.getElementById('leadpic'+pos).style.display = 'block';
	document.getElementById('leadstory'+pos).style.display = 'block';
	document.getElementById('pos').innerHTML = pos;
	
	if (timer2 !== 0) nextLead = setTimeout("swap('next')",timer2);
}

function clearTimer(foo) {
	clearTimeout(nextLead);
	timer2 = 0;
	swap(foo);
}

// SCRIPT TO SWAP TABS AND TABBED CONTENT ON THE HOME PAGE
function swaptabs(foo) {
	for (i=0 ; i<tabbies.length ; i++) if (tabbies[i].className === 'tabbedlead') tabbies[i].style.display = 'none';
	for (i=0 ; i<mories.length ; i++) if (mories[i].className === 'btn624-1') mories[i].style.display = 'none';
	for (i=0 ; i<linkies.length ; i++) linkies[i].className = '';
	document.getElementById(foo+'leads').style.display = 'block';
	document.getElementById(foo+'tab').className = 'active';
	document.getElementById('more'+foo).style.display = 'block';
}

// ALL SCRIPTS THAT RUN ON PAGE LOAD
function setup() {
	
	nextLead = setTimeout("swap('next')",timer2);
	
	// OUTBOUND LINKS OPEN IN A NEW WINDOW UNLESS EXPLICITLY TOLD OTHERWISE
	// FORCE SAME WINDOW: rel="self" in anchor
	// FORCE EXTERNAL WINDOW: rel="external" in anchor
	var domain = window.location+'';
	domain = domain.replace('//','');
	domain = domain.substring(domain.indexOf(':')+1,domain.indexOf('/'));
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {
		var URL = anchors[i].href;
		if ((URL.search('webhostsummit')===-1 && URL.search('http')!==-1 && anchors[i].rel !== 'self') || anchors[i].rel === 'external') anchors[i].target = "_blank";
	}
}

window.onload = setup;
