/**
 * Javascript file: tool
 * @for the what's hot section (slideviewer).
 * @author Michael Ortali
 */
function whbody2() 
{
	/**
	 * @var whobody
	 */
	var _instance = this;
	
	/**
	 * @attribute Integer the current tab
	 */
	this.current = 1;
	
	/**
	 * @attribute Boolean if the user's mouse is on the top of the tab, we're stopping
	 * 	the scroll so he can read. 
	 */
	this.hover = false;
	
	/** 
	 * @attribute [JQuery Element] all the links to the 5 sections.
	 */
	this.items = $('#whats-hot ul a');
	
	/**
	 * Constructor 
	 * We're creating the intervale (5000 ms) before switching to another view 
	 * and if the user's mouse is on the top of the announce, we're stopping it.
	 * At the main time, we're making sure that each link has an action.
	 */
	this.items.click(function() { _instance.goTo(parseInt($(this).html())) });
	setInterval(function() { _instance.next() }, 5000);
	$('#wh-scroll .content').hover(function() { _instance.hover = true; }, function() { _instance.hover = false; });
	$('#wh-tab li').eq(0).attr('class', 'num1selected');
	
	/**
	 * @param Integer of the tabulation we want to see. 
	 * @return void
	 */
	this.goTo = function(id) 
	{
		this.current = id;
		
		/**
		 * Each link has a style. The tabulation selected is displaying 
		 * the link in another style (to differenciate the current from 
		 * the others, style name: numIDselected).
		 */
		var link;
		for(var i=0; i < this.items.length; i++)
		{
			link = $('#wh-tab li').eq(i);
			if(i+1 == id)
				link.attr('class', 'num'+(i+1)+'selected');
			else
				link.attr('class', 'num'+(i+1));
		}
		link = null; 
		
		// Time to animate!
		$('#wh-scroll').animate({marginLeft:-(id-1)*813});
	};
	
	/**
	 * Displaying the next tabulation. However, we're 
	 * taking in consideration the user's mouse: if hover
	 * we're aboarting. 
	 * @return void
	 */
	this.next = function() {
		if(this.hover) return;
		this.current++;
		if(this.current > this.items.length) 
		{
			this.current = 1;
		}
		this.goTo(this.current);
	}
};

// END of the new code.

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;
			}
			
		}
	};
	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";

/* jQuery Start **/
$(document).ready(function(){
	$('.popup-contents a').attr({target: '_blank'});
	/**
	/* 	Change Image On Click
	 */
	var normalState = "#tab1, #tab2, #tab4, #tab5, #tab6";
	var altState = "#tab3"
	var imgChange = "#whats-on img:first"
	new whbody2();
	
	$(normalState).click(function () {
		$(imgChange).attr({ 
			src: "/images/whats_on.jpg"
		});
	});

	$(altState).click(function () {
		$(imgChange).attr({ 
			src: "/images/whats_on_alt.jpg"
		});
	});
	
	// openbox
	$(".thickbox").colorbox({iframe:true, innerWidth:690, innerHeight:580});
});
