/* Onload */
jQuery(document).ready(function($) 
{
	// Navigation highlighting
	if ($(".post.category-blog").length != 0)
	{
		$("#menu-item-47").addClass("current_page_item");
	}
	if ($(".post.category-product-news").length != 0)
	{
		$("#menu-item-48").addClass("current_page_item");
	}

	
	// Navigation effects
	if ($.browser.msie && $.browser.version <= 8) // Maybe 9 won't suck?
	{
		$("#nav a").hover(function() 
		{
			$(this).addClass("active").css({ backgroundPosition : "50% 4px" });
			$("#nav a:not(.active)").css({ backgroundPosition : "50% 11px" });
		}, 
		function() 
		{
			$(this).removeClass("active");
			if ($("#nav a.active").length == 0) resetNavIE();
		}
		);
		
		function resetNavIE()
		{
			if ($("#nav li.active").length > 0)
			{
				$("#nav li.active a").css({ backgroundPosition : "50% 11px" });
				$("#nav li:not(.active) a").css({ backgroundPosition : "50% 11px" });
			}
			else
			{
				$("#nav li:not(.active) a").css({ backgroundPosition : "50% 11px" });
			}
		}
		
		resetNavIE();
		
	}
	else
	{
		$("#nav a").hover(function() 
		{
			$(this).addClass("active").animate({ opacity : 1, backgroundPosition : "50% 4px" }, { queue: false, duration: 200 });
			$("#nav a:not(.active)").animate({ opacity : 0.7, backgroundPosition : "50% 11px" }, { queue: false, duration: 200 });
		}, 
		function() 
		{
			$(this).removeClass("active");
			if ($("#nav a.active").length == 0) resetNav();
		}
		);
		
		function resetNav()
		{
			if ($("#nav li.active").length > 0)
			{
				$("#nav li.active a").animate({ opacity : 1, backgroundPosition : "50% 11px" }, { queue: false, duration: 200 });
				$("#nav li:not(.active) a").animate({ opacity : 0.7, backgroundPosition : "50% 11px" }, { queue: false, duration: 200 });
			}
			else
			{
				$("#nav li:not(.active) a").animate({ opacity : 1, backgroundPosition : "50% 11px" }, { queue: false, duration: 200 });
			}
		}

		resetNav();
		
	}
	
	// Homepage banner
	$(window).load(function() {
	
		if ($('#banner').length)
		{
			$('#banner .photo img').each(function () {
				$(this).parent().parent().css({
					position: "absolute",
					visibility: "hidden",
					display: "block"
				})
				img_height = $(this).height();
				$(this).parent().parent().css({
					position: "",
					visibility: "",
					display: ""
				})
				offset_y = (img_height - $('#banner').height()) / 2;
				$(this).css("margin-top", "-" + offset_y + "px");
			});
			$('#banner').cycle({
				fx: 'scrollDown',
				speed: 750, 
				timeout: 6500,
				pager:  '#pager', 
				pagerAnchorBuilder: function(idx, slide) { 
					return '<li><a href="#">&bull;</a></li>'; 
				}
			});			
		}
		
		/*if ($('.centre-me').length)
		{
			$('.centre-me').each(function() {
				if ($(this).width() > 270)
					$(this).css("margin-left",-(($(this).width() - 250)/2)-$(this).width() / 8);
				else
					$(this).css("margin-left",-(($(this).width() - 250)/2));
				$(this).fadeIn(2000);
			});
		}*/
	
	});

	var sb = $('#social-box');
	var sb_orig = $('#social-box').offset().top;
	var sb_limit = $('.post').offset().top + $('.post').height() - 150;
	sb.css({ top : sb_orig, marginTop : 0 });
	
	$(window).scroll(function() {
		if ($(window).scrollTop() < sb_orig)
			sb.css({'position' : 'absolute', top : sb_orig });
		else if ($(window).scrollTop() > sb_limit)
			sb.css({'position' : 'absolute', top : sb_limit });
		else
			sb.css({'position' : 'fixed', top : 10 });
	});

});
