/*
--------------------------------------------------

Javascript Application Code [application.js]

Joe Morrow [joe.morrow@acquitygroup.com]
04/21/2009

Copyright © 2009 Acquity Group LLC

--------------------------------------------------
*/


$(document).ready(function() {

	// BGIframe 
	//$('.fix-z-index').bgiframe();
	$('#nav li ul').bgiframe();

	// Browser & OS Detection
	if (/Safari/.test(navigator.userAgent))
		$("body").addClass("safari");


	// Print Link
	$('#print a').click(function() {
		window.print();
		return false;
	});


	// Auto-clear inline prompt text, stored in "title" attribute
	$(".inline-prompt").each(function() {
		if ($(this).attr("title").length == 0)
			$(this).attr("title", $(this).val());
	}).focus(function() {
		if ($(this).val() == $(this).attr("title"))
			$(this).val("").removeClass("inline-prompt");
	}).blur(function() {
		if ($(this).val() == "")
			$(this).val($(this).attr("title")).addClass("inline-prompt");
	});


	// Handle checkbox for different billing and shipping address
	if ($("#billing-different").length > 0) {
		var billingDifferentChange = function() {
			if ($(this).attr("checked"))
				$("#shipping-group").removeClass("disabled").find("input, select, textarea").removeAttr("disabled");
			else
				$("#shipping-group").addClass("disabled").find("input, select, textarea").attr("disabled", "disabled");
		};
		$("#billing-different").each(billingDifferentChange);
		if (isIE())	// IE only fires a change event on fade
			$("#billing-different").click(billingDifferentChange);
		else
			$("#billing-different").change(billingDifferentChange);
	}
		

	// Handle checkbox for saving an address for future use
	if ($("input.toggleActivator").length > 0) {
		var addressSaveChange = function() {
			if ($(this).attr("checked"))
				$(this).parents(".displayToggle").children("fieldset.toggleDependent").show().children("input").removeAttr("disabled");
			else
				$(this).parents(".displayToggle").children("fieldset.toggleDependent").hide().children("input").attr("disabled", "disabled");
		};
		$("input.toggleActivator").each(addressSaveChange);
		if (isIE())	// IE only fires a change event on fade
			$("input.toggleActivator").click(addressSaveChange);
		else
			$("input.toggleActivator").change(addressSaveChange);
	}


	// Handle select for selecting a stored credit card
	if ($("form#checkout-form fieldset#payment-saved-group select").length == 1) {
		var savedCreditCardChange = function() {
			if ($(this).val())
				$("form#checkout-form fieldset#payment-card-group, form#checkout-form fieldset#payment-holderName-group, form#checkout-form fieldset#payment-cardNumber-group, form#checkout-form fieldset#payment-creditCardExpirationMonth-group, form#checkout-form fieldset#payment-creditCardExpirationYear-group, form#checkout-form fieldset#payment-security-group, form#checkout-form fieldset#payment-save-group, form#checkout-form fieldset#payment-referenceName-group").addClass("disabled").find("input, select, textarea").attr("disabled", "disabled");
			else
				$("form#checkout-form fieldset#payment-card-group, form#checkout-form fieldset#payment-holderName-group, form#checkout-form fieldset#payment-cardNumber-group, form#checkout-form fieldset#payment-creditCardExpirationMonth-group, form#checkout-form fieldset#payment-creditCardExpirationYear-group, form#checkout-form fieldset#payment-security-group, form#checkout-form fieldset#payment-save-group, form#checkout-form fieldset#payment-referenceName-group").removeClass("disabled").find("input, select, textarea").removeAttr("disabled");
		};
		$("form#checkout-form fieldset#payment-saved-group select").each(savedCreditCardChange);
		if (isIE())
			$("form#checkout-form fieldset#payment-saved-group select").click(savedCreditCardChange);
		else
			$("form#checkout-form fieldset#payment-saved-group select").change(savedCreditCardChange);
	}
	$(".editShippingLink").click( function() {
		$("#popHeaderString").html("Edit Shipping Recipient Information");
		$(".multipopwin").show();
										   });
	$(".addNewShippingLink").click( function() {
		$("#popHeaderString").html("Add New Shipping Recipient");
		$(".multipopwin").show();
										   });
	
	
	//$(".viewShippingOptions").hover(function(){$(".shippopwin").show();},function(){$(".shippopwin").hide();});
	
	
	$(".viewShippingOptions").click(function(){$(".shippopwin").show();}),
	$(".hideShippingOptions").click(function(){$(".shippopwin").hide();});
	
	
	// Top Nav Menu Drop-Down Suckerfish
	// http://htmldog.com/articles/suckerfish/dropdowns/
	sfHover = function() {
		var sfEls = document.getElementById("nav").getElementsByTagName("LI");
		for (var i=0; i<sfEls.length; i++) {
			sfEls[i].onmouseover=function() {
				this.className+=" sfhover";
			}
			sfEls[i].onmouseout=function() {
				this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
			}
		}
	}
	if ($("#topNav").length > 0)
		if (window.attachEvent) window.attachEvent("onload", sfHover);
	// end Top Nav Menu Drop-Down Suckerfish	
	
});


