
// CREATED ON JANUARY 22, 2009
// CREATED BY MZ

$(document).ready(function()
{
	// IF THERE ARE 6 OR LESS STORIES, THE CAROUSEL IS NOT USED.
	// THE BUTTON ARROWS ARE NOT INSERTED, SO THE LEFT MARGIN NEEDS TO BE CORRECTED
	if ($(".slide_block li").length <= 3)
	{
		$(".slide_block").css("margin-left", "32px");
	} // if
	
	$("#monthselect").bind("change", function()
	{
		var sel = $(this).val();
		if (sel != "") { window.location = sel; } // if
	}); // #monthselect.bind
	
	// ACTIVATE JCAROUSEL LITE
	$(".slide_block").jCarouselLite({btnNext: ".next", btnPrev: ".prev"});
	
	// BUTTON ROLLOVER EVENTS
	var slideNavOver = function()
	{
		$(this).find("img").attr("src", $(this).find("img").attr("src").replace("off", "rollover"));
	}; // slideNavOver
	
	var slideNavOut = function()
	{
		$(this).find("img").attr("src", $(this).find("img").attr("src").replace("rollover", "off"));
	}; // slideNavOut
	
	$(".prev, .next").hover(slideNavOver, slideNavOut);
	
	// FOR FEATUERD ARTICLE
	if ($("#storyList2in").length == 1)
	{
		var lineSize = $("#storyList2 p").css("line-height").replace("px", "");
		
		var readMoreSpacing = $("#storyList2readmore").outerHeight();
		var trueHeight = (2 * $("#storyList2").height()) - $("#storyList2").outerHeight();
		var relativePositionTop = Math.round($("#storyList2in").position().top - $("#storyList2").position().top);
		
		var newHeight = trueHeight - relativePositionTop - readMoreSpacing;
		var rem = newHeight % lineSize;
		
		if (rem > 0 && rem <= 2)
		{
			newHeight = parseInt(newHeight) + parseInt(lineSize);
		} // if
		
		newHeight = newHeight - rem;
		$("#storyList2in").height(newHeight);
	} // if
	
	// JQUERY TOOLTIP
	var moveTip = function(e)
	{
		var x = e.pageX + 5;
		var y = e.pageY + 10;
		var tipW = $("#ztooltip").outerWidth();
		var tipH = $("#ztooltip").outerHeight();
		var windowW = $(window).width();
		var windowH = $(window).height();
		var scrL = $(document).scrollLeft(); // AMOUNT HIDDEN TO THE LEFT
		var scrT = $(document).scrollTop(); // AMOUNT HIDDEN TO THE TOP
		if ((x - scrL + tipW) > windowW) // IF TIP STARTS GOING OFF SCREEN TO THE RIGHT
		{
			x = windowW - tipW + scrL;
		} // if
		if ((y - scrT + tipH) > windowH) // IF TIP STARTS GOING OFF SCREEN TO THE BOTTOM
		{
			y = windowH - tipH + scrT;
		} // if
		$("#ztooltip").css({left: x + "px", top: y + "px"});
	}; // moveTip
	var tip = "";
	var showTip = function(e)
	{
		tip = $(this).attr("title");
		$(this).attr("title", "");
		if (tip === "") { return; }
		$("body").append("<div id='ztooltip'>" + tip + "</div>");
		$("#ztooltip").width(320);
		$("#ztooltip").css({"background-color": "#8bd", "border": "1px solid #369", "padding": "4px", "position": "absolute"});
		moveTip(e);
	}; // showTip
	var hideTip = function(e)
	{
		$(this).attr("title", tip);
		$("#ztooltip").remove();
	}; // hideTip
	$("*[title]").hover(showTip, hideTip); // *[title].hover
	$("*[title]").mousemove(moveTip); // *[title].mousemove
}); // document.ready

