YAHOO.namespace('gaia.app.Arena');
function initTabChangeAvatar(settings){
	
    TabChangeAvatar = new YAHOO.gaia.app.Arena.TabChangeAvatar();
    TabChangeAvatar.init(settings);
	
}
YAHOO.gaia.app.Arena.TabChangeAvatar = function() {
    this._settings = null;
    this._ajaxRequest= null;
 }
YAHOO.gaia.app.Arena.TabChangeAvatar.prototype.init = function(settings) {
	  this._settings = {
	  	
		 populartablink : YAHOO.util.Dom.get(settings.populartablink),
		 recenttablink : YAHOO.util.Dom.get(settings.recenttablink),
		 popularAjaxURLavatar: settings.popularAjaxURLavatar,
		 popularAjaxURLcosplay : settings.popularAjaxURLcosplay,
		 ajaxURLsettabcookie: settings.ajaxURLsettabcookie,
		 popularavatarsize :settings.popularavatarsize,
		 popularcosplaysize :settings.popularcosplaysize,
		 recentAjaxURLavatar: settings.recentAjaxURLavatar,
		 recentAjaxURLcosplay : settings.recentAjaxURLcosplay,
		 recentavatarsize :settings.recentavatarsize,
		 recentcosplaysize :settings.recentcosplaysize
		
		
	};
	var tabCookie = YAHOO.util.Cookie.get("tabType");
		if (tabCookie != null ) { 
        if( tabCookie == 'popular') {
			this._loadAvatarPopularTab();
            YAHOO.util.Event.addListener(this._settings.recenttablink, "click", this._loadAvatarRecentTab,this,true);
        }else if( tabCookie == 'recent'){
			this._loadAvatarRecentTab();
			YAHOO.util.Event.addListener(this._settings.populartablink, "click", this._loadAvatarPopularTab,this,true);
        }
    }else{
		this._loadAvatarPopularTab();
        YAHOO.util.Event.addListener(this._settings.recenttablink, "click", this._loadAvatarRecentTab,this,true);
      }
	
}
YAHOO.gaia.app.Arena.TabChangeAvatar.prototype._setrecenttabCookie = function(e, elem_id){
	settabcookieRecent = new YAHOO.gaia.app.Arena.Setcookie(
	 {
	 			tabType : "recent",
				ajaxURL : this._settings.ajaxURLsettabcookie
	 } 
	);
	
}
YAHOO.gaia.app.Arena.TabChangeAvatar.prototype._setpopulartabCookie = function(e, elem_id){
	settabcookiePopular = new YAHOO.gaia.app.Arena.Setcookie(
	 {
	 			tabType : "popular",
				ajaxURL : this._settings.ajaxURLsettabcookie
	 } 
	);
}
YAHOO.gaia.app.Arena.TabChangeAvatar.prototype._loadAvatarRecentTab = 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.recentavatarsize > 0) {
		browsepopularavatar = new YAHOO.gaia.app.Arena.Browse({
			arenaType: "gaia",
			contentType: "avatar",
			request: "sublanding",
			results: 5,
			size: this._settings.recentavatarsize,
			divId: "dhtml-carousel1",
			prevArrow: "prev-arrow-container1",
			nextArrow: "next-arrow-container1",
			ajaxURL: this._settings.recentAjaxURLavatar
		});
	}
	if (this._settings.recentcosplaysize > 0) {
		browsepopularcosplay = new YAHOO.gaia.app.Arena.Browse({
			arenaType: "gaia",
			contentType: "avatar",
			request: "sublanding",
			results: 5,
			size: this._settings.recentcosplaysize,
			divId: "dhtml-carousel2",
			prevArrow: "prev-arrow-container2",
			nextArrow: "next-arrow-container2",
			ajaxURL: this._settings.recentAjaxURLcosplay
		});
	}
	
}

YAHOO.gaia.app.Arena.TabChangeAvatar.prototype._loadAvatarPopularTab = 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.populartablink, "click");
	YAHOO.util.Event.addListener(this._settings.populartablink, "click", this._setpopulartabCookie,this,true);
	settabcookiePopular = new YAHOO.gaia.app.Arena.Setcookie(
	 {
	 			tabType : "popular",
				ajaxURL : this._settings.ajaxURLsettabcookie
	 } 
	);
	if (this._settings.popularavatarsize > 0) {
		browsepopularavatar = new YAHOO.gaia.app.Arena.Browse({
			arenaType: "gaia",
			contentType: "avatar",
			request: "sublanding",
			results: 5,
			size: this._settings.popularavatarsize,
			divId: "dhtml-carousel3",
			prevArrow: "prev-arrow-container3",
			nextArrow: "next-arrow-container3",
			flag: 1,
			ajaxURL: this._settings.popularAjaxURLavatar
		});
	}
	if (this._settings.popularcosplaysize > 0) {
		browsepopularcosplay = new YAHOO.gaia.app.Arena.Browse({
			arenaType: "gaia",
			contentType: "avatar",
			request: "sublanding",
			results: 5,
			size: this._settings.popularcosplaysize,
			divId: "dhtml-carousel4",
			prevArrow: "prev-arrow-container4",
			nextArrow: "next-arrow-container4",
			flag: 1,
			ajaxURL: this._settings.popularAjaxURLcosplay
		});
	}
	
}
