function ApplySpinner()
{	
    if (jQuery('.spinner').length) {
        jQuery(".spinner").spinner({max: 100, min: 0});
    };
}

jQuery(document).ready(function() {
	// Put your custom jQuery in here - it will execute after DOM completion
  
	/* Focus/blur search box */
	
	jQuery("input.search_box").focus(function() {
		if( this.value == this.defaultValue ) {
			this.value = "";
		}
	}).blur(function() {
		if( !this.value.length ) {
			this.value = this.defaultValue;
		}
	});
	
	// Mega drop down
	
	//  Config
	var config = {
	     sensitivity: 1, // number = sensitivity threshold (must be 1 or higher)
	     interval: 100, // onMouseOver polling interval (ms). Neilson recommends 0.5 second delay)
	     over: megaHoverOver, // function = onMouseOver callback (REQUIRED)
	     timeout: 100, // number = milliseconds delay before onMouseOut
	     out: megaHoverOut // onMouseOut polling interval (ms). Neilson recommends 0.5 second delay)
	};
	
	// Add hover intent to primary navigation menu items
	jQuery("div#nav-primary ul li#range").hoverIntent(config); //Trigger Hover intent with custom configurations
	jQuery("div#nav-primary ul li#faq").hoverIntent(config); //Trigger Hover intent with custom configurations
			
	// Mega Drop Down Hover Over
	function megaHoverOver(){
	    jQuery(this).find(".megadropdown").stop().show(); 
	    jQuery(this).find(".navitem").addClass("hover")
		// Add drop down drop shadow
		jQuery('div#nav-primary .megadropdown').dropShadow({left: -1, top: 1, opacity: 0.9, blur: 2});
	 }
	 
	// Mega Drop Down Hover Out
	function megaHoverOut(){
	  jQuery(this).find(".megadropdown").stop().hide(); 
	  jQuery(this).find(".navitem").removeClass("hover");
	  // Remove drop down drop shadow
	  jQuery('div#nav-primary .megadropdown').removeShadow()
	}
	
	// Basket drop down
	
	//  Config
	var configbasket = {
	     sensitivity: 1, // number = sensitivity threshold (must be 1 or higher)
	     interval: 100, // onMouseOver polling interval (ms). Neilson recommends 0.5 second delay)
	     over: basketHoverOver, // function = onMouseOver callback (REQUIRED)
	     timeout: 100, // number = milliseconds delay before onMouseOut
	     out: basketHoverOut // onMouseOut polling interval (ms). Neilson recommends 0.5 second delay)
	};
	
	// Add hover intent to basket link
	jQuery("ul.search li.last").hoverIntent(configbasket); //Trigger Hover intent with custom configurations
			
	// Basket Drop Down Hover Over
	function basketHoverOver(){
	    jQuery(this).find(".basketdropdown").stop().slideDown('fast'); 
	    jQuery('ul.search li.last').addClass("hoverBasket");
		// Add drop down drop shadow
		jQuery('.basketdropdown').dropShadow({left: -1, top: 1, opacity: 0.9, blur: 2});
	 }
	 
	// Basket Drop Down Hover Out
	function basketHoverOut(){
	  jQuery(this).find(".basketdropdown").stop().hide(); 
	  jQuery('ul.search li.last').removeClass("hoverBasket");
	  // Remove drop down drop shadow
	  jQuery('.basketdropdown').removeShadow()
	}
   
    ApplySpinner();
  
  if (jQuery('a.google-maps').length) {
    jQuery('a.google-maps').fancybox({
      'width'       : '60%',
      'height'      : '90%',
      'autoScale'       : false,
      'transitionIn'    : 'none',
      'transitionOut'   : 'none',
      'centerOnScroll'  : 'true',
      'overlayColor'    : '#000',
      'type'            : 'iframe',
      'titleShow'       : false
    });
  };
  
  if (jQuery('a#printpage').length) {
    jQuery('a#printpage').text('Click here');
    jQuery('a#printpage').click(function(){
      window.print();
      return false;
    });
  };
  
  if (jQuery('div#image-viewer').length) {
    jQuery('div.thumbnail a').click(function() {
      jQuery('div#main-image a').attr('href', (jQuery(this).find('img.imgLarge')).attr('src'));
      jQuery('div#main-image a').attr('title', (jQuery(this).find('img.imgLarge')).attr('alt'));
      jQuery('div#main-image img').attr('src', (jQuery(this).find('img.imgMedium')).attr('src'));
      jQuery('div#main-image img').attr('alt', (jQuery(this).find('img.imgMedium')).attr('alt'));
      return false;
    });
    
    jQuery('div#main-image a').fancybox({
      // 'titleShow' : false
          hideOnContentClick : false,
          width:550,
          height:550
    });

  };
  
    if (jQuery('div.variant-imageviewer').length) {
    jQuery('div.thumbnail a').click(function() {
       
//      jQuery('div.variant-mainimage a').attr('href', (jQuery(this).find('img.imgLarge')).attr('src'));
//      jQuery('div.variant-mainimage a').attr('title', (jQuery(this).find('img.imgLarge')).attr('alt'));
//      jQuery('div.variant-mainimage img').attr('src', (jQuery(this).find('img.imgMedium')).attr('src'));
//      jQuery('div.variant-mainimage img').attr('alt', (jQuery(this).find('img.imgMedium')).attr('alt'));
      return false;
    });
    
    jQuery('div.variant-mainimage a').fancybox({
      // 'titleShow' : false
          hideOnContentClick : false,
          width:500,
          height:300
          
    });
    
    

  };
  
 
  
  if (jQuery('form#details').length) {
    jQuery('form#details').validationEngine() 
  };
  
  if (jQuery('form#payment').length) {
    jQuery('form#payment').validationEngine() 
  };
  
//  if (jQuery('form#aspnetForm').length) {
//    jQuery('form#aspnetForm').validationEngine()
//  };
  
  if (jQuery('a#terms-and-conditions').length) {
    jQuery('a#terms-and-conditions').fancybox();
  }
  
  
  if (jQuery('body.subcategory').length) {
        jQuery('.coda_bubble').codaBubble({
              distances : [10,10,10],
              leftShifts : [-40,-40,-40],
              bubbleTimes : [400,400,400],
              hideDelays : [0,0,0],
              bubbleWidths : [120,120,120],
              bubbleImagesPath : '/assets/img/layout/bubble/',
              msieFix : true
        });
  };


}); // end ready

