// Begin jQuery
$(document).ready(function() {
  $.fn.pulsate = function (properties, duration, type, speed, callback) {
    type = type || 'Swing'
    speed = speed || 'Normal';
    this.animate(properties, duration, 'pulsate' + type + speed, callback);
  };
     
  function createPulsateLinear (speed) {
    speed *= 2;
    return function (p, n) {
      return (Math.asin(Math.sin(Math.PI * n / speed)) + Math.PI / 2) / Math.PI;
    }
  }
                 
  function createPulsateSwing (speed) {
    return function (p, n) {
      return (1 + Math.sin(n / speed)) / 2;
    }
  }
                 
  function createPulsateBounce (speed) {
    speed *= 2;
    return function (p, n) {
      return (
        ((Math.asin(Math.sin(Math.PI * n / speed)) + Math.PI / 2) / Math.PI) *
        (Math.sin(Math.PI * n / speed) + 1) / -2 + 1
      );
    }
  }
  
  var speeds = {
    fast: 100,
    normal: 200,
    slow: 800
  }
   
  $.extend(jQuery.easing, {
    pulsateLinearFast: createPulsateLinear(speeds.fast),
    pulsateLinearNormal: createPulsateLinear(speeds.normal),
    pulsateLinearSlow: createPulsateLinear(speeds.slow),
    pulsateSwingFast: createPulsateSwing(speeds.fast),
    pulsateSwingNormal: createPulsateSwing(speeds.normal),
    pulsateSwingSlow: createPulsateSwing(speeds.slow),
    pulsateBounceFast: createPulsateBounce(speeds.fast),
    pulsateBounceNormal: createPulsateBounce(speeds.normal),
    pulsateBounceSlow: createPulsateBounce(speeds.slow)
  });
  
// =Shadow Nav-------------------------------------------------------------------------- 
	// Append shadow image to each LI
	$("#menu li").append('<img class="shadow" src="images/icons-shadow.png" width="104" height="27" alt="" />');
	// Animate buttons, shrink and fade shadow
	$("#menu li").hover(function() {
		var e = this;
		$(e).find("a").stop().animate({ marginTop: "-14px" }, 250, function() {
			$(e).find("a").animate({ marginTop: "-10px" }, 250);
		});
		$(e).find("img.shadow").stop().animate({ width: "80%", height: "20px", marginLeft: "8px", opacity: 0.25 }, 250);
	},function(){
		var e = this;
		$(e).find("a").stop().animate({ marginTop: "4px" }, 250, function() {
			$(e).find("a").animate({ marginTop: "0px" }, 250);
		});
		$(e).find("img.shadow").stop().animate({ width: "100%", height: "27px", marginLeft: "0", opacity: 1 }, 250);
	});
  var
    pulsatingBlocks = $('.logo'),
    forever = 5 * 24 * 60 * 60 * 1000; // 5 days! (Which is forever in Internet time)
  
  pulsatingBlocks.filter('.opacity').each(function () {
    $(this).pulsate({opacity: 0.2}, forever, this.className.split(' ')[0], 'Slow');
  });
    
  pulsatingBlocks.filter('.top').each(function () {
    $(this).pulsate({bottom: 20}, forever, this.className.split(' ')[0], 'Slow');
  });
// End jQuery
});
