	// debugging
	jQuery.log = function(message) {
	     console.debug(message);
	};
		
	function clearBox(boxID) {
        document.getElementById(boxID).value = "";
    }
    function goto(url) {
	    location.href=url;
	}
    function openWin(url, params) {
    	if(!params) {
    		params = 'location=1,status=1,scrollbars=1,status=1,toolbar=1,menubar=1,resizable=1';
    	} else {
    		//alert(params);
    	}
    	window.open(url,"mywindow",params);
    	return false;
    }
    	
	function hideAll()	{
		$(".hover").each(function() {
			$(this).hide();
		});
	};
	
	function showWelcome() {
		$("#welcomeMessageText").slideDown( function() {
			$(this).oneTime(3000, function() {
		    	$(this).slideUp();
			});
		});
		
	}
	
	$(document).ready(function() {
		
		$("body").click( function (event) {
			hideAll();
		});
				
		$(".productHoverQuantity, #productHoverQuantityArea").click( function(event) {
			event.stopImmediatePropagation();
			return false;
		});
		
		$('#flyouts > li > ul.hover, .productDetailsHover, .productDetailsHoverLast, .productDetailsHoverBottom, .productDetailsHoverBottomLast, .categoryDetailsHover, .categoryDetailsHoverLast').css('opacity', 0.90);
		//$('.solid').css('opacity', 1.00);
		/*
			add an onclick to all LI elements inside the lefnav div so clicking
			the area produces the same result as clicking the link text
		*/
		$("#leftNav li").each(function() {
			$(this).click(function(event)	{
				goto($(this).find("a").attr("href"));
				event.stopPropagation();
			});	   
		});
		//prevent double click effect for left nav items
		$("#leftNav a").click(function(event) {
			event.stopPropagation();
		});
		
		//modified to reposition navhover if the hover goes below the "fold"
		$("#flyouts > li").hover( function ()	{
			windowHeight = $(window).height();
			windowScroll = $(window).scrollTop();
			windowBottom = windowHeight + windowScroll;
			navPosition = $(this).offset().top;
			$(this).children("ul.hover").show();
			thisHeight = $(this).children("ul.hover").outerHeight();
			thisTop = $(this).children("ul.hover").offset().top;
			thisBottom = thisHeight + thisTop;
			if(thisBottom > windowBottom) {
				//position bottom to the left nav elements position 
				bottomDifference = thisBottom - navPosition;
				newTop = thisTop - bottomDifference + 110;
				$(this).children("ul.hover").css({top:newTop});
			}
		},function(){
			$(this).children("ul.hover").hide();
		});
		
		//rebind the nav elements if the user scrolls the window
		

		
		//IE6 fix
		if($.browser.msie && $.browser.version.substr(0,3)<"7"){
			$("#flyouts > li").hover( function ()	{
				$("select").hide();
			},function(){
				$("select").show();
			});
		}
			
		$(".nav").hover( function ()	{
				$(this).removeClass('hoverOff');
                $(this).addClass('hoverOn');
			},function(){
				$(this).removeClass('hoverOn');
                $(this).addClass('hoverOff');
		});//hover
		
		
		//call this here because cartArea functions have been moved
		//to the initBinding function
		//this is because of the ajaxcallback on the addToCart functionality
		//we need to re-bind the hover functions because ajax replaced
		//the areas
		initBinding(); 
		
		$(".addToCartForm").each(function() { 
			$(this).submit(function(event) {
				
				//call these for coremetrics only
				cmCreateShopAction5Tag($(this).find('.skuId').attr('value'),$(this).find('.productName').attr('value'),$(this).find('.quantity').attr('value'),$(this).find('.productPrice').attr('value'), $(this).find('.productCategory').attr('value'));
                cmDisplayShop5s();
				//end coremetrics specific stuff, continue on to normal program operations
                
				$.get($(this).children('.successURL').attr('value'), { 
					dcs_action: 'additemtocart', 
					url_catalog_ref_id: $(this).find('.skuId').attr('value'),
					url_product_id: $(this).find('.productId').attr('value'),
					url_quantity: $(this).find('.quantity').attr('value')
					},
					function(data){
						$.ajax( { 
			            	url: '/common/dynamicMiniCart.jsp', 
				            success: function(html) 
				            { 
				                $('#dynamicMiniCart').empty().append(html); 
				                initBinding(); 
				                $('#cartFlyout').show();

				                //call cartFlyout coremetrics specific functions since you are showing the cart 
				                //callCoremetricsFunctions()
				                
				                $('#cartFlyout').oneTime(2000, function() {
							    	$(this).hide();
								});
				            } 
				        }); 
					}
		 		); 
				return false;
			});
		});
		
		$(".addToCartLink").click(function() {
			addToCartAjax($(this).attr('href'));
			return false;
		}); 
		
		//scripts for product list info bubbles
		$(".categoryProduct, .categoryProductLast, .breedAlphaCategoryBox, .categoryMediumFeature, .categoryLargeFeature").hover( function ()	{
				hideAll();
				$(this).children("div").fadeIn(1000);
				//$(this).children("div").animate({"opacity": "show"}, "slow");
				//IE6 fix
				if($.browser.msie && $.browser.version.substr(0,3)<"7"){
					$("select").hide();
			  	}
			}, function() { 
				$(this).children("div").hide();
				//IE6 fix
				if($.browser.msie && $.browser.version.substr(0,3)<"7"){
			    	$("select").show();
			  	}
		}); 
		
		//only needed on the product detail page
		$("#viewAllProducts").click( function ()	{
			$("#allProducts").append("loading...");
			$("#allProducts").show();
			$("#allProducts").load("/catalog/frgProdAllProds.jsp?categoryId="+catId+"&productId="+prodId+"&catNavCount=1");
			return false;
		});	
		
		//for category pages with dropdowns to forward page when dropdown changed
		$("#childCategories").change( function ()	{
			goto($(this).val());
		});	
		
		$(".coverflowTab").click( function() {
			$(".coverflowTab").each(function() {
				$(this).removeClass("coverflowTabOn");
				$(this).addClass("coverflowTabOff");
			});
			$(this).addClass("coverflowTabOn");
		});
		
		$("#shippingName").change( function() {
			goto('/checkout/shipping.jsp?nickName='+$(this).attr('value') + '&init=true');
			//alert($(this).attr('value'));
		});
		$("#creditCard").change( function() {
			goto('/checkout/billing.jsp?cardNickName='+$(this).attr('value') + '&init=true');
			//alert($(this).attr('value'));
		});				
		$(".giftMessage").keyup( function(event) {
			textVal = $(this).val();
			textLen = textVal.length;
			if(textLen > 250) {
				$(this).val(textVal.substr(0,250));
			}
			
		});
		
		$("#useShipping").click( function() {
			//alert($(this).attr('checked'));
			if($(this).attr('checked') == true) {
				//alert("its tru do it");
				$('#useShippingAsBilling').val('true');
			} else {
				//alert('its false');
				$('#useShippingAsBilling').val('false');
			}	
			this.form.submit();
		});
		
		$("#welcomeMessageBox").hover(function() {
			showWelcome();
		});
		 
		
        $("#countryNewAddress").change ( function() {
			$("#addAddress").attr('action', "new_address.jsp?countryCode="+$(this).attr('value'));
			$("#addAddress").submit();
        });

        $("#countryEditAddress").change ( function() {
			$("#editAddress").attr('action', "edit_address.jsp?countryCode="+$(this).attr('value'));
			$("#editAddress").submit();
        });

        $("#billingAddress").change ( function() {
			$("#newBilling").attr('action', "billing.jsp?nickName=&countryCode="+$(this).attr('value'));
			$("#newBilling").submit();
        });

        $("#shippingAddress").change ( function() {
			$("#newShippingAddress").attr('action', "shipping.jsp?nickName=&countryCode="+$(this).attr('value'));
			$("#newShippingAddress").submit();
        });
	});
	
