/************************************************
 *    @Module - topstories_functions.js
 *    @Developers:
 *          James Kersbergen [JHK :: jkersbergen@nexstar.tv]
 *    @Dependancies:
 *					 - Yahoo User Interface (YUI) library
 *					 - topstories.js file loaded first
 * 
 *  Javascript functions used by the top stories module
 *
 * =================================
 * Revision History
 * =================================
 * Date          Developer    Description
 * ==========    =========    ====================
 * 2009.08.14    JHK          added this comment block to track updates
 *														added entry and exit logging
 *														initial creation of resizeTopStoriesModule()
 * 2009.08.15    JHK          initial creation of resizeTopStoriesModule()
 *														added variable 'topstories_functions_build_num'
 * 2009.08.16		 JHK          updated breakingNewsRotate()
 * 2009.08.17    JHK          updtaed tabUpdateContent()
 *														updated resizeTopStoriesModule()
 * 2009.08.18    JHK          updated listItemSlideshow()
 *                            updated switchTab()
 *                            updated listItemSlideshow()
 *                            initial creation of noResultsReturned()
 * 2009.08.27    JHK          initial creation of activateListItem()
 * 2009.08.31    JHK          updated activateListItemContent()
 * 2009.09.01    JHK          updated breakingNewsUpdateContent()
 * 2009.09.09    JHK          initial creation of topStorieslistItemMouseOver()
 *                            initial creation of topStorieslistItemMouseOut()
 *                            initial creation of topStorieslistItemMouseOverLoad()
 *                            updated activateListItem()
 *
 ************************************************/
 
topstories_functions_build_num = '7D938D-nxd'; // used to track latest file version
if (showLog) nxdLogCall("topstories_functions.js","enter file (build : "+topstories_functions_build_num+")",null,"info","topstories_functions.js");

function imageError(img,image_size)
{
	image_size = (typeof(image_size) == 'undefined') ? 0 : image_size;
	img.src='/common/top_stories/img/broken_'+image_size+'.gif';
}

/************************************************
 *    @Function - resizeTopStoriesModule
 *    @Author - James Kersbergen [JHK]
 *    @Arguments : n/a
 *    @Returns : formatted log message
 * 
 *  Resizes module to fit position.
 *
 * =================================
 * Revision History
 * =================================
 * Date          Developer    Description
 * ==========    =========    ====================
 * 2009.08.14    JHK          initial creation of function.
 * 2009.08.17    JHK          added list container and itmes resizing
 * 
 ************************************************/
function resizeTopStoriesModule()
{
	if (showLog) nxdLogCall("resizeTopStoriesModule()","enter function",null,"script","topstories_functions.js");
	if (top_stories_container_width >= top_stories_min_width)
	{
		top_stories_size_dif = top_stories_container_width - top_stories_min_width;
		top_stories_list_container_width = top_stories_list_min_width + top_stories_size_dif;
		top_stories_list_item_content_width = top_stories_list_content_min_width + top_stories_size_dif;
		top_stories_companion_banner_left = parseInt((top_stories_container_width-490)/2);
		top_stories_legend_left = parseInt((top_stories_container_width-376)/2);
		tab_num = tabsArray.tabs.length;
		tab_spacer_adjust = (7 * (tab_num -1)) + 12;
		tab_avail_space = top_stories_container_width - tab_spacer_adjust;
		tab_min_size = parseInt(tab_avail_space/tab_num);
		tab_rem_px = tab_avail_space%tab_num;
		if (showLog)
		{
			loggerArgs =  new Object ( );
			loggerArgs = { 'top_stories_size_dif' : top_stories_size_dif, 'top_stories_list_container_width' : top_stories_list_container_width, "top_stories_companion_banner_left" : top_stories_companion_banner_left, "top_stories_legend_left" : top_stories_legend_left, 'tab_num':tab_num, 'tab_spacer_adjust' : tab_spacer_adjust, 'tab_avail_space' : tab_avail_space, 'tab_min_size' : tab_min_size, 'tab_rem_px' : tab_rem_px };
			nxdLogCall("resizeTopStoriesModule()","js Variables",loggerArgs,"script","topstories_functions.js");
		}
		YAHOO.util.Dom.setStyle("top_stories_list","width",top_stories_list_container_width+"px");
		YAHOO.util.Dom.setStyle("tab_more","width",top_stories_list_container_width+"px");
		YAHOO.util.Dom.setStyle("tab_more_content","width",top_stories_list_item_content_width+"px");
		YAHOO.util.Dom.setStyle("top_stories_container","width",top_stories_container_width+"px");
		YAHOO.util.Dom.setStyle("top_stories_tab_container","width",top_stories_container_width+"px");
		YAHOO.util.Dom.setStyle("ts_compainion_banner","left",top_stories_companion_banner_left+"px");
		YAHOO.util.Dom.setStyle("ts_legend_container","left",top_stories_legend_left+"px");
		YAHOO.util.Dom.setStyle("top_stories_container","display","block");
		return true;
	}
	else
	{
		return false;
	}
}

/************************************************
 *    @Function -  initTopStories
 *    @Author - James Kersbergen [JHK]
 *    @Arguments : n/a
 *    @Returns : formatted log message
 * 
 *  Initializes the "Top Stories" module
 *
 * =================================
 * Revision History
 * =================================
 * Date          Developer    Description
 * ==========    =========    ====================
 * 2009.08.15    JHK          initial creation of function.
 * 
 ************************************************/
