GupShup.html.indexPage = {};

GupShup.html.indexPage.tabHeaderHolder = 'tabHeader';

GupShup.html.indexPage.changeTabHeader = function(newLabel) {
 document.getElementById(GupShup.html.indexPage.tabHeaderHolder).innerHTML = newLabel;
}

GupShup.html.indexPage.handleActiveTabChange = function (e) {
var oldTab = e.prevValue;
var newTab = e.newValue;
GupShup.connectionManager.addTransaction({obj:newTab.dataConnection,type:'TABSWITCH',onAbort:function(){newTab._loading = false;}});
if(oldTab == newTab)
	return;
else
{
	oldTab.set('content', "");
	GupShup.html.dynamicBar.update(oldTab.gupshupConf.tabType,newTab.gupshupConf.tabType,'right');
}
GupShup.html.indexPage.changeTabHeader(newTab.get('label'));
}

GupShup.html.indexPage.processIndexTabCustomResponse = function(text){
var xhr = new Object();
xhr.responseText = text;
xhr.argument = {tab:GupShup.conf.indexTabView.yahooTabView.get('activeTab')}
GupShup.callback.processIndexTabResponse(xhr);
}

GupShup.callback.processIndexTabResponse = function (xhr) {
	var tab = xhr.argument.tab;
	var indexPageContent = GupShup.util.getJsonFromResponse(xhr.responseText);
	if(indexPageContent.status == 'SUCCESS')
	{
		var ele = new Array();
		var paginationObj = {
			start:indexPageContent.params.start,
			total:'',
			returned:indexPageContent.entities.length,
			windowSize:1
		};
		var reqObj =  {
				url:GupShup.conf.readUrl,
				queryStr:'type=' + tab.gupshupConf.tabType, 
				callBack:{
				success:GupShup.callback.processIndexTabResponse,
				failure:GupShup.callback.processIndexTabError,
				argument:{tab:tab} 
				} 
			};
		switch(tab.gupshupConf.tabType)
		{
			case 'GLOBAL_POPULAR':
			case 'GLOBAL_MOST_JOINED':
			case 'GLOBAL_FEATURED':
			case 'GLOBAL_RECENTLY_CREATED': paginationObj.total = indexPageContent.totalForPg, paginationObj.windowSize = GupShup.conf.windowSize; break;
			case 'GLOBAL_PICTURE_TIMELINE': 
			case 'GLOBAL_TIMELINE' :	reqObj.queryStr += "&needTotalForPg=false";break;
		}
		var paginationContent = GupShup.util.expandPaginationTemplate(reqObj,paginationObj,tab.gupshupConf.tabType);
		if(paginationObj.windowSize == 1)
			ele = indexPageContent.entities.slice(0,GupShup.conf.ITEMS_PER_PAGE);
		else
			ele = indexPageContent.entities;
			
		var content = GupShup.util.expandTemplate(GupShup.util.getInnerHTML('entityMsgTemplate'),GupShup.msgTemplates.entityMsgMap,ele);
		tab.set('content', content + paginationContent);
	}
};

GupShup.callback.processIndexTabError = function (xhr, tab, args) {
}