$(document).ready(function()
{
	$('div.gallery img').preload();
	
	// Move the navigation up/down page onscroll/resize
	var msie6 = $.browser == 'msie' && $.browser.version < 8;
	if (!msie6) 
	{
		var top = $('#primary-navigation').offset().top - parseFloat($('#primary-navigation').css('marginTop').replace(/auto/, 0));
		var bot = $('#page-footer').offset().top - parseFloat($('#page-footer').css('marginTop').replace(/auto/, 0));
		var nav = $('#primary-navigation').height();
		var tidemark = bot - nav - 110;

		$(window).bind(
			"load scroll resize",
			function () 
			{
				var y = $(this).scrollTop();
				if (y >= top) 
				{
					if (y >= tidemark)
					{
						$('#primary-navigation').removeClass('fixed');
						$('#primary-navigation').addClass('fixed-alt');
						$('#primary-navigation').css('top', tidemark);
					}
					else
					{
						$('#primary-navigation').removeClass('fixed-alt');
						$('#primary-navigation').css('top', '0');
						$('#primary-navigation').addClass('fixed');
					}
				} 
				else 
				{
					$('#primary-navigation').removeClass('fixed');
					$('#primary-navigation').css('top', '30px');
				}
			}
		);
	}

	// Open links with CSS class of .new-window in new window/tab
	$("a.new-window, .new-window a, .new-window-icon").click(
		function()
		{
			window.open($(this).attr("href"));
			return false;
		}
	);
	
	// Facebox modal/lightbox popup
	$("a[rel*=modal]").facebox({
		loadingImage: '/wp-content/themes/akot/images/facebox/loading.gif',
		closeImage: '/wp-content/themes/akot/images/facebox/closelabel.gif'
	});
	
	// Call placeholder swap
	$("input[type=text]").subPlaceholder();
});

// Function to substitute placeholder text in/out of form fields
$.fn.subPlaceholder = function() 
{
	return this.focus(function() 
	{
		if (this.value == $(this).attr("placeholder")) 
		{
			this.value = "";
		}
	}).blur(function() 
	{
		if (!this.value.length) 
		{
			this.value = $(this).attr("placeholder");
		}
	});
};


