$(document).ready( function () {

	// misc ui elements
	$('#home-fourup li:last-child').addClass("fourup-last-item");
	$('#home-twoup li:last-child').addClass("twoup-last-item");
	$('.zebra-rows tr:even').addClass('alt');
	setDefaultInputText();
	
	$('#slider').anythingSlider({
	    autoPlay: true,
	    buildArrows : false,
	    buildStartStop: false,
	    delay : 5000  
	});

	// quick order
	$('a.back-link').click( function () {
		history.go(-1)
	});

	// set page
	$('input#digital-all').click( function () {
		if (this.checked) {
			$('.digital-single').attr("disabled", true);
			$('.digital-single').attr("checked", false);
			$('.single').addClass("disable-text");
		} else {
			$('.digital-single').attr("disabled", false);
			$('.single').removeClass("disable-text");
		}
	});
	// form validation
	$("form#CatalogRequest").validate();
	$("form#QuickOrderShoppingCartAdd").validate();

	$("form#CheckOut").validate({
		rules: {
			ShippingNote_SHIP: {
				maxlength: 48
			},
			NameOnCard: {
				minlength: 2
			},
			CardNumber: {
				creditcard: true
			},
			ConfEmail: {
				equalTo: "#EMail"
			},
			CEmail_SHIP: {
				equalTo: "#Email_SHIP"
			},
			confirm_create_account_password: {
				equalTo: "#create_account_password"
			},
			DigitalAgree: {
				required: true
			}
		},
		messages: {
			NameOnCard: "Enter the name on your card",
			CreditCardType: "Select a credit card type",
			DigitalAgree: "ERROR: Please accept our Terms of Service",
			confirm_create_account_password: "Passwords do not match",
			CardNumber: {
				creditcard: "Enter valid card number"
			}
		}
	});

	// form validation - custom validators
	jQuery.validator.addMethod("billingRequired", function (value, element) {
		if ($("#bill_to_co").is(":checked"))
			return $(element).parents(".subTable").length;
		return !this.optional(element);
	}, "");
	
	jQuery.validator.addMethod("phoneUS", function (phone_number, element) {
		phone_number = phone_number.replace(/\s+/g, "");
		return this.optional(element) || phone_number.length > 9 &&
		phone_number.match(/^(1-?)?(\([2-9]\d{2}\)|[2-9]\d{2})-?[2-9]\d{2}-?\d{4}$/);
	}, "Please enter valid phone number");
	
	jQuery.validator.addMethod("postalcode", function (postalcode, element) {
		return this.optional(element) || postalcode.match(/(^\d{5}(-\d{4})?$)|(^[ABCEGHJKLMNPRSTVXYabceghjklmnpstvxy]{1}\d{1}[A-Za-z]{1} ?\d{1}[A-Za-z]{1}\d{1})$/);
	}, "Please a valid zip code");
	
	// create tabs
	$("#product-tabs").tabs();
	$(".product-child-tabs").tabs();

	// lightbox dialogs
	$("a#zoom").fancybox({
		'titleShow': false,
		'transitionIn': 'fade',
		'transitionOut': 'fade'
	});

	$("a.dialog").fancybox({
		'width': 800,
		'height': 550
	});

	$("a#dialog").fancybox({
		'width': 800,
		'height': 550
	});

	$("a#dialog-med").fancybox({
		'width': 550,
		'height': 450
	});
	
	$("a.dialog-med").fancybox({
		'width': 550,
		'height': 450
	});

	$("a#dialog-small").fancybox({
		'width': 400,
		'height': 325
	});
	
	$("a.dialog-small").fancybox({
		'width': 400,
		'height': 325
	});

    $( "#header #sitetools ul li.cart a" ).hoverIntent( {
        over: function() { $( "#floating-cart" ).stop( true, true ).filter( ":hidden" ).show( "drop", { direction: "up" }, 800 ); },
        timeout: 200,  
        out: function() {}
    } );

    $( "#floating-cart" ).hoverIntent( {
        over: function() {},
        timeout: 200,  
        out: function() { $( this ).stop( true, true ).filter( ":visible" ).hide( "drop", { direction: "down" } ); }
    } );
    
    $( document ).click( function() {
        $( "#floating-cart" ).stop( true, true ).filter( ":visible" ).hide( "drop", { direction: "down" } ); 
    } );
    
    $( "#floating-cart" ).click( function( event ) {
        event.stopPropagation();
    } );

});
