/**
 * @note Application level jQuery and/or javascript code
 */
jQuery(document).ready(function() {
						   
  jQuery('#CAT_Search').textPlaceholder();
  
	if(jQuery("body#products").length > 0){
	   // hide no prods if empty on cat view
		if(jQuery("li.productItemNotFound").text() == "This catalog has no products."){
			 jQuery("div.prodList").hide();
		}
				   
		// hide no prods if empty on cat view
		if(jQuery("li.catalogueItemNotFound").text() == "This catalog has no sub-catalogs."){
			 jQuery("div.catList").hide();
		}
	}
  
	// show amount in span from amount form field
	jQuery("span.amountSpan").text(jQuery("input#Amount").val());  
  
  	// paypal
	jQuery("#PaymentMethodType_5").click(function(){
		jQuery(".hide-cc").hide();
	});
	
	jQuery("#PaymentMethodType_1").click(function(){
		jQuery(".hide-cc").show();
	});
		 
	
	// if zero
	if (jQuery('input#Amount').val() === '0.00') {
		jQuery('#PaymentMethodType_9').attr('checked','checked');
		   jQuery('#credit-card-information').css('display','none');   
		   // alert($('input#Amount').val());   
		   }else{
			 //console.log('nope not zero');
		}

	// -----------------------------------------------------
	// This will copy over the shipping address value to the 
	// billing address.  Make sure the checkbox Id is "SameAsShipping"
	//
	// * Update - changed to check length and clear fields on unchecked
	// -----------------------------------------------------	
	if(jQuery("#f-shipping-same").length > 0){
		jQuery("#f-shipping-same").bind("change", function(e){
			
			var n = jQuery("#f-shipping-same:checked").length
				if(n == 0){
					
					jQuery("#BillingAddress").val('');
					jQuery("#BillingCity").val('');
					jQuery("#BillingState").val('');
					jQuery("#BillingZip").val('');
					jQuery("#BillingPhone").val('');
				}else{
					
					
					jQuery("#BillingAddress").val(jQuery("#ShippingAddress").val());
					jQuery("#BillingCity").val(jQuery("#ShippingCity").val());
					jQuery("#BillingState").val(jQuery("#ShippingState").val());
					jQuery("#BillingZip").val(jQuery("#ShippingZip").val());
					jQuery("#BillingPhone").val(jQuery("#ShippingPhone").val());
				}
		
		});
	
	}
	
	// product large
	if(jQuery("ul.productLarge, table.productLarge").length > 0){
		
		if(jQuery("section#product-details p.price").text() != "$0.00"){
				jQuery("p.price").show();
			}
	
		if(jQuery("section#product-details p.onSale").text() == 1 && jQuery("section#product-details p.price").text() != "$0.00" && jQuery("section#product-details p.productType").text() != "wholesale"){
			jQuery(".productSubmitInput, input.productTextInput").show();
		}
	}
	
	// product small
	if(jQuery("ul.productSmall, table.productTable").length > 0){
		jQuery("ul.productSmall li, table.productSmall td").each(function(){
			if(jQuery(this).find("p.price").text() != "$0.00"){
				jQuery(this).find("p.price").show();
			}
		});
	}

// Similar Items
if(jQuery("aside#ancillary td.productItem").length > 0){
jQuery("aside#ancillary td.productItem").each(function(){
    
    if(jQuery(this).find("p.price").text() == "$0.00"){
				jQuery(this).find("p.price").hide();
			}else{
                               jQuery(this).find("p.price").show();
                        }
});
} // similar items

	
	// change top nav if logged in to offer log out.
	if(jQuery("div#isLoggedIn").text() == "1"){
		jQuery("li#nav-login").html("<a href='/LogOutProcess.aspx'>Log Out</a>");
	}
	
	
	
	     // hide no prods if empty on cat view
		 
		 if(jQuery("div.prodList").length > 0 || jQuery("div.catList").length > 0 ){
		 
                    if(jQuery("td.productItemNotFound").text() == "This catalog has no products."){
                         jQuery("div.prodList").hide();
                    }
                   
                    // hide no prods if empty on cat view
                    if(jQuery("td.catalogueItemNotFound").text() == "This catalog has no sub-catalogs."){
                         jQuery("div.catList").hide();
                    }
		 }

//* active nav addon for ecom */
if(jQuery("#nav-cats").length > 0 ){

	if(window.location.href.indexOf("/products/chandeliers") != -1){
		jQuery("li#ecom-nav-chandeliers").addClass("selected");
	}
	if(window.location.href.indexOf("/products/sconces") != -1){
		jQuery("li#ecom-nav-scones").addClass("selected");
	}
	if(window.location.href.indexOf("/products/tabletops-and-accessories ") != -1){
		jQuery("li#ecom-nav-tabletops-and-accessories ").addClass("selected");
	}
	if(window.location.href.indexOf("/products/lamps-and-shades") != -1){
		jQuery("li#ecom-nav-lamps-and-shades").addClass("selected");
	}
	if(window.location.href.indexOf("/products/antiques") != -1){
		jQuery("li#ecom-nav-antiques").addClass("selected");
	}
	if(window.location.href.indexOf("/products/jewelry") != -1){
		jQuery("li#ecom-nav-jewelery").addClass("selected");
	}
	
	if(window.location.href.indexOf("/products/") != -1 && window.location.href.indexOf("/products/jewelry") == -1){
		jQuery("li#nav-products").addClass("selected");
	}
	
	if(window.location.href.indexOf("/products/jewelry") != -1){
		jQuery("li#nav-jewelry").addClass("selected");
	}
	

}

// products nav addon

if(jQuery("nav#nav-cats").length > 0){
		
	jQuery("nav#nav-cats ul li").each(function(){
		if(jQuery(this).find("ul").length > 0){
			jQuery(this).find("a").css("background","url('/assets/img/arrows-a.gif') 100% 4% no-repeat");
		}
	});
	
	jQuery("nav#nav-cats ul li").each(function(){
		jQuery("li.sub-nav-item.selected a").css("background","url('/assets/img/arrows-b.gif') 100% 4% no-repeat");
	});
	
	
	jQuery("nav#nav-cats ul li ul li a").each(function(){
		jQuery(this).css("background","none");
	});

}

// fancybox for beachchart
jQuery("a.fancyBox").fancybox({
	'transitionIn'	: 'elastic',
	'transitionOut'	: 'elastic'
});

// add page to pagination
if(jQuery("div.prod-pagination").length > 0 && jQuery("table.productLarge").length != 1 && jQuery("div.prod-pagination span.pagination").length > 0){
	jQuery("div.prod-pagination").prepend("Page");
}

  
}); // ready
