/******************************************** 
` Menu Dropdown
*********************************************/
$(document).ready(function() {
    	function megaHoverOver(){
    		$(this).find(".sub").stop().fadeTo('fast', 1).show();

    	}

    	function megaHoverOut(){ 
    	  $(this).find(".sub").stop().fadeTo('fast', 0, function() {
    		  $(this).hide(); 
    	  });
    	}

    	var config = {    
    		 sensitivity: 1, // number = sensitivity threshold (must be 1 or higher)    
    		 interval: 50, // number = milliseconds for onMouseOver polling interval    
    		 over: megaHoverOver, // function = onMouseOver callback (REQUIRED)    
    		 timeout: 50, // number = milliseconds delay before onMouseOut    
    		 out: megaHoverOut // function = onMouseOut callback (REQUIRED)    
    	};

    	$(".menu-primary ul li.sub").css({'opacity':'100'});
    	$(".menu-primary ul li").hoverIntent(config);
    	$(".dropdown ul li.sub").css({'opacity':'100'});
    	$(".dropdown ul li").hoverIntent(config);
});
/******************************************** 
` Hide Input Fields
*********************************************/
$(document).ready(function() {
    bind_sitesearch_input_title();
});
function bind_sitesearch_input_title() {
    $('input[title]').each(function() {
        if($(this).val() === '') {
            $(this).val($(this).attr('title'));
        }

        $(this).focus(function() {
            if($(this).val() == $(this).attr('title')) {
                $(this).val('').addClass('focused');
            }
        });
        $(this).blur(function() {
            if($(this).val() === '') {
                $(this).val($(this).attr('title')).removeClass('focused');
            }
        });
    });
}
/******************************************** 
` Sticky Footer
*********************************************/
$(document).ready(function() {
  $("#canvas-footer").stickyFooter();
});

(function($){
  var footer;

  $.fn.extend({
    stickyFooter: function(options) {
      footer = this;
      
      positionFooter();

      $(window)
        .scroll(positionFooter)
        .resize(positionFooter);

      function positionFooter() {
        var docHeight = $(document.body).height() - $("#sticky-footer-push").height();
        if(docHeight < $(window).height()){
          var diff = $(window).height() - docHeight;
          if (!$("#sticky-footer-push").length > 0) {
            $(footer).before('<div id="sticky-footer-push"></div>');
          }
          $("#sticky-footer-push").height(diff);
        }
      }
    }
  });
})(jQuery);
/******************************************** 
` Verticaly Align Image
*********************************************/
(function ($) {
$.fn.vAlign = function() {
  return this.each(function(i){
  var ah = $(this).height();
  var ph = $('.inventory-capsule').height();
  var mh = (ph - ah) / 2;
  if(mh>0) {
    $(this).css('margin-top', mh);
  } else {
    $(this).css('margin-top', 0);
  }
});
};
})(jQuery);
/******************************************** 
` Z-index Fix
*********************************************/
$(document).ready(function() {
	var zIndexNumber = 1000;
	$('div').each(function() {
		$(this).css('zIndex', zIndexNumber);
		zIndexNumber -= 10;
	});
});