function initTopStories()
{
	if (showLog) nxdLogCall("initTopStories()","enter function",null,"script","simpletopstories.class.php");
	
	if (showLog) nxdLogCall("initTopStories()","[topstories_modules_arr_len :"+topstories_modules_arr_len+"]",null,"script","simpletopstories.class.php");
	
	/************************************************
	 *	Check module container size and return error
	 *  if container is too small using "top_stories_min_width" variable
	 ************************************************/
	if (top_stories_size_valid)
	{
		if (showLog) nxdLogCall("initTopStories()","container size OK",null,"info","simpletopstories.class.php");
		/************************************************
		 *	Check location and make Breaking News AJAX
		 *	call in on the home page
		 ************************************************/
		if (location.pathname == "/" || location.pathname == "/index.php")
		{
			if (showLog) nxdLogCall("initTopStories()","start breaking news AJAX Call",null,"AJAX","simpletopstories.class.php");
			YAHOO.util.Connect.asyncRequest('GET', breakingNewsURL, breakingNewsCallback);
		}
		if (showLog) nxdLogCall("initTopStories()","[tabsArray.tabs.length : "+tabsArray.tabs.length+"]",null,"script","simpletopstories.class.php");
			
		for (i=0;i<tabsArray.tabs.length;i++)
		{
			var tab_id = tabsArray.tabs[i].tab_id;
			var tab_cat_id = tabsArray.tabs[i].cat_id;
			var tab_link_id_str = "tab_"+tab_id+"_link";
			var tab_css_id = "tab_"+tab_id;
			var tab_link_el = document.getElementById(tab_link_id_str);
			
			YAHOO.util.Dom.setStyle(tab_css_id,"width",tab_min_size+"px");
			var tab_href = 'javascript:switchTab(\''+tab_cat_id+'\','+tab_id+')';
			if (showLog)
			{
				loggerArgs =  new Object ( );
				loggerArgs = { 'tab_id':tab_id, 'tab_cat_id' : tab_cat_id, 'tab_link_id_str' : tab_link_id_str, 'tab_href' : tab_href, 'tab_min_size' : tab_min_size };
				nxdLogCall("initTopStories()","js Variables",loggerArgs,"script","topstories_functions.js");
			}
			
			tab_link_el.href = tab_href;
		}
		
		if (YAHOO.util.Dom.hasClass('top_stories_tabs', 'display_none')) YAHOO.util.Dom.replaceClass("top_stories_tabs",'display_none','display_block');
		switchTab(tabsArray.tabs[0].cat_id, tabsArray.tabs[0].tab_id, false);
	}
	else
	{
		var top_stories_container_el = document.getElementById(topstories_module_div_id);
		top_stories_container_el.innerHTML = '<div class="dialog"><img src="/common/images/_.gif" class="dialog_img_24 dialog_cancel_24" />&ldquo;'+topstories_module_title+'&rdquo; is not available.</div>';
		if (showLog) nxdLogCall("initTopStories()","!!container size too small!!",null,"error","simpletopstories.class.php");
	}
	if (showLog) nxdLogCall("initTopStories()","exit function",null,"script","simpletopstories.class.php");
}

/************************************************
 *    @Function -  ts_tab_over
 *    @Author - James Kersbergen [JHK]
 *    @Arguments :
 *        el - current link element [obj] (required)
 *        tab - tab li tag id [str] (required)
 *    @Returns : true
 * 
 *  tab mouseover script
 *
 * =================================
 * Revision History
 * =================================
 * Date          Developer    Description
 * ==========    =========    ====================
 * 2009.08.15    JHK          initial creation of function.
 * 
 ************************************************/
function ts_tab_over(el,tab_css_id)
{
	if (showLog) nxdLogCall("ts_tab_over","enter function",null,"script","topstories_functions.js");
	if (YAHOO.util.Dom.hasClass(tab_css_id, 'normal') && !YAHOO.util.Dom.hasClass(tab_css_id, 'active')) YAHOO.util.Dom.replaceClass(tab_css_id,'normal','over');
	if (showLog) nxdLogCall("ts_tab_over","exit function [return : true]",null,"script","topstories_functions.js");
	return true;
}

/************************************************
 *    @Function -  ts_tab_out
 *    @Author - James Kersbergen [JHK]
 *    @Arguments :
 *        el - current link element [obj] (required)
 *        tab - tab li tag id [str] (required)
 *    @Returns : true
 * 
 *  tab mouseout script
 *
 * =================================
 * Revision History
 * =================================
 * Date          Developer    Description
 * ==========    =========    ====================
 * 2009.08.15    JHK          initial creation of function.
 * 
 ************************************************/
function ts_tab_out(el,tab_css_id)
{
	if (showLog) nxdLogCall("ts_tab_out","enter function",null,"script","topstories_functions.js");
	if (YAHOO.util.Dom.hasClass(tab_css_id, 'over')) YAHOO.util.Dom.replaceClass(tab_css_id,'over','normal');
	if (showLog) nxdLogCall("ts_tab_out","exit function [return : true]",null,"script","topstories_functions.js");
	return true;
}

function playVideo(videoID)
{
	if(typeof(listItemSlideshowInterval) != "undefined") clearInterval(listItemSlideshowInterval);
	loadVideo(videoID);
}

function startItemSlideshowInterval()
{
	listItemSlideshowInterval = setInterval("listItemSlideshow()", 5000);
}

function displayPrerollCompanion(adZoneID)
{
	if (adZoneID !== null)
	{
		adjustment = 62;
		var cbRnd =Math.floor(Math.random()*9999999999);
		var nRnd =Math.floor(Math.random()*9999);
		
		var ts_compainion_banner_image_el = document.getElementById('ts_compainion_banner_image');
		var ts_compainion_frame_el = document.getElementById('ts_compainion_frame');
		
		var top_stories_container_height_str = (top_stories_container_height + adjustment) + 'px';
		YAHOO.util.Dom.setStyle("top_stories_container","height",top_stories_container_height_str);
		
		var ts_legend_container_top_str = (ts_legend_container_top + adjustment) + 'px';
		YAHOO.util.Dom.setStyle("ts_legend_container","top",ts_legend_container_top_str);
		
		YAHOO.util.Dom.setStyle("ts_compainion_banner","display","block");
		YAHOO.util.Dom.setStyle(ts_compainion_banner_image_el,"display","block");
		
		var ad_src = 'http://ads.nexstardigital.com/www/delivery/afr.php?zoneid='+adZoneID+'&cb='+cbRnd;
		ts_compainion_frame_el.src = ad_src;
		
	}
	
}

