$(document).ready(function() {	   
						   
	$('ul#topnav li:last').prev('li').find('ul:first').css({left: 'auto', right: '0px'});
	$('ul#topnav li').hover(function() {
		var list = $(this).find('ul');
		var children = $(this).find('li').length;
		if (children >= 3) {
			list.css({'width' :510});
		} else {
			list.css({'width' : children * 170})
		}
		$(this).find('ul').show();
	}, function() {
		$(this).find('ul').hide();
	});
	
	// fancy box
	$("a.fancybox").fancybox({
		'hideOnContentClick': false,
		'frameWidth':411,
		'frameHeight':480,
		'padding':0,
		'callbackOnShow':function(){
			//$('#fancy_outer').height( $('#fancy_ajax div').outerHeight() );
		}
	});
	
	
	$('#checkout-codes #credit_code').prev('label').remove();
	$('#checkout-codes #credit_code').remove();
	$('#checkout-payment-details #payment_type_phone').parent().remove();
	$('#checkout-payment-details #payment_type_fax').parent().remove();
	
	$("#optin").click(function(){
		if(!$(this).attr("checked")){
			$("#vision6").attr("name","");
		} else {
			$("#vision6").attr("name","formType[]");
		}
	});
	
	// Alternating row colours on the product nutritional information tables
	$('.specs .left tbody tr:even, .specs .right tbody tr:even').addClass('even');
	
});


// Hover effects
$(document).ready(function(){  
	$('#content-right .recipe-result-thumb').hover(
       function(){ $(this).addClass('hover') },
       function(){ $(this).removeClass('hover') }
	);

	$('#content-right .product-range-thumb').hover(
       function(){ $(this).addClass('hover') },
       function(){ $(this).removeClass('hover') }
	);

	$('#home-carousel .images').hover(
       function(){ $(this).addClass('hover') },
       function(){ $(this).removeClass('hover') }
	);
	
	$('#header dl.cart').hover(
       function(){ $(this).addClass('hover') },
       function(){ $(this).removeClass('hover') }
	);
	
	$('#header dl.cart').mouseenter(function(){ 
		$('dd', this).show(); 
	});
	$('#header dl.cart').mouseleave(function(){ 
		$('dd', this).hide(); 
	});
			
	
	// Select form elements under menu. BGIframe plugin should fixed this.
	$('#content-left #content-left-grey #recipe-search-left form select').bgiframe();
});


// Clear subscribe fields and onblur fields too
$.fn.clearOnFocus = function(){
 
    return this.focus(function(){
        var v = $(this).val();
        $(this).val( v === this.defaultValue ? '' : v );
    }).blur(function(){
        var v = $(this).val();
        $(this).val( v.match(/^\s+$|^$/) ? this.defaultValue : v );
    });
 
};

$('input').clearOnFocus();
