$(document).ready(function() {

if ((screen.height>=770))
{
	$("body").addClass("high-res");
	
} else {

	$("body").addClass("low-res");
	
};


if ($.fn.browserTouchSupport.touches) { 
	$("body").addClass("touch-enabled");

} else {
	$("body").addClass("not-touch-enabled");
	
};

if ($.layout.name != 'webkit') {
	$("#landing-page .error-message").fadeIn('fast');
};


//$("input.phone-input").mask("(999)999-9999");

$.ajaxSetup({ cache: false });

var ajax_load_large = "<img src='/new_images/ajaxloader/ajax-loader-bw-large.gif' alt='loading...' />";
var ajax_load_small_orange = "<img src='/new_images/ajaxloader/ajax-loader-small-orange.gif' alt='loading...' />";


//Flash Tutorial
$(".msie6 .remove-for-ie").remove();
$(".msie7 .remove-for-ie").remove();



$("a#watch-tutorial-button[rel]").overlay({
	
	 mask: { 
        color: '#333', 
        loadSpeed: 200, 
        opacity: 0.5 
    }, 
     closeOnClick: false
 });
 
/*!Global Validation Settings*/
/*jQuery.validator.setDefaults({ */
	
	/*Set container for error elements */
	/*errorElement: "span",
	wrapper: "cite",

	
	invalidHandler: function(e, validator) {
	var errors = validator.numberOfInvalids();
	if (errors) {
	var message = errors == 1
	? 'You missed 1 field. It has been highlighted below'
	: 'You missed ' + errors + ' required fields.  They have been highlighted on the form.';
	$("div.error-message span").html(message);
	$("div.error-message").show();
	
	} else {
	$("div.error-message").hide();
	}
	},	
	
	rules: {
		brimar_card_number: {
				maxlength: 10
			},
		shipphonenumber1 : {
			minlength: 3,
			digits: true
		},
		
		phonenumber1 : {
			minlength: 3,
			digits: true
		},
		
		shipphonenumber2 : {
			minlength: 3,
			digits: true
		},
		
		phonenumber2 : {
			minlength: 3,
			digits: true
		},
		
		shipphonenumber3 : {
			minlength: 4,
			digits: true
		},
		
		phonenumber3 : {
			minlength: 4,
			digits: true
		}
	},
	
	messages: {
	
		shippingmethod: {
			required: "Please choose a shipping method"
		},
		
		payment : {
		required : "Please select a payment method"
		},
		
		contact_email : {
		required : "Please enter your email address"
		},
		
		email : {
		required : "Please enter your email address"
		},
		
		username : {
		required : "Please enter a username, this is usually your email address"
		},
		
		userpassword: {
		required : "Please enter your password"
		},
		
		createpassword: {
		required : "Please create a password"
		},
		
		confirmpassword: {
		required : "Please enter your password again",
		equalTo : "Please enter the same password again"
		},
		
		shipfirstname : {
		required : "Please enter your first name"
		},
		
		name : {
		required : "Please enter your name"
		},
		
		firstname : {
		required : "Please enter your first name"
		},
		
		contact_name : {
		required : "Please enter your name"
		},
		
		shiplastname : {
		required : "Please enter your last name"
		},
		
		lastname : {
		required : "Please enter your last name"
		},
		
		shipphonenumber : {
		required : "Please enter your phone number"
		},
		
		phonenumber : {
		required : "Please enter your phone number"
		},
		
		contact_phone : {
		required : "Please enter your phone number"
		},
		
		shipaddress1 : {
		required : "Please enter your shipping address"
		},
		
		address1 : {
		required : "Please enter your billing address"
		},
		
		billaddress1 : {
		required : "Please enter your billing address"
		},
		
		shipcity : {
		required : "Please enter your city"
		},
		
		city2 : {
		required : "Please enter your city"
		},
		
		billcity : {
		required : "Please enter your city"
		},
		
		sstate : {
		required : "Please choose a state"
		},
		
		state : {
		required : "Please choose a state"
		},
		
		shipzip : {
		required : "Please enter your zip code"
		},
		
		billzip : {
		required : "Please enter your zip code"
		},
		
		zipcode : {
		required : "Please enter your zip code"
		},
		
		brimar_card_number : {
		required: "Please enter your account number",
		maxlength: "The maximum amount of characters is 10. Ex. ABCDEFN001"
		},
		
		credit_card_number : {
		required : "Please enter your credit card number",
		creditcard : "Please enter a valid credit card number"
		},
		
		CCExpiresMonth: {
			required: "Please select a expiration date"
		},
		
		CCExpiresYear: {
			required: "Please select a expiration date"
		},
		
		security_code : {
		required : "Please enter your security code"
		},
		
		brimar_security_number : {
		required : "Please enter your security code"
		},
		
		shippingmethod: {
		required: "Please choose a shipping method"
		},
		
		payment : {
		required : "Please choose a payment method"
		},
		
		message: {
		required : "Please enter a message"
		},
		
		order_number: {
		required : "Please enter your order number"
		},
		
		credit_card_type : {
		required : "Please choose your credit card type"
		},
		
		shipphonenumber1 : {
		required : "Please enter your phone number"
		},
		
		phonenumber1 : {
		required : "Please enter your phone number"
		},
		
		shipphonenumber2 : {
		required : "Please enter your phone number"
		},
		
		phonenumber2 : {
		required : "Please enter your phone number"
		},
		
		shipphonenumber3 : {
		required : "Please enter your phone number"
		},
		
		phonenumber3 : {
		required : "Please enter your phone number"
		}
	
},

groups: {
	expirationdate: "CCExpiresMonth CCExpiresYear",
	shipphonenumber: "shipphonenumber1 shipphonenumber2 shipphonenumber3",
	billphonenumber: "phonenumber1 phonenumber2 phonenumber3"

},

 errorPlacement: function(error, element) { 
 	var parentElement = element.parent();
            if ( element.is(":radio") ) 
                 error.prependTo( element.parents("div#shipping-options"));
             else if(element.attr("name") == "CCExpiresMonth" || element.attr("name") == "CCExpiresYear" || element.attr("name") == "phonenumber1" || element.attr("name") == "phonenumber2" || element.attr("name") == "phonenumber3" || element.attr("name") == "shipphonenumber1" || element.attr("name") == "shipphonenumber2" || element.attr("name") == "shipphonenumber3")
             	error.appendTo(parentElement).addClass("phone-error");
             else    
                error.insertAfter(element); 
			
 			}
});*/

 
/*!Feedback Form Page Slide*/


$('form#site-feedback').validate({

invalidHandler: function(e, validator) {
var errors = validator.numberOfInvalids();
if (errors) {
var message = errors == 1
	? 'You missed 1 field. It has been highlighted below'
	: 'You missed ' + errors + ' required fields.  They have been highlighted below';
$("div#feedback-error-message span").html(message);
$("#feedback-intro").hide();
$("div#feedback-error-message").show();

} else {
$("div#feedback-error-message").hide();
$("#feedback-intro").show();
}
},
rules: {
    email: {
      required: true,
      email: true
    }
}, 
submitHandler: function(form) {
$(form).ajaxSubmit({
	beforeSubmit: showLargeLoadGraphic,
	success: showThankyouMessage

});}});




$("a#feedback").click(function(){ 

var feedbackForm = $("#feedback-form");
var closeFeedback = $("a.close-siderail")

if (Modernizr.csstransitions) {
		
	$(feedbackForm).css("display", "block").bind('webkitAnimationEnd', function() {
		$(closeFeedback).click(function(){
			$(feedbackForm).css("-webkit-animation-name","slideouttoright").bind('webkitAnimationEnd', function() {
				$(feedbackForm).css("display", "none").css("-webkit-animation-name","slideinfromright").unbind('webkitAnimationEnd');
		});
		});
	
	});
	
} else {

	$(feedbackForm).animate({
	
		width: ['50%','swing']

	}, "fast", function() {
			
	$(closeFeedback).click(function(){ 
		$(feedbackForm).fadeOut();}
	)});
			
	}
});

function showOther(divToOpen) {
	$(divToOpen).css("display", "block");

};


//Google Landing Pages 
if ($.fn.browserTouchSupport.touches) {
	
	var divToOpen = $("#other-sign-categories");
	
	$("#see-other-categories").bind("touchstart", function(){
		
		$(this).css("background-color", "red");
	
	return false; });
	
	$("#see-other-categories").bind("touchend", function(){
		
		showOther(divToOpen);
	
	return false; });
	
  	
} else {

$("#see-other-categories").click(function(){
	
	$("#other-sign-categories").slideDown('fast', function(){
		
$("#choose-another-category-footer").addClass("opened");
	
	$("#close-landing-page-menu").click(function(){
		$("#other-sign-categories").slideUp('fast');
		$("#choose-another-category-footer").removeClass("opened");
	});

return false;
});

});}

/*
$("a#watch-tutorial-button").fancybox({
	'hideOnContentClick': true
});
*/

$("div#movie_container").flashembed("/tutorials/custom_tool_demo.swf", { 
 	wmode: 'transparent',
 	expressInstall: '/tutorials/expressinstall.swf'}); 

//Focus Span next to Radio Buttons

//Clear form fields when user enters text

 $('.clearable').clearField({ blurClass: 'blurredinput', activeClass: 'activeinput' });


//Search Autocomplete

$("#search-input").autocomplete( nxt_ac_words, { 
 	selectFirst: false,
	autoFill: false,
	width: 260,
	scroll: false });


//Shopping Cart Preview Using jQuery Tools Tooltip

var shopPreviewconfig = {    
     sensitivity: 4, // number = sensitivity threshold (must be 1 or higher)    
     interval: 200 // number = milliseconds for onMouseOver polling interval    
        
};

//Prevent people from using spaces in email

function inputRestrictions() {
$("input.nospace").alphanumeric({ichars:' '});
$("input.number-for-sign-input").numeric({});
$("input.quantity").numeric({});
$("input#credit-card-number").alphanumeric({ichars:' '}); 
$("input#credit-card-number").bestupper({}); 
};

inputRestrictions();

//Set Global Variable for Price


function showShoppingCart(shopPreview) {

$('#shopping-cart-preview').slideDown('fast');
$(shopPreview).removeClass("loading");

}

$('html:not(.msie6,.msie7) a#view-your-shopping-cart').each(function() { 
	var shopPreview = $(this);
	$(this).hoverIntent( function() {
	$('dd#how-much span#go-to-cart').text("Go To Cart");
	$('span#totalhide').fadeOut('fast');
	$(this).addClass("showpreview").addClass("loading");

	$('#shopping-cart-preview').load('/shoppingcartpreview.php','',showShoppingCart(shopPreview));
},

function() {
	$('dd#how-much span#go-to-cart').text('My Cart:');
	$('span#totalhide').fadeIn('fast');
	$('#shopping-cart-preview').hide('fast');
	$(shopPreview).removeClass("showpreview");

});

})

//Add to Cart Form validation

	//Add a class of current-form to add-to-cart form inputs to isolate validation
	

//$('form.addtocart input[value = ""]').nextAll("button").attr("disabled","disabled");
//$('form.addtocart input.add-to-cart-input').attr("disabled","disabled");


//$('form.addtocart input.add-to-cart-input').attr("disabled","disabled");

//Add To Cart Custom Focus
$("input[name='designapproval']").click(function() {
	$("input[name='designapproval']").parent("div").removeClass("focus");
	$(this).parent("div").addClass("focus");
	var approval = $(this).val(); 	
	$("input[name='designapprovalchoice']").val(approval);
	
});

	
$('form.addtocart input[value = ""]').focus(function(){
	$(this).parents("form").addClass("validate-me");
	$(this).next("button").removeAttr("disabled");
	
});
	
$('form.addtocart input.add-to-cart-input').blur(function(){
	$(this).parents("form").addClass("validate-me");
	$(this).next("button").removeAttr("disabled");
	
});
	
//If Item has mounting option show mounting option div

$('form.custom.addtocart input.quantity:text').focus(function(){
$("div.has-material").fadeOut();
$("div.has-number-input").fadeOut();
if ($(this).attr("value")!="") {
	$(this).next("div.has-material").fadeIn("fast"); }
});

$('form.custom.addtocart input:text').keypress(function(){
if ($(this).attr("value")=="") {	
	$(this).next("div.has-material").show("fast");
	$(this).next("div.has-number-input").show("fast"); }
});

$('form.custom.addtocart input:text').blur(function(){
//$(this).next("div.has-material").show("fast");
	if ($(this).attr("value")=="") {
	$(this).nextAll("div.has-material").hide("fast");
	$(this).nextAll("div.has-number-input").hide("fast");
}
});
//If Item quantity is empty then hide mounting options
	
	
$('form.custom.addtocart input').blur(function(){
	$(this).parents("form").removeClass("validate-me");
});
//Validate that quanity field is not empty

function validate(formData, jqForm, options) { 
	var returnv=true;	
 	$(".add-to-cart-confirmation.showme").removeClass("showme");
	$("tr.data-row.over .add-to-cart-requiretext.showme").removeClass("showme");
    var form = jqForm[0];
    var formParent = $(form).parent();

	/*if ($("#line_1").length > 0)
	{
		if($("#line_1").val()=="")
		{
			$("tr.data-row.over .add-to-cart-requiretext").addClass("showme");
			$("tr.data-row.over .add-to-cart-requiretext.showme").fadeIn("fast");
			returnv=false;
		}
	}*/
    if (!form.qtyField.value||form.qtyField.value=='0') { 
        returnv= false;
	}
    if(!returnv)
	    return returnv;    
    else{
    $(form).find(".add-to-cart-button").attr("disabled","disabled");
	$("<div/>", {
	"class": "adding",
	text: "Adding...."
	}).appendTo(formParent);
    
    }
  	
    var currentquanity = $('tr.data-row.over input[name=qtyField]').fieldValue();
  	var currentmaterial = $('tr.data-row.over input[name=mounting_choice]').fieldValue();
  	
 	$("tr.data-row.over .add-to-cart-confirmation span.qty").text(currentquanity +'')
 	$("tr.data-row.over .add-to-cart-confirmation span.mounting").text(currentmaterial+'')
 	$("tr.data-row.over .add-to-cart-confirmation").addClass("showme");
 	$("div.has-material").fadeOut("fast");
 

}
function htmlvalidate(formData, jqForm, options) { 
	var returnv=true;	
 	$(".add-to-cart-confirmation.showme").removeClass("showme");
	$("tr.data-row.over .add-to-cart-requiretext.showme").removeClass("showme");
    var form = jqForm[0];
    var formParent = $(form).parent();
	if ($("#line_1").length > 0)
	{
		if($("#line_1").val()=="")
		{
			$("tr.data-row.over .add-to-cart-requiretext").addClass("showme");
			$("tr.data-row.over .add-to-cart-requiretext.showme").fadeIn("fast");
			 $(form).find("input:last-child").remove();			
			returnv=false;
		}
	}
	if($("#overmaximum").length>0)
	{
		if($("#overmaximum").is(':visible'))
			returnv=false;
	}
    if (!form.qtyField.value||form.qtyField.value=='0') { 
        returnv= false;
	}
    if(!returnv)
	    return returnv;    
    else{
    $(form).find(".add-to-cart-button").attr("disabled","disabled");
	$("<div/>", {
	"class": "adding",
	text: "Adding...."
	}).appendTo(formParent);
    
    }
  	
    var currentquanity = $('tr.data-row.over input[name=qtyField]').fieldValue();
  	var currentmaterial = $('#mounting_option').val();
  	
 	$("tr.data-row.over .add-to-cart-confirmation span.qty").text(currentquanity +'')
 	$("tr.data-row.over .add-to-cart-confirmation span.mounting").text(currentmaterial+'')
 	$("tr.data-row.over .add-to-cart-confirmation").addClass("showme");
 	$("div.has-material").fadeOut("fast");
 

}
function validateNumberform(formData, jqForm, options) { 
 
 	$(".add-to-cart-confirmation.showme").removeClass("showme");
    var form = jqForm[0]; 
    if (!form.qtyField.value ) { 
        return false; 
    } else if (!form.number_for_sign.value) {
    	return false; 
    	
    }
  
    var currentquanity = $('tr.data-row.over input[name=qtyField]').fieldValue();
  	var currentnumber = $('tr.data-row.over input[name=number_for_sign]').fieldValue();
 	
 	$("tr.data-row.over .add-to-cart-confirmation span.qty").text(currentquanity +'')
 	$("tr.data-row.over .add-to-cart-confirmation span.number").text('With the number ' + currentnumber+'')
 	$("tr.data-row.over .add-to-cart-confirmation").addClass("showme");
 	 
 	$("div.has-number-input").fadeOut("fast");
 
}


function showAddConfirm(responseText, statusText, xhr, $form) { 
	
	var form = $form;
	var formParent = $(form).parent();
	$(formParent).removeClass("loading");
	$(formParent).find("div.adding").remove();
	//$(form).find(".add-to-cart-button").attr("disabled","");
	$(form).find(".add-to-cart-button").removeAttr('disabled');
  $(".add-to-cart-confirmation.showme").fadeIn("fast");
 	var updateTop = responseText.split("|");
  $("div#items-in-your-cart-header dl").effect("highlight", {}, 1000);
  $("span#totalhide").text(" " + updateTop[2]);
  $("span#carthide").text(updateTop[1]);
  
  $(this).resetForm();
   $('.clearable').clearField({ blurClass: 'blurredinput', activeClass: 'activeinput' });



}

//Close confirmation box



$('form.custom.addtocart.has-number-input').ajaxForm({
 
 	beforeSubmit: validateNumberform,
 	resetForm: true,
 	success: showAddConfirm
 		
});

$('form.addtocart:not(.has-number-input)').ajaxForm({
 	
	beforeSerialize: function($form, options) { 
	      $("<input type='hidden' name='submit_type' value='ajax_submit' />").appendTo($form)         
	},
 	beforeSubmit: validate,
 	resetForm: true,
 	success: showAddConfirm
 		
});
$('form.addtocart.htmlcustom:not(.has-number-input)').ajaxForm({
 	
	beforeSerialize: function($form, options) { 
	      $("<input type='hidden' name='submit_type' value='ajax_submit' />").appendTo($form)         
	},
 	beforeSubmit: htmlvalidate,
 	resetForm: true,
 	success: showAddConfirm
 		
});

$('.add-to-cart-confirmation a.continue-shopping').click(function(){

	$('.add-to-cart-confirmation.showme').fadeOut("fast");
	return false;


});



function succesfulContactForm() {

	$(".form-container div.loading").fadeOut("fast")
	$(".form-container div.thankyou").fadeIn("fast");
	

}

function showLargeLoadGraphic() {

	$("form.contacting").fadeOut("fast");
	$(".form-container div.loading").fadeIn("fast").html(ajax_load_large);
	

}


/* !Validate Contact Form */
$('form#contact-form').validate({

rules: {
    contact_email: {
      required: true,
      email: true
    }
}
//, 
//submitHandler: function(form) {
//$(form).ajaxSubmit({
//	beforeSubmit: showLargeLoadGraphic,
//	success: succesfulContactForm
//});}
});

//If user chooses "other" for return reason then display a message box
$('#return-reason-selector').change(function() {
  if ($(this).val() == 'other') { 
     $("#other-reason-for-return").fadeIn();
  } else {
  
  	 $("#other-reason-for-return").fadeOut();
  
}});




jQuery.validator.addMethod("nowhitespace", function(value, element) {
	return this.optional(element) || /^\S+$/i.test(value);
}, "Spaces are not allowed"); 


$('form#new-user-register').validate({
invalidHandler: function(e, validator) {
var errors = validator.numberOfInvalids();
if (errors) {
	var message = errors == 1
		? 'You missed 1 field. It has been highlighted below'
		: 'You missed ' + errors + ' required fields.  They have been highlighted below';
	$("div.error-message span").html(message);
	$("div.error-message").show();
	
} else {
	$("div.error-message").hide();
}
},
rules: {
    email: {
      required: true,
      email: true
    },
    createpassword: {
    	required: true,
      	minlength: 5,
      	nowhitespace: true
    
    },
    confirmpassword: {
      equalTo: "#create-password"
    }
    
  },
submitHandler: function(form) {
	
	$(form).ajaxSubmit(
{
	success: function(msg){

	if(msg==1) 
	{
	javascript:location.reload(true);
	}
	else if(msg==0) 
	{
	$('form#new-user-register input#email').removeClass('valid').addClass('error');
	$('div#email-address-already-in-use').show('fast');
	
}}

});

}});


//Validate Standalone Guest Form

$('form#new-user-guest-checkout').validate({
invalidHandler: function(e, validator) {
var errors = validator.numberOfInvalids();
if (errors) {
	var message = errors == 1
		? 'You missed 1 field. It has been highlighted below'
		: 'You missed ' + errors + ' required fields.  They have been highlighted below';
	$("div.error-message span").html(message);
	$("div.error-message").show();
	
} else {
	$("div.error-message").hide();
}
},
rules: {
    email: {
     
      email: true
    },
    createpassword: {
   
      	minlength: 5,
      	nowhitespace: true
    
    },
    confirmpassword: {
   
    	equalTo: "#create-password"
    }
    
  }
});


$('form#returning-user-signins').validate({
	invalidHandler: function(e, validator) {
	var errors = validator.numberOfInvalids();
	if (errors) {
	var message = errors == 1
	? 'You missed 1 field. It has been highlighted below'
	: 'You missed ' + errors + ' required fields.  They have been highlighted below';
	$("div.error-message span").html(message);
	$("div.error-message").show();

	} else {
	$("div.error-message").hide();
	}
},
rules: {
    username: {
      required: true,
      email: true
    }
    
  }
});

//Default form tooltip
$("input.hastooltip").tooltip({ 
 
    // place tooltip on the right edge 
    position: "top center", 
    
    relative: true, 
 
 	
 	offset: [-10, 0], 

    // a little tweaking of the position 
 
    // use the built-in fadeIn/fadeOut effect 
    effect: "fade", 
 
    // custom opacity setting 
    opacity: 1, 
 
    // use this single tooltip element 
    tip: '.form-tooltip' 
 
});



//Show home button
$("div#header.container").hover(function() {
	$("h1#logo").addClass("preview")
}, 
      function () { 
      	$("h1#logo").removeClass("preview");
      }
      
);



//Add To Cart Panels
$("ul#item-detail-slide-navigation").tabs("div#additional-details-slider > div.panel",{
    effect: 'slide', 
    fadeOutSpeed: "fast", 
    rotate: true 

});

//Add to Cart Switch Details and Atributes

$("div#details-navigation ul").tabs("div#detail-attribute-panel > div.details-panel",{
    effect: 'slide', 
    fadeOutSpeed: "fast", 
    rotate: true 

});

function boldLabels(inputToChange) {
	$(inputToChange).next('label').addClass("chosen");
}

//NFPA Severity Switcher
$("div.choose-an-attribute input[type='radio']").click(function() {
	graphicToChange = $(this).attr("name");
	switchNumberto = $(this).val().replace(/ /g,'_').toLowerCase();
	$("div#"+graphicToChange).removeClass();
	$("div#"+graphicToChange).addClass("hazard_"+switchNumberto);
	$("div#"+graphicToChange+"-hazard label").removeClass("chosen")
	inputToChange = $(this)
	$("input."+graphicToChange).val(switchNumberto);
	boldLabels(inputToChange);
});


//Set up NFPA Choices as Global Variables



//Sign Color Switcher
$("div#choose-color.choose-an-attribute input[type='radio']").click(function() {
	colorSignToChange = $(this).attr("id");
	switchNumberto = $(this).val().replace(/ /g,'_').toLowerCase();
	
	$("img.current-sign-color").removeClass("current-sign-color").hide();
	$("img#item-"+colorSignToChange).show().addClass("current-sign-color");
	$("div#choose-color.choose-an-attribute label").removeClass("chosen")
	inputToChange = $(this)
	boldLabels(inputToChange);

})



/* !Add to Cart Preview Popup */

$('form:not(.custom) input.add-to-cart-input').focus(function() {
	$("div#loading-text").remove();
	$(this).after("<div id='loading-text' class='noshow'><h4>You've just added</h4><p><span class='qty'></span><span class='item-added'></span></p></div>");
		
$("td.add-to-cart-form a ").click(function() {

itemAddedAttributes();
	
}) });

//AddtoCart Verify Quanity if it has a mounting choice then display tooltip

$("form.has-material-option input.remotetooltip").tooltip({ 
 
    // place tooltip on the right edge 
    position: "center right", 
 	
 	offset: [-2, 20], 
    // a little tweaking of the position 
 	relative: true, 
 
    // use the built-in fadeIn/fadeOut effect 
    effect: "fade", 
 
    // custom opacity setting 
    opacity: 0.9, 
 
    // use this single tooltip element 
    tip: '.new-user-form-tooltip' 
 
});




$('div#expand-click-area').click(function(){
	$("div#loading-text").hide();
	$("div.add-to-cart-confirmation").hide();
 	$("div.add-to-cart-requiretext").hide();
})


//Remote Sign In

$("html:not(.msie6,.msie7) body:not('#signin-page') a.signin-remote-button[rel]").overlay({
	expose: { 
        color: '#333', 
        loadSpeed: 200, 
        opacity: 0.5 
    } 
 });

$("a#account-trigger").click( function(){

	$('div#why-sign-up-and-login').hide('fast');
	$('div#create-an-account').show('fast');
	return false;

});


//Set Equal Heights

$.fn.equalHeights = function(px) {
	$(this).each(function(){

		var currentTallest = 0;
		$(this).children().each(function(i){
			if ($(this).height() > currentTallest) { currentTallest = $(this).height(); }
		});
		//if (!px || !Number.prototype.pxToEm) currentTallest = currentTallest.pxToEm(); //use ems unless px is specified
		// for ie6, set height since min-height isn't supported
		if ($.browser.msie && $.browser.version == 6.0) { $(this).children().css({'height': currentTallest}); }
		$(this).children().css({'min-height': currentTallest}); 
		
	});
	return this;
	
};

//Set Equal Heights for Browse Product Pages
/*
$(window).load(function() {
	
	$('html:not(.msie6) div.product-subcategory-group').equalHeights(true);
	$('html:not(.msie6) div#item-image-and-description').equalHeights(true);
});
*/



$("div#custom-signs .edit-info").scrollable({
	
	size: 1
	  
}).navigator();

function removeItem() {
	// get handle to scrollable api
	var api = $("div.edit-form.choose").scrollable();

	// move in 1 millisecond to the end to see what will happen
	api.end(1);

	// remove last item with jQuery's remove() method
	api.getItems().filter(".delete").remove();

	// rebuild scrollable and go one step backward
	api.reload().prev();
}




//Submit Button Rollovers
		
$('input.search-btn').hover(   

	function() {
		$(this).attr({ src: "images/search_btn.png"});
	},
	function() {
		$(this).attr({ src: "images/search_btn_hover.png"});
	}
);


//Show and hide Search refinements

$('a.show-more').click(function() {
	$(this).prev("span.hidden-refined-results").slideToggle("fast").addClass("down");
	return false
});

$('a.show-more').toggle(

function() {

	$("span.button-copy",this).html("Show less ");

	return false
},

function() {

	$("span.button-copy",this).html("Show More ");

	return false
}

);

//TR Mouse overs
$('table tr.data-row').mouseover(function(){$(this).addClass("over");}).mouseout(function(){$(this).removeClass("over");});


//Highlighting Form Elements
function highlightFormContainers() {
$('input,textarea').each(function(){
	$(this).focus(function() {
		$(this).parents('div.form-container')
		.addClass('focused');
		$(this).prev('label').addClass('focused');
	
		}).blur(function() {
			$(this).parents('div.form-container').removeClass('focused');
			$(this).prev('label').removeClass('focused');
	});
});

}

highlightFormContainers();



/* !Validate Checkout Form */
$.metadata.setType("attr", "validate");


$(".checkout-form").validate({

rules: {
	

	credit_card_number: {
		required: true,
     	creditcard: true
	},
	
	 email: {
      required: true,
      email: true
    },
    
    zipcode: {
      required: true

    },
    
    shipzip: {
      required: true
      

    },
    
     shippingmethod: {
      required: true

    }
    
 
    
    }
	});

//Validate Edit Forms
//Shipping 


//http://furrybrains.com/2009/01/02/capturing-autofill-as-a-change-event/

$("form#checkout-form").listenForChange();  
$("form#edit-shipping-data").listenForChange();  



//Checkout Optional Steps
$('input#ship-zip-code').live('blur', function () {
	
	var shipcity = $("div#shipping-address input#ship-city").attr("value");
	var shipstate = $("div#shipping-address select#ship-state").attr("value");
	var shipzip = $(this).attr("value");
	var shipcountry = $("div#shipping-address select#ship-country").attr("value");

	$("#shipping-options").load("process/calculate-shipping-ajax.php", {'shipcity':shipcity,'shipstate':shipstate,'shipzip': shipzip,'shipcountry': shipcountry }, function(){
		$('div#shipping-options').slideDown('fast');
		} );
});

$('div#shipping-address-fields select#ship-country').change(function () {
	
	var shipcity = $("div#shipping-address input#ship-city").attr("value");
	var shipstate = $("div#shipping-address select#ship-state").attr("value");
	var shipcountry = $(this).attr("value");
	var shipzip = $("div#shipping-address input#ship-zip-code").attr("value");
	$("#shipping-options").load("process/calculate-shipping-ajax.php", {'shipcity':shipcity,'shipstate':shipstate,'shipzip': shipzip,'shipcountry': shipcountry }, function(){
		$('div#shipping-options').slideDown('fast');
		} );
});


// !Display Tax based on Customer's Shipping State //

$("body.NJ .conditional-tax").show();

function initializeTaxStatus() {

$("#ship-state").change(function() {
    var taxState = $(this).val();
    if (taxState != "NJ") {
        $(".conditional-tax").hide();
    } else {
          $(".conditional-tax").show();
    }
});

}

initializeTaxStatus(); 

$("a#why-is-my-card-declined[rel]").overlay({
	expose: { 
        color: '#333', 
        loadSpeed: 200, 
        opacity: 0.5 
    }
	
});

$("a#find-ccv-link").click(function() {

	$("#find-ccv").slideDown('fast');

})


//Grab checkout form input values

function displayVerifiedAddress(){
	
	var verifyshipaddress1 = $('input#ship-address1').val();
	var verifyshipaddress2 = $('input#ship-address2').val();
	var verifyshipcity = $('input#ship-city').val();
	var verifyshipstate = $('input#ship-state').val();
	var verifyshipzip = $('input#ship-zip-code').val();
	
	var UserShipAddress = [verifyshipaddress1,verifyshipaddress2,verifyshipcity,verifyshipstate,verifyshipzip];
	$('dl.verify-address-preview dd').each(function (i) {
		$(this).text(UserShipAddress[i]);
	
	});	
		
	
	
};

//Tabs for My Account Page
$("div.tab-container").tabs("div.options-tab > div.edit-form",{
	effect: 'slide', 
	api: true,
	initialIndex: null
	
});

//Scrollable Elements on Verify and My Account pages
/*
$(".edit-form.choose").scrollable({
	vertical: true,
	clickable: false,
	size: 2
	
}).navigator();
*/

function showChosenCard(action,edit) {
	var currentCard = $("input[name='payment']:checked").val();
if ($("input[name='payment']:checked").val() === 'Brimar') {

	$('div.credit-cards.payment-form').remove();
	$("div#insert-payment-method").load("/templates/checkout-sec/brimar-card-section.php",{'edit' : edit,'action':action },function(){
	$('.brimar-container.payment-form').fadeIn('fast');
	$('div#insert-billing-info').fadeIn('fast');
	restrictInputforBrimar(currentCard); 
	
	});	 	
	
		} else if ($("input[name='payment']:checked").val() !== 'Brimar') {
		
		$('.brimar-container.payment-form').remove();
		
		$("div#insert-payment-method").load("/templates/checkout-sec/credit-card-section.php",{'edit' : edit,'action':action },function(){
		$('div.credit-cards.payment-form').fadeIn('fast');
		$('div#insert-billing-info').fadeIn('fast');
		restrictCreditCardInput(currentCard);

});	
	}
} 

/* !Validate Shipping Edit Form */
function validateThisForm() {
	
	$("#edit-shipping-form").validate({
	
		rules: {
		shipzip: {
      	required: true
       

    }}
	
});
	 
$("#edit-payment-data").validate({
	
	rules: {
	credit_card_number: {
	required: true,
	creditcard: true
	}}
		
	
	}); 
}


/* !Get Card */

function GetCardType(number)
        {            
            var re = new RegExp("^4");
            if (number.match(re) != null)
                return "Visa";
 
            re = new RegExp("^(34|37)");
            if (number.match(re) != null)
                return "Amex";
 
            re = new RegExp("^5[1-5]");
            if (number.match(re) != null)
                return "Mastercard";
 
            re = new RegExp("^6011");
            if (number.match(re) != null)
                return "Discover";
                
            
}


function intializeCreditCardNumber() {

$("input#credit-card-number").change(function(){

	var number = $(this).val();
	var customersCard = GetCardType(number);
	var newCardImage = "<span id='dynamic-credit-card-image' class='"+customersCard+"'></span>";
	
	$("span#dynamic-credit-card-image").remove();
	$("input#payment-choice").val(customersCard);
	$("label#credit-card-number-label").append(newCardImage);

	
});

};

//intializeCreditCardNumber(); 

function intializePayByThis() {

$("div#pay-by-this-method ul li a").click(function(){
	$("div#pay-by-this-method ul li").removeClass("selected");
	$(this).parent("li").addClass("selected");
	var typeOfCard = $(this).attr("rel");
	if (typeOfCard == "credit-card") {
		$("#current-card-header").text("Enter Your Credit Card Information");
		$("label#credit-card-number-label span.text").text("Card Number");
		$("input#credit-card-number").attr('name', 'credit_card_number').val("").attr('title', '<span>Please do not enter any spaces</span>');
		$("div.card-number").removeClass("net30-card");
		$("p#net30-pitch").hide();
		$("a#security-code-help").show();
		$("input#security-code").attr('name', 'security_code').val("");
		$("#credit-card-expires-container").fadeIn("fast", function() {
		
			$(this).children("select").addClass("required");
		
		
		});
	
	} else {
		
		$("#current-card-header").text("Enter Your Brimar Net 30 Account Information");
		$("input#payment-choice").val("Brimar");
		$("label#credit-card-number-label span.text").text("Account Number");
		$("input#credit-card-number").attr('name', 'brimar_card_number').val("");
		$("div.card-number").addClass("net30-card");
		$("p#net30-pitch").show();
		$("a#security-code-help").hide();
		$("input#security-code").attr('name', 'brimar_security_number').val("");
		$("#credit-card-expires-container").fadeOut("fast", function() {
		
			$(this).children("select").removeClass("required");
		
		
		});
	
	}
return false; });

};


//intializePayByThis(); 

/* !Verification Page Scripts */ 

$('a.edit.inuse').click(function(){ 
	
	$("div.inserted").hide('fast').remove();
	var formBeingEdited = $(this).closest('form');
	
	var thisBody = $(this).parents("body").attr('id'); 
	if (thisBody == 'verify-page'){
	var edit = $(formBeingEdited).children('input.edit').val();
	var action = $(formBeingEdited).children('input.action').val();
	} else { 
	var edit = "";
	var action = "";
	}
	var myContainer = $(this).closest("div.edit-info");
	var myHighlight = $(this).closest("div.edit-info").find("div.highlight-edit");
	var urlToLoad = $(this).attr("rel");
	var loadFormHere = $(myContainer).find("div.add-new");
	
	
	if (thisBody == 'verify-page'){
			$(formBeingEdited).data('doingAinlineEdit', 'yes');
		} else {
		
			$(formBeingEdited).data('doingAinlineEdit', 'no');
		
		}
	
	$(myHighlight).effect("highlight", {}, 1000);
	$(loadFormHere).load( urlToLoad,{'edit' : edit,'action':action },function(){
	$(loadFormHere).children("div.inserted").fadeIn('fast').data('currentState', 'on'); 
	$(loadFormHere).show();
	//intializeCreditCardNumber();
	//intializePayByThis();
	inputRestrictions();
	initializeTaxStatus();
	//showChosenCard(action,edit);
	validateThisForm(); 
	var whatIstheState = $(this).children("div.inserted").data('currentState');
	//$("input.phone-input").mask("(999)999-9999");
});
closeEditForm();
return false;	
});


$('a.edit.inline').click(function(){
$("div.inserted").hide('fast').remove();
var myHighlight = $(this).parents("div.account-option-input").find("div.highlight-edit");
var formBeingEdited = $(this).parents('form');
$(formBeingEdited).data('doingAinlineEdit', 'yes');
var urlToLoad = $(this).attr("rel");
var action = $(formBeingEdited).children('input.action').val();
var edit = $(formBeingEdited).children('input.edit').val();
var divBeingEdited = $(this).closest("div.account-option-input");
var heightToChange = $(divBeingEdited).parents("div.choose");
var originalHeight = $(divBeingEdited).parents("div.choose").height();
	function setNewHeight(insertedHeight,insertedForm) {
		var newHeight = $(divBeingEdited).position().top + parseFloat(insertedHeight) + $(divBeingEdited).height() + 40;
			$(heightToChange).animate({
				height: newHeight }, 'slow');	
			}

	//$(myHighlight).effect("highlight", {}, 1000);
	var loadFormHere = $(divBeingEdited).find("div.add");
	$(loadFormHere).load(urlToLoad,{'edit': edit,'action': action},function(){
	
	var insertedForm = $(this).children("div.inserted");
	var insertedHeight = $(insertedForm).css('height');
		$(insertedForm).fadeIn('fast');
	//setNewHeight(insertedHeight,insertedForm);
	inputRestrictions();
	//intializeCreditCardNumber();
	//intializePayByThis();
	
	//showChosenCard(action,edit);
	validateThisForm();
	//$("input.phone-input").mask("(999)999-9999");
	var whatIstheState = $(this).children("div.inserted").data('currentState');
		
});
closeEditForm(originalHeight);
return false;	
});

/* !Cancel Verify Edit */


function closeEditForm(heightToChange,originalHeight,insertedForm) {
	$("button.canceledit").live("click", function(){
		var api = $("div.tab-container").tabs("div.options-tab > div.edit-form",{api: true});
	$(this).click(function(){ api.click(0); });
		$("div.inserted").fadeOut("fast").remove();
		$(heightToChange).animate({
			height: originalHeight}, 'fast');	
		
		return false
	});
		
};



/* verify page shipping record makedefult*/
$('a.make-default').live("click", function(){ 
	var rowToMakeDefault = $(this).parents('div.account-option-input');
	var edit = $(rowToMakeDefault).attr('id');
	var action = 'makedefault'
	var pathname = window.location.pathname;
	var currentDefault = $(this).parents('form').find("div.row.default");
	var buttonCopy = $(rowToMakeDefault).find("a.make-default span.button-copy");
	var defaultButtonCopy = $(currentDefault).find("a.make-default span.button-copy");
	var thisBody = $(this).parents("body").attr('id'); 
	var urlToLoad = $(this).attr("rel");
	var currentDefaultDisplay = $(this).parents("form").find("div.inuse-highlight");
	var textToReload = $(this).parents("form").find("div.inuse-highlight span.reload-me");
	var sectionId = $(this).parents('form').attr('id');
	$(rowToMakeDefault).addClass('active');

		function changeDefaultlisting() {
		
			$(rowToMakeDefault).addClass('default').removeClass('active');
			$(currentDefault).removeClass('default');
			$(buttonCopy).text("Current");
			$(defaultButtonCopy).text("Make Default");
			if (thisBody == 'verify-page'){
			verifyredirect();
			}
		
		}
	
	$.ajax({
	type: "POST",
	url: urlToLoad,
	data: {'edit': edit,'action': action},
	success: function(){
	$(currentDefaultDisplay).effect("highlight", {}, 1000);
	
	if(sectionId == 'edit-shipping-form') {
			$(currentDefaultDisplay).load("/myaccount.php form#edit-shipping-form span.reload-me",function(){
		changeDefaultlisting();
		
	});} else if (sectionId == 'edit-payment-data') {
		$(currentDefaultDisplay).load("/myaccount.php form#edit-payment-data span.reload-me",function(){
		changeDefaultlisting();
	});}
	
	}});
});

/* !shipping record delete */
$('a.delete').live("click", function(){ 
	var rowTodelete = $(this).closest('div.account-option-input');
	var edit = $(rowTodelete).attr('id');
	var action = 'delete'
	var countIcon = $(this).parents("form").find("a.count span.icon");
	var currentCount = $(countIcon).text();
	var urlToLoad = $(this).attr("rel");
	
	$.prompt('Are Your Sure, you want to delete this address?',{ 
	buttons: { Ok: true, Cancel: false },
	callback: function(v,m,f){
	
	if(v){
	
	$.ajax({
	type: "POST",
	url: urlToLoad,
	data: {'edit': edit,'action': action},
	success: function(){

	$(rowTodelete).hide('fast').remove();
	$(countIcon).text(currentCount - 1);
	if(urlToLoad=="/templates/checkout-sec/billing-status-update.php")
	{
	$("#inuse-payment").removeClass('div.inuse-highlight highlight-edit');
	$("#inuse-payment").hide('fast').remove();
	$("div#default-billing-options").load("process/get_default_billing_address.php", function(response, status, xhr){
	$('div#default-billing-options').fadeIn("slow");
	})
	}	 
	
	
	}
	});

	} else{}
	
	}
});
return false;	
});

$("a.edit.oneform").click(function(){
	var myContainer = $(this).closest("div.edit-info");
	var myHighlight = $(this).closest("div.edit-info").find("div.highlight-edit");
	$(myHighlight).effect("highlight", {}, 1000);
	$(myContainer).find('.edit-form').fadeIn('fast').data('currentState', 'on');
	return false;	

});



$('div.noajax button.canceledit').click(function() {
	var myContainerstate = $(this).parents("div.edit-info").find('.edit-form');
	if (myContainerstate.data('currentState', 'on')) {
		myContainerstate.data('currentState', 'off');
		myContainerstate.fadeOut('fast');
	
	
	}
	return false;	
});

//Add Class to default elements in My Account/Verification Pages

$('div.edit-form input[type="radio"]').click(function() {
	$('div.account-option-input').removeClass('focused');
	$(this).parents('div.account-option-input').addClass('focused rounded-corner');
	
});


$('div.account-option-input.row').hover(function() {
	$('div.account-option-input.row').removeClass('focused');
	$(this).addClass('focused');
	
});


function restrictInputforBrimar(currentCard) {

	$("input#brimar-card-number").alphanumeric({allcaps:true});
	$("input.hastooltip").tooltip({ 
 
  // place tooltip on the right edge 
    position: "top center", 
    
    relative: true, 
 
 	
 	offset: [-10, 0], 

    // a little tweaking of the position 
 
    // use the built-in fadeIn/fadeOut effect 
    effect: "fade", 
 
    // custom opacity setting 
    opacity: 1, 
 
    // use this single tooltip element 
    tip: '.form-tooltip' 
 
 
});
	
 $("body#checkout-page input#brimar-card-number").val(currentCard+" Number");
 $("#current-card-header").text("Enter Your "+currentCard+" Card Information").effect("highlight", {}, 1000);
 $('.clearable').clearField({ blurClass: 'blurredinput', activeClass: 'activeinput' });

};


/* !Credit Card Input*/
function restrictCreditCardInput(currentCard) {

	$("input.nospace").alphanumeric({ichars:' ',allcaps:true});
	$("input.hastooltip").tooltip({ 
 
// place tooltip on the right edge 
    position: "top center", 
    
    relative: true, 
 
 	
 	offset: [-10, 0], 

    // a little tweaking of the position 
 
    // use the built-in fadeIn/fadeOut effect 
    effect: "fade", 
 
    // custom opacity setting 
    opacity: 1, 
 
    // use this single tooltip element 
    tip: '.form-tooltip' 
 
 
});
$("#current-card-header").text("Enter Your "+currentCard+" Account Information").effect("highlight", {}, 1000);
 $("body#checkout-page input#credit-card-number").val(currentCard+" Number");
 $('.clearable').clearField({ blurClass: 'blurredinput', activeClass: 'activeinput' });

};


//Change payment method form based on what Radio button is clicked. 
$("input[name='payment']").live("click", function(){
$('#insert-billing-info').show('fast');

var currentCard = $(this).val();
$("ul.credit-card-type li").removeClass("selected");
$(this).parent("li").addClass("selected");
var action = $('form#edit-payment-data input#billingaction').val();

if ($('form#edit-payment-data').data('doingAinlineEdit') == "yes") {
	
	var edit = $('form#edit-payment-data input#billingedit').val();
}

if ($("input[name='payment']:checked").val() === 'Brimar') {
	
	$('ul.credit-cards.payment-form').remove();
	$("div#insert-payment-method").load("/templates/checkout-sec/brimar-card-section.php",{'edit' : edit,'action':action },function(){
	$('.brimar-container.payment-form').fadeIn('fast');
	restrictInputforBrimar(currentCard); 
	});	
	
		
		} else if ($("input[name='payment']:checked").val() !== 'Brimar') {
		
		$('.brimar-container.payment-form').remove();
		
		$("div#insert-payment-method").load("/templates/checkout-sec/credit-card-section.php",{'edit' : edit,'action':action },function(){
		highlightFormContainers();
		$('ul.credit-cards.payment-form').fadeIn('fast');
		$("a#security-code-help").tooltip({
		position: "bottom center"	
		});
		restrictCreditCardInput(currentCard);
});	
	}
});







/*direct function*/
function redirect()
{
location.replace("myaccount.php");	
}


function verifyredirect()
{
location.replace("verify.php");	
}


//Edit Forms Ajax Submit and update



$('#edit-shipping-data').ajaxForm({
	dataType:  'json', 
	success:   setEditedShippingData,
	clearForm: 'true'
	
});
$('#edit-billing-data').ajaxForm({
	dataType:  'json', 
	success:   setEditedBillingData,
	clearForm: 'true'
});

$('#edit-shipping-method').ajaxForm({
	dataType:  'json', 
	success:   setEditedShippingMethod,
	clearForm: 'true'
});

function setEditedShippingData(data) { 

		$('address#shipping-info').fadeOut("fast").fadeIn("fast")
		$('span#shipaddress1').text(data.shipaddress1);
		$('span#shipaddress2').text(data.shipaddress2);
		$('span#shipcity').text(data.shipcity);
		$('span#shipstate').text(data.shipstate);
		$('span#shipzip').text(data.shipzip);
		$('span#shipfirstname').text(data.shipfirstname);
		$('span#shiplastname').text(data.shiplastname);
		$('span#shipcompany').text(data.shipcompany);
		$('span#shipcountry').text(data.shipcountry);
		
		//Close Expanconsoleded Box
		$('div#edit-shipping-address.expandee').slideToggle("fast");
}

function setEditedBillingData(data) { 
		$('address#billing-info').fadeOut("fast").fadeIn("fast")
		$('span#address1').text(data.address1);
		$('span#address2').text(data.address2);
		$('span#city').text(data.city);
		$('span#state').text(data.state);
		$('span#zip').text(data.zipcode);
		$('span#firstname').text(data.firstname);
		$('span#lastname').text(data.lastname);
		$('span#company').text(data.company);
		$('span#country').text(data.country);
		
		//Close Expanded Box
		$('div#edit-billing-address.expandee').slideToggle("fast");
}

function setEditedShippingMethod(data) { 
		$('p#current-shipping-method').fadeOut("fast").fadeIn("fast")
		$('p#current-shipping-method').text(data.shippingmethod);

		
		//Close Expanded Box
		$('div#edit-shipping-method.expandee').slideToggle("fast");
}



//Sort Order History Tables
 $("#orderHistory").tablesorter(); 

//Help Tooltips
$("a.help").tooltip({
	
 position: "center left",
 
 events: { 
    def:      "click,hover",                // default show/hide events for an element 
    input:     "focus,blur",                        // for all input elements 
    widget:    "focus mouseover,blur mouseout"   // select, checkbox, radio, button 
               // the tooltip element 
},
effect: 'slide',
direction: 'left',
slideOffset: 10,
bounce: true }
);

$("#edit-cart").tooltip({ 
	position: "center left",
	effect: 'slide',
	direction: 'left',
	slideOffset: 10,
	bounce: true
	
});



$('.click-to-expand').click(function() {

	$(this).toggleClass('selected');
	$(this).nextAll('div.expandee').slideToggle("fast").addClass("expanded");
	return false;
});

$('a.close').click(function() {
		
		$(this).parents(".expanded").slideUp("fast").removeClass("expanded");
});

//Close Notices
$('div.notice div.close').click(function() {
		
		$(this).parent(".notice").fadeOut("fast");
});


//Generate a table of contents
$("#toc").tableOfContents(
      $("body.questions .help-container"),      // Scoped to div#wrapper
      {
        startLevel: 3,    // H2 and up
        depth:      4,    // H2 through H5,
        topLinks:   true // Add "Top" Links to Each Header
      }
     

    ); 
  //Smooth Anchor Scrolling  
  
$("a.toc-top-link").click(function(){
$.scrollTo( 0, 500);
return false;
});


/* !Validate Contact Form */
//Change Guest Checkout div based on what Radio button is clicked. 
$('input[name=new_user_checkout]:radio#register').click(function() {
		$('div#create-an-account.expandee').fadeIn("fast");
		$('input#new_user_register').fadeIn('fast',function(){
		$('div#new-users-signup p.benifits span').html("Register to use <strong>convenient features</strong> and <strong>quick checkout</strong>");
		});
		$('div#guest_user_submit-container').fadeOut("fast");
		
		//setRegisterformValidation();
	
}); 

$('input[name=new_user_checkout]:radio#check_out_as_guest').click(function() {
		$('div#create-an-account.expandee').fadeOut("fast");
		$('input#guest_user_submit').fadeIn("fast");
		$('div#guest_user_submit-container').fadeIn("fast");
		$('input#new_user_register').fadeOut("fast");
		$('div#new-users-signup p.benifits span').html("Check out without registering for an account");
	
}); 

//Tooltips 
$(".trigger").tooltip({ 
    position: ['center', 'center'], 
 	offset: [-50,-50], 
 	effect: 'slideup',   
    opacity: 1
 
    
});

$(".trigger-tweak").tooltip({ 
    position: ['center', 'center'], 
 	offset: [-50,20], 
 	effect: 'slideup',   
    opacity: 1
 
    
});

//Copy Billing Address to Shipping Address

$('#copy-billing').click(function(){

if($('#copy-billing').is(":checked")) {
$('#bill-address-fields input',':visible',document.body).each(function(i) {

$(this).val($('#shipping-address input.copy').eq(i).val() );
});

$('#bill-address-fields select',':visible',document.body).each(function(i) {

	$(this).val($('#shipping-address select').eq(i).val() );
});
		
} else {

$('#bill-address-fields input', ':visible', document.body).each(function(i) { 
//set shipping_fields inputs to blank
$(this).val(""); 
});

}

});


//Show Tax Exempt Message
$("input[name='tax_exempt_status']").change(function(){ 
	if( $("input[name='tax_exempt_status']:checked").val()=='Y' ) {
		$("p#tax-exempt-notice").fadeIn("slow");
	
	} else {
		$("p#tax-exempt-notice").fadeOut("fast");
	}
	

});



//Zoom Product Images

//Set the dafault directory for images

  
function resizeFancybox() {
	var newHeight = $('div#fancy_div div.table-wrap').height();
	var newHeightpadding = newHeight + 21;
	$('div#fancy_outer').height(newHeight + 21);

};


$("a.zoom").fancybox({
'imageScale': true, 
'overlayShow' : true,
'zoomSpeedIn' : 300,
'zoomSpeedOut' : 300,
'easingIn' : 'easeInCubic',
'easingOut' : 'easeOutBounce' });
/*
$("a.preview-pricing[rel]").overlay({
	expose: { 
        color: '#333', 
        loadSpeed: 200, 
        opacity: 0.5 
    },
    top: '25%'
   
});*/

$("a.preview-pricing[rel]").overlay({
	expose: { 
        color: '#333', 
        loadSpeed: 200, 
        opacity: 0.5 
    },
	top: '25%',
	
	 onBeforeLoad: function(event) { 
	    var count = this.getTrigger().parents('div.zoom-preview').find('form.preview-price-form input.count').val();
		var productno = this.getTrigger().parents('div.zoom-preview').find('form.preview-price-form input.productno').val();
      	// grab wrapper element inside content
			var wrap = this.getContent().find(".table-wrap");

			// load the page specified in the trigger
			wrap.load(this.getTrigger().attr("href"),{'productno':productno });
		
    }
   
});




$("a.verify-address").fancybox({

 'hideOnContentClick': true,
 'frameWidth' : '300.0',
  'callbackOnStart' : displayVerifiedAddress
 
});




//Filter Signs by Category
$('ul#filter a').click(function() {

	$('h3#filtered-category').addClass('hidden');
	$('div.product-subcategory-group h3').addClass('hidden');
		$(this).css('outline','none');
		
		$('ul#filter .current').removeClass('current');
		$(this).parent().addClass('current');
		var filterVal = $(this).text().toLowerCase().replace(/ /g,'-').replace(/\./g,'-').replace(/\//g,'-');
		
		var headerVal = $(this).text();		
		$("div#category-filter").after('<h3 id="filtered-category" class="'+ filterVal +'" >' + headerVal + '</h3>');
		if(filterVal == 'show-all') {
			$('li#show-all a').text('Filter Signs');
			$('li#show-all').addClass('disabled');
			$('div.product-container.hidden').fadeIn('slow').removeClass('hidden');
			$('div.product-container').width(140).css('border-left-style','none');
			$('div.product-subcategory-group h3').fadeIn('slow').removeClass('hidden');
			$('h3#filtered-category.show-all').addClass('hidden');
			$('div.product-subcategory-group').css('display','block').css('border-style','solid');
			
		} else {
			
			$('li#show-all a').text('Show All');
			$('li#show-all').removeClass('disabled');
			$('div.product-subcategory-group').css('display','inline').css('border-style','none');
			$('div.product-container').each(function() {
			
				if(!$(this).hasClass(filterVal)) {
					$(this).fadeOut('normal').addClass('hidden');
				} else {
					$(this).fadeIn('slow').removeClass('hidden').width(138).css('border-left-style','solid');
					
				
				}
			});
		}
		
		return false;
	});




$(".nonjs").fadeOut("fast");

$(".hasjs").fadeIn("slow");

/*ada sign*/

$('div#filtering-dropdown select#adasign_by_state').change(function () {
	var state = $("div#filtering-dropdown select#adasign_by_state").attr("value");
	var subcategory = $('#subcategory').val();
	$("#response").load("/process/ada-bystate-ajax.php", {'state':state,'subcategory':subcategory }, function(){
		$('div#response').slideDown('fast');
		$('div#active').hide();	
		$('div#activenew').hide();
		});
		$("#fun-facts-response").load("/process/ada-bystate-image-ajax.php", {'state':state,'subcategory':subcategory }, function(){
		$('div#fun-facts-response').slideDown('fast');
		$('div#fun-facts').hide();	
		} );

});


/*$(".adamap").click(function(){
var state = $(this).attr( 'value');
	$('div#filtering-dropdown select#adasign_by_state').val(state);
	$("#response").load("/process/ada-bystate-ajax.php", {'state':state }, function(response){
		//alert(response);
		//$('div#response').append(response);		
		$('div#response').slideDown('fast');
		$('div#active').hide();	
		$('div#activenew').hide();	
		
		} );

});*/
$(".showhidedes").click(function()
	{	
		var element_id=$(this).attr("id");
		var selement_sepa=element_id.split('_');
		var hideid=selement_sepa[1];
		$('#hiddendes_'+hideid).toggle();
		
		if($(this).val()=='+')
		{
			$(this).val('-');
			$(this).parent("div").find("span").html('Hide Custom Detail');
		}
		else
		{
			$(this).val('+');
			$(this).parent("div").find("span").html('View Custom Detail');
		}
	});	


$("a.product_details_content").fancybox({
'imageScale': true,
'overlayShow' : true,
'zoomSpeedIn' : 500,
'zoomSpeedOut' : 500,
'autoDimensions' : false,
'width' : 730,
'height' : '80%'
});

$(".groupfilter").click(function()
	{	
		var id_data=$(this).attr("id");
		
		var result_set=id_data.split('|');
		var base_id=result_set[0];
		var group_id=result_set[1];
		var hideid=result_set[2];
		var category=result_set[3];
		var startcategory=result_set[4];
		var g=result_set[5];
		$('.subgroup').delay(1000).css("background-color","#FF9108");
		//$('.groupcategorybg').empty();
		
		//$('.groupcategorybg').val('');
		if($('#hiddendes_'+hideid).css('display')=='none')
		{ 
		for(i=0;i<startcategory;i++)
		{
			if(i==hideid)
			{
			$('#cid_'+hideid).delay(1000).css("background-color","#FF9108");
			$('#hiddendes_'+hideid).css('display');
		    $('#hiddendes_'+hideid).toggle();
			}
			else
			{
			$('#hiddendes_'+i).hide();
			$('#cid_'+i).delay(1000).css("background-color","");
			//$('#cid'+group_id).delay(1000).css("background-color","#FF9108");
			}
		}
		} 
		else 
		{ 
		$('#hiddendes_'+hideid).hide('slow'); 
		}
		
		//$('#hiddendes_'+hideid).toggle();
		var base_id = jQuery.trim(base_id);
		var group_id = jQuery.trim(group_id);
		
		$("#groupresponse").load("/process/category-group-ajax.php",{'base_id':base_id,'group_id':group_id,'category':category,'g':g },
		function(){
		$('div#groupresponse').slideDown('fast');
		$('div#withoutgroup').hide();	
		});	
		
		$("#groupheaderresponse").load("/process/category-group-header-content.php",{'base_id':base_id,'group_id':group_id,'startcategory':startcategory},function(){
		$('div#groupheaderresponse').slideDown('fast');
		$('div#withoutgroupheader').hide();			
		});
		
	});	


$("#search-input_landing").autocomplete( nxt_ac_words, { 
 	selectFirst: false,
	autoFill: false,
	width: 260,
	scroll: false });
/*11-9-2011*/
$("select#language-select").change(function(){
var url = $(this).val();
$(location).attr('href',url);
});

});

