$(document).ready(function() {

var pathname = window.location.href;

if(pathname.indexOf('nz.') > -1){
	$('#shoppingCartDescription').hide();
        $('#topRightNav').hide();
        $('.priceList').hide();

$('#colourDetails').html('<div class="details_btn2"><a href="/store-locator">FIND A STOCKIST</a></div>');
}

if(pathname.indexOf('au.') > -1){
	$('.productsListTitle').find('a').each(function(){
		if($(this).attr('href') == '/clearance/euro-990-vest' || $(this).attr('href') == '/clearance/euro-818-cape'){
			$(this).parentsUntil('.stormlineProductsOverall').parent().hide();
		}
	});

		if(pathname.indexOf('clearance/euro-818-cape') > -1){
		window.location.href = '/';
	}

	if(pathname.indexOf('clearance/euro-990-vest') > -1){
		window.location.href = '/';
	}

		
	}

$('.productsListTitle').find('a').each(function(){
		
	if(($(this).attr('href').indexOf('accessories/apron')) > -1){
		$(this).parentsUntil('.stormlineProductsOverall').parent().find('.priceList').hide();
	}



});

var disabled_items = new Array("apron", "deckhands-220-jacket", "deckhands-674-bib-and-brace");
var pagename = pathname.split("/");
	pagename = pagename[pagename.length - 1];

if(disabled_items.indexOf(pagename) > -1) {
	$('.priceDetail').empty();
	$('#colourDetails').html('<p style="padding-left: 35px;padding-right: 30px;">' + $('.productDescriptionFull').text() + '</p>');

}



//shipping checkbox <3 jquery
$('.select_same_ship').click(function(){
	if($(this).attr('checked')){
		$('#BillingAddress').val($('#ShippingAddress').val());
		$('#BillingState').val($('#ShippingState').val());
		$('#BillingCity').val($('#ShippingCity').val());
		$('#BillingZip').val($('#ShippingZip').val());
		$('#BillingCountry').val($('#ShippingCountry').val());
	}else{
		$('#BillingAddress').val('');
		$('#BillingState').val('');
		$('#BillingCity').val('');
		$('#BillingZip').val('');
		$('#BillingCountry').val('');
	}
});


$("a[rel='prettyPhoto']").toggle(function(){
$('#inline_demo').slideDown();
},function(){
$('#inline_demo').slideUp();
});
	

//reset zoom link rel
$('.zoom a').attr('rel', '');

//hide non-existing images
$('.thumb img').each(function(index){
	$(this).error(function(){
		$(this).parent().hide();
        $('.zoom' + (index + 1)).attr('rel','');
	});
});

$('.thumb img').each(function(index){
	
if (!$(this).hasClass('hidden')) {
		//Sets each zoom href to the corresponding images src but the zoom version
		
		$('.zoom' + (index + 1)).attr('href', $(this).attr('src').replace('thumb', 'zoom')).attr('rel', 'lightbox');
	}	

});

$('.productPhotoList a').each(function(){
	$(this).attr('href', $(this).parent().prev().children().attr('href'));
});

$('.productPhotoList a').each(function(){
	$(this).attr('href', $(this).parent().prev().children().children().attr('href'));
});


$('.thumb:first').css('background-image', 'url(/images/thumb-bg-on.png)').addClass('selected');

$('.thumb').hover(function(){
		if(!$(this).hasClass('selected')){
			$(this).css('background-image', 'url(/images/thumb-bg-on.png)');
		}
	},function(){
		if(!$(this).hasClass('selected')){
			$(this).css('background-image', 'url(/images/thumb-bg.png)');
		}
	}
);

//THUMB CLICK
$('.thumb').click(function(){
	//make currently active tabs inactive ready for tab change
	$('.thumb').css('background-image', 'url(/images/thumb-bg.png)');
	
	$('.thumb').removeClass('selected');
	
	//get source of thumbnail image, replace thumb with large
	$('.productPhotoDetail').children('img').attr('src', $(this).children('img').attr('src').replace('thumb', 'large'));
	
	//change tab to active
	$(this).css('background-image', 'url(/images/thumb-bg-on.png)').addClass('selected');
	
	$('.zoom a').attr('rel', '');
	
	$('.thumb img').each(function(index){
		if (!$(this).hasClass('hidden')) {
			//Sets each zoom href to the corresponding images src but the zoom version
			$('.zoom' + (index + 1)).attr('href', $(this).attr('src').replace('thumb', 'zoom')).attr('rel', 'lightbox');
		}
	});


	switch ($(this).children('img').attr('alt')){
		case '1' : break;
		case '2' :
			var temp = $('.zoom1').attr('href');			
			$('.zoom1').attr('href', $('.zoom2').attr('href'));
			$('.zoom2').attr('href', temp);
			break;
		case '3' :
			var temp = $('zoom1').attr('href');
			$('.zoom1').attr('href', $('.zoom3').attr('href'));
			$('.zoom3').attr('href', temp);
			break;		
	}
				

	//	}
});//END THUMB CLICK

//When the page has completely loaded, apply lightbox to items with rel='lightbox'
$(window).load(function() { 


    $('.zoom a[rel="lightbox"]').lightBox({fixedNavigation:false});

 }); 


//add labels to search items
$('.tag_phone').each(function(){

if ($(this).html()) {
    // The cell has stuff in it
    $(this).prepend("<b>Phone: </b>")
}

});

$('.tag_fax').each(function(){

if ($(this).html()) {
    // The cell has stuff in it
    $(this).prepend("<b>Fax: </b>")
}

});

$('.tag_email').each(function(){

if ($(this).html()) {
    // The cell has stuff in it
    $(this).prepend("<b>Email: </b>")
}

});

//end add items to search items

//submit search on change   
//$('.cat_button').hide();

$('.search_top').live("change keyup", function (){
    $(this).children('form').submit(); 
    $('.search_explain div').hide();
});

$('.faq-question').click(function(){
	if (!$(this).next('div').is(':visible')) {
		$('.faq-answer').slideUp(400);
		$(this).next('div').slideDown(400);
	}
});

//END DOCUMENT
});
