YAHOO.namespace('gaia.app.Arena');
function initTabChangeHome(settings){
	
    TabChangeHome = new YAHOO.gaia.app.Arena.TabChangeHome();
    TabChangeHome.init(settings);
	
}
YAHOO.gaia.app.Arena.TabChangeHome = function() {
    this._settings = null;
    this._ajaxRequest= null;
 }
YAHOO.gaia.app.Arena.TabChangeHome.prototype.init = function(settings) {
	  this._settings = {
	  	
		 populartablink : YAHOO.util.Dom.get(settings.populartablink),
		 recenttablink : YAHOO.util.Dom.get(settings.recenttablink),
		 popularAjaxURLhome: settings.popularAjaxURLhome,
		 ajaxURLsettabcookie: settings.ajaxURLsettabcookie,
		 popularhomesize: settings.popularhomesize,
		 recenthomesize: settings.recenthomesize,
		 recentAjaxURLhome: settings.recentAjaxURLhome
		
		
	};
	var tabCookie = YAHOO.util.Cookie.get("tabType");
		if (tabCookie != null ) { 
        if( tabCookie == 'popular') {
			this._loadHomePopularTab();
            YAHOO.util.Event.addListener(this._settings.recenttablink, "click", this._loadHomeRecentTab,this,true);
        }else if( tabCookie == 'recent'){
			this._loadHomeRecentTab();
			YAHOO.util.Event.addListener(this._settings.populartablink, "click", this._loadHomePopularTab,this,true);
        }
    }else{
		this._loadHomePopularTab();
            YAHOO.util.Event.addListener(this._settings.recenttablink, "click", this._loadHomeRecentTab,this,true);
    }
	
}
YAHOO.gaia.app.Arena.TabChangeHome.prototype._setrecenttabCookie = function(e, elem_id){
	settabcookieRecent = new YAHOO.gaia.app.Arena.Setcookie(
	 {
	 			tabType : "recent",
				ajaxURL : this._settings.ajaxURLsettabcookie
	 } 
	);
	
}
YAHOO.gaia.app.Arena.TabChangeHome.prototype._setpopulartabCookie = function(e, elem_id){
	settabcookiePopular = new YAHOO.gaia.app.Arena.Setcookie(
	 {
	 			tabType : "popular",
				ajaxURL : this._settings.ajaxURLsettabcookie
	 } 
	);
}
YAHOO.gaia.app.Arena.TabChangeHome.prototype._loadHomeRecentTab = function(e, elem_id){
	YAHOO.util.Dom.removeClass(this._settings.populartablink.parentNode, "selected");
	YAHOO.util.Dom.addClass(this._settings.recenttablink.parentNode, "selected");
	YAHOO.util.Dom.get('tab1').style.display = 'block';
	YAHOO.util.Dom.get('tab2').style.display = 'none';
	YAHOO.util.Event.removeListener(this._settings.recenttablink, "click");
	YAHOO.util.Event.addListener(this._settings.recenttablink, "click", this._setrecenttabCookie,this,true);
	settabcookieRecent = new YAHOO.gaia.app.Arena.Setcookie(
	 {
	 			tabType : "recent",
				ajaxURL : this._settings.ajaxURLsettabcookie
	 } 
	); 
	if(this._settings.recenthomesize > 0){
		browserecenthome = new YAHOO.gaia.app.Arena.Browse(
		 {
		 			arenaType : "gaia",
					contentType : "home",
					request : "sublanding",
					results: 2,
					divId : "dhtml-carousel1",
					ajaxURL : this._settings.recentAjaxURLhome
		 } 
		);
	}
	
}
YAHOO.gaia.app.Arena.TabChangeHome.prototype._loadHomePopularTab = function(e, elem_id){
	YAHOO.util.Dom.removeClass(this._settings.recenttablink.parentNode, "selected");
	YAHOO.util.Dom.addClass(this._settings.populartablink.parentNode, "selected");
	YAHOO.util.Dom.get('tab1').style.display = 'none';
	YAHOO.util.Dom.get('tab2').style.display = 'block';
	YAHOO.util.Event.removeListener(this._settings.tablink, "click");
	YAHOO.util.Event.addListener(this._settings.tablink, "click", this._setpopulartabCookie,this,true);
	settabcookiePopular = new YAHOO.gaia.app.Arena.Setcookie(
	 {
	 			tabType : "popular",
				ajaxURL : this._settings.ajaxURLsettabcookie
	 } 
	);

	if (this._settings.popularhomesize > 0) {
		browsepopularhome = new YAHOO.gaia.app.Arena.Browse({
			arenaType: "gaia",
			contentType: "home",
			request: "sublanding",
			results: 2,
			divId: "dhtml-carousel2",
			flag: 1,
			ajaxURL: this._settings.popularAjaxURLhome
		});
	}
	
}
