jQuery(function($)
{
	// Fix the link color-transition when page is loading (webkit only)
	$('body').attr('link', '#1a1a1a');
	
	// Opens the print dialog for the page
	if ($('body').hasClass('do_print')) { setTimeout(function(){window.print();}, 500); }
	
	// Hide highlight if article has multiple categories
	if ($('nav#main ul li.current-post-parent').length > 1)
	{
		// Loop through every item with this class
		$('nav#main ul li.current-post-parent').each(function(i)
		{
			// Remove the class
			if (i != 1) $(this).removeClass('current-menu-parent current-post-parent');
			
		});
		
	}
	
	// Show the "sent to friend" form if an error ocurred 
	if ($('div.wpcf7-validation-errors').length != 0) { $('div#sendviaemail').show(); }
	
	if ($('div.wpcf7-mail-sent-ok').length != 0) { setTimeout(function(){$('div.wpcf7-mail-sent-ok').hide();}, 3000); }
	
	// Hide the form when user clicks "Cancel"
	if ($('div#sendviaemail').length != 0) { $('input#reset').click(function(){ $('div#sendviaemail').hide(); }) }
	
	// Open up the "Sent to friend" form
	$('a#sendtofriend').click(function()
	{
		if ($('div#sendviaemail').is(':hidden'))
		{
			$('div#sendviaemail').show();
			$('input#email').focus();
			
		}
		else
		{
			$('div#sendviaemail').hide();
			
		}
		
		return false;
		
	});
	
	// Semi-placeholder for search form
	if ($('#search2'))
	{
		$('#search2').focus(function()
		{
			if ($(this).val() == 'Type to search and hit return...') {$(this).val('') };
	
		}).blur(function()
		{
			if ($(this).val() == '') { $(this).val('Type to search and hit return...') };
			
		});
		
	}
	
	// Semi placeholder for username
	if ($('#username2'))
	{
		$('#username2').focus(function()
		{
			if ($(this).val() == 'Username') {$(this).val('') };
	
		}).blur(function()
		{
			if ($(this).val() == '') { $(this).val('Username') };
			
		});
		
	}
	
	// Semi placehodler for password
	if ($('#password2'))
	{
		$('#password2').focus(function()
		{
			if ($(this).val() == 'Password') {$(this).val('') };
	
		}).blur(function()
		{
			if ($(this).val() == '') { $(this).val('Password') };
			
		});
		
	}
	
	// Newsletter archive
	if ($('select#archive'))
	{
		$('select#archive').change(function()
		{
			$('form#change_archive').submit();
			
		});
		
	}
	
	// Go to daily newsletter
	if ($('select#goto_newsletter'))
	{
		$('select#goto_newsletter').change(function()
		{
			if ($(this).val()) { window.location.href = $(this).val(); }
			
		});
	}
	
});
