﻿$(document).ready(function() {
	//home page article cycles	
	var show_story = 0;
	var temp;
	var myTopStoryTimer;
	var is_active = true;
	var is_first_time = true;
	function next_story() {
    	if(is_active == true)
    	{
    	    if (is_first_time != true)
    	        is_active = false;
    	    else
    	        is_first_time = false;
    	            	        
		    if (show_story >= num_stories)
		    {
			    show_story = 0;
		    }
		    var x = show_story;

		    $("#r_top_summary .r_top_item:eq("+ temp +")").fadeOut("normal", function() 
		        {
		            $("#r_top_summary .r_top_item:eq("+ x +")").fadeIn("normal", function()
		                {
		                    is_active = true;
		                }
		            );
		        }
		    );

		    temp = x;
		    show_story++;

		    myTopStoryTimer = setTimeout(next_story, 5000);		
		}
	}


	$("#r_top_summary .r_top_item").css("display", "none");
	$("#r_top_summary .r_top_item:eq(0)").css("display", "block");
	$(".r_top_image").css("max-width", "250px");
	

	var num_stories = $("#r_top_summary .r_top_item").length;
    
	for (x = 0; x < num_stories; x++)
	{
		var pageNum = $("#r_top_pagination").append("<li><a id='goStory_" + x + "' href='#'>" + eval(x+1) + "</a></li>");
		$("#goStory_" + x).click( function() {						
			if (is_active == true)
			{			 
			    clearTimeout(myTopStoryTimer);
			    show_story = ($(this).html() -1);
			    next_story();			    
			}
		});
	}

	next_story();
	
	
	
	//fix image sizes
	
	function resize_tab_images() {
		var tab_num_images = $("#tab_main img").length;
	    for (y = 0; y < tab_num_images; y++)
	    {	        
	        $("#tab_main img:eq("+ y +")").width(180);	     
	    }
	    
	    var row_num_images = $("#r_top_ten img").length;
	    for (y = 0; y < tab_num_images; y++)
	    {	        
	        $("#r_top_ten img:eq("+ y +")").width(160);	     
	    }
	}
	    
    /*$("#tab_main").bind("click mousemove", function () {
	    resize_tab_images(); //call it once on the event
    });*/
	
	resize_tab_images(); //call it once to start it off.
	
	//remove empty sidebar div
	if (jQuery.trim($("#r_toolbar_outer").html()).length == 0)
    {
        $("#r_toolbar_outer").remove();
    }
    if (jQuery.trim($("#r_sidebar_outer").html()).length == 0)
    {
        $("#r_sidebar_outer").remove();
    }    
});


