/************************************************
 *    @Module - topstories_ls.js
 *    @Developers:
 *          James Kersbergen [JHK :: jkersbergen@nexstar.tv]
 *    @Dependancy - Yahoo User Interface (YUI) library
 * 
 *  Initial javascript files for the top stories module
 *	sets initial variable values
 *	also contains AJAX calls for the module
 *
 * =================================
 * Revision History
 * =================================
 * Date          Developer    Description
 * ==========    =========    ====================
 * 2009.08.15    JHK          added this comment block to track updates
 *														added variable 'topstories_functions_build_num'
 *														added variable 'top_stories_min_width'
 * 2009.08.16    JHK          updated 'breakingNewsSuccess' to not rotate when only 1 item in breaking news
 * 2009.08.17    JHK          added variable 'top_stories_list_min_width'
 *														added variable 'top_stories_list_content_min_width'
 *														added logging to AJAX variables
 * 2009.08.18    JHK          updated 'tabContentSuccess" to return error to user if no results returned
 *
 ************************************************/
 
topstories_build_num = '7D9332-nxd'; // used to track latest file version
if (showLog) nxdLogCall("topstories_ls.js","enter file (build : "+topstories_build_num+")",null,"info","topstories_ls.js");

var breakingNewsURL = "/common/top_stories/ajax.php?data=breaking_news";
var breakingNewsResponse;
var breakingNewsRotateNum = 0;
var listItemSlideshowNum = 1;
var top_stories_container_height = 411;
var ts_legend_container_top = 388;
var count_tab_pageview = false;
var top_stories_min_width = 558; // smallest width for top stories container
var top_stories_list_min_width = 231;  // smallest width for top stories list container
var top_stories_list_content_min_width = 219;  // smallest width for top stories list item content

if (showLog)
{
	loggerArgs =  new Object ( );
	loggerArgs = 
	{
		"breakingNewsURL" : breakingNewsURL,
		"breakingNewsResponse" : breakingNewsResponse,
		"breakingNewsRotateNum" : breakingNewsRotateNum,
		"listItemSlideshowNum" : listItemSlideshowNum,
		"top_stories_container_height" : top_stories_container_height,
		"ts_legend_container_top" : ts_legend_container_top,
		"count_tab_pageview" : count_tab_pageview,
		"top_stories_min_width" : top_stories_min_width,
		"top_stories_list_min_width" : top_stories_list_min_width
	} 
	nxdLogCall("topstories_ls.js","js Variables",loggerArgs,"script","topstories_ls.js");
}

var breakingNewsSuccess = function(o)
{
	if (showLog) nxdLogCall("breakingNewsSuccess","enter",null,"ajax","topstories_ls.js");
	if(o.responseText !== undefined)
	{
		if (showLog) nxdLogCall("breakingNewsSuccess","responseText => defined",null,"ajax","topstories_ls.js");
		try
		{ 
			breakingNewsResponse = YAHOO.lang.JSON.parse(o.responseText);
			if (breakingNewsResponse.results.length >=1)
			{
				breakingNewsUpdateContent();
				YAHOO.util.Dom.setStyle("breakingnews_container","display","block");
				YAHOO.util.Dom.setStyle("module","height","503px");
				if (breakingNewsResponse.results.length > 1) breakingNewsInterval = setInterval("breakingNewsRotate()", 8000);
			}
			else if (showLog) nxdLogCall("breakingNewsSuccess","responseText => no results returned",null,"ajax","topstories_ls.js");
		}
		catch (e) {if (showLog) nxdLogCall("breakingNewsSuccess","responseText => defined",e,"error","topstories_ls.js");}
	}
}

var breakingNewsFailure = function(o)
{
	if (showLog) nxdLogCall("breakingNewsFailure","enter",null,"error","topstories_ls.js");
	if(o.responseText !== undefined)
	{
	}
}

var breakingNewsCallback =
{
	success:breakingNewsSuccess,
	failure: breakingNewsFailure
};

			
var tabContentIDs = '0';
var tabContentURL = "/common/top_stories/ajax.php?data=tab_content_ls&flag=all";
var tabContentResponse;
var tabContentNum = 0;

var tabContentSuccess = function(o)
{
	if (showLog) nxdLogCall("tabContentSuccess","enter",null,"ajax","topstories_ls.js");
	if(o.responseText !== undefined)
	{
		if (showLog) nxdLogCall("tabContentSuccess","responseText => defined",null,"ajax","topstories_ls.js");
		try
		{ 
			tabContentResponse = YAHOO.lang.JSON.parse(o.responseText);
			if (showLog) nxdLogCall("tabContentSuccess","typeof(tabContentResponse.results) "+ typeof(tabContentResponse.results),null,"ajax","topstories_ls.js");
			if (typeof(tabContentResponse.results) != 'undefined' && tabContentResponse.results.length >=1)
			{
				tabUpdateContent();
				activateListItemContent(1);
				startItemSlideshowInterval();
				if (count_tab_pageview) omCountTabPageview();
			}
			else
			{
				if (showLog) nxdLogCall("tabContentSuccess","responseText => no results returned",null,"ajax","topstories_ls.js");
				noResultsReturned();
			}
		}
		catch (e)
		{
			if (showLog) nxdLogCall("tabContentSuccess","responseText => defined",e,"error","topstories_ls.js");
			noResultsReturned('json_error');
		}
	}
}

var tabContentFailure = function(o)
{
	if (showLog) nxdLogCall("tabContentFailure","enter",null,"error","topstories_ls.js");
	if(o.responseText !== undefined)
	{
	}
}

var tabContentCallback =
{
	success:tabContentSuccess,
	failure:tabContentFailure
};

if (showLog) nxdLogCall("topstories_ls.js","exit file",null,"info","topstories_ls.js");