$(document).ready(function() {
  $("body").addClass("js");
  
  //IE uses alpha filters which look like crap when animated.
  if ( ! jQuery.support.opacity ) { return; } 
  
  //preload png sprite
  $("<img>").attr("src", "_images/ventures-fade.png");
  
  //variables
  var $logo = $("h1.logo a").not(".active");
  var $nav = $("#nav li a").not(".active");
  var $vent = $("#ventures li a");
  var $intro = $('body#home #content p.intro a');
  var duration = 300; //milliseconds for fade effect
  
  //logo hover animation
    $logo.css({
      "opacity" : 1.0
    });
    $logo.hover(
      function() {
        if ( $logo.data('currently') == 'showing' ) {
          return;
        }
        $logo.data('currently', 'showing');
        $logo
          .stop()
          .fadeTo(duration, 0.5, function() {
            $logo.data('currently', '');
          });
      },
      function() {
        if ( $logo.data('currently') != 'showing' ) {
          $logo.stop();
        }
        $logo.fadeTo(duration, 1);
      }
    );
    
  //nav hover animation
	$nav.each(
	function() {
	  var $this = $(this);
	  $this.css({
	  	"opacity" : 0.34
	  });
	  $this.hover(
        function() {
          if ( $this.data('currently') == 'showing' ) {
          return;
        }
        $this.data('currently', 'showing');
        $this
          .stop()
          .fadeTo(duration, 0.8, function() {
            $this.data('currently', '');
          });
      },
      function() {
        if ( $this.data('currently') != 'showing' ) {
          $this.stop();
        }
        $this.fadeTo(duration, 0.34);
      }
    );
	});
	
  //homepage ventures links hovers
  $vent.each(function() {
    var $this = $(this);
    var $spans = $this.find("span");
  	var $ventfade = $("<span class='ventfade'></span>").hide().appendTo($this);
  	var $venthover = $("<span class='venthover'></span>").hide().appendTo($this);
  	$this.css({
  	  "position" : "relative"
  	});
	$this.hover(
	  function() {
	  if ( $ventfade.data('currently') == 'showing'
	  	|| $venthover.data('currently') =='showing'
	  	|| $spans.data('currently') == 'showing'
	  ) {
	  	return;	 
	  }
	  $ventfade.data('currently', 'showing');
	  $venthover.data('currently', 'showing');
	  $spans.data('currently', 'showing');
	    $ventfade.stop()
	      .css({ "opacity" : 0 })
	      .show()
	      .fadeTo(500, 0.5, function() {
	        $ventfade.data('currently', '');
	      });
	    $venthover.stop()
	      .css({ "opacity" : 0 })
	      .show()
	      .fadeTo(300, 0).fadeTo(400, 1, function() {
	        $venthover.data('currently', '');
	      });
	    $spans.stop()
	      .fadeTo(500, 0.2, function() {
	        $spans.data('currently', '');
	      });
	  },
	  function() {
	  if ($ventfade.data('currently') != 'showing') {
	    $ventfade.stop();
	  }
	  if ($venthover.data('currently') != 'showing') {
	    $venthover.stop();
	  }
	  if ($spans.data('currently') != 'showing') {
	    $spans.stop();
	  }
	    $ventfade.fadeTo(500, 0.5).fadeOut(500);
	    $venthover.fadeOut(500);
	    $spans.fadeTo(500, 1);
	});
  });
  
  //homepage intro paragraph link animation
  $intro.css({ "opacity" : 0 });
  $intro.hover(
      function() {
        if ( $intro.data('currently') == 'showing' ) {
          return;
        }
        $intro.data('currently', 'showing');
        $intro
          .stop()
          .fadeTo(duration, 1, function() {
            $intro.data('currently', '');
          });
      },
      function() {
        if ( $intro.data('currently') != 'showing' ) {
          $intro.stop();
        }
        $intro.fadeTo(duration, 0);
      }
    );

// end doc ready
});

