var clicky = {
	log: function(){
		return;
	},
	goal: function(){
		return;
	}
};
var clicky_site_id = 201871;

$(function(){
  $(".entry-callouts a").hover(
    function(e){
      $("span.callout-more-img", $(this)).stop().animate( {
        width: '58px'
      }, 1000, 'easeOutBounce' );
    },
    function(e){
      $("span.callout-more-img", $(this)).stop().animate( {
        width: '18px'
      }, 1000, 'easeOutBounce' );
    }
  );
  
  var nav = $("#site-header-nav");
  var navWidth = nav.width();
  $("ul.main-nav > li", nav).hover(
    // MouseOver
    function(e){
      // Get the dropdown
      var dd = $("div.sub-nav", $(this));
      
      // Get the position of the nav item
      var leftPos = $("a.main-nav-item", $(this)).position().left;
      
      // Get the width of the dropdown
      var ddWidth = dd.width();
      var leftMax = navWidth - ddWidth;
      
      // Position the dropdown
      dd.css( {
        left: Math.min( leftPos, leftMax )
      } );
      
      dd.stop(true, true).slideDown( '250' );
    },
    // MouseOut
    function(e){
      var dd = $("div.sub-nav", $(this));
      
      dd.stop(true, true).slideUp( '250' );
    }
  );
  
  $("a.zoom").fancybox( {
		autoScale: true,
		overlayShow: true,
		transitionIn: 'elastic',
		transitionOut: 'elastic',
		speedIn: 600,
		speedOut: 500,
		easingIn: 'easeOutBack',
		easingOut: 'easeInBack',
		hideOnContentClick: true,
		centerOnScroll: true
	} );
	
	//console.log( $(".entry-intro").children(":first-child").height() );
  $(".entry-intro")
    .css( {
      height: function(){ return $(this).children(':first-child').height()+"px"; }
    } )
    .cycle( {
      fx: 'fade',
      speed: 2500,
      timeout: 7000
    } );
  
  // Slider
  $("#parts-list").codaSlider( {
    dynamicArrows: false,
    dynamicTabsAlign: "left",
    panelTitleSelector: "h3.title",
    externalTriggerSelector: "a.slider-trigger"
  } );
  
  $('input[type=text]').each( function(){
    var field = $(this);
    var placeholder = field.attr( 'placeholder' );
    field.attr( 'placeholder', '' );
    
    if (field.val() == '') {
      field.val( placeholder );
    }
    
    field.focus( function(){ 
      if (field.val() == placeholder) {
        field.val('');
      }
    } );
  
    field.blur( function(){
      if (field.val() == '') {
        field.val( placeholder );
      } 
    } );
  } );
  
  // Tracking Functions
  $('a[href$=".pdf"]').click( function(){
		var href = $(this).attr( 'href' );
		pageTracker._trackPageview( href );
		//clicky tracking
		clicky.goal( '343' );
		clicky.pause( 500 );
	} );
});
