// JavaScript Document
var whbody =new function(){
	this.size=5;
	this.showTab=function(idx,obj){
		isauto=false;
		class_code='num'+idx;
		if(obj.parentNode.className==class_code){
			ulObj=obj.parentNode.parentNode;
			nodes=ulObj.getElementsByTagName('li');
			for(i=0;i<nodes.length;i++){
				nodes[i].className='num'+(i+1);
			}
			for(i=1;i<=this.size;i++){
				id='wh-body-'+i;
				document.getElementById(id).style.display='none';				
			}
			currentObj='wh-body-'+idx;
			document.getElementById(currentObj).style.display='block';
			//alert(obj.parentNode.className);
			obj.parentNode.className=obj.parentNode.className+'selected';
		}
	};
	this.showIndexTab=function(idx){
		//currentObj='wh-body-'+idx;
		//document.getElementById(currentObj).style.display='block';
		/*obj.parentNode.className=obj.parentNode.className+'selected';*/
	};
	this.autoSlide=function(){
		if(isauto){
			showIndexTab(start);
		}
		if(start==5){
			start=1;
		}else{
			start++;
		}
	};	
};
function showIndexTab(idx){
		pTab = document.getElementById("wh-tab");
		if (!pTab)
			return;
		list=pTab.getElementsByTagName('li');
		for(i=0;i<list.length;i++){
			id='wh-body-'+(i+1);
			document.getElementById(id).style.display='none';
			list[i].className='num'+(i+1);
		}
		currentObj='wh-body-'+idx;
		document.getElementById(currentObj).style.display='block';
		list[idx-1].className='num'+idx+'selected';						   
		/*obj.parentNode.className=obj.parentNode.className+'selected';*/
}

function TrackTabs(TabName){
	var s=s_gi(s_account);
	s.linkTrackVars='prop6';
	s.linkTrackEvents='';
	s.events='';
	s.prop6="'" + TabName + "'";
	s.tl(this,'o',"'Whats on Too Much For TV this Month'");
}

var whon =new function(){
	this.size=7;
	this.showTab=function(idx,obj){
		//alert(obj.className);
		if(obj && (obj.className=='wh_on_link')){			
			parentNode=obj.parentNode;		
			parentNode=parentNode.parentNode;
			links=parentNode.getElementsByTagName('a');
			
			for(i=0;i<links.length;i++){
				links[i].className='wh_on_link';
			}
			//turn on selected tab
			obj.className='wh_on_link_selected';
			displayItem='what-on-'+idx;
			
			pItem = document.getElementById("what-on-item");
			if (pItem){
				pItem.innerHTML=document.getElementById(displayItem).innerHTML;
			}			
			TrackTabs(obj.innerHTML);
		}
	};
	this.itemOpen=function(obj){
		rootNode=obj.parentNode;
		childs=rootNode.getElementsByTagName('p');
		if(childs.length>0){
			if(childs[0].style.display=='block'){
				for(i=0;i<childs.length;i++){
					childs[i].style.display='none';
				}
				imgs=rootNode.getElementsByTagName('img');
				imgs[0].src='images/collapse.jpg';
			}else{
				for(i=0;i<childs.length;i++){
					childs[i].style.display='block';
				}
				imgs=rootNode.getElementsByTagName('img');
				imgs[0].src='images/opened.jpg';
			}
		}
	};
	this.init=function(){		
		pItem = document.getElementById("what-on-item");
		if (pItem){
			pItem.innerHTML=document.getElementById("what-on-1").innerHTML;
		}
	}	
};
var findObj = new function(){
	this.doFocus=function(obj){
		if(search_default_text==obj.value.toLowerCase()){
			obj.value='';
		}
	};
	this.doLostFocus=function(obj){
		if(''==obj.value.toLowerCase()){
			obj.value='zip code';
		}
	};
	this.keydownSubmit=function(e){
		if(e.keyCode==13){
			this.doSubmit();
		}
	};
	this.doSubmit=function(){
		try{
			var txtSearch = document.getElementById('zip-code-zip-text-box');
			//alert(txtSearch.value);
			txtSearchString = txtSearch.value;
			//alert(txtSearchString);
			var w=screen.width;
			var h=screen.height-220;
			searchLayer=document.getElementById('search-result-panel');
			var layerWidth=searchLayer.clientWidth;
			if(layerWidth==0) layerWidth=400;
			searchLayer.style.left=Math.round((w-layerWidth)/2)+'px';
			searchLayer.style.display='block';
			$("#search-result-content").load("/findTM4TV.do?zip="+ txtSearchString);
		}
		catch (e){
			alert("Error: " + e);
		}
	};
	this.close=function(){
		document.getElementById('search-result-panel').style.display='none';
	};
};
//var whbody =new hotTabs();
//var whon =new whatOnTabs();
//var findObj = new searchEngine();
var start=1;
var isauto=true;
var search_default_text="zip code";
setInterval(whbody.autoSlide,2000);


