// --------------------------------------------------------
//    start 'er up!
// --------------------------------------------------------
jQuery(document).ready(
	function () {		
		initFadeText();	
		initPopularCommentsModule();		
		initLeadStories();
	}
);


// --------------------------------------------------------
//    fade in/fade out text above logo
// -------------------------------------------------------- 
function initFadeText() { 
	jQuery("#tagline").fadeTransition({pauseTime: 5000, transitionTime: 2000}); 
};


// --------------------------------------------------------
//    popular posts/comments
// --------------------------------------------------------
function initPopularCommentsModule () {
	jQuery("#most-popular-commented h3 a").click(handlePopularCommentsClick);
};

function handlePopularCommentsClick () {
	if (jQuery(this).is(".popular")) {
		jQuery("#most-popular").show();
		jQuery("#most-comments").hide();
	}
	else if (jQuery(this).is(".comments")) {
		jQuery("#most-popular").hide();
		jQuery("#most-comments").show();
	};
	
	jQuery("#most-popular-commented h3 a").removeClass("active");	
	jQuery(this).addClass("active");
	
	return false;
};

// --------------------------------------------------------
//   lead story scrolly things
// --------------------------------------------------------
var g_slideWidth = -1;

function initLeadStories () {
	jQuery("ul#nav-lead-stories li a").click(handleLeadStoriesNavClick);
	g_slideWidth = jQuery("ul#lead-stories-slides li:first-child").width();
	jQuery("ul#lead-stories-slides li").each(
		function (i) 		{
			jQuery(this).css({
				top: 0,
				left: i * g_slideWidth
			});
		}
	);
		
	jQuery("ul#lead-stories-slides").width(jQuery("ul#lead-stories-slides li").length * g_slideWidth);	
	jQuery("ul#lead-stories-slides").css("visibility", "visible").show();	
	jQuery("ul#nav-lead-stories").show();
};

function handleLeadStoriesNavClick () {
	var index = jQuery("#nav-lead-stories li").index(jQuery(this).parent());
	jQuery('#nav-lead-stories li:first-child a').addClass('cur');	
	jQuery("ul#lead-stories-slides").animate({
		left: -1 * index * g_slideWidth
	}, {
		duration: 750,
		easing: "swing",
		complete: function () { }
	});
    jQuery('.cur').removeClass('cur');
    jQuery(this).addClass('cur');
	return false;
};