$(document).ready(function() {
	
	// Homepage menu roll overs
	if($('#menu'))
	{
		$('#about').bind('mouseenter', function(){
			$('.page-item-2 a').css({color:"#cc3333", fontWeight:"bold"});
		});
		$('#about').bind('mouseleave', function(){
			$('.page-item-2 a').css({color:"", fontWeight:""});
		});
		
		$('#shop').bind('mouseenter', function(){
			$('.page-item-5 a').css({color:"#cc3333", fontWeight:"bold"});
		});
		$('#shop').bind('mouseleave', function(){
			$('.page-item-5 a').css({color:"", fontWeight:""});
		});

		if($('#shop-new-season').length)
		{
			$('#shop-new-season').bind('mouseenter', function(){
				$('.page-item-5 a').css({color:"#cc3333", fontWeight:"bold"});
			});
			$('#shop-new-season').bind('mouseleave', function(){
				$('.page-item-5 a').css({color:"", fontWeight:""});
			});
		}
		else if($('#shop-sale-on').length)
		{
			$('#shop-sale-on').bind('mouseenter', function(){
				$('.page-item-5 a').css({color:"#cc3333", fontWeight:"bold"});
			});
			$('#shop-sale-on').bind('mouseleave', function(){
				$('.page-item-5 a').css({color:"", fontWeight:""});
			});
		}
		
		$('#archive').bind('mouseenter', function(){
			$('.page-item-7 a').css({color:"#cc3333", fontWeight:"bold"});
		});
		$('#archive').bind('mouseleave', function(){
			$('.page-item-7 a').css({color:"", fontWeight:""});
		});
		
		$('#stockists').bind('mouseenter', function(){
			$('.page-item-8 a').css({color:"#cc3333", fontWeight:"bold"});
		});
		$('#stockists').bind('mouseleave', function(){
			$('.page-item-8 a').css({color:"", fontWeight:""});
		});
		
		$('#subscribe').bind('mouseenter', function(){
			$('.page-item-13 a').css({color:"#cc3333", fontWeight:"bold"});
		});
		$('#subscribe').bind('mouseleave', function(){
			$('.page-item-13 a').css({color:"", fontWeight:""});
		});
		
		$('#noticeboard').bind('mouseenter', function(){
			$('.page-item-10 a').css({color:"#cc3333", fontWeight:"bold"});
		});
		$('#noticeboard').bind('mouseleave', function(){
			$('.page-item-10 a').css({color:"", fontWeight:""});
		});
		
		$('#media').bind('mouseenter', function(){
			$('.page-item-11 a').css({color:"#cc3333", fontWeight:"bold"});
		});
		$('#media').bind('mouseleave', function(){
			$('.page-item-11 a').css({color:"", fontWeight:""});
		});
		
		$('#contact').bind('mouseenter', function(){
			$('.page-item-12 a').css({color:"#cc3333", fontWeight:"bold"});
		});
		$('#contact').bind('mouseleave', function(){
			$('.page-item-12 a').css({color:"", fontWeight:""});
		});
		
		$('#gallery').bind('mouseenter', function(){
			$('.page-item-gallery a').css({color:"#cc3333", fontWeight:"bold"});
		});
		$('#gallery').bind('mouseleave', function(){
			$('.page-item-gallery a').css({color:"", fontWeight:""});
		});
		
		
		/*
		*/
		$('.page-item-2').bind('mouseenter', function(){
			$('#about a').removeClass('aboutEgg');
			$('#about a').addClass('aboutEggHover');
		});
		$('.page-item-2').bind('mouseleave', function(){
			$('#about a').removeClass('aboutEggHover');
			$('#about a').addClass('aboutEgg');
		});
		
		$('.page-item-5').bind('mouseenter', function(){
			if($('#shop-new-season').length)
			{
				$('#shop-new-season a').removeClass('shopEgg');
				$('#shop-new-season a').addClass('shopEggHover');
			}
			else if($('#shop-sale-on').length)
			{
				$('#shop-sale-on a').removeClass('shopEgg');
				$('#shop-sale-on a').addClass('shopEggHover');
			}
			else
			{
				$('#shop a').removeClass('shopEgg');
				$('#shop a').addClass('shopEggHover');
			}
		});
		$('.page-item-5').bind('mouseleave', function(){
			if($('#shop-new-season').length)
			{
				$('#shop-new-season a').removeClass('shopEggHover');
				$('#shop-new-season a').addClass('shopEgg');
			}
			else if($('#shop-sale-on').length)
			{
				$('#shop-sale-on a').removeClass('shopEggHover');
				$('#shop-sale-on a').addClass('shopEgg');
			}
			else
			{
				$('#shop a').removeClass('shopEggHover');
				$('#shop a').addClass('shopEgg');
			}
		});
		
		$('.page-item-7').bind('mouseenter', function(){
			$('#archive a').removeClass('archiveEgg');
			$('#archive a').addClass('archiveEggHover');
		});
		$('.page-item-7').bind('mouseleave', function(){
			$('#archive a').removeClass('archiveEggHover');
			$('#archive a').addClass('archiveEgg');
		});
		
		$('.page-item-8').bind('mouseenter', function(){
			$('#stockists a').removeClass('stockistsEgg');
			$('#stockists a').addClass('stockistsEggHover');
		});
		$('.page-item-8').bind('mouseleave', function(){
			$('#stockists a').removeClass('stockistsEggHover');
			$('#stockists a').addClass('stockistsEgg');
		});
		
		$('.page-item-13').bind('mouseenter', function(){
			$('#subscribe a').removeClass('subscribeEgg');
			$('#subscribe a').addClass('subscribeEggHover');
		});
		$('.page-item-13').bind('mouseleave', function(){
			$('#subscribe a').removeClass('subscribeEggHover');
			$('#subscribe a').addClass('subscribeEgg');
		});
		
		$('.page-item-10').bind('mouseenter', function(){
			$('#noticeboard a').removeClass('noticeboardEgg');
			$('#noticeboard a').addClass('noticeboardEggHover');
		});
		$('.page-item-10').bind('mouseleave', function(){
			$('#noticeboard a').removeClass('noticeboardEggHover');
			$('#noticeboard a').addClass('noticeboardEgg');
		});
		
		$('.page-item-11').bind('mouseenter', function(){
			$('#media a').removeClass('mediaEgg');
			$('#media a').addClass('mediaEggHover');
		});
		$('.page-item-11').bind('mouseleave', function(){
			$('#media a').removeClass('mediaEggHover');
			$('#media a').addClass('mediaEgg');
		});
		
		$('.page-item-12').bind('mouseenter', function(){
			$('#contact a').removeClass('contactEgg');
			$('#contact a').addClass('contactEggHover');
		});
		$('.page-item-12').bind('mouseleave', function(){
			$('#contact a').removeClass('contactEggHover');
			$('#contact a').addClass('contactEgg');
		});
		
		$('.page-item-gallery').bind('mouseenter', function(){
			$('#gallery a').removeClass('galleryEgg');
			$('#gallery a').addClass('galleryEggHover');
		});
		$('.page-item-gallery').bind('mouseleave', function(){
			$('#gallery a').removeClass('galleryEggHover');
			$('#gallery a').addClass('galleryEgg');
		});
		
	}
	
	
	
	
	// Popup, for links that have the class outta-site
	$('.outta-site').click(function(){
		newWindow = window.open($(this).attr('href'), $(this).attr('href'));
		if(window.focus)
		{
			newWindow.focus();
		}
		return false;
	});
	
	
	if($('#gift_msg').length)
	{
		// run on page load, hack with 21
		wordLimit('gift_msg', 21, 'gift_info');
		
		$('#gift_msg').keyup(function(event){
			wordLimit('gift_msg', 20, 'gift_info');
		});
	}
	
	function wordLimit(textid, limit, infodiv)
	{
		var text = $('#' + textid).val();
		text = text.trim();
		var words = text.split(" ");
		console.log(words.length);
		var wordlength = words.length;
		var info;

		if(wordlength > limit)
		{
			$('#' + infodiv).html("You cannot write more than " + limit + " words.");
			return false;
		}
		else
		{
			if((limit - wordlength) == 1)
				info = "You have " + (limit - wordlength) + " word left.";
			else
				info = "You have " + (limit - wordlength) + " words left.";
				
			$('#' + infodiv).html(info);
			return true;
		}
	}
	
	
	
	
	if($('#step4_form').length)
	{
		$('#step4_form').submit(function(){
			$('#loader').show();
			$('#submit').attr("disabled", true);
			//return false;
		});
	}
});


function nancybird_showCVN()
{
	
	$("body").append("<div id='overlay'></div>");
	$("body").append("<div id='overlaycontent'></div>")
	$("#overlaycontent").load("/cvn_info.php");
	return false;

}


function nancybird_hideCVN()
{
	
	$("#overlay").remove();
	$("#overlaycontent").remove();
	return false;
	

}

String.prototype.trim = function(){
	a = this.replace(/^\s+/, '');
	return a.replace(/\s+$/, '');
}