$(window).load
(
function()
{
	var graphH = $(".products-graph").height();
	if(graphH<=244)
	{
	var graphMarginTop = $(".products-graph").css("marginTop");
	var newMargin = 244-graphH;
	$(".products-graph").css("marginTop", newMargin/2);
	$(".products-graph-title").addClass("products-graph-title-absolute");
	}
}
);
$(document).ready
(
function ()
{
	$(".columnize").columnize({width: 400, lastNeverTallest: true, ignoreImageLoading: true});
	
	var ulOffset = $("#main-ul").offset();
	if(ulOffset.top!=0)
	{
		$("#main-ul").css({top: -ulOffset.top});
	}
	var win=$(window).width();
	var doc=$(document).width();
	
	$(".main-li").hover
	(
	function()
	{
		if($(this).hasClass("expanded") == false)
		{
			clearExpanded();
		}
	},
	function()
	{
		if($(this).hasClass("expanded") == false)
		{
			clearExpanded();
		}
		$(".sub-ul").hide();
	}
	);
	
	function clearNav()
	{
		$(".sub-ul").hide();
		$(".main-li").removeClass("expanded");
	}
	function clearExpanded()
	{
		$(".expanded a").removeClass("active"); 
	}
	$(document).click
	(
	function()
	{
		clearNav();
		clearExpanded();
		$(".main-li a").removeClass("active"); 
	}
	);
	$(document).keyup
	(
	function(e) 
	{
	  if (e.keyCode == 27) 
	{ 
		clearNav();
		clearExpanded();
		$(".main-li a").removeClass("active"); 
	}
	});
	$(".sub-li").click
	(
	function()
	{
		var href=$("a", this).attr('href');
		window.location=href;
	}
	);
	$(".expandable").click
	(
	function()
	{
		if($(this).hasClass("expanded"))
		{
			clearNav();
		}
		else
		{
			clearNav();
			clearExpanded();
			$(".sub-ul", this).show();
			$(this).addClass("expanded"); 
			var subTop = $("#header").height()+1;
			var liPos = $(this).position();
			var subLeft = liPos.left-1;
			$(".sub-ul", this).css({top: subTop, left: subLeft});
			$("a:last", this).css({"border-bottom": "1px solid #666"});
			var subLiW = $(".sub-li", this).widestSize();
			var mainLiW = $(this).width();
			if(subLiW < mainLiW)
			{
				$(".sub-li", this).width(mainLiW+20);
			}
		}
		return false;
	}
	);
	$(".expandable").mouseover
	(
	function()
	{
		if($(".main-li").hasClass("expanded"))
		{
			clearNav();
			clearExpanded();
			$(".sub-ul", this).show();
			$(this).addClass("expanded");
			var subTop = $("#header").height()+1;
			var liPos = $(this).position();
			var subLeft = liPos.left-1;
			$(".sub-ul", this).css({top: subTop, left: subLeft});
			$("a:last", this).css({"border-bottom": "1px solid #666"});
			var subLiW = $(".sub-li", this).widestSize();
			var mainLiW = $(this).width();
			if(subLiW < mainLiW)
			{
				$(".sub-li", this).width(mainLiW+20);
			}
		}
	}
	);
	$(".main-li").mouseover
	(
	function()
	{
		if($(this).hasClass("expandable") == false)
		{
			if($(".main-li").hasClass("expanded"))
			{
				$(".sub-ul").hide();
			}
		}
	}
	);
	
	if($("#more-news div").length > 0)
	{
		$("#more-news-link").parent().css("display", "block");
		var moreNews =  $("#more-news").html();
		$("#more-news-link").fpPopup({data: moreNews, type: "html", width: 500, animation: false, coverOpacity: "90", backgroundColor: "222", textColor: "fff"});
	}
	
	$(".products-right tr:even").css("background-color", "#EDEDED");
	$(".products-right td:even").width(330);
	$(".products-right td:odd").width(230);
	$(".links-table tr:last td").css("border-bottom", "1px solid #c8c8c8");

	$(".products-hi-res").fpPopup({type: "image", height: 800, vPadding: 0, hPadding: 0, animation: false});
	
	/*
	$('.products-hi-res').popupWindow({ 
	centerBrowser:1,
	scrollbars:1,
	height:840, 
	width:840 
	}); 
	*/
	$(".products-right:last *:first").css("margin-top", 0);
	$(".products-list-item").hover
	(
		function()
	{
		$("p, h4, h5", this).css({color: "#003366"});
		$(".products-list-series, a", this).css({color: "#996600"});
	},
	function()
	{
		$("p, h4, h5", this).css({color: "#333"});
		$(".products-list-series, a", this).css({color: "#996600"});
	}
	);
	$(".products-list-item").click
	(
		function()
	{
		var href= $("a", this).attr("href");
		window.location = href;
	}
	);
	$(".products-list-item:last, .retailer:last").css("border-bottom", "1px solid #c8c8c8");
	$(".products-right td:first").css("width", "30%");
	$(".video-item").click
	(
	function()
	{
		var video_link=$("a", this).attr("id");
		var video_title=$("h5", this).text();
		var video_description=$("p", this).text();
		$(".video-item").removeClass("video-active");
		$(this).addClass("video-active");
		$("#video-info h2:first").html(video_title);
		$("#video-info p:first").html(video_description);
		$("#video-frame").attr("src", video_link);
		var videoOffset = $('#content').offset();
		$('html, body').animate({scrollTop: videoOffset.top});
		return false;
	}
	);
	$(".video-item:first img").css({opacity: "1"});
	$(".video-item:first").addClass("video-active");
	$(".video-item").hover
	(
		function()
		{
			$(".video-item img").stop().animate({opacity: "0.5"}, 500);
			$("img", this).stop().animate({opacity: "1"}, 300);
			
			var thisPos=$(this).position();
			var thisW=$(this).width();
			$(".video-item-info", this).css({width: thisW-8, top: thisPos.top, left: thisPos.left});
			$(".video-item-info", this).show();
		},
		function()
		{
			$(".video-item-info", this).hide();
			$("img", this).stop().animate({opacity: "0.5"}, 500);
			$(".video-active img").stop().animate({opacity: "1"}, 300);
		}
	);
}
);

