$(document).ready(function(){   
	
	$(document).pngFix();
	
	$('#imagechanger').innerfade({
		speed: 4000,
		timeout: 7000,
		type: 'sequence',
		containerheight: '177px'
	});
	
	$(".fancybox").fancybox();
		$(".fancyframe").fancybox({
		'zoomSpeedIn': 0, 
		'zoomSpeedOut': 0, 
		'overlayShow': true ,
		'frameWidth': 800,
		'frameHeight': 564
	});	
	
	$('input[type="text"]').focus(function() {
		$(this).addClass("keycol");
	});
	$('input[type="text"]').blur(function() {
		$(this).removeClass("keycol");
	});
	
	$(".addtobasket").submit(function(){
		
		var addtobasket = $(this);
		
		if ($('#variant').attr("selectedIndex") == 0){
		   alert('Please select a product option'); 
		   return false;
		}
	   
		$.getJSON('/ajax/addtobasket.php', $(this).serialize(), function(data) {
			if (data.errmsg) {
				alert(data.errmsg);
			} else {
				$("#basketsummary").animate({opacity: '0'}, 200, function() {
					$("#basketsummary").html(data.basketsummary);
					$("#basketsummary").animate({opacity: '1'}, 200);
			    });
				$("#bigbasketsummary").animate({opacity: '0'}, 200, function() {
					$("#bigbasketsummary").html(data.bigbasketsummary);
					$("#bigbasketsummary").animate({opacity: '1'}, 200);
			    });
				addtobasket.find(".itemcount").html(data.itemcount);
				addtobasket.addClass("inbasket");
				$.prompt('This product has been added to your shopping basket.<br/>'+data.basketsummary,{ 
					buttons:{"checkout now":true, "continue shopping":false},
					overlayspeed: "fast",
					top: "35%",
					callback: function(v){
						if (v) { location.href="/shopping-basket"; }
					}
				});
			}
		});

	});
	
	$(".plusone").live('click', function(){
		$.getJSON('/ajax/plusonebasket.php?plus='+$(this).attr("rel"), function(data) {
			if (data.errmsg) {
				alert(data.errmsg);
			} else {
				$("#basketsummary").html(data.basketsummary);
				$("#bigbasketsummary").html(data.bigbasketsummary);
			}
		});
	});

	$(".removeone").live('click', function(){
		$.getJSON('/ajax/plusonebasket.php?remove='+$(this).attr("rel"), function(data) {
			if (data.errmsg) {
				alert(data.errmsg);
			} else {
				$("#basketsummary").html(data.basketsummary);
				$("#bigbasketsummary").html(data.bigbasketsummary);
			}
		});
	});

});

function updatestockists(country,productarea) {
	$('.stockscroll').html("<p>Loading...</p>");
	$.ajax({
		  url: '/includes/inc_stockistlist.php?country='+country+'&productarea='+productarea,
		  success: function(data) {
			$('.stockscroll').html(data);	
		  }
	});
}

$(function () {
	var tabContainers = $('div.prodtabs > div');
	$('div.prodtabs ul.tabNav a').click(function () {
		tabContainers.hide().filter(this.hash).show();
		$('div.prodtabs ul.tabNav a').removeClass('selected');
		$('div.prodtabs ul.tabNav li').removeClass('current');
		$(this).addClass('selected');
		$(this).parent().addClass('current');
		return false;
}).filter(':first').click();});	