function clearPrerollCompanion()
{

	var ts_compainion_banner_image_el = document.getElementById('ts_compainion_banner_image');
	ts_compainion_banner_image_el,innerHTML = '';
	
	YAHOO.util.Dom.setStyle("ts_compainion_banner","display","none");
	
	var top_stories_container_height_str = top_stories_container_height + 'px';
	YAHOO.util.Dom.setStyle("top_stories_container","height",top_stories_container_height_str);
	
	var ts_legend_container_top_str = ts_legend_container_top + 'px';
	YAHOO.util.Dom.setStyle("ts_legend_container","top",ts_legend_container_top_str);
	
}

/************************************************
 *    @Function -  tabUpdateContent
 *    @Author - James Kersbergen [JHK]
 *    @Arguments : n/a
 *    @Returns : true
 * 
 *  tab mouseout script
 *
 * =================================
 * Revision History
 * =================================
 * Date          Developer    Description
 * ==========    =========    ====================
 * 2009.08.17    JHK          added this comment block for tracking
 *														added logging
 *                            added list item resizing
 * 
 ************************************************/
function tabUpdateContent()
{
	if (showLog) nxdLogCall("tabUpdateContent()","enter function",null,"script","topstories_functions.js");
	var list_element = document.getElementById('top_stories_list');
	var tab_more_element = document.getElementById('tab_more_content');
	
	for (i=0; i< tabContentResponse.results.length; i++)
	{
		top_stories_preview_images = new Image(); 
		top_stories_preview_img =(tabContentResponse.results[i]['content_image'] == null) ? module_default_image : tabContentResponse.results[i]['content_image'];
		if (showLog) nxdLogCall("tabUpdateContent","Preload Image : '"+top_stories_preview_img+"'",null,"script","topstories_functions.js");
		top_stories_preview_images.src = top_stories_preview_img;
		
		
		listItemHtm = getListItemContent(i);
		YAHOO.util.Dom.setStyle('top_stories_list_loading',"display",'none');
		list_element.innerHTML += listItemHtm;
		var item_id = i + 1;
		var ts_list_item_id_str = 'item_'+item_id;
		var ts_list_item_content_id_str = 'item_'+item_id+'_content';
		var ts_list_item_headline_id_str = 'item_'+item_id+'_headline';
		var ts_list_item_date_id_str = 'item_'+item_id+'_date';
		
		if (showLog)
		{
			loggerArgs =  new Object ( );
			loggerArgs = { 'item_id': item_id, 'ts_list_item_id_str' : ts_list_item_id_str, 'ts_list_item_content_id_str' : ts_list_item_content_id_str, 'ts_list_item_headline_id_str' : ts_list_item_headline_id_str, 'ts_list_item_date_id_str' : ts_list_item_date_id_str, 'top_stories_list_container_width' : top_stories_list_container_width, 'top_stories_list_item_content_width' : top_stories_list_item_content_width  };
			nxdLogCall("tabUpdateContent()","js Variables",loggerArgs,"script","topstories_functions.js");
		}
		YAHOO.util.Dom.setStyle(ts_list_item_id_str,'width',top_stories_list_container_width+'px');
		YAHOO.util.Dom.setStyle(ts_list_item_content_id_str,'width',top_stories_list_item_content_width+'px');
		YAHOO.util.Dom.setStyle(ts_list_item_headline_id_str,'width',top_stories_list_item_content_width+'px');
		YAHOO.util.Dom.setStyle(ts_list_item_date_id_str,'width',top_stories_list_item_content_width+'px');
	}
	if (tabContentResponse.results.length < 8)
	{
		blank_item_htm = '<div id="item_blank" class="top_stories_list_item normal">\n';
		blank_item_htm += '<div id="item_blank_arrow" class="ts_arrow"><img src="\/common\/top_stories/img\/_.gif" class="ts_arrow_spacer"\/><\/div>\n';
		blank_item_htm += '<div id="item_blank_content" class="ts_content">\n';
		blank_item_htm += '<\/div>\n';
		blank_item_htm += '<\/div>\n';
		list_element.innerHTML += blank_item_htm;
		YAHOO.util.Dom.setStyle('item_blank','width',top_stories_list_container_width+'px');
		YAHOO.util.Dom.setStyle('item_blank_content','width',top_stories_list_item_content_width+'px');
	}
	
	
	temp_tab_num = active_tab-1;
	tab_more_element.innerHTML = '<a href="'+tabsArray.tabs[temp_tab_num]['more_link']+'" id="tab_more_link"><img src="\/common\/top_stories\/img\/_.gif" id="tab_more_icon" />More from '+tabsArray.tabs[temp_tab_num]['cat_name']+'<\/a>';
	YAHOO.util.Dom.setStyle('tab_more','display','block');
	
	if (showLog) nxdLogCall("tabUpdateContent","exit function",null,"script","topstories_functions.js");
}

/************************************************
 *    @Function -  setLoading
 *    @Author - James Kersbergen [JHK]
 *    @Arguments : n/a
 *    @Returns : n/a
 * 
 *  script used to swicth tab content
 *
 * =================================
 * Revision History
 * =================================
 * Date          Developer    Description
 * ==========    =========    ====================
 * 2009.08.18    JHK          added this comment block for change tracking
 *                            added logging
 *                            added code to adjust the left of the "top_stories_list_loading" block
 * 
 ************************************************/
