YAHOO.namespace('gaia.app.Arena');
function initTabChangeWriting(settings){
	TabChangeWriting = new YAHOO.gaia.app.Arena.TabChangeWriting();
    TabChangeWriting.init(settings);
}
YAHOO.gaia.app.Arena.TabChangeWriting = function() {
    this._settings = null;
    this._ajaxRequest= null;
 }
YAHOO.gaia.app.Arena.TabChangeWriting.prototype.init = function(settings) {
	  this._settings = {
	  	 populartablink : YAHOO.util.Dom.get(settings.populartablink),
		 recenttablink : YAHOO.util.Dom.get(settings.recenttablink),
		 popularAjaxURLfiction: settings.popularAjaxURLfiction,
		 popularAjaxURLnonfiction: settings.popularAjaxURLnonfiction,
		 popularAjaxURLpoetry: settings.popularAjaxURLpoetry,
		 popularfictionsize : settings.popularfictionsize,
		 popularnonfictionsize : settings. popularnonfictionsize,
		 popularpoetryandlyricssize : settings.popularpoetryandlyricssize,
		 ajaxURLsettabcookie: settings.ajaxURLsettabcookie,
		 recentAjaxURLfiction: settings.recentAjaxURLfiction,
		 recentAjaxURLnonfiction: settings.recentAjaxURLnonfiction,
		 recentfictionsize : settings.recentfictionsize,
		 recentnonfictionsize : settings. recentnonfictionsize,
		 recentpoetryandlyricssize : settings.recentpoetryandlyricssize,
		 recentAjaxURLpoetry: settings.recentAjaxURLpoetry
		
		
	};
	var tabCookie = YAHOO.util.Cookie.get("tabType");
	if (tabCookie != null ) { 
        if( tabCookie == 'popular') {
			this._loadWritingPopularTab();
            YAHOO.util.Event.addListener(this._settings.recenttablink, "click", this._loadWritingRecentTab,this,true);
        }else if( tabCookie == 'recent'){
			this._loadWritingRecentTab();
			YAHOO.util.Event.addListener(this._settings.populartablink, "click", this._loadWritingPopularTab,this,true);
        }
    }else{
		this._loadWritingPopularTab();
        YAHOO.util.Event.addListener(this._settings.recenttablink, "click", this._loadWritingRecentTab,this,true);
     }
	
	
}
YAHOO.gaia.app.Arena.TabChangeWriting.prototype._setrecenttabCookie = function(e, elem_id){
	settabcookieRecent = new YAHOO.gaia.app.Arena.Setcookie(
	 {
	 			tabType : "recent",
				ajaxURL : this._settings.ajaxURLsettabcookie
	 } 
	);
	
}
YAHOO.gaia.app.Arena.TabChangeWriting.prototype._setpopulartabCookie = function(e, elem_id){
	settabcookiePopular = new YAHOO.gaia.app.Arena.Setcookie(
	 {
	 			tabType : "popular",
				ajaxURL : this._settings.ajaxURLsettabcookie
	 } 
	);
}
YAHOO.gaia.app.Arena.TabChangeWriting.prototype._loadWritingRecentTab = 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.recentfictionsize > 0) {
		browsepopularfiction = new YAHOO.gaia.app.Arena.Browse({
			arenaType: "writing",
			contentType: "text",
			request: "sublanding",
			results: 1,
			divId: "dhtml-carousel1",
			ajaxURL: this._settings.recentAjaxURLfiction
		});
	}
	if (this._settings.recentnonfictionsize > 0) {
		browsepopularnonfiction = new YAHOO.gaia.app.Arena.Browse({
			arenaType: "writing",
			contentType: "text",
			request: "sublanding",
			results: 1,
			divId: "dhtml-carousel2",
			ajaxURL: this._settings.recentAjaxURLnonfiction
		});
	}
	if (this._settings.recentpoetryandlyricssize > 0) {
		browsepopularpoetry = new YAHOO.gaia.app.Arena.Browse({
			arenaType: "writing",
			contentType: "text",
			request: "sublanding",
			results: 1,
			divId: "dhtml-carousel3",
			ajaxURL: this._settings.recentAjaxURLpoetry
		})
	}
	
}

YAHOO.gaia.app.Arena.TabChangeWriting.prototype._loadWritingPopularTab = 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);
	settabcookieRecent = new YAHOO.gaia.app.Arena.Setcookie(
	 {
	 			tabType : "popular",
				ajaxURL : this._settings.ajaxURLsettabcookie
	 } 
	);
	if(this._settings.popularfictionsize > 0){
	 browsepopularfiction = new YAHOO.gaia.app.Arena.Browse(
	 {
	 			arenaType : "writing",
				contentType : "text",
				request : "sublanding",
				results: 1,
				divId : "dhtml-carousel4",
				flag:1,
				ajaxURL : this._settings.popularAjaxURLfiction
	 } 
	);
	}
	if (this._settings.popularnonfictionsize > 0) {
		browsepopularnonfiction = new YAHOO.gaia.app.Arena.Browse({
			arenaType: "writing",
			contentType: "text",
			request: "sublanding",
			results: 1,
			divId: "dhtml-carousel5",
			flag: 1,
			ajaxURL: this._settings.popularAjaxURLnonfiction
		});
	}
	if (this._settings.popularpoetryandlyricssize > 0) {
		browsepopularpoetry = new YAHOO.gaia.app.Arena.Browse({
			arenaType: "writing",
			contentType: "text",
			request: "sublanding",
			results: 1,
			divId: "dhtml-carousel6",
			flag: 1,
			ajaxURL: this._settings.popularAjaxURLpoetry
		})
	}
	
}
