$(document).ready(
	function(){

	$(document).pngFix();

	/* Frontpage */

	if ($("#frontpage").length !== 0) {
			$.fn.supersized.options = {
				startwidth: 1425,
				startheight: 1000,
				vertical_center: 1,
				slideshow: 0,
				transition: 0
			};
	        $('#supersize').supersized();
	}



	/* Big Target ? footer & shop pages */

	$(".bigtarget a").bigTarget({
    	hoverClass: "over" // CSS class applied to the click zone onHover
	 });

	 $(".product_list li h3 a").bigTarget({
    	hoverClass: 'over', // CSS class applied to the click zone onHover
	    clickZone : 'li:eq(0)' // jQuery parent selector
	 });


	/* Sky Planter page */

	// Check if #hero_pot is present
	if ($("#hero_pot").length !== 0) {

	// Check browser — IE 6 can't handle cycle & pngFix
	if($.browser.msie && $.browser.version=="6.0")	{
		$("#hero_pot div").hide();
		$("#hero_pot div:first").show();
	}
	else if ($.browser.msie && $.browser.version=="7.0") {
		$("#hero_pot").cycle({
			random: 1,
			next: $("#hero_pot"),
			fx: 'none'
		})
	}
	else {
		$("#hero_pot").cycle({
			random: 1,
			next: $("#hero_pot")
		})

	}
	}

	$("#skyplanter a.zoom").fancybox({
		'frameHeight': 460,
		'padding':30,
		'overlayColor':'#000'
	});



	$('.thumbnails li').hover(
		function(){
			$(this).find('img').fadeTo('fast',.4);
			$(this).find('dd').fadeIn('fast');
		},
		function(){
			$(this).find('img').fadeTo('slow',1);
			$(this).find('dd').fadeOut('fast');
		}
		)



	/* Distribution page */

	if ($("#distribution").length>0) {
		$('.country').hide();

		$('#countries a').click(function(e){
			e.preventDefault();
			$.scrollTo(0,500);
			$('#countries a').removeClass("selected");
			$(this).addClass('selected');
			$('#featured').hide();
			$('.country').hide();
			var $country = $(this).attr('href');
			$($country).show();
				return false;
		})
	}




/* FAQ */
	if ($(".faq").length>0) {
		$(".faq dd").hide();

	if (location.hash){
		$(location.hash).addClass('current');
		$(location.hash).find('dd').show();
	}

		$(".faq ol li dt a").click(function(){
			$('.faq dl').removeClass('current');
			$(this).parent().parent().addClass('current');
			$('.faq dl').not('.current').find('dd').slideUp();
			$(this).parent().parent().find('dd').slideDown();
			return false;
		})
	}






	/* Shop */

	/* Show only first image */
	$('#product_hero img').hide();
	$('#product_hero img:first').show();


	/* Colour selector */
	$('#colour-selector li:first').addClass('selected');

	$('#colour-selector li label').click(function(){
		$('#colour-selector li').removeClass('selected');
		$(this).closest('li').addClass('selected');
		var $colour = $(this).find('input').attr('rel');
		$('#product_hero').find('img').hide();
		$('#product_hero').find('img.'+$colour).show();
	})



	$('#different-address-option').change(function(){
		if ($(this).is(":checked")){
				$('#shipping-address').slideDown();
			}
		else {
			$('#shipping-address').slideUp();
		}
	})


	/* Quantity controller */

	var $unitprice = $('#product-price .amount').text();

	$('#qty-controller li').click(function(){
		var $qty = eval($('#qty').attr('value'));

		if ($(this).attr('class') == 'qty-more' && $qty < 99) {
			$qty += 1;
		} else if ($(this).attr('class') == 'qty-less' && $qty > 1) {
			$qty -= 1;
		}

		if ($qty > 0 && $qty < 10) {
			$('#qty').attr('value',"0"+$qty);
		}
		else {
			$('#qty').attr('value',$qty);
		}

		// adjust price

		var $price = $qty * $unitprice;
		 $('#product-price .amount').text($price.toFixed(2));

		})


	$('#qty-controller #qty').focusout(function(){
		var qty = eval($(this).attr('value'));
		if (qty == null ) {
			$(this).attr('value', '01');
		}
		if (qty > 0 && qty < 10) {
			$('#qty').attr('value',"0"+qty);
		}
		})


	$('a[href^=http]').each(function(){
		$(this).attr('target', '_blank');
	});
});