function setLoading()
{
	if (showLog) nxdLogCall("setLoading()","enter function",null,"script","topstories_functions.js");
	var list_element = document.getElementById('top_stories_list');
	var video_player_object_el = document.getElementById('video_player_object');
	var tab_more_element = document.getElementById('tab_more_content');
	var detail_headline_el = document.getElementById('ts_story_detail_headline');
	var detail_dateline_el = document.getElementById('ts_story_detail_dateline');
	var detail_shorttext_el = document.getElementById('ts_story_detail_shorttext');
	YAHOO.util.Dom.setStyle('video_player_loading_container','display','block');
	YAHOO.util.Dom.setStyle('tab_more','display','none');
	list_element.innerHTML = '<div id="top_stories_list_loading">Loading...<br \/><img src="\/common\/top_stories\/img\/loading_bar.gif" class="ts_loading_bar" \/><\/div>';
	video_player_object_el.innerHTML = '';
	detail_shorttext_el.innerHTML = '';
	detail_dateline_el.innerHTML = '';
	detail_headline_el.innerHTML = '';
	if (showLog) nxdLogCall("setLoading()","exit function",null,"script","topstories_functions.js");
}

/************************************************
 *    @Function -   getListItemContent
 *    @Author - James Kersbergen [JHK]
 *    @Arguments :
 *        item_num - number of the item to activate [str] (required)
 *    @Returns : n/a
 * 
 *  load content HTML for a list item
 *
 * =================================
 * Revision History
 * =================================
 * Date          Developer    Description
 * ==========    =========    ====================
 * 2009.08.27    JHK          added this comment block for change tracking
 * 
 ************************************************/
function getListItemContent(item_num)
{
	item_id = item_num + 1;
	
	return_htm = '<div id="item_'+item_id+'" class="top_stories_list_item normal">\n';
	
	return_htm += '<div id="item_'+item_id+'_arrow" class="ts_arrow"><img src="\/common\/top_stories\/img\/_.gif" class="ts_arrow_spacer"\/><\/div>\n';
	
	return_htm += '<div id="item_'+item_id+'_content" class="ts_content">\n';
	return_htm += '<a href="'+tabContentResponse.results[item_num]['content_url']+'" onmouseover="topStorieslistItemMouseOver('+item_id+',true);true" onmouseout="topStorieslistItemMouseOut();true" class="ts_list_item_link">'
	
	ts_headline_video_icon = (!showIconView && tabContentResponse.results[item_num]['content_videourl'] != null) ? '<img src="\/common\/top_stories\/img\/_.gif" class="ts_video_icon" \/>' : '';
	
	return_htm += '<span id="item_'+item_id+'_headline" class="ts_list_headline">\n';
	return_htm += (tabContentResponse.results[item_num]['content_featured'] == 1) ? '<img src="\/common\/top_stories\/img\/_.gif" class="ts_featured_icon" title="Featured Story"\/>\n' : '';
	return_htm += tabContentResponse.results[i]['content_title']+'<\/span>\n';
	return_htm += '<span id="item_'+item_id+'_date" class="ts_list_date">\n';
	return_htm += tabContentResponse.results[item_num]['created_date_short'];
	return_htm += '<\/span>\n';
	return_htm += '</a>';
	
	if (showIconView)
	{
		return_htm += '<div id="item_'+item_id+'_iconview" class="ts_list_item_iconview">\n';
		return_htm += '<a href="'+tabContentResponse.results[item_num]['content_url']+'"><img src="\/common\/top_stories\/img\/_.gif" class="ts_read_icon" title="read more" \/><\/a>\n';
		return_htm += (tabContentResponse.results[item_num]['content_liveurl'] != null) ? '<a href="'+tabContentResponse.results[item_num]['content_liveurl']+'" target="_blank"><img src="\/common\/top_stories\/img\/_.gif" class="ts_live_icon" title="watch live" \/><\/a>\n' : '';
		return_htm += (tabContentResponse.results[item_num]['content_videourl'] != null) ? '<a href="'+tabContentResponse.results[item_num]['content_videourl']+'"><img src="\/common\/top_stories\/img\/_.gif" class="ts_watch_icon" title="watch video" \/><\/a>\n' : '';
		return_htm += '<\/div>\n';
	}
	return_htm += '<\/div>\n';
	
	return_htm += '<\/div>\n';
	
	return return_htm;
}


/************************************************
 *    @Function -  activateListItem
 *    @Author - James Kersbergen [JHK]
 *    @Arguments :
 *        item_num - id of the item to activate [str] (required)
 *        stop_interval - flag to determine if "listItemSlideshowInterval" should be stopped [bol] (required)
 *    @Returns : n/a
 * 
 *  script used to trigger active content chnage
 *
 * =================================
 * Revision History
 * =================================
 * Date          Developer    Description
 * ==========    =========    ====================
 * 2009.08.27    JHK          itital creation of this function
 * 
 ************************************************/
function activateListItem(item_num,stop_interval)
{
	if (showLog)
	{
		loggerArgs =  new Object ( );
		loggerArgs = { 'item_num': item_num, 'stop_interval' : stop_interval };
		nxdLogCall("activateListItem()","arguments",loggerArgs,"info","topstories_functions.js");
	}
	if (videoPlayerStateCode != 3)
	{
		if (showLog) nxdLogCall("activateListItem()","[active_item_css_id : "+active_item_css_id+"]",null,"info","topstories_functions.js");
		if (active_item_css_id != 'item_'+item_num) activateListItemContent(item_num,stop_interval);
	}
	else
	{
		if (showLog) nxdLogCall("activateListItem()","video playing no item change...",null,"info","topstories_functions.js");
	}
}


