/*
        _____                                  _  __ __      
     __/\  __`\                              /' \/\ \\ \     
    /\_\ \ \/\ \  __  __    __  _ __  __  __/\_, \ \ \\ \    
    \/\ \ \ \ \ \/\ \/\ \ /'__`\\`'__\\ \/\ \/_/\ \ \ \\ \_  
     \ \ \ \ \\'\\ \ \_\ \\  __/ \ \/\ \ \_\ \ \ \ \ \__ ,__\
     _\ \ \ \___\_\ \____/ \____\ \_\ \/`____ \ \ \_\/_/\_\_/
    /\ \_\ \/__//_/\/___/ \/____/\/_/  `/___/> \ \/_/  \/_/  
    \ \____/                              /\___/             
     \/___/                               \/__/              
     
     Copyright 2010-forever (mt) Media Temple, Inc.
     
     jQuery 14 contest page by: Dain Kennison

*/

$(document).ready(function() {

  // bubble arrows
	if (jQuery.support.boxModel = true) {
  	$('#winners dl').each(function() {
      $(this).append('<dd class="tail">&nbsp;<\/dd>');
    });
  }
  
  // scroll to anchor
  $('a[href^="#"]').click(function(event){
    //prevent the default action for the click event
    event.preventDefault();
    
    //get the full url - like mysitecom/index.htm#home
    var full_url = this.href;
    
    //split the url by # and get the anchor target name - home in mysitecom/index.htm#home
    var parts = full_url.split("#");
    var trgt = parts[1];
    
    //get the top offset of the target anchor
    var target_offset = $("#"+trgt).offset();
    var target_top = target_offset.top;
    
    //goto that anchor by setting the body scroll top to anchor top
    $('html, body').animate({scrollTop:target_top}, 500, 
      
      function() {
      
        window.location.hash = "#"+trgt;
        
     });
  });
  
  // nav animations
  
  // override existing css hovers
  $('#nav').css({
    'width' : 38
  });
  $('#nav ul').css({
    'padding-left' : 8
  });
  $('#nav span').show().css({
    'width' : 0,
    'opacity' : 0,
    'text-indent' : '-120px'
  });
  
  // top level animation
  $('#nav').hover(function() {
    var $this = $(this);
    $this.animate({
      width: 45
    },100);
    $this.find('ul').animate({
      'padding-left' : 15
    },100);  
  }, function() {
    var $this = $(this);
    $this.animate({
      width: 38
    },100);
    $this.find('ul').animate({
      'padding-left' : 8
    },100);
  });
  
  // pop-out nav animation
  $('#nav a').hover(function() {
    var $this = $(this);
    $this.children('span').animate({
      'width' : 120,
      'opacity' : 1,
      'text-indent' : 8
    },150);
  },function() {
    var $this = $(this);
    $this.children('span').animate({
      'width' : 0,
      'opacity' : 0,
      'text-indent' : '-120px'
    },150);
  });
  
  // share-tweet animation
  $('.share-tweet').css({
    'width' : 38
  });
  $('.share-tweet').hover(function() {
    $(this).animate({
      'width' : 45
    },150);
  },function() {
    $(this).animate({
      'width' : 38
    },150);
  });
  
  // winner tooltip/hover animations
  
  $('#winners dl').css({
    'opacity' : 0,
    'top' : 130
  });
  $('#winners li').hover(function() {
  
    var $this = $(this);
    
    var winner_img = $this.children('a.won').css('background-image');
  
    $this.children('dl').show().animate({
      'opacity' : 1,
      'top' : 150
    },150);
        
    $this.children('a.won').children('span').css({
      'background-image'    : winner_img,
      'background-repeat'   : 'no-repeat',
      'background-position' : 'left -110px'
    }).animate({
      'opacity' : 1
    },150);
  
  },function() {
  
    var $this = $(this);
  
    $this.children('dl').animate({
      'opacity' : 0,
      'top' : 130
    },150, function() {
      $(this).hide();
    });
    
    $this.children('a.won').children('span').animate({
      'opacity' : 0
    },150);
  
  });
  
  $('#winners li').click(function(){
    var $winner_url = $(this).children('a.won').attr('href');
    if ($winner_url != null) {
      window.location = $winner_url;
    }
  });
  
  
});
