// JavaScript Document

var nochange = false;

function set_hash() {
	if (!nochange) {
		var index;

		if ($('.address-container:visible').length != 0) {
			index = $('.address-container:visible').index();
		}
		else {
			index = '';
		}

		var tab = $('.my-account-tab a.active').attr('id');
		var content = $('.my-account-tab a.active').attr('href');

		window.location = '#'+tab+'~'+index;

		$(content+' form').attr('action', window.location.hash);
	}
}

jQuery(function($){

	//$('.footer-slide dl, .footer-slide, .footer-col-7').hide();


	$('#body-container').mouseenter(function() {

		if(!$('.basket-sliding-div-outer, .signin-sliding-div').is(':visible'))
		{
			$('.signin-sliding-div').hide();
			$('.basket-sliding-div-outer').hide();
		}
		else
		{
		}
	});

	if ($('#signup').children().children().children().hasClass('error') ||  $('#signup').find('.successText').length>0){
		$('.footer-slide').slideDown(500, function(){
			$('.footer-slide dl,.footer-col-7').fadeIn(500);
			$('.footer-slide-btn img').attr('src','/assets/img/footer-bullet-down.gif');
			$(window).scrollTo($(window).scrollTop() + $(window).height(), 2000);

		});

	}

	//footer scroll to
	//$('footer').localScroll({});

	//Header toogle for the signup

	$('.sign-up-btn').click(function () {

			$('.signin-sliding-div').slideToggle();
			$('.sign-up-btn ').toggleClass('sign-up-btn-highlight');
			$('.basket-sliding-div-outer').hide();

	});

	//Header toogle for the basket

	$('.quick-shopping-bag').mouseenter(function () {
			$('.sign-up-btn').removeClass('sign-up-btn-highlight');
			$('.basket-sliding-div-outer').show();
			$('.signin-sliding-div').hide();
			$('#bag-outer').addClass('bag-outer-hover');

			}).mouseleave(function(){

			$('.basket-sliding-div-outer').hide();
			$('#bag-outer').removeClass('bag-outer-hover');


	});

	//Footer show hide function

	$('.footer-slide-btn').click(function () {

			if(!$('.footer-slide').is(':visible'))
			{
				$('.footer-slide').slideDown(500, function(){
					$('.footer-slide dl,.footer-col-7').fadeIn(500);

					$('.footer-slide-btn img').attr('src','/assets/img/footer-bullet-down.gif');

					$(window).scrollTo($(window).scrollTop() + $(window).height(), 2000);
				});
			}
			else
			{
				$('.footer-slide dl,.footer-col-7').fadeOut(250, function(){
					$('.footer-slide').slideUp(500);
					$('.footer-slide-btn img').attr('src','/assets/img/footer-bullet.gif');
				});
			}
			return false;
	});

	//Show hide on mouse enter for the shop page items

//	$(".products-shop-details").hide();
//	$('.products-shop-item-container').mouseenter(function() {
//		$('.products-shop-image',this).stop(false, true).fadeOut(500);
//		$('.products-shop-details',this).stop(false, true).fadeIn(500);
//	}).mouseleave(function(){
//		$('.products-shop-image',this).stop(false, true).fadeIn(500);
//		$('.products-shop-details',this).stop(false, true).fadeOut(500);
//	});

/* Shop grid calc */


if($('.showcase-image').size() > 0)
{
	$('.products-shop-item-container').each(function(i)
	{
		if(i <= 8)
		{
			if ((i+1)%3 == 0){
            	$(this).addClass('right');
			}
        }

	});

	$('.products-shop-item-container:nth-child(5n+15)').addClass('right');

}
else
{
	$('.products-shop-item-container:nth-child(5n)').addClass('right');
}

	//$(".products-shop-details").hide();
	$('.products-shop-item-container.hasimg').live('mouseenter mouseleave', function(event) {
		if ( event.type == "mouseenter" ) {
			// do something on mouseover
			$('.products-shop-image',this).stop(false, true).fadeOut(500);
			$('.products-shop-details',this).stop(false, true).fadeIn(500);
		} else {
			// do something on mouseout
			$('.products-shop-image',this).stop(false, true).fadeIn(500);
			$('.products-shop-details',this).stop(false, true).fadeOut(500);
		}
	});

	$('.products-shop-image img').load(function(){
		$(this).closest('.products-shop-item-container').addClass('hasimg');
		$(this).parent().siblings('.products-shop-details').hide();
	});

	//Make the shop products div clickable

	$('.products-shop-details').live('click',function(){
		window.location=$(this).find('a').attr('href');
		return false;
    });

	$('.filter').click(function(){
      window.location=$(this).find('a').attr('href');return false;
    });

	$('.filter-result').click(function(){
      window.location=$(this).find('a').attr('href');return false;
    });

	//Filters

	$('.filter-options-container').hide();

	$('.filter').click(function (){
		if ($(this).hasClass('kwok')) {


		}
		else
		{
			$('.filter-options-container').slideUp()
			$('.filter').removeClass('kwok');
			var filterOptions = $(this).attr('id');
			$('.'+filterOptions+'').slideDown();
			$(this).addClass('kwok');
		}
	});

	//Product page accordian

	$('.product-accordian-content').hide();
	$('#product-accordian-content-first').show();
	$('.product-accordian-btn:first').addClass('on');

	//ACCORDION BUTTON ACTION (ON CLICK DO THE FOLLOWING)
	$('.product-accordian-btn').click(function() {

		//REMOVE THE ON CLASS FROM ALL BUTTONS
		$('.product-accordian-btn').removeClass('on');

		//NO MATTER WHAT WE CLOSE ALL OPEN SLIDES
	 	$('.product-accordian-content').slideUp('normal');

		//IF THE NEXT SLIDE WASN'T OPEN THEN OPEN IT
		if($(this).next().is(':hidden') == true) {

			//ADD THE ON CLASS TO THE BUTTON
			$(this).addClass('on');

			//OPEN THE SLIDE
			$(this).next().slideDown('normal');
		 }

	 });

	 // Lookbook next/prev
	 $('#product-next').live('click', function() {
		 // Get the image name
		 var src = $('#product-image img').attr('src').split('/').pop();

		 // Find the small image with the same name
		 var small_img = $('#style-assistant img[src$="/'+src+'"]');

		 // Index of this
		 var index = small_img.parent().index();

		 // If it's the last one
		 if (index == ($('#style-assistant img').length - 1)) {
			 index = 0; // First one
		 }
		 else {
			 index++;
		 }

		 // Click
		 $('#style-assistant a').eq(index).trigger('click');

		 // False
		 return false;
	 });
	 $('#product-prev').live('click', function() {
		 // Get the image name
		 var src = $('#product-image img').attr('src').split('/').pop();

		 // Find the small image with the same name
		 var small_img = $('#style-assistant img[src$="/'+src+'"]');

		 // Index of this
		 var index = small_img.parent().index();

		 // If it's the first one
		 if (index == 0) {
			 index = ($('#style-assistant img').length - 1); // First one
		 }
		 else {
			 index--;
		 }

		 // Click
		 $('#style-assistant a').eq(index).trigger('click');

		 // False
		 return false;
	 });

	//Product Page Share

//	$('.share-container').hide();

	$('#share-btn, #share-icon-btn').click(function(e) {

		e.preventDefault();

		if($('.share-container').is(':visible'))
		{
			$('.share-container').fadeOut(500);
		}
		else
		{
			$('.share-container').fadeIn(500);
		}
	});

	$('.cancel').click(function(e) {

		e.preventDefault();

		$('.share-container').fadeOut(500);
		$('#share-form .textbox, #share-form .textarea').val('');
	});

	//View Large image

	$('.full-size-container').hide();

	$('.view-full-size').click(function(e) {

		e.preventDefault();

		$('.full-size-container .full-image img').attr('src', $(this).attr('href'));
		$('.full-size-container').fadeIn('normal');
		$('.full-size-container-outer').show();
		$('#style-assistant-product-container').fadeTo(150, 0.33);

	});

	$('.product-image-thumbs-container img').click(function() {
		var img = $(this).attr('src').split('/').pop();

		$('.view-full-size').attr('href', '/data/products-medium/'+img);
	});

	$('.full-size-close, .full-size-container-outer').click(function(e) {

		e.preventDefault();
		$('.full-size-container').fadeOut('normal');
		$('.full-size-container-outer').hide();
		$('#style-assistant-product-container').fadeTo(150, 1);


	});

	$(".show-illustration").live("click", function (e){
		e.preventDefault();
		$(this).fadeOut();
		$(".size-illustration").slideDown();
	})

	$(".close-illustration").live("click", function (e){
		e.preventDefault();
		$(".size-illustration").slideUp();
		$(".show-illustration").fadeIn();
	})	

	// thumb click chandler

	$('.full-size-container ul a').click(function(e)
	{
		e.preventDefault();

		var src = $(this).attr('href');

		$('.full-image img:first').attr('src', src);

	});

	function productbox()
	{
		var winW = $(window).width();
		var left = (winW - 960)/2;
		$('.full-size-container').css('left',left);

	}

	productbox();

	$(window).resize(function(){
		productbox();
	});


	//Shop Page Carousel Hover

	$('.style-assistant-product-item').live('mouseenter mouseleave', function(event) {
		if (!$(this).find('.style-assistant-product-detail').hasClass('noimg')) {
			if ( event.type == "mouseenter" ) {
				// do something on mouseover
				$('.style-assistant-product-image',this).stop(false, true).fadeTo(150, 0.33);

				$('.style-assistant-product-detail',this).stop(false, true).fadeIn(150);
			} else {
				// do something on mouseout
				$('.style-assistant-product-image',this).stop(false, true).fadeTo(150, 1);
				$('.style-assistant-product-detail',this).stop(false, true).fadeOut(150);
			}
		}
	});

	$('.style-assistant-product-detail').click(function(){
		window.location=$(this).find('a').attr('href');

		return false;
    });

	//Checkout Delivery

	//$('.delivery-address-form-checkout').hide();
	//wrap radio buttons with span
	$('input:radio').wrap('<span class="radio"></span>');
	$('input:radio:checked').parent('span.radio').addClass('selected');

	//when span clicked change class on selected radio
	$('span.radio').live('click', function(event){
		//remove background on previous selected radio button
		var radioName = $(this).children('input:radio').attr('name');

		$("input[name='"+radioName+"']").parent('span').removeClass('selected');

		//add selected background to selected radio button
		$(this).addClass('selected');
	});

	$('#delivery-different').change(function() {
		if ($(this).is(':checked')) {
			$('[name="delivery_address_id"]:first').attr('checked', 'checked');
		}
	});

	$('#new-card').change(function() {
		if ($(this).is(':checked')) {
			$('.checkout-payment-container-stored').slideUp();
			$('.checkout-payment-container').slideDown();
		}
	});

	$('#prev-card').change(function() {
		if ($(this).is(':checked')) {
			$('.checkout-payment-container-stored').slideDown();
			$('.checkout-payment-container').slideUp();
		}
	});

	//Payment Radio Toggles

	$('#registered').show();

	$('.payment-radio-btn').attr('state', 'closed');

	$('.payment-radio-btn:first, #payment-stored-toggle').click(function(e) {

		var storedcardOpen = $('.payment-radio-btn:first').attr('state');
		e.preventDefault();
		if(storedcardOpen == 'closed')
		{
			$('.payment-radio-btn:first').addClass('on');
			if ($('#registered').is(':visible')){
				$('#registered').slideUp('normal');
				$('.payment-radio-btn:last').removeClass('on');
				$('.payment-radio-btn:last').attr('state','closed');
			}
			$('.checkout-payment-container-stored').slideDown('normal');
			$('.payment-radio-btn:first').attr('state', 'open');
		}
		else
		{

			$('.payment-radio-btn:first').removeClass('on');

			$('.checkout-payment-container-stored').slideUp('normal');
			$('.payment-radio-btn:first').attr('state', 'closed');
		}


	});

	$('.return-submit-btn').live('click', function(e) {
		e.preventDefault();
		var $form = $(this).parents('form');
		var $order_id = $form.find('.return-order-id').val();
		$.post( '/myaccount/return/returnitems/'+$order_id, $form.serialize(), function(data){
			set_hash();
			update_myaccount($order_id);
		})
	});
	
	// New returns
	
	$('.return-confirm-btn').live('click', function(e) {
		e.preventDefault();
		var $this = $(this);
		var href = $(this).attr('href');
		$.post(href)
			.success(function(data){
				$.fancybox(data, {width: 960, height: 550});
				$this.parents('.my-orders-info').find('.return-options').hide();
			});
	});
	
	$('.return-item-btn').live('click', function(e) {
		e.preventDefault();
		var $this = $(this);
		var $exchange_options = $this.parents('.my-orders-info').find('.exchange-options')
		
		$exchange_options.find('.size-choose').hide();
		$exchange_options.find('.reason-choose').show();
		$exchange_options.show();
		
	});
	
	$('select[name="return_reason"]').live('change', function(e) {
		$this = $(this);
		var order_id = $this.parents('.my-orders-item').find('input[name="order_id"]').val();
		var item_id = $this.parents('.my-orders-info').find('input[name="item_id"]').val();
		var return_reason = $this.val();
		$.post('/myaccount/return/return_item_ajax/'+order_id+'/', {'item_id': item_id, 'return_reason' : return_reason })
			.success(function(data){
				$.fancybox(data, {width: 450, height: 'auto'});
				$this.parents('.my-orders-info').find('.return-options').hide();
			});
	});
	
	$('.return-more-btn').live('click', function(e) {
		e.preventDefault();
		$.fancybox.close();
	});
	
	$('.exchange-item-btn').live('click', function(e) {
			e.preventDefault();
			
			var $this = $(this);
			var $exchange_options = $this.parents('.my-orders-info').find('.exchange-options');
			$exchange_options.show();
			$exchange_options.find('.size-choose').show();
			$exchange_options.find('.reason-choose').hide();
			$this.addClass('active');
		});
	
	$('.size-choose #item').live('change', function() {
		$this = $(this);
		var exchange_prod_id = $this.val();
		var order_id = $this.parents('.my-orders-item').find('input[name="order_id"]').val();
		var item_id = $this.parents('.my-orders-info').find('input[name="item_id"]').val();
		$.post('/myaccount/return/exchange_item_ajax/'+order_id+'/', {'item_id': item_id, 'exchange_item_id' : exchange_prod_id })
			.success(function(data) {
				$.fancybox(data, {height: 'auto', width: 450});
				$this.parents('.my-orders-info').find('.return-options, .exchange-options').hide();
			});
	});
	
	$('.return-confirmation-btn').live('click', function(e) {
		e.preventDefault();
		$.post('/myaccount/return/process_returns_ajax')
			.success(function(data) {
				$.fancybox(data, {height: 'auto', width: 960});
				update_myaccount();
			});
	});
	
	// End
	
	function update_myaccount(order_id) {
		$.ajax({
			url: '/myaccount/account/ajax',
			cache: false,
			success: function(html){
				$('#body-container').html(html);
				// Put us back on the correct tab.
				do_myaccount_tabs();
				$('.my-orders-info, .my-return-item, .my-return-items-info').hide();
				$('.my-orders-info-btn').attr('title' , 'show');
				$('.my-returns-info-btn').attr('title' , 'show');
				if(order_id != null)
				{
					// If we're supplying an item id then hide the
					// order info (like when page is first loaded)	
					$('.order-'+order_id+' .my-orders-info-btn:first').trigger('click');
				}
			},
			error: function(){
			}
		});
	}

	$('.payment-radio-btn:last, #payment-new-toggle').click(function(e) {

		e.preventDefault();

		var newcardOpen = $('.payment-radio-btn:last').attr('state');

		if(newcardOpen == 'closed')
		{
			$('.payment-radio-btn:last').addClass('on');
			if ($('.checkout-payment-container-stored').is(':visible')){
				$('.checkout-payment-container-stored').slideUp('normal');
				$('.payment-radio-btn:first').removeClass('on');
				$('.payment-radio-btn:first').attr('state','closed');
			}
			$('#registered').slideDown('normal');
			$('.payment-radio-btn:first').removeClass('on');
			$('.payment-radio-btn:last').attr('state', 'open');
		}
		else
		{
			$('.payment-radio-btn:last').removeClass('on');

			$('#registered').slideUp('normal');
			$('.payment-radio-btn:last').attr('state', 'closed');
		}

	});

	$('.address-form-parent input[type="text"]').keydown(function() {
		$(this).closest('.address-form-parent').find('.address_radio').removeAttr('checked');
	});

	$('.address-form-parent select').change(function() {
		$(this).closest('.address-form-parent').find('.address_radio').removeAttr('checked');
	});

	$('.add-address-btn').click(function(e) {
		e.preventDefault();

		var div = $(this).closest('.address-form-parent').find('.address-form-box');

		if (div.is(':visible')){
			div.slideUp();
		}
		else
		{
			div.slideDown();
			$(this).closest('.address-form-parent').find('.address_radio').removeAttr('checked');
			$(this).closest('.address-form-parent').find('.radio').removeClass('selected');

		}

	});

	$('.address_radio').click(function() {
		var div = $(this).closest('.address-form-parent').find('.address-form-box:visible');

		if (div.length > 0) {
			div.slideUp();
		}
	});

	//My Account Tabs
	function do_myaccount_tabs()
	{
		$('.my-account').hide();
		$('.my-account:first').show();
		$('ul.tabs li:first').addClass('active');

		$('ul.tabs li a').click(function(e) {
			e.preventDefault();
			$('ul.tabs li a').removeClass('active');
			$(this).addClass('active');
			var currentTab = $(this).attr('href');
			$('.my-account').hide();
			$(currentTab).show();

			set_hash();
		});

		var hashparts = window.location.hash.split('~');
		nochange = true;
		$(hashparts[0]).trigger('click');
		var tabparts = hashparts[0].split('_');

		$('#content_'+tabparts[1]).children().eq(hashparts[1]).show();

		if ($('#content_'+tabparts[1]).children().eq(hashparts[1]).offset()) {
			var top = $('#content_'+tabparts[1]).children().eq(hashparts[1]).offset().top;
			$('html').scrollTop(top);
		}

		nochange = false;
	}
	do_myaccount_tabs();

	//My Account page

	$('.address-btn').click(function(e) {
		e.preventDefault();

		var content = $(this).parent().nextAll('.address-container:first');

		if (content.is(':hidden')) {
			$('.address-container').slideUp();
			$('.address-btn').text('Edit');

			content.slideDown(function() {
				set_hash();
			});
			$(this).text('Close');
		}
		else
		{
			content.slideUp(function() {
				set_hash();
			});
			$(this).text('Edit');
		}
	});



	//My Account My Orders

	$('.my-orders-info, .my-return-item').hide();

	$('.my-orders-info-btn').attr('title' , 'show');

	$('.my-orders-info-btn').live('click', function(e) {

		var state = $(this).attr('title');

		if(state == 'show')
		{

			//$('.my-orders-info').slideDown('normal');
			$(this).text('Hide Order');
			$(this).css("background-image", "url('/assets/img/up-icon-white.gif')");
			$(this).parents('.my-orders-item').find('.my-orders-info, .my-return-item').slideDown();
			$(this).attr('title', 'hide');
		}
		else
		{

			//$('.my-orders-info').slideDown('normal');
			$(this).text('More Info');
			$(this).css("background-image", "url('/assets/img/shop-more-details-arrow.gif')");
			$(this).parents('.my-orders-item').find('.my-orders-info, .my-return-item').slideUp();
			$(this).attr('title', 'show');
		}

		e.preventDefault();
  		e.stopPropagation();


	});


	//My Account my returns
	$('.my-return-items-info').hide();

	$('.my-returns-info-btn').attr('title' , 'show');

	$('.my-returns-info-btn').live('click',function(e) {

		var state = $(this).attr('title');

		if(state == 'show')
		{

			//$('.my-orders-info').slideDown('normal');
			$(this).text('Hide returns');

			$(this).parents('.my-orders-item').find('.my-return-items-info').slideDown();
			$(this).attr('title', 'hide');
		}
		else
		{

			//$('.my-orders-info').slideDown('normal');
			$(this).text('Return items');

			$(this).parents('.my-orders-item').find('.my-return-items-info').slideUp();
			$(this).attr('title', 'show');
		}

		e.preventDefault();
  		e.stopPropagation();


	});


	// Location Map

	if($('.map-container').size() > 0)
	{
		var url = window.location.href;
		//check if hash exists
		if(url.indexOf("#")!=-1)
		{
			url = url.substr(url.indexOf('#')+1,url.length);
			$('.locations').hide();
			$('.locations-container' + ' .' + url).show();
		}
		else
		{
			$('.locations').not('.uk').hide();
		}
	}


	$('.map-container div').click(function(e)
	{
		e.preventDefault();
		var loc = $(this).attr('class');
		loc = loc.substr(0,loc.indexOf(" "));
		loc = loc.substr(loc.indexOf('-') + 1,loc.length);
		loc = loc.replace(/[0-9]/g, '');
		$('.locations-container .locations').hide();
		$('.locations-container' + ' .' + loc).show();
	});

	$('.location-wrap').hover(
		function(){
			var caption = $(this).attr('class');
			caption = caption.substr(0,caption.indexOf(" "));
			caption = caption.replace("location","caption");

			$('.'+caption).stop(true,true).fadeIn();
		},
		function(){
			var caption = $(this).attr('class');
			caption = caption.substr(0,caption.indexOf(" "));
			caption = caption.replace("location","caption");

			$('.'+caption).stop(true,true).fadeOut();
	});

	//My Account Wish List

	$(".my-account-wish-details").hide();
	$('.my-account-wish-container').mouseenter(function() {
		$('.my-account-wish-image',this).stop(false, true).fadeOut(500);
		$('.my-account-wish-details',this).stop(false, true).fadeIn(500);
	}).mouseleave(function(){
		$('.my-account-wish-image',this).stop(false, true).fadeIn(500);
		$('.my-account-wish-details',this).stop(false, true).fadeOut(500);
	});

	// DROP DOWN STYLING

	$('select.select').each(function(){
		var title = $(this).attr('title');
		if( $('option:selected', this).val() != ''  ) title = $('option:selected',this).text();
		$(this)
			.css({'z-index':10,'opacity':0,'-khtml-appearance':'none'})
			.after('<span class="select">' + title + '</span>')
			.change(function(){
			val = $('option:selected',this).text();
				$(this).next().text(val);
				})
	});

	$('select').each(function () {
		if($(this).hasClass('error')) {
			$(this).siblings('span.select').addClass('error-select');
		}
	});

	//refresh qty select
	if($('#item').length>0) {
		$('select.#item').live("change", function(){
			//var quantity = 	$('#quantity option:first').text();
			//$('#quantity').siblings('.select').text(quantity);
		});
	}


	 //Select box selector thing

	$('.select-overlay div ul li').click(function(e)
	{
		e.preventDefault();
		e.stopPropagation();
		alert('g');

	});

	//Static Page Fade In Bespoke tailoring

	//$('.fade1').hide();
	/*
	$('.fade2 img:first').hide();
	$('.fade2 img:last').hide();
	$('.fade3 img:first').hide();
	$('.fade3 img:last').hide();
	$('p.fade4').hide();
	*/
	//$('.fade2, .fade3, .fade4, .fade5').hide();

	setTimeout( function() {
		$('#large-image .bespoke-tailoring').animate({left:"60px"}, 1000);
	}, 1000 );

	//$('.fade1').delay(0).fadeIn(500);

	/*
	$('.fade2 img:first').delay(1000).fadeIn(500);
	$('.fade2 img:last').delay(1500).fadeIn(500);
	$('.fade3 img').delay(2000).fadeIn(500);
	$('p.fade4').delay(2000).fadeIn(500);
	*/
	//$('.fade2').delay(0).fadeIn(250);
	//$('.fade3').delay(250).fadeIn(250);
	//$('.fade4').delay(500).fadeIn(250);
	//$('.fade5').delay(750).fadeIn(250);


	//Static pages images

	//$('.static-images').hide();

	//$('.static-images').fadeIn(1500);

	//Static Page Fade In Heritage

	//$('.fade1').hide();
	//$('.fade2 img:first').hide();
	//$('.fade2 img:last').hide();
	//$('.fade3 img:first').hide();
	//$('.fade3 img:last').hide();
	//$('p.fade4').hide();

	setTimeout( function() {
		$('#large-image .heritage').animate({left:"17px"}, 1000);
	}, 1000 );


	//$('.fade1').delay(0).fadeIn(500);
	//$('.fade2 img:first').delay(1000).fadeIn(500);
	//$('.fade2 img:last').delay(1500).fadeIn(500);
	//$('.fade3 img').delay(2000).fadeIn(500);
	//$('p.fade4').delay(2000).fadeIn(500);


	// populate the categories in the footer
	$.ajax({
		url: "/shop/ajax/categories.json",
		dataType:'json',
		success: function(data){

			var col3 = '';
			var col4 = '';
			var alt = true;

			$.each(data, function(i) {

				if (alt) {
					col3 += '<dt><a href="/shop/products/all?category='+data[i].id+'">'+data[i].name+'</a></dt>';
					alt = false;
				} else {
					col4 += '<dt><a href="/shop/products/all?category='+data[i].id+'">'+data[i].name+'</a></dt>';
					alt = true;
				}

			});

			$('.footer-col-3').html(col3);
			$('.footer-col-4').html(col4);
		}
	});


	// prevent pasting "Confirmation Email" on contact page
	$("#contactform-email2, #feedbackform-email2").bind("paste", function(e) {
		e.preventDefault();
	});
	
	$('#addtowishlist').click(function(e){
		e.preventDefault();
		$.post('/basket/update/addtowishlist_ajax', $(this).parents('form').serialize())
			.success(function(data){
				if( $('.flash-notice').length > 0)
				{
					$('.flash-notice').text(data);
				}
				else
				{
					$('#body-container').prepend('<div class="flash-notice">'+data+'</div>');
				}
			});
	});


	$('.remove-lookbook-item').live('click', function() {
		var id = $(this).siblings('.prod-id').val();

		var self = this;

		// Ajax remove
		$.get('/myaccount/account/remove_from_wishlist/'+id+'/', function(data) {
			if (data == 1) {
				if ($('.my-account-wish-container').length == 1) {
					$(self).closest('.my-account').html('<h3>Sorry</h3><p>There are currently no products in your wish list. Feel free to browse the <a href="/shop/"> to add products.</p>');
				}
				else {
					$(self).closest('.my-account-wish-container').remove();
				}
			}
		});
	});
	
	//register 'Other Title' Dropdown
	$('#form_title').change(function(){
		$('.title_alt').hide();
		$('.othertitle').attr('disabled', 'disabeled');

		if($(this).find("option:selected").val() == "Other") {
			$("#other_title").show();
			$('.othertitle').removeAttr('disabled');
		}
	});

});//end jquery