/************************************************
 *    @Function -  topStorieslistItemMouseOver
 *    @Author - James Kersbergen [JHK]
 *    @Arguments :
 *        item_num - id of the item to activate [str] (required)
 *        stop_interval - flag to determine if "listItemSlideshowInterval" should be stopped [bol] (required)
 *    @Returns : n/a
 * 
 *  script used to trigger active content chnage
 *
 * =================================
 * Revision History
 * =================================
 * Date          Developer    Description
 * ==========    =========    ====================
 * 2009.09.09    JHK          itital creation of this function
 * 
 ************************************************/
 function topStorieslistItemMouseOver(item_num,stop_interval)
 {
	if (showLog)
	{
		loggerArgs =  new Object ( );
		loggerArgs = { 'item_num': item_num, 'stop_interval' : stop_interval };
		nxdLogCall("topStorieslistItemMouseOver()","arguments",loggerArgs,"info","topstories_functions.js");
	}
	top_stories_over_list_item = item_num;
	
	setTimeout("topStorieslistItemMouseOverLoad("+item_num+","+stop_interval+")",top_stories_list_item_change_delay);
	
	if (showLog) nxdLogCall("topStorieslistItemMouseOver()","[top_stories_over_list_item : "+top_stories_over_list_item+"]",null,"script","topstories_functions.js");
 	if (showLog) nxdLogCall("topStorieslistItemMouseOver()","exit function",null,"script","topstories_functions.js");
 }


/************************************************
 *    @Function -  topStorieslistItemMouseOverLoad
 *    @Author - James Kersbergen [JHK]
 *    @Arguments :
 *        item_num - id of the item to activate [str] (required)
 *        stop_interval - flag to determine if "listItemSlideshowInterval" should be stopped [bol] (required)
 *    @Returns : n/a
 * 
 *  script used to trigger active content change
 *
 * =================================
 * Revision History
 * =================================
 * Date          Developer    Description
 * ==========    =========    ====================
 * 2009.09.09    JHK          itital creation of this function
 * 
 ************************************************/
 function topStorieslistItemMouseOverLoad(item_num,stop_interval)
 {
	if (showLog)
	{
		loggerArgs =  new Object ( );
		loggerArgs = { 'item_num': item_num, 'stop_interval' : stop_interval };
		nxdLogCall("topStorieslistItemMouseOverLoad()","arguments",loggerArgs,"info","topstories_functions.js");
	}
 	if (top_stories_over_list_item == item_num)
 	{
 		activateListItem(item_num,stop_interval);
 	}
 	else
 	{
 		if (showLog) nxdLogCall("topStorieslistItemMouseOverLoad()","no item change, mouse no longer over item",null,"info","topstories_functions.js");
 	}
 	if (showLog) nxdLogCall("topStorieslistItemMouseOverLoad()","exit function",null,"script","topstories_functions.js");
 }


/************************************************
 *    @Function -  topStorieslistItemMouseOut
 *    @Author - James Kersbergen [JHK]
 *    @Arguments : n/a
 *    @Returns : n/a
 * 
 *  changes the 'top_stories_over_list_item' variable
 *
 * =================================
 * Revision History
 * =================================
 * Date          Developer    Description
 * ==========    =========    ====================
 * 2009.09.09    JHK          itital creation of this function
 * 
 ************************************************/
 function topStorieslistItemMouseOut()
 {
 	if (showLog) nxdLogCall("topStorieslistItemMouseOut()","enter function",null,"script","topstories_functions.js");
	top_stories_over_list_item = -1;
	if (showLog) nxdLogCall("topStorieslistItemMouseOut()","[top_stories_over_list_item : "+top_stories_over_list_item+"]",null,"script","topstories_functions.js");
 	if (showLog) nxdLogCall("topStorieslistItemMouseOut()","exitr function",null,"script","topstories_functions.js");
 }


/************************************************
 *    @Function -  activateListItemContent
 *    @Author - James Kersbergen [JHK]
 *    @Arguments :
 *        item_num - id of the item to activate [str] (required)
 *        stop_interval - flag to determine if "listItemSlideshowInterval" should be stopped [bol] (required)
 *    @Returns : n/a
 * 
 *  script used change the active content
 *
 * =================================
 * Revision History
 * =================================
 * Date          Developer    Description
 * ==========    =========    ====================
 * 2009.08.27    JHK          added this comment block for change tracking
 * 2009.08.31    JHK          added animation to acivation
 * 2009.09.02    JHK          changed animation to use cover div
 * 
 ************************************************/
