(function($){
	var baseURL="http://"+window.location.hostname;
	var pathURL=baseURL+"/wp-content/themes/whiskylounge";
	var currentURL=window.location;
	
	//Load
	img1= new Image(); 
	img1.src=pathURL+"/images/transparent_on.png"; 
	img2= new Image(); 
	img2.src=pathURL+"/images/ajax.gif"; 

	if ($(".ie7,.ie8").length==0) {
		$("#search dd input").corner("7px");	
		$("#newsletter_form dd input,#newsletter_form dd.select,#contact_form dd input,#contact_form dd textarea,.simpleCart_checkout,.item_add,.quantity,.item_quantity,.external_booking").corner("7px");
	}
	$(".page-id-85 #generic_content article img").css("opacity",0.4).mouseover(function(){
		$(this).stop().animate({opacity:1},150);
	}).mouseout(function(){
		$(this).stop().animate({opacity:0.4},150);
	});
	$("#searchsubmit").val("");
	
	$("#social a").css("opacity",0.6);
	
	$("#fanbox").append('<fb:fan profile_id="117227954967292" stream="false" connections="6" width="360" height="160" css="http://northandsouthdigital.com/css/whiskylounge_fanbox.css?v=1"></fb:fan>');
	
	//$("#whisky_fact").css({"height":$("#whisky_fact article").height()+"px"});
	
	//Interactive
	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");}});}});}
	
	if ($("#home_slideshow .gallery").length>0) {
		$("#home_slideshow .gallery-item:gt(0)").hide();
		setInterval(function(){$('#home_slideshow .gallery-item:first').fadeOut(2500).next('.gallery-item').fadeIn(2500).end().appendTo('#home_slideshow .gallery');}, 5000);
	}
	
	if ($("#last_event_gallery").length>0) {
		$("#last_event_gallery li:gt(0)").hide();
		$("#last_event_gallery li:first").addClass("active");
		if ($('#last_event_gallery .active').prevAll("li").length==0) { $("#gallery_prev").animate({opacity:0.6}).addClass("disabled"); }
	}
	
	$("#gallery_next").live("click",function(){
		if ($('#last_event_gallery .active').nextAll("li").length>0) { $('#last_event_gallery .active').fadeOut(1000).removeClass("active").next('#last_event_gallery li').fadeIn(1000).addClass("active"); }
		if ($('#last_event_gallery .active').nextAll("li").length==0) { $("#gallery_next").animate({opacity:0.6}).addClass("disabled"); }
		else { $("#gallery_prev").animate({opacity:1}).removeClass("disabled"); }
	});
	$("#gallery_prev").live("click",function(){
		if ($('#last_event_gallery .active').prevAll("li").length>0) { $('#last_event_gallery .active').fadeOut(1000).removeClass("active").prev('#last_event_gallery li').fadeIn(1000).addClass("active"); }
		if ($('#last_event_gallery .active').prevAll("li").length==0) { $("#gallery_prev").animate({opacity:0.6}).addClass("disabled"); }
		else { $("#gallery_next").animate({opacity:1}).removeClass("disabled"); }
	});
	$("#last_event_gallery a").attr("rel","gallery").fancybox({overlayColor:"#000"});
	$(".product_image").fancybox({overlayColor:"#000"});
	$(".entry-content a").find("img").parent().attr("rel","gallery").fancybox({overlayColor:"#000"});
	
	/*setInterval(function(){
		$.post(pathURL+"/php/whisky_fact.php",function(data){
			$("#whisky_fact article").hide().html(data);
			$("#whisky_fact").animate({height:$("#whisky_fact article").height()+"px"});
			$("#whisky_fact article").fadeIn();
		});
	},10000);*/
	
	$(".widgetHover").fullLink();

	twttr.anywhere(function (T) {
		T("#twitter").hovercards({expanded:true});
	});
	
	$("#social a").mouseover(function(){
		$(this).stop().animate({opacity:1},150);
	}).mouseout(function(){
		$(this).stop().animate({opacity:0.6},150);
	});
	
	/*$("a[href='/shop/']").mouseover(function(){
		$(this).prepend('<div class="coming_soon">Coming Soon</div>');
		$(".coming_soon").css({"opacity":0}).stop().animate({opacity:1,marginTop:"-55px"},150);
	}).mouseout(function(){
		$(".coming_soon").stop().animate({opacity:0,marginTop:"-45px"},150,function(){$(this).remove();});
	}).live("click",function(){ 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); }
		});
	});
	
	$("#newsletter_js").val("yes");
	$("#newsletter_submit").css("opacity",1);
	$("#newsletter_form").live("submit",function(){
		$("#newsletter_submit").attr("disabled","disabled").animate({opacity:0.6},150);
		$.post(pathURL+"/php/newsletter_signup.php",$(this).serialize(),function(data){
			if (data.status==0) {
				$("#newsletter_feedback").hide().html(data.error).fadeIn();
				$("#newsletter_submit").removeAttr("disabled").animate({opacity:1},150);
			} else {
				$("#newsletter_feedback").hide().html(data.error).fadeIn();
				$("#newsletter_form").hide();
			}
		},"json");
		return false;
	});
	
	$("#contact_js").val("yes");
	$("#contact_submit").css("opacity",1);
	$("#contact_form").live("submit",function(){
		$("#contact_submit").attr("disabled","disabled").animate({opacity:0.6},150);
		$.post(pathURL+"/php/contact_signup.php",$(this).serialize(),function(data){
			if (data.status==0) {
				$("#contact_feedback").hide().html(data.error).fadeIn();
				$("#contact_submit").removeAttr("disabled").animate({opacity:1},150);
			} else {
				$("#contact_feedback").hide().html(data.error).fadeIn();
				$("#contact_form").hide();
			}
		},"json");
		return false;
	});
	
	$("#content_left #archive").addClass("ajax_archive");
	$(".ajax_archive a.expand").live("click",function(){
		$(".ajax_content").hide().html("").removeClass("ajax_active");
		var thisLink = $(this);
		var thisAjax = thisLink.next(".ajax_content");
		thisAjax.addClass("ajax_active").html('<p class="center"><img src="'+pathURL+'/images/ajax.gif"></p>').fadeIn();
		$.post(thisLink.attr("href"),function(data){
			thisAjax.html(data);
			if ($("#last_event_gallery").length>0) {
				$("#last_event_gallery li:gt(0)").hide();
				$("#last_event_gallery li:first").addClass("active");
				if ($('#last_event_gallery .active').prevAll("li").length==0) { $("#gallery_prev").animate({opacity:0.6}).addClass("disabled"); }
				$("#last_event_gallery a").attr("rel","gallery").fancybox({overlayColor:"#000"});
			}
		});
		return false;
	});

	
	setTimeout(function(){
		if ($(".fb_iframe_widget").length==0) {
			$("#fanbox").append('<fb:fan profile_id="117227954967292" stream="false" connections="6" width="360" height="160" css="http://northandsouthdigital.com/css/whiskylounge_fanbox.css"></fb:fan>');
		}
	},5000);
	
	$(".widgetHover").mouseover(function(){
		$("a.large_arrow",this).stop().animate({backgroundPosition:"100% -31px"},150);
		$("a.small_arrow",this).stop().animate({backgroundPosition:"100% -41px"},150);
		$("a.xsmall_arrow",this).stop().animate({backgroundPosition:"100% -23px"},150);
	}).mouseout(function(){
		$("a.large_arrow",this).stop().animate({backgroundPosition:"100% 0px"},150);
		$("a.small_arrow",this).stop().animate({backgroundPosition:"100% 0px"},150);
		$("a.xsmall_arrow",this).stop().animate({backgroundPosition:"100% 0px"},150);
	});
	
	$("#newsletter_submit,#contact_submit").mouseover(function(){
		$(this).stop().animate({backgroundPosition:"100% -38px"},150);
	}).mouseout(function(){
		$(this).stop().animate({backgroundPosition:"100% 3px"},150);
	});
	
	$("#latest_news .large_arrow").mouseover(function(){
		$(this).stop().animate({backgroundPosition:"100% -31px"},150);
	}).mouseout(function(){
		$(this).stop().animate({backgroundPosition:"100% 0px"},150);
	});
	
	$("#last_event .small_arrow").mouseover(function(){
		$(this).stop().animate({backgroundPosition:"100% -41px"},150);
	}).mouseout(function(){
		$(this).stop().animate({backgroundPosition:"100% 0px"},150);
	});
	
	// Cart
	simpleCart.checkoutTo = PayPal;
	simpleCart.email = "eddie@thewhiskylounge.com";
	simpleCart.currency = GBP;
	simpleCart.cartHeaders = ["Remove","Quantity","Name","Description","Location"];
	$(".item_quantity").blur(function(){
		var thisItem = $(this);
		var thisParent = thisItem.parent().parent().parent();
		var thisCost = thisParent.find(".item_price").text().replace("£","");
		var newCost = thisItem.val()*thisCost;
		thisItem.parent().find(".change_cost").hide().html("&pound;"+newCost.toFixed(0)).fadeIn();
	});
})(this.jQuery);