//this gets called on document.ready and after an ajax callback
//because after ajax, we need to rebind the hover
function initBinding() {
	$("#cartArea").hover( function () {
		$("#cartFlyout").show();
		//IE6 fix
		if($.browser.msie && $.browser.version.substr(0,3)<"7"){
			$("select").hide();
	  	}
	});
	
	$("#cartArea,#cartFlyout,#cartFlyoutDetails,#cartFlyoutButtons").click( function () {
		$("#cartFlyout").show();
	});
	
	$("#cartArea,#cartFlyout,#cartFlyoutDetails,#cartFlyoutButtons").mouseout( function () {
		$("#cartFlyout").oneTime(1000, function() {
	    	$(this).hide();
			//IE6 fix
			if($.browser.msie && $.browser.version.substr(0,3)<"7"){
				$("select").show();
		  	}
		});
	});
			
	$("#cartArea,#cartFlyout,#cartFlyoutDetails,#cartFlyoutButtons").mouseover( function () {
		$("#cartFlyout").stopTime();
	});
} 

//this function supports addToCart buttons that are not forms or cannot
//be initialized during pageLoad
function addToCartAjax(url) {
	$.get(url,
		function(data){
			$.ajax( { 
	        	url: '/common/dynamicMiniCart.jsp', 
	            success: function(html) { 
	                $('#dynamicMiniCart').empty().append(html); 
	                initBinding(); 
	                $('#cartFlyout').show();
	                
	                //call cartFlyout coremetrics specific functions since you are showing the cart 
	                //callCoremetricsFunctions()
	                	                
	                $('#cartFlyout').oneTime(2000, function() {
				    	$(this).hide();
					});
	            } 
	        }); 
		}
	); 
}