function activateListItemContent(item_num,stop_interval)
{
	var detail_headline_el = document.getElementById('ts_story_detail_headline');
	var detail_dateline_el = document.getElementById('ts_story_detail_dateline');
	var detail_shorttext_el = document.getElementById('ts_story_detail_shorttext');
	var video_player_object_el = document.getElementById('video_player_object');
	var video_swf_container_el = document.getElementById('video_player_swf_container');
	var item_result_num = item_num - 1;
	
	stop_interval = (typeof(stop_interval) == 'undefined') ? false : stop_interval;
	if (stop_interval)
	{
		listItemSlideshowNum = 1;
		if(typeof(listItemSlideshowInterval) != "undefined") clearInterval(listItemSlideshowInterval);
	}
	
	clearPrerollCompanion();
	
	video_swf_container_el.innerHTML = '<div id="video_player_swf"><\/div>';
	
	YAHOO.util.Dom.setStyle(video_player_object_el,'display','block');
	
	for (i=1; i<= tabContentResponse.results.length; i++)
	{
		item_css_id = 'item_'+i;
		if (YAHOO.util.Dom.hasClass(item_css_id, 'active')) YAHOO.util.Dom.replaceClass(item_css_id,'active','normal');
	}
	active_item_css_id = 'item_'+item_num;
	YAHOO.util.Dom.replaceClass(active_item_css_id,'normal','active');
	detail_headline_htm = '<a href="'+tabContentResponse.results[item_result_num]['content_url']+'">'+tabContentResponse.results[item_result_num]['content_title']+'</a>';
	detail_dateline_htm = tabContentResponse.results[item_result_num]['created_date_long'];
	read_more_htm = '&nbsp;&nbsp;&nbsp;<a href="'+tabContentResponse.results[item_result_num]['content_url']+'">read more&raquo;</a>';
	detail_shorttext_htm = tabContentResponse.results[item_result_num]['content_shorttext']+read_more_htm;
	
	YAHOO.util.Dom.setStyle('video_player_loading_container','display','none');
	
	video_object_img = (tabContentResponse.results[item_result_num]['content_image'] == null) ? module_default_image : tabContentResponse.results[item_result_num]['content_image'];
	video_object_controller_img = (tabContentResponse.results[item_result_num]['content_videourl'] == null) ? '/common/images/_.gif' : '/common/top_stories/img/controller_flash_320.gif';
	
	video_object_link_open = (tabContentResponse.results[item_result_num]['media_file'] == null)? '' : '<a href="javascript:playVideo('+tabContentResponse.results[item_result_num]['media_id']+');">';
	video_object_link_close = (tabContentResponse.results[item_result_num]['media_file'] == null)? '' : '<\/a>';
	
	preview_image_link_open = (tabContentResponse.results[item_result_num]['media_file'] == null) ? '<a href="'+tabContentResponse.results[item_result_num]['content_url']+'">' : '';
	preview_image_link_close = (tabContentResponse.results[item_result_num]['media_file'] == null) ? '</a>' : '';
	
	video_object_htm = '<div id="video_player_image_container">'+preview_image_link_open+'<img src="'+video_object_img+'" id="video_player_image" onerror="imageError(this,4)"  \/>'+preview_image_link_close+'<\/div>\n';
	video_object_htm += '<div id="video_player_controller_container">'+video_object_link_open+'<img src="'+video_object_controller_img+'" id="video_player_controller" \/>'+video_object_link_close+'<\/div>\n';
	video_object_htm += (tabContentResponse.results[item_result_num]['content_videourl'] == null) ? '' : '<div id="video_player_play_image_container">'+video_object_link_open+'<img src="/common/videoplayer/img/play_320.gif" id="video_player_play_image" alt="watch video" \/>'+video_object_link_close+'<\/div>';
	
	YAHOO.util.Dom.setStyle('top_stories_detail_fader','display','block');
	
	var deactivateAnim = new YAHOO.util.Anim('top_stories_detail_fader');
	deactivateAnim.attributes.opacity = { to: 1 };
	deactivateAnim.duration = 0.5;
	
	var activateAnim = new YAHOO.util.Anim('top_stories_detail_fader');
	activateAnim.attributes.opacity = { to: 0 };
	activateAnim.duration = 0.5;

	
	deactivateAnim.onComplete.subscribe(function() {
		detail_headline_el.innerHTML = detail_headline_htm;
		detail_dateline_el.innerHTML = detail_dateline_htm;
		detail_shorttext_el.innerHTML = detail_shorttext_htm;
		video_player_object_el.innerHTML = video_object_htm;
		activateAnim.animate();
	});
	
	activateAnim.onComplete.subscribe(function() {
		YAHOO.util.Dom.setStyle('top_stories_detail_fader','display','none');
	});
	
	deactivateAnim.animate();
	
}

/************************************************
 *    @Function -   breakingNewsUpdateContent
 *    @Author - James Kersbergen [JHK]
 *    @Arguments :
 *        item_num - id of the item to activate [str] (required)
 *        stop_interval - flag to determine if "listItemSlideshowInterval" should be stopped [bol] (required)
 *    @Returns : n/a
 * 
 *  script used change the active content
 *
 * =================================
 * Revision History
 * =================================
 * Date          Developer    Description
 * ==========    =========    ====================
 * 2009.09.01    JHK          added this comment block for change tracking
 *                            added animation to acivation
 *                            added image preload
 * 
 ************************************************/
