/////////// Change Style Sheet ////////////////////////////////////
///////////////////////////////////////////////////////////////////


/////////// Drop Down Menus ////////////////////////////////////////
///////////////////////////////////////////////////////////////////

startList = function() {
	if (document.all&&document.getElementById) {
		if(document.getElementById("nav")){
		navRoot = document.getElementById("nav");
		for (i=0; i<navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			if (node.nodeName=="LI") {
				node.onmouseover=function() {
					this.className+=" over";
				}
				node.onmouseout=function() {
					this.className=this.className.replace(" over", "");
				}
			}
		}
		}
	}
	
/////////// ajax tabs ////////////////////////////////////////
//////////////////////////////////////////////////////////////

if(document.getElementById('container')){
	var tabs = document.getElementsByClassName('tabs');
		for (var i = 0; i < tabs.length; i++) {
			$(tabs[i].id).onclick = function () {
				ticker.clicked = true;
				getTabData(this.id);
				oldIDGlobal = this.id.substr(3,1) * 1;
			}
		}
	
	oldIDGlobal = 0;
	var ticker = new Ticker();
	ticker.tick(1);
	}
}

function Ticker(){
    this.count = 0;
    this.timer = new Timer(this);
    this.clicked = false;
}

Ticker.prototype.tick = function(d){
    if(!this.clicked){
	//if we've hit the last tab, select the first tab again
		if (d>4){ d = 1 }
		getTabData('tab'+d);
		oldIDGlobal = d;
		d++;
		this.timer.setTimeout("tick", 10000, d);

	}
}
                   
function getTabData(id) {
	changeTabStyle(id);
	var url = '/other/front_tab/headlines/index.php';
	var rand = Math.random(9999);
	var pars = 'id=' + id + '&rand=' + rand;
	var myAjax = new Ajax.Request( url, {method: 'get', parameters: pars, onLoading: showLoad, onComplete: showResponse} );
}

function showLoad () {
	$('load').style.display = 'block';
}

function changeTabStyle(newid) {
	//set old tab style back to unselected tab style
	if(document.getElementById("tab"+oldIDGlobal)){
		currentStyle = document.getElementById("tab"+oldIDGlobal);
		currentStyle.className=currentStyle.className.replace("tabs_over", "tabs");
	}

	//set new tab style to selected tab style
	currentStyle = document.getElementById(newid);
	currentStyle.className=currentStyle.className.replace("tabs", "tabs_over");
}

function showResponse (originalRequest) {
	var newData = originalRequest.responseText;
	$('load').style.display = 'none';
	$('content').innerHTML = newData;
}

window.onload=startList;