//same as above function but contains the coreMetrics tag need for click in flash panel
function addToCartAjaxFlash(url, name, pageID, refId, quantity, price, category) {
	//alert("url = " + url + " \n name= " + name + " \n pageID= " + pageID);
	//alert(refId + " -- " + quantity + " -- " + price + " -- " + category);
	cmCreateManualLinkClickTag(url,name,pageID);
	cmCreateShopAction5Tag(refId,name,quantity,price,category);
    cmDisplayShop5s();
	$.get(url,
		function(data){
			$.ajax( { 
	        	url: '/common/dynamicMiniCart.jsp', 
	            success: function(html) { 
	                $('#dynamicMiniCart').empty().append(html); 
	                initBinding(); 
	                $('#cartFlyout').show();
	                
	                //call cartFlyout coremetrics specific functions since you are showing the cart 
	                //callCoremetricsFunctions()
	                	                
	                $('#cartFlyout').oneTime(2000, function() {
				    	$(this).hide();
					});
	            } 
	        }); 
		}
	); 
}

//check for images that are missing	
$(window).bind('load', function() {
	$('img').each(function() {
		if((typeof this.naturalWidth != "undefined" &&
			this.naturalWidth == 0 ) 
			|| this.readyState == 'uninitialized' ) {
			lastSlash = $(this).attr("src").lastIndexOf("/"); 
			prefix = $(this).attr("src").substr(0,lastSlash);
			$(this).attr("src", prefix+"/missingImage.png");
		}
	});
})	
	

// url param function for jquery shortcut
$.urlParam = function(name){
	var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href);
	return results == null ? "" : results[1] ;
}
//usage $.urlParam('id');  
// could return idname	
	
//scripts to support the coverflow scroller
function getFlashMovie(movieName) {   
	var isIE = navigator.appName.indexOf("Microsoft") != -1;   
	return (isIE) ? window[movieName] : document[movieName];  
}  
function reloadXML(tabname, category) {
 	var xmlPath = "";
	if(category == 'home') {
		/*
		switch (tabname){
			case "topSellers": 
				categoryID = "cat30904";
				break;
			case "featured": 
				categoryID = "cat30902";
				break;
			case "bargains": 
				categoryID = "cat30902";
				break;
			default : 
				xmlPath = "cat30902";
		}
		*/
		xmlPath = "/xml/calendarGallery.jsp?tab=none&id="+tabname;
	} else {
		xmlPath = "/xml/calendarGallery.jsp?tab="+tabname+"&id="+category;
	}
				 	
	//CALL TO FLASH - "main" id of the <OBJECT> or <EMBED> tag
	getFlashMovie("coverflowFlash").reloadXML( xmlPath );
}
	
	
	