function breakingNewsUpdateContent(story_number,clear_content)
{
	story_number = (typeof(story_number) == 'undefined') ? 0 : story_number;
	var bn_headline = document.getElementById('breakingnews_headline');
	var bn_shorttext = document.getElementById('breakingnews_shorttext');
	var bn_img_container = document.getElementById('breakingnews_image_container');
	var bn_image = document.getElementById('breakingnews_image');
	var bn_video = document.getElementById('breakingnews_video');
	var bn_image_src;
	YAHOO.util.Dom.setStyle("breakingnews_container","width",top_stories_container_width+"px");
	bn_headline_left = 10;
	bn_headline_width = top_stories_container_width-20;
	bn_shorttext_left = bn_headline_left + 10;
	bn_shorttext_width = bn_headline_width - 20;
	bn_image_left = 3;
	bn_img_container_width = 86;
	bn_img_container_display = 'none';
	bn_video_display = 'none';
	bn_video_htm = '';
	
	var bn_video_dsp = (breakingNewsResponse.results[story_number].content_videourl !== null || breakingNewsResponse.results[story_number].content_liveurl !== null) ? true: false;
	var bn_live_dsp = (breakingNewsResponse.results[story_number].content_liveurl !== null) ? true: false;
	var bn_image_dsp = (breakingNewsResponse.results[story_number].content_image !== null || bn_video_dsp) ? true: false;
	
	
	
	if (bn_image_dsp)
	{
	
		breakingnews_preview_images = new Image(); 
		breakingnews_preview_img =breakingNewsResponse.results[story_number].content_image;
		if (showLog) nxdLogCall("breakingNewsUpdateContent","Preload Image : '"+breakingnews_preview_img+"'",null,"script","topstories_functions.js");
		breakingnews_preview_images.src = breakingnews_preview_img;
	
		bn_headline_left += (bn_video_dsp) ? 139 : 96;
		bn_headline_width -= (bn_video_dsp) ? 139 : 96;
		bn_shorttext_left = bn_headline_left + 10;
		bn_shorttext_width = bn_headline_width - 20;
		bn_image_left = (bn_video_dsp) ? 46 : 3;
		bn_img_container_width = (bn_video_dsp) ? 129 : 86;
		bn_img_container_display = "block";
		bn_image_src = breakingNewsResponse.results[story_number].content_image;
		if (bn_video_dsp)
		{
			bn_video_display = 'block';
			bn_video_url = (bn_live_dsp) ? breakingNewsResponse.results[story_number].content_liveurl : breakingNewsResponse.results[story_number].content_videourl;
			bn_live_txt = (bn_live_dsp) ? ' LIVE ' : ' Video ';
			bn_live_target = (bn_live_dsp) ? ' target="_blank"' : '';
			bn_video_htm = '<a href="'+bn_video_url+'"'+bn_live_target+'">Watch'+bn_live_txt+'Now!<\/a>';
		}
	}
	
	
	
	
	
	var deactivateBreakingAnim = new YAHOO.util.Anim('breakingnews_content');
	deactivateBreakingAnim.attributes.top = { to: 75, units: 'px' };
	deactivateBreakingAnim.duration = 0.75;
	
	var activateBreakingAnim = new YAHOO.util.Anim('breakingnews_content');
	activateBreakingAnim.attributes.top = { to: 0, units: 'px' };
	activateBreakingAnim.duration = 0.75;

	
	deactivateBreakingAnim.onComplete.subscribe(function() {
		YAHOO.util.Dom.setStyle(bn_headline,"left",bn_headline_left+"px");
		YAHOO.util.Dom.setStyle(bn_headline,"width",bn_headline_width+"px");
		YAHOO.util.Dom.setStyle(bn_shorttext,"left",bn_shorttext_left+"px");
		YAHOO.util.Dom.setStyle(bn_shorttext,"width",bn_shorttext_width+"px");
		YAHOO.util.Dom.setStyle(bn_image,"left",bn_image_left+"px");
		YAHOO.util.Dom.setStyle(bn_img_container,"width",bn_img_container_width+"px");
		YAHOO.util.Dom.setStyle(bn_video,"display",bn_video_display);
		YAHOO.util.Dom.setStyle(bn_img_container,"display",bn_img_container_display);
		YAHOO.util.Dom.setStyle(bn_video,"display",bn_video_display);
		bn_video.innerHTML = bn_video_htm;
		bn_image.innerHTML = '<a href="'+breakingNewsResponse.results[story_number].content_url+'"><img src="'+bn_image_src+'" width="80px" height="60px" onerror="imageError(this)" \/></a>';
		bn_headline.innerHTML = '<a href="'+breakingNewsResponse.results[story_number].content_url+'">'+breakingNewsResponse.results[story_number].content_title+'<\/a>';
		bn_shorttext.innerHTML = breakingNewsResponse.results[story_number].content_shorttext+'&nbsp;&nbsp;&nbsp;<a href="'+breakingNewsResponse.results[story_number].content_url+'">read more&raquo;<\/a>';
		activateBreakingAnim.animate();
	});
	
	deactivateBreakingAnim.animate();
	
	
	
}

/************************************************
 *    @Function -  breakingNewsRotate
 *    @Author - James Kersbergen [JHK]
 *    @Arguments : n/a
 *    @Returns : n/a
 * 
 *  rotate content for breaking news box
 *
 * =================================
 * Revision History
 * =================================
 * Date          Developer    Description
 * ==========    =========    ====================
 * 2009.08.16    JHK          added this comment block to track updates
 *														added log code for debugging
 * 
 ************************************************/
function breakingNewsRotate()
{
	if (showLog) nxdLogCall("breakingNewsRotate()","enter function",null,"info","topstories_functions.js");
	numMax = breakingNewsResponse.results.length;
	if (showLog) nxdLogCall("breakingNewsRotate()","[numMax : "+numMax+"]",null,"script","topstories_functions.js");
	breakingNewsRotateNum++;
	if (breakingNewsRotateNum == breakingNewsResponse.results.length) breakingNewsRotateNum = 0;
	breakingNewsUpdateContent(breakingNewsRotateNum);
	if (showLog) nxdLogCall("breakingNewsRotate()","exit function",null,"info","topstories_functions.js");
}


/************************************************
 *    @Function -  listItemSlideshow
 *    @Author - James Kersbergen [JHK]
 *    @Arguments : n/a
 *    @Returns : n/a
 * 
 *  activates next item in the list
 *
 * =================================
 * Revision History
 * =================================
 * Date          Developer    Description
 * ==========    =========    ====================
 * 2009.08.18    JHK          added comment block for change tracking
 *														added logging
 *                            updated "numMax" to show last item
 * 
 ************************************************/
function listItemSlideshow()
{
	if (showLog) nxdLogCall("listItemSlideshow()","enter function",null,"info","topstories_functions.js");
	numMax = tabContentResponse.results.length + 1;
	listItemSlideshowNum++;
	if (listItemSlideshowNum > numMax)
	{
		listItemSlideshowNum = 1;
		clearInterval(listItemSlideshowInterval);
	}
	activateItemNum = (listItemSlideshowNum > 1) ? listItemSlideshowNum - 1 : listItemSlideshowNum;
	if (showLog)
	{
		loggerArgs =  new Object ( );
		loggerArgs = { 'numMax': numMax, 'listItemSlideshowNum' : listItemSlideshowNum, 'activateItemNum' : activateItemNum  };
		nxdLogCall("listItemSlideshow()","js Variables",loggerArgs,"script","topstories_functions.js");
	}
	activateListItem(activateItemNum);
	if (showLog) nxdLogCall("listItemSlideshow()","exit function",null,"info","topstories_functions.js");
}

