//=======================================================================================================
//-------------------------------------------------------------------------------------------------------
//	Custom Javascript functions
//-------------------------------------------------------------------------------------------------------
//=======================================================================================================
$(document).ready(function() {
	//	Standard Toggle
	$('.toggle').toggle(function() {
		$(this).parent().next('.toggle-content').slideDown(function(){
			$(this).find('label.overlabel').css('display','block');
		});
		$(this).addClass('open');
	}, function() {
		$(this).parent().next('.toggle-content').find('label.overlabel').fadeOut();
		$(this).parent().next('.toggle-content').slideUp();
		$(this).removeClass('open');
	});

	//	infield labels
	$('label.infield').each(function(){
		var formElement = $(this).attr('for');

		//	Position with js so non js browsers don't have the field obscured by the label
		$(this).css('position','absolute');
	
		//	Fade out 50% on focus
		$('#'+formElement).focus(function(){
			if ($(this).val() == '') {
				$('label.infield[for='+formElement+']').fadeTo('slow',0.5);
			}
		});

		//	Fade out completely when the user types
		$('#'+formElement).keydown(function(){
			if ($(this).val() == '') {
				$('label.infield[for='+formElement+']').fadeOut();
			}
		});

		//	Fade back in on blur if there's no input
		$('#'+formElement).blur(function(){
			if ($(this).val() == '') {
				$('label.infield[for='+formElement+']').fadeTo('slow',1);
			};
		});
	});

 	// Remove empty menus
    $('ul.m1:empty,ul.m1 ul:empty').remove();

});

function openEmailPopup( id )
{
	sizeX = 500;
	sizeY = 400;
	
	//	Center the window
	leftpos	= (screen.width)  ? (screen.width-sizeX)/2 : 100;
	toppos	= (screen.height) ? (screen.height-sizeY)/2 : 100;

	//	Define the window size
	widthVar  = 'width=' + sizeX + ',';
	heightVar = 'height=' + sizeY + ',';
	
	//	Open the window
	contenturl				= '/blog/email.php/id/' + id;
	target					= 'email' + id;
	winobject				= window.open(contenturl,target,"menubar=0,statusbar=0,scrollbars=1,toolbar=0,location=0," + widthVar + heightVar + "left=" + leftpos + ",top=" + toppos + ",resizable=1" );
	winobject.focus();
}
