	// debugging
	jQuery.log = function(message) {
//	     console.debug(message);
	};
	/* Added 2010/04/20 -- jodell -- dynamically adds script or link tags to <HEAD> */
	var Import = Import || {
		css: function() {
			for(var i=0,len=arguments.length;i<len;i++){
				var tag = document.createElement('link');
				tag.setAttribute('type','text/css');
				tag.setAttribute('rel','stylesheet');
				tag.setAttribute('href',arguments[i]);
				document.getElementsByTagName('head')[0].appendChild(tag);
			}
		},
		js: function(){
			for(var i=0,len=arguments.length;i<len;i++){
				var tag = document.createElement('script');
				tag.setAttribute('type','text/javascript');
				tag.setAttribute('src',arguments[i]);
				document.getElementsByTagName('head')[0].appendChild(tag);
			}
		}
	};
		
	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();
			});
		});
		
	}
	
	function random_string() {
		var time = String((new Date()).getTime()).replace(/\D/gi, '');
		return time;
	}
	
	$(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;
			
			// debug
			/*console.dir({
				'windowHeight':windowHeight,
				'windowScroll':windowScroll,
				'windowBottom':windowBottom,
				'navPosition':navPosition
			});*/
			
			$(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(); 
		
		$(".addToCart, .addToCart1").live('click', function(event) {				
			//call these for coremetrics only
			var target = jQuery(this).parents('.addToCartForm');
			cmCreateShopAction5Tag(target.find('.skuId').attr('value'),target.find('.productName').attr('value'),target.find('.quantity').attr('value'),target.find('.productPrice').attr('value'), target.find('.productCategory').attr('value'));
			console.log(target.find('.skuId').attr('value'));
           			cmDisplayShop5s();
			//end coremetrics specific stuff, continue on to normal program operations
			
			$.get(target.children('.successURL').attr('value'), { 
				dcs_action: 'additemtocart', 
				url_catalog_ref_id: target.find('.skuId').attr('value'),
				url_product_id: target.find('.productId').attr('value'),
				url_quantity: target.find('.quantity').attr('value'),
				url_related: target.find('.related').attr('value'),
				rnd: random_string()
				},
				function(data){
					$.ajax( { 
		            	url: '/dbs/common/dynamicMiniCart.jsp?rnd=' + random_string(), 
			            success: function(html) 
			            { 	
			                $('#dynamicMiniCart').empty().append(html); 
			                initBinding(); 
			                $('#cartFlyout').fadeIn("slow");

			                //call cartFlyout coremetrics specific functions since you are showing the cart 
			                //callCoremetricsFunctions()
			                
			                $('#cartFlyout').oneTime(2500, function() {
						    	$(this).fadeOut();
							});
			            }
			        }); 
				}
			);
				 
			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("/dbs/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('/dbs/checkout/shipping.jsp?nickName='+$(this).attr('value') + '&init=true');
		//alert($(this).attr('value'));
	});
	$("#shippingNameMobile").change( function() {
		goto('/dbs/mobile/checkout/shipping.jsp?nickName='+$(this).attr('value') + '&init=true');
		//alert($(this).attr('value'));
	});
	$("#creditCard").change( function() {
		goto('/dbs/checkout/billing.jsp?cardNickName='+$(this).attr('value') + '&init=true');
		//alert($(this).attr('value'));
	});	
	$("#creditCardMobile").change( function() {
		goto('/dbs/mobile/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();
    });
    
    $("#submitOrder").submit(function(e){
//    	console.log('clicked');
    	$('<div id="mask"/>').css({
    		position:"absolute",
    		height:$("#orderSubmitButton").height(),
    		width:$("#orderSubmitButton").width(),
    		top:$("#orderSubmitButton").position().top,
    		left:$("#orderSubmitButton").position().left
    	}).insertAfter("#orderSubmitButton");
    });
    
    $("#newBilling").submit(function(e){
//       	console.log('clicked');
    	$('<div id="mask"/>').css({
    		position:"absolute",
    		height:$("#enterNewCreditCardButton").height(),
    		width:$("#enterNewCreditCardButton").width(),
    		top:$("#enterNewCreditCardButton").position().top,
    		left:$("#enterNewCreditCardButton").position().left
    	}).insertAfter("#enterNewCreditCardButton");
    });
});

//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: '/dbs/common/dynamicMiniCart.jsp?rnd=' + random_string(), 
            success: function(html) { 
                $('#dynamicMiniCart').empty().append(html); 
                initBinding(); 
                $('#cartFlyout').fadeIn("slow");

                
                //call cartFlyout coremetrics specific functions since you are showing the cart 
                //callCoremetricsFunctions()
                	                
                $('#cartFlyout').oneTime(2500, function() {
			    	$(this).fadeOut("slow");


				});
            } 
        }); 
	}
); 
}

//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: '/dbs/common/dynamicMiniCart.jsp?rnd=' + random_string(), 
            success: function(html) { 
                $('#dynamicMiniCart').empty().append(html); 
                initBinding(); 
                $('#cartFlyout').fadeIn("slow");

                
                //call cartFlyout coremetrics specific functions since you are showing the cart 
                //callCoremetricsFunctions()
                	                
                $('#cartFlyout').oneTime(2500, function() {
			    	$(this).fadeOut("slow");


				});
            } 
        }); 
	}
); 
}

//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);
            if(prefix=="")
            	$(this).attr("src", "/img/missingImage.png");
            else
            	$(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 = "/dbs/xml/calendarGallery.jsp?tab=none&id="+tabname;
} else {
	xmlPath = "/dbs/xml/calendarGallery.jsp?tab="+tabname+"&id="+category;
}
			 	
//CALL TO FLASH - "main" id of the <OBJECT> or <EMBED> tag
getFlashMovie("coverflowFlash").reloadXML( xmlPath );
}