function omCountTabPageview()
{
	s.t();
}

/************************************************
 *    @Function -  switchTab
 *    @Author - James Kersbergen [JHK]
 *    @Arguments :
 *        cat_id - category id for the tab [str] (required)
 *        tab_id - tab id switching to [str] (required)
 *        tab_pageview - boolean used to determain if to count a page view for tab refresh [bol]
 *    @Returns : n/a
 * 
 *  script used to swicth tab content
 *
 * =================================
 * Revision History
 * =================================
 * Date          Developer    Description
 * ==========    =========    ====================
 * 2009.08.18    JHK          added this comment block for change tracking
 *                            added logging
 *														added code to remove the mouseover when clicked
 * 
 ************************************************/
function switchTab(cat_id, tab_id, tab_pageview)
{
	if (showLog)
	{
		loggerArgs =  new Object ( );
		loggerArgs = { 'cat_id': cat_id, 'tab_id' : tab_id, 'tab_pageview' : tab_pageview  };
		nxdLogCall("switchTab()","arguments",loggerArgs,"info","topstories_functions.js");
	}
	tab_pageview = (typeof(tab_pageview) == 'undefined') ? true : tab_pageview;
	count_tab_pageview = tab_pageview;
	if(active_tab != tab_id)
	{
		if (showLog) nxdLogCall("switchTab()","tab not active :: start content refresh",null,"script","topstories_functions.js");
		var act_tab_css_id = 'tab_'+tab_id;
		if (YAHOO.util.Dom.hasClass(act_tab_css_id, 'over')) YAHOO.util.Dom.replaceClass(act_tab_css_id,'over','normal');
		active_tab = tab_id;
		active_tab_cat_id = cat_id;
		listItemSlideshowNum = 1;
		if(typeof(listItemSlideshowInterval) != "undefined") clearInterval(listItemSlideshowInterval);
		clearPrerollCompanion();
		for (i=0; i<=js_tab_count; i++)
		{
			tab_num = i + 1;
			tab_css_id = 'tab_'+tab_num;
			if (YAHOO.util.Dom.hasClass(tab_css_id, 'active')) YAHOO.util.Dom.replaceClass(tab_css_id,'active','inactive');
			if (tab_num == tab_id) YAHOO.util.Dom.replaceClass(tab_css_id,'inactive','active');
		}
		
		setLoading();
		
		tabContentURL = tabContentURL+'&cat_id='+cat_id+'&xids='+tabContentIDs;
		YAHOO.util.Connect.asyncRequest('GET', tabContentURL, tabContentCallback);
		tabContentURL = "/common/top_stories/ajax.php?data=tab_content";
	}
	
	if (showLog) nxdLogCall("switchTab()","exit function",null,"info","topstories_functions.js");

}


/************************************************
 *    @Function -  noResultsReturned
 *    @Author - James Kersbergen [JHK]
 *    @Arguments :
 *        error_code - error if this is as a result of an error [str]
 *    @Returns : n/a
 * 
 *  updated display when no results are returned from Tab AJAX call
 *
 * =================================
 * Revision History
 * =================================
 * Date          Developer    Description
 * ==========    =========    ====================
 * 2009.08.18    JHK          initial creation of script
 * 2009.08.19    JHK          added error code
 * 
 ************************************************/
function noResultsReturned(error_code)
{
	if (showLog)
	{
		loggerArgs =  new Object ( );
		loggerArgs = { 'error_code': error_code  };
		nxdLogCall("noResultsReturned()","enter function",loggerArgs,"info","topstories_functions.js");
	} 
	
	var dialog_icon_type = (typeof(error_code) == 'undefined') ? 'info' : 'warning';
	var list_element = document.getElementById('top_stories_list');
	var video_player_object_el = document.getElementById('video_player_object');
	var tab_more_element = document.getElementById('tab_more_content');
	var detail_headline_el = document.getElementById('ts_story_detail_headline');
	var detail_dateline_el = document.getElementById('ts_story_detail_dateline');
	var detail_shorttext_el = document.getElementById('ts_story_detail_shorttext');
	YAHOO.util.Dom.setStyle('video_player_loading_container','display','none');
	
	var tab_arr_pos = active_tab -1;
	if (showLog) nxdLogCall("noResultsReturned()","[tab_arr_pos : "+tab_arr_pos+"]",null,"info","topstories_functions.js");
	
	list_element.innerHTML = '<div id="top_stories_list_error" class="dialog"><img src="/common/images/_.gif" class="dialog_img_32 dialog_'+dialog_icon_type+'_32" />No Stories found for &ldquo;'+tabsArray.tabs[tab_arr_pos].cat_name+'&rdquo;<\/div>';



	var video_player_object_el = document.getElementById('video_player_object');
	
	video_object_img = module_default_image;
	video_object_controller_img = 'controller_blank_320.gif';
	
	video_object_htm = '<div id="video_player_image_container"><img src="'+video_object_img+'" id="video_player_image" onerror="imageError(this,4)"  \/><\/div>\n';
	video_object_htm += '<div id="video_player_controller_container"><img src="/common/images/_.gif" id="video_player_controller" \/><\/div>\n';
	
	video_player_object_el.innerHTML = video_object_htm;
	
	YAHOO.util.Dom.setStyle('tab_more','display','none');
	
	if (showLog) nxdLogCall("noResultsReturned()","exit function",null,"info","topstories_functions.js");
}

if (showLog) nxdLogCall("topstories_functions.js","exit file",null,"info","topstories_functions.js");
