$.validator.addMethod("shippingFiller", function(element,value) {
	//$('#shipSame').hide();
	

	
	if($('#shipSame').is(":checked") == true){
		
		
		
		
	$('#shipFirstName').val($('#FirstName').val());
	$('#shipLastName').val($('#LastName').val());
	$('#shipAddress').val($('#Address').val());
	$('#shipAddress2').val($('#Address2').val());
	$('#shipCity').val($('#City').val());
	//$('#shipState').val($('#State').val());
	$('#shipZip').val($('#Zip').val());
	$('#shipCompany').val($('#Company').val());
	
	stateValues();

	$('#shipCountry').val($('#Country').val());
	
	
	
	//$('#shipStateDiv').html($('#shipStateDiv').html());
	

	//$("#myselect2").selectOptions("Value 2", true);
	}
	//return value == "buga";
	if ($('#shipCountry').val() == 'United States'){
		$('#InternationalShippingOptions').hide();
		$('#USShippingOptions').show();
	} else {
		$('#InternationalShippingOptions').show();
		$('#USShippingOptions').hide();
	}
	//alert($('#shipCountry').val());
	return true;
});







function stateValues(){
	$('#shipStateDiv select').val($('#stateDiv select').val());
	$('#shipStateDiv input').val($('#stateDiv input').val());
	
	
}


$(document).ready(function(){
	//$("#sample-menu-3").superfish();
	
	
	//alternating table rows
    $('table.zebra tr:odd').addClass('odd');
    $('table.zebra tr:even').addClass('even');
	
	
	
	//initilizing mega menu
	function addMega(){
        $(this).addClass("hovering");
        }

      function removeMega(){
        $(this).removeClass("hovering");
        }

    var megaConfig = {
         interval: 500,
         sensitivity: 4,
         over: addMega,
         timeout: 500,
         out: removeMega
    };

    $("li.mega").hoverIntent(megaConfig);

	
	
	
//turns on validation for new account form	
$("#newAccountForm").validate({
rules: {
	username: "required",
		email: "required",
	
		confirm_password: {
			required: true,
			equalTo: "#password"
		}
	}
	});
	
	
	// check if confirm password is still valid after password changed
$("#password").blur(function() {
	$("#confirm_password").valid();
});
	
//turns on the validation for product page
$("#productForm").validate();

//$("#sample-menu-3").superfish();



//turns on the validation for basket page
$("#basketForm").validate();
var basketValidator = $("#basketForm").validate();
$("#recalc").click(function() {
	basketValidator.form();
});

	//log-in form validation
	$("#loginForm").validate();
	
	//Customer Details Form Validation
	var validator = $("#custDetailsForm").validate({
	rules:{
	FirstName: "shippingFiller",
	LastName: "shippingFiller",
	Address: "shippingFiller",
	Address2: "shippingFiller",
	City: "shippingFiller",
	State: "shippingFiller",
	Zip: "shippingFiller",
	Country: "shippingFiller",
	shipCountry: "shippingFiller",
	confirm_email: {
		required: true,
		equalTo: "#Email"
	}
	
	}
	});
	
	//$("#shipSame").focus(function() {
	//$("#shipFirstName").value = 'hello';

	
	//all .blur functions below fills out shipping information
	$("#FirstName2").blur(function(){
	validator.form();
	
	});
	
	$("#LastName2").blur(function(){
	validator.form();
	
	});
	
	$("#Address2").blur(function(){
	validator.form();
	
	});
	
	$("#Address22").blur(function(){
	validator.form();
	
	});
	
	$("#City2").blur(function(){
	validator.form();
	
	});
	
	$("#State2").blur(function(){
	validator.form();
	
	});
	
	$("#Zip2").blur(function(){
	validator.form();
	
	});
	
	$("#Country2").blur(function(){
	validator.form();
	
	});
	
	$("#shipSame2").focus(function(){
	validator.form();
	
	});


	$("select#Country").change(function(){
		if($('#shipSame').is(":checked") == true){
		ColdFusion.navigate('/source/cfc/ajax.cfc?method=selectState&Country=' + $('#Country').val() + '&optionName=shipState&returnFormat=plain','shipStateDiv',stateValues);
		}
		});
	
	
	
	
	
	//disables the giftwrapMessage textarea box by default
	$("#giftwrapMessage").attr("disabled","disabled");
	
	//hides giftwrapDiv which contains giftwrapMessage box and additional information
	$('#giftwrapDiv').hide();
	
	//hides all of the shipping information fields on custDetails page
	$('#shippingInfoDiv').hide();
	
	//hides the entire address form for guests
	$('#addressFormDiv').hide();
	$("#clickHereGuest").click(function() {
		$('#addressFormDiv').show();
		$('#guestIntroDiv').hide();
	});
	
	//hiding checkout page divs
	$('#InternationalShippingOptions').hide();
	$('#ccvSample').hide();
	
	$("#whatsThis").click(function() {
		$('#ccvSample').show();
	});
	
	
	//if the shipsame box is checked hide shipping info, if not display them
	$("#shipSame").click(function() {
		if($('#shipSame').is(":checked") == true){
			$('#shippingInfoDiv').hide();
		} else {
			$('#shippingInfoDiv').show();
		}
	});
	
	//displays the giftwrap message box and additonal information
	$("#giftwrap").click(function() {
		if($('#giftwrap').is(":checked") == true){
		$("#giftwrapMessage").removeAttr("disabled"); 
		$('#giftwrapDiv').show();
		} else {
			$("#giftwrapMessage").attr("disabled","disabled");
			$('#giftwrapDiv').hide();
		}
	});

	
	//this disabled all itemMessages boxes unless a radio was marked as "yes". 
	//wasn't a valid approach for all products
	
	//$("#itemMessage").attr("disabled","disabled");
	//$("input[type='radio']").click(function() {
		//if($('#yesno_1').is(":checked") == true){
			//$("#itemMessage").removeAttr("disabled"); 
		//} else {
			//$("#giftwrapMessage").attr("disabled","disabled");
		//}
	//});


	
	
	//additonal Photos
    $(function() {
        $('#gallery a').lightBox();
    });
    
    //$(function() {
    	//smooth scrolling anchors
    	//$("a.anchorLink").anchorAnimate();
    //});

    //Buy Now/Ship Later
    $('#buyNowShipLater').hide();
    $("#buyNowShipLaterYes").click(function() {
    	$('#buyNowShipLater').show();
    });	
    $("#buyNowShipLaterNo").click(function() {
    	$('#buyNowShipLater').hide();
    });
    
    $("#tabbyClick").click(function() {
    var $tabs = $('#container-1').tabs();
    $tabs.tabs('select', '#fragment-6');
		window.location.hash = $("#tabbyClick").attr("href");
    
    return false;

});
    
     
    
});