(function($){
	// Load
	var baseURL = "http://www.liverpoolfoodanddrinkfestival.co.uk";
	var pathURL = baseURL+"/wp-content/themes/foodanddrink";
	var thisURL = window.location;
	
	$("#addthis").append('<fb:like layout="button_count" width="80" ref="top_nav"></fb:like>');
	$("#fanbox").html('<fb:fan profile_id="181093118592505" stream="false" show_faces="true" connections="10" width="312" height="300" css="'+pathURL+'/css/fanbox.css"></fb:fan>');
	$("a[href='"+thisURL+"']").addClass("thisURL");
	$("nav ul a,#offers_list a,.follow_us span").not(".ie6 nav ul a").corner("4px");
	$("input[type=submit]").val("");
	if ($("#home_left .gallery").not("#home_left .lightbox .gallery,.page-template-page-generic-php .gallery,.page-template-page-awards-php .gallery,.page-template-page-gallery-single-php .gallery").length>0) { $.getScript(pathURL+"/js/home_gallery.js"); }
	if ($("#week_left .gallery").length>0) { $.getScript(pathURL+"/js/week_gallery.js"); }
	if ($(".generic_left article").length>0) { $.getScript(pathURL+"/js/generic_left_article.js"); }
	if ($("#launch_days").length>0) { $.getScript(pathURL+"/js/launch.js"); }
	if ($("#week_days").length>0) { $.getScript(pathURL+"/js/week_days.js"); }
	if ($("#week_right").length>0) { $.getScript(pathURL+"/js/week_right.js"); }
	if ($("#home_right #offers_content").length>0) { $.getScript(pathURL+"/js/home_offers_content.js"); }
	if ($("#voting_form").length>0) { $.getScript(pathURL+"/js/voting.js"); }
	if ($(".lightbox").length>0) {
		$.getScript(pathURL+"/js/colorbox.js");
		$.getScript(pathURL+"/js/gallery.js");
	}
	$("#sponsors_scroll").simplyScroll({ autoMode:'loop',speed:3 });
	$(".generic_left blockquote").corner("4px");
	$("#fb-root").html('<fb:comments href="'+thisURL+'" num_posts="10" width="592"></fb:comments>');
	$(".page-template-page-gallery-single-php .gallery-item:nth-child(4n)").css("margin-right","0px");
	//$("#panel_area li").hide();
	//$("#panel_area li:eq("+Math.floor(Math.random()*$("#panel_area li").length)+")").show();

	// Interaction
	jQuery.fn.fullLink=function(link){jQuery(this).each(function(){var thisElem=jQuery(this);if(jQuery("a",thisElem).length>0){thisElem.css("cursor","pointer").click(function(){if(link){window.location=jQuery("a:nth-child("+link+")",this).attr("href");}else{window.location=jQuery("a",this).attr("href");}});}});}
	$("nav .sub-menu").corner("tr bl br 4px").mouseover(function(){ $(this).parent().addClass("current-menu-item"); }).mouseout(function(){ $(this).parent().removeClass("current-menu-item"); });
	$(".widget,#foodlab,#tier_1 .sponsor,#tier_2 .sponsor,#tier_3 .sponsor,#tier_4 .sponsor,#home_vote").fullLink();
	$("#newsletter_js,#small_js,#contact_js").val("yes");

	$("#more_offers_top").mouseover(function(){
		$("#more_offers_btm").fadeIn();
		$("#offers_move").animate({top:"0px"},3000,function(){ $("#more_offers_top").fadeOut(); });
	}).mouseout(function(){
		$("#offers_move").stop();
	});
		
	$("#more_offers_btm").mouseover(function(){
		$("#more_offers_top").fadeIn();
		$("#offers_move").animate({top:"-"+Math.ceil($("#offers_move").height()-380)+"px"},3000,function(){ $("#more_offers_btm").fadeOut(); });
	}).mouseout(function(){
		$("#offers_move").stop();
	});
	
	$("#capture_form form").live("submit",function(){
		$.post(pathURL+"/php/newsletter.php",$(this).serialize(),function(data){
			if (data.status==0) {
				$(".newsletter_feedback").hide().text(data.error).fadeIn();
			} else {
				$(".newsletter_feedback").hide().text(data.error).fadeIn();
				$("#newsletter_name").val("Enter name");
				$("#newsletter_email").val("Enter email address");
			}
		},"json");
		return false;
	});
	$("#contact_form form").live("submit",function(){
		$.post(pathURL+"/php/contact_form.php",$(this).serialize(),function(data){
			if (data.status==0) {
				$(".contact_feedback").hide().html(data.error).fadeIn();
			} else {
				$(".contact_feedback").hide().html(data.error).fadeIn();
				$("#contact_form form").hide();
				$("#contact_form input").val("");
				$("#contact_form textarea").text("").val("");
				setTimeout(function(){
					$(".contact_feedback").hide();
					$("#contact_form form").fadeIn();
				},7000);
			}
		},"json");
		return false;
	});
	$("#week_days form,form.small").live("submit",function(){
		$.post(pathURL+"/php/small_newsletter.php",$(this).serialize(),function(data){
			if (data.status==0) {
					$("#week_days form label,form.small label").hide().text(data.error).fadeIn();
				setTimeout(function(){
					$("#week_days form label,form.small label").hide().text("Join Our Mailing List").fadeIn();
				},7000);
			} else {
				$("#week_days form label,form.small label").hide().text(data.error).fadeIn();
				setTimeout(function(){
					$("#small_email").val("Leave your email address");
					$("#week_days form label,form.small label").hide().text("Join Our Mailing List").fadeIn();
				},7000);
			}
		},"json");
		return false;
	});
	$("input[type=text]").each(function(){
		var thisVal=$(this).val();
		$(this).bind("focus",function(){
			if ($(this).val()==thisVal) { $(this).val(""); }
		}).bind("blur",function(){
			if ($(this).val()=="") { $(this).val(thisVal); }
		});
	});
})(this.jQuery);
