// FontDeck

WebFontConfig = {
   custom: { families: ['Franklin Gothic FS Book', 'Din Display Pro Thin'],
   urls: [ 'http://f.fontdeck.com/s/css/OmzMnj6OzIsj6rChDzo6yWt/m/c/markcharlesboots.com/4648.css' ] }
};
 
(function() {
   var wf = document.createElement('script');
   wf.src = ('https:' == document.location.protocol ? 'https' : 'http') + '://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js';
   wf.type = 'text/javascript';
   wf.async = 'true';
   var s = document.getElementsByTagName('script')[0];
   s.parentNode.insertBefore(wf, s);
})();

// Document Ready Functions
    
$(document).ready(function() {

	//Contact Us
	if( $("#contactform").length ) {
	$("#contactform").validate({
		submitHandler: function(form) {
			// Disable Submit
			$("#contactform .submit").attr("disabled","true").fadeTo("slow", 0.20).addClass("disabled");

			SubmitContactForm();
			return false;
		}
	});
	}
	
	// Join Mark's World
	if( $("#joinform").length ) {
		$("#joinform").validate({
			submitHandler: function(form) {
				// Disable Submit
				$("#joinform .submit").attr("disabled","true").fadeTo("slow", 0.20).addClass("disabled");

				SubmitJoinForm();
				return false;
			}
		});
	}

	// Comments
	if( $("#commentform").length ) {
	$("#commentform").validate({
		submitHandler: function(form) {
			// Disable Submit
			$("#commentform .submit").attr("disabled","true").fadeTo("slow", 0.20).addClass("disabled");

			SubmitJoinForm();
			return false;
		}
	});
	}

	// SeaOfClouds Twitter
    if($(".tweet").length) {
		$(".tweet").tweet({
            username: "markcharles_",
            join_text: "auto",
            avatar_size: 32,
            count: 4,
            auto_join_text_default: "we said,",
            auto_join_text_ed: "we",
            auto_join_text_ing: "we were",
            auto_join_text_reply: "we replied to",
            auto_join_text_url: "we were checking out",
            loading_text: "loading tweets..."
		});
	}

	
	/* Product Quantity Box */
	
	$(".cart-product-quantity").focus(function() {$(this).addClass("cart-product-quantity-selected");}).blur(function() {$(this).removeClass("cart-product-quantity-selected");});
	
	$(".cart-actions-change").click(function(event) {
		event.preventDefault();
		$(this).siblings('input').focus().select();
	});
	
	/* Login Box */
	
	$(function() {
		var slid = 0;
		$("#login_bttn,.login_link").click(function(){
			$("#login-form").slideToggle(150);
			if(slid == 0) {
				slid = 1;
				$('#login-form input[name="username"]').focus();
			} else {
				slid = 0;
			};
			return false;
		});
		$(document).click(function(){
			if(slid == 1) {
				$("#login-form").slideToggle(150);
				slid = 0;
			}
		});
		$("#login-form").click(function(e){e.stopPropagation();});
	});
	
	// Just a wee script to show the AJAX login if appropriate
	$("ul#top-nav li#login_bttn_noscript").css('display','none');
	$("ul#top-nav li#login_bttn").css('display','inline');
	
	// Home Page Fades
	if($("#home").length) {
		$("#header,#footer,#footer_base,.footer_base_text_centre").css('opacity','0');
		$("#content").children().hide();
		$("#content div:first").delay(500).fadeIn(1000);
		$("#content div:last").delay(2000).fadeIn(1000);
		$("#header,#footer,#footer_base,.footer_base_text_centre").delay(3500).fadeTo("slow", 1);
	}

	// The Art Landing Page Fades
	if($("#page-marks-world.the-art-landing").length) {
		$("body").animate({ backgroundColor: '#000'},1500);
		$("#header,#footer,#footer_base,.footer_base_text_centre").css('opacity','0');
		$("#content").hide();
		$("#content").delay(1000).fadeIn(1000);
		$("#header,#footer,#footer_base,.footer_base_text_centre").delay(2000).fadeTo("slow", 1);

		setTimeout('window.location = "http://markcharlesboots.com/marks-world/the-art/materials"', 7000);
	}
	
	// Mark's World Stuff
	
	var slidAway = 0;
	
	if($("#page-marks-world").length) {
    	$(".continue-next").hide().fadeTo(0.01);
    	if($(".slideshow").length) {$(".slideshow").hide().delay(500).fadeTo(1000,1);};
		$(".the-art-content").hide().delay(500).fadeTo(1000,1);
		$(".the-art-content").delay(6000).animate({bottom: '-140px'}, 1000,function() { slidAway = 1; });
		$(".continue-next").delay(3500).fadeTo("slow", 1);
		if($(".slideshow").length) {
    		$('.slideshow').cycle({
				fx: 'fade',
				pause:  0,
				delay:  4000  
			});
		};
    }
	
	// Arty Stuff
	if ($("#page-marks-world .art").length) {
		$("#page-marks-world .art").hover(function() {
			if(slidAway == 1) {
				$(this).children(".the-art-content").stop().animate({bottom: '0'}, 500);
			}
		}, function() {
			if(slidAway == 1) {
				$(this).children(".the-art-content").stop().animate({bottom: '-120px'}, 500);
			}
		});

	}

	// PRETTYPHOTO, Zoom functionality throughout content
	$("a[rel^='prettyPhoto']").each(function() {
			$(this).hover(function() {$(this).children('.zoom').fadeIn(250);}, function() {$(this).children('.zoom').fadeOut(250);});
		})
		.append('<img src="/themes/site_themes/mcb/images/zoom.png" alt="zoom" class="zoom" />')
		.prettyPhoto({
			showTitle: true,
			counter_separator_label: " of "
		});
		
	$("a[rel^='sizeGuide']").prettyPhoto();
		
	$(".hidden-rows").hide();
	
	$(".unhide").click(function() {
		var toShow;
		toShow = $(this).attr("href");
		$(this).parent().hide();
		$(toShow).fadeIn();
		return false;
	});
	
	/* Kill off Password fields on page load in the event that the browser has remembered password data */
	
	$('#member_form input[type="password"]').attr('value','');
	
	/* Billing Address to Shipping Address */
	
	if ($("input#use_billing_info").is(':checked')) {$("#shipping-hide").hide();}
	
	// Do this thang on Checkbox click.
	$("input#use_billing_info").click(function() {
	
		if ($("input#use_billing_info").is(':checked')) {
			
			var shippingAddress;
			$("#billing-address input,#billing-address select").each(function() {
				billingAddress = $(this).attr('id');
				shippingAddress = "#shipping_" + $(this).attr('id');
				$(shippingAddress).val($(this).val());
				});
			$("#shipping-hide").slideUp("fast");

		} else {$("#shipping-hide").slideDown("fast");};

	});

	// Also do this thang on Submit Button click and return the form.
	$("#submit_address,#checkout-button").click(function() {
	
		if ($("input#use_billing_info").is(':checked')) {
			var shippingAddress;
			$("#billing-address input,#billing-address select").each(function() {
				billingAddress = $(this).attr('id');
				shippingAddress = "#shipping_" + $(this).attr('id');
				$(shippingAddress).val($(this).val());
			});
		};
		return true;
	});
	// That's enough of that.
	
	// Account Login and Register box on Shipping Page
	
	var Slider
	
	$(".login-register").hide();
	$("#login-register-box .links a").click(function() {
		Slider = $(this).attr("href");
		$(".login-register").not(Slider).slideUp();
		$(Slider).slideDown();
		$("#login-register-box .links a").not(this).removeClass("active");
		$(this).addClass("active");
		return false;
	});
	
	$(".fieldset-hide").hide();
	
	$(".yes-please input").removeAttr('checked').hide();
	
	$(".yes-please label").click(function() {
		if($(this).siblings("input").is(':checked')) {$(this).removeClass("checked");} else {$(this).addClass("checked");}
	});
	
	if($("#slider3").length) {
	
	$("#slider3").anythingSlider({
		expand				: false,
		buildNavigation     : false,
		enableNavigation    : false,
		toggleControls      : false,
		enableArrows		: true,
		autoPlay            : false,
		navigationFormatter : function(i, panel) {
			return ['Top', 'Right', 'Bottom', 'Left'][i - 1];
		}
	})
	.anythingSliderFx({
		'.caption-top'		: ['caption-Top', '50px'],
		'.caption-right'	: ['caption-Right', '130px'],
		'.caption-bottom'	: ['caption-Bottom', '50px'],
		'.caption-left'		: ['caption-Left', '130px']
	})
	.find('div[class*=caption]').css({ position: 'absolute' }).prepend('<span class="close">x</span>').find('.close').click(function(){
			var cap = $(this).parent(),
				ani = { bottom : -50 }; // bottom
			if (cap.is('.caption-top')) { ani = { top: -50 }; }
			if (cap.is('.caption-left')) { ani = { left: -150 }; }
			if (cap.is('.caption-right')) { ani = { right: -150 }; }
			cap.animate(ani, 400, function(){cap.hide();} );
		});
		
	}
	
	$('[rel="modal"]').click(function() {
		return hs.expand(this);
	});
	
	$("#other-products ul li").css('opacity','0.6').hover(function() {$(this).stop().fadeTo(400,1);}, function() {$(this).stop().fadeTo(400,0.6);});
	
	// Select In-Stock Items
	
	$("#prod_size").children("option").removeAttr("selected");
	$("#prod_size").children("option").not(".grey").first().attr("selected","selected");
	
	var retEx;
	
	if ($('input[name="return_or_exchange"]:checked').length) {
		retEx = $('input[name="return_or_exchange"]:checked').val();
		$(".return-exchange-span").text(retEx);
		$("#return-exchange-button").val('Submit ' + retEx + ' request');
		$('input[name="return_or_exchange"]:checked').siblings("label").addClass("selected");
		$('input[name="return_or_exchange"]').css('visibility','hidden');
	}
	
	$('return-exchange-radios, input[name="return_or_exchange"]').click(function() {
		retEx = $('input[name="return_or_exchange"]:checked').val();
		$(".return-exchange-span").text(retEx);
		$("#return-exchange-button").val('Submit ' + retEx + ' request');
	});
	
	$(".return-exchange-radios label").click(function() {
		$(".return-exchange-radios label").not(this).removeClass("selected");
		$(this).addClass("selected");
	});
	
	if ($.browser.msie  && parseInt($.browser.version) == 7) {
	
		// IE7 does not support table row highlighting in this case.
	
	} else {
	
		$("#returns-table tbody tr").css("cursor","pointer");
		$('#returns-table tbody tr input[type="radio"]').css("visibility","hidden");
		$('#returns-table tbody tr input[type="radio"]:checked').parents("tr").addClass("selected");
		
		$("#returns-table tbody tr.order-row").click(function() {
			$("#returns-table tbody tr.order-row").not(this).removeClass("selected").find('input[type="radio"]').removeAttr("checked");
			$(this).find('input[type="radio"]').attr("checked","checked");
			$(this).addClass("selected");
		});
		
	}
	
	/* FORM VALIDATION */
	
	/* Returns and Exchanges */
	
	$("#returns_exchanges").validate({
		rules: {
			reasons: "required"
		},
		messages: {
			reasons: "Please fill this in."
		}
	});

	/* Billing & Shipping */
	
	$('#customer_info_form input[type="submit"], #submit_address').click(function() {
	
		if($("#use_billing_info").is(':checked')) {
			
			$(this).parents("form").validate({
					rules: {
						first_name: "required",
						last_name: "required",
						address: "required",
						city: "required",
						state: "required",
						zip: "required",
						phone: {required:true,number:true},
						email: {required:true,email:true}
					},
					messages: {
						first_name: "Please enter your first name",
						last_name: "Please enter your last name",
						address: "Please fill this in",
						city: "Please fill this in",
						state: "Please fill this in",
						zip: "Please fill this in",
						phone: "Please enter a telephone number, beginning with 0",
						email: "Please enter a valid email address"
					}
			});
			
		} else {
		
			$(this).parents("form").validate({
					rules: {
						first_name: "required",
						last_name: "required",
						address: "required",
						city: "required",
						state: "required",
						zip: "required",
						phone: {required:true,number:true},
						email: {required:true,email:true},
						shipping_first_name: "required",
						shipping_last_name: "required",
						shipping_address: "required",
						shipping_city: "required",
						shipping_state: "required",
						shipping_zip: "required"
					},
					messages: {
						first_name: "Please enter your first name",
						last_name: "Please enter your last name",
						address: "Please fill this in",
						city: "Please fill this in",
						state: "Please fill this in",
						zip: "Please fill this in",
						phone: "Please enter a telephone number, beginning with 0",
						email: "Please enter a valid email address",
						shipping_first_name: "Please fill this in",
						shipping_last_name: "Please fill this in",
						shipping_address: "Please fill this in",
						shipping_city: "Please fill this in",
						shipping_state: "Please fill this in",
						shipping_zip: "Please fill this in"
					}
					
			});
				
		}
		
	});
	
	$('#spoil_submit_address').click(function() {
	
		$.ch = {};
		$.ch.l = $(".yes-please input:checked").length;
	
		if($.ch.l < 1) {

			$("form#spoil_shipping :input").not("#shipping_address2").removeClass("error").removeClass("required");
			$("#can_you_help_me").addClass("required");
			$("form#spoil_shipping").validate();
		
		} else if($.ch.l >= 1) {
		
			$("form#spoil_shipping :input").not("#shipping_address2").addClass("required");
			$("#can_you_help_me").removeClass("error").removeClass("required");
			$("form#spoil_shipping").validate();
			
		}
	
	});
	
});







