function cartboxHTML(data) {
	$('#cartBox').html(data);
}

this.imagePreview = function(){	
	/* CONFIG */
		
		xOffset = 220;
		yOffset = 30;
		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result
		
	/* END CONFIG */
	$("a.preview").hover(function(e){
		this.t = this.title;
		this.title = "";
		var alt = $(this).attr("alt");
		var c = (this.t != "") ? "<br/>" + this.t : "";
		$("body").append("<p id='preview'><img src='"+ alt +"' alt='Image preview' />"+ c +"</p>");								 
		$("#preview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");						
    },
	function(){
		this.title = this.t;	
		$("#preview").remove();
    });	
	$("a.preview").mousemove(function(e){
		$("#preview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};

$(document).ready(function() {
	
	
	$("#toggle").click(function() {
									 
		$.get("/priceToggle.php", { toggle : 'toggle' },
			function(data) {
				$('#toggle').html(data);
				window.location = document.location.href; 
			}
		);
	
	});
	
	$.get("/priceToggle.php", 
			function(data) {
				$('#toggle').html(data);
			}
	);
	
	
	$.get("/address_finder.php", { location : 'address' },
			function(data) {
				$('#addressBlock').html(data);
			}
	);
	
	
	
	$.get("/address_finder.php", { location : 'delivery' },
			function(data) {
				$('#addressBlock2').html(data);
			}
	);
	
	
	
	$('#viewCartButton').click( function(){
		$('#cartDetails').slideToggle('fast')
	} );
	
	
	
	var cartbox = $('#cartBox');
	cartbox.delegate('#viewCartButton', 'click', function() {
		$('#cartDetails').slideToggle('fast');
		
		var text = $('#viewCartButton').text();
   		$('#viewCartButton').text(
        text == "Show order" ? "Hide order" : "Show order");

	});
	
	$.get("/quickcart.php", cartboxHTML);
	
	$('#coda-slider-1').codaSlider({
        dynamicArrows: false,
        dynamicTabs: false
    });
	
	$('a[rel*=modal]').facebox(); // Applies modal window to any link with attribute rel="modal"
	
	$(function() {
		$("#copyAddress").click(function() {
			if ($('input[name=copyAddress]').is(':checked')) {
				$("#custDelAddress").val($("#custDelAddress").attr('alt'));
				$("#custDelAddress2").val($("#custDelAddress2").attr('alt'));
				$("#custDelAddress3").val($("#custDelAddress3").attr('alt'));
				$("#custDelTown").val($("#custDelTown").attr('alt'));
				$("#custDelCounty").val($("#custDelCounty").attr('alt'));
				$("#custDelPostcode").val($("#custDelPostcode").attr('alt'));
			} else {
				$("#custDelAddress").val('');
				$("#custDelAddress2").val('');
				$("#custDelAddress3").val('');
				$("#custDelTown").val('');
				$("#custDelCounty").val('');
				$("#custDelPostcode").val('');
			}
		});
	});
	
	imagePreview();
	
});





function addtocart($productID, $qty) {
	
		$('html, body').animate({scrollTop:0}, 'slow');
		$.get("/quickcart.php", { action : 'addtocart',productID : $productID, qty : $qty }, function(data) {
				$('#cartBox').html(data);
				$('#cartDetails').slideToggle('fast')
			});
					

	}
	
	
	
function removeItem($sessionKey) {

	$.get("/quickcart.php", { action : 'removeItem',sessionKey : $sessionKey },
		function(data) {
			var cartbox = $('#cartBox');
				cartbox.html(data);
				cartbox.find('#cartDetails').show('fast')
		}
	);
	
}


function getPostcode($postcode, $location, $div) {
		$.get("/address_finder.php", { postcode : $postcode, location : $location },
			function(data) {
				$('#'+$div).html(data);
			}
		);

	}
	
	
function useAddress($address, $location, $div) {
	$.get("/address_finder.php", { address : $address, location : $location },
		function(data) {
			$('#'+$div).html(data);
		}
	);

}

