$(document).ready(function() {
  
  if ($('#mycarousel').length) {
    $('#mycarousel').jcarousel({
      vertical: true,
      wrap: 'circular',
      scroll: 4
    });
  };
  
	if ($('input#find-nearest-retailer-postcode').length) {
		$('input#find-nearest-retailer-postcode').snapForm();
	};
  
  if ($('div#product-gallery').length) {
    
    $('div.navigation').css({'width' : '300px', 'float' : 'left'});
    $('div.content').css('display', 'block');

    var onMouseOutOpacity = 0.8;
    $('#thumbs ul.thumbs li').opacityrollover({
      mouseOutOpacity:   onMouseOutOpacity,
      mouseOverOpacity:  1.0,
      fadeSpeed:         'fast',
      exemptionSelector: '.selected'
    });

    
    var gallery = $('#thumbs').galleriffic({
      delay:                     2500,
      numThumbs:                 15,
      preloadAhead:              10,
      enableTopPager:            false,
      enableBottomPager:         false,
      maxPagesToShow:            7,
      imageContainerSel:         '#slideshow',
      controlsContainerSel:      '#controls',
      captionContainerSel:       '#caption',
      loadingContainerSel:       '#loading',
      renderSSControls:          false,
      renderNavControls:         false,
      enableHistory:             false,
      autoStart:                 false,
      syncTransitions:           true,
      defaultTransitionDuration: 900,
      onSlideChange:             function(prevIndex, nextIndex) {
        // 'this' refers to the gallery, which is an extension of $('#thumbs')
        this.find('ul.thumbs').children()
          .eq(prevIndex).fadeTo('fast', onMouseOutOpacity).end()
          .eq(nextIndex).fadeTo('fast', 1.0);
      },
      onPageTransitionOut:       function(callback) {
        this.fadeTo('fast', 0.0, callback);
      },
      onPageTransitionIn:        function() {
        this.fadeTo('fast', 1.0);
      }
    });
        
  };
  
	/* 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
	$("#nav-primary ul li#range").hoverIntent(config); //Trigger Hover intent with custom configurations
			
	// Mega Drop Down Hover Over
	function megaHoverOver(){
	    $(this).find(".megadropdown").stop().show();
	    $(this).find(".navhandle").addClass("hover")
	 }
	 
	// Mega Drop Down Hover Out
	function megaHoverOut(){
	  $(this).find(".megadropdown").stop().hide(); 
	  $(this).find(".navhandle").removeClass("hover");
	}
	  
});


// for quick links

function MM_jumpMenu(targ,selObj,restore){ //v3.0
	  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
	  if (restore) selObj.selectedIndex=0;
	}
