/**
 * Syn.WhatToWatch for the TV Channel, loads content for tabs
 * @pacakge agdistis
 */
Syn.WhatToWatch = Syn.Component.extend (
{
	/**
	 * Initialize the component class. This is called automatically by the default constructor.
	 * @param {Object} config The configuration data structure
	 */
	init: function(config)
	{
		//Init parent class
		this._super(config);
		this.mode = null;

		this.syn_tv_pop = new Syn.TvPopup(config);

		this.syn_tv_pop.removePopups();

		this.uniqueElmt("tv_watch").find("a.wtw_ondemand_asset").connect("click",this,"createPopup");
		this.uniqueElmt("what_to_watch_right").find("a.also_ondemand_asset").connect("click",this,"createPopup");
		this.uniqueElmt("what_to_watch_left").find("a.ondemand_asset").connect("click",this,"createPopup");
	
		this.uniqueElmt("wtw_today").find("a").connect("click",this,"showTab",["today"]); 
		this.uniqueElmt("wtw_tomorrow").find("a").connect("click",this,"showTab",["tomorrow"]); 
		this.uniqueElmt("wtw_ondemand").find("a").connect("click",this,"showTab",["ondemand"]); 
	},

	
	/**
	 * Calls the Syn.TvPopup.showPopup method 
	 * @param {Object} element
	 */
	createPopup: function (element) 
	{
		return this.syn_tv_pop.showPopup(element, "tv_vod_popup");
	},


	/** 
	 * Make and Request for the tab content
	 * @param {String} tab_name
	 * @param {String} mode
 	 */
	showTab: function(tab_name, mode)
	{
		this.mode = mode;
			
	 	this.submit (
		{
			"wtw_tab"  : tab_name,
			"wtw_mode" : mode		
		});

		this.highlightTab(tab_name, mode);
	
		return false;
	},


	/**
	 * Set the current tab to be highlighted with class = on
	 * @param {String} tab_name
	 */
	highlightTab : 	function (tab_name)
	{
		if(this.mode == "details")
		{
			this.uniqueElmt("tabbed_nav").find("li").removeClass("on");
			this.uniqueElmt("wtw_" + tab_name + "_details").addClass("on");
		}
		else
		{
			this.uniqueElmt("tv_tabbed_nav li").find("li").removeClass("on");
			this.uniqueElmt("wtw_" + tab_name).addClass("on");
		}
	}					
});
