jQuery(document).ready(function($) {

// Carousel

  $('a[href^="mailto:"]').addClass('email');
  
  if ($('a.email').length > 0) {
    $('a.email').defuscate();
  }

  if( $("#carousel").length > 0) {
    $("#carousel").jCarouselLite({
      btnNext: "#btn-next",
      btnPrev: "#btn-prev",
      auto: 3000,
      easing: 'easeInOutCubic',
      visible: 2,
      circular: true,
      speed: 900
    });

    //Prevent the stupid link thing for buttons
    $("a#next, a#back").attr({ onClick: "return false;" });
  }
  
  $('.spritesnav').sprites();

  $("#twitter-widget").tweet({
      username: "telethonnz",      
      join_text: "auto",
      avatar_size: null,
      count: 1,
      auto_join_text_default: "",
      auto_join_text_ed: "",
      auto_join_text_ing: "",
      auto_join_text_reply: "",
      auto_join_text_url: "",
      loading_text: ""
  });

  if ($('#logo_tv').length > 0) {
    $('#logo_tv').cycle({ 
      fx:     'curtainX', 
      speed:  300, 
      next:   '#logo_tv', 
      timeout: 0,
      sync:  false
    });
  };
  

  $('#subnav li').hover( function(){ 
    if(!$(this).hasClass('extra-subnav')) { $(this).addClass('sn-hover'); }
  }, function (){
    $(this).removeClass('sn-hover');
  });

  $('#subnav li').click( function() {
    address = $(this).children().attr('href')
    window.location.href = address; 
    return false;
  });
  
  $('button').hover( function() { $(this).css('cursor', 'pointer') })
  var i = 1;
  
  if ($('ul.thumb').length > 0) {
      $("ul.thumb").children().each( function () {
        if ( i < 10 ) { i = '0' + i; }
        $(this).append('<a href="' + i + '"><img src="img/letters/thumbs/' + i + '.gif" alt="" /></a>');
        i++;
      });
      
      $("ul.thumb li").hover(function() {
      $(this).css({'z-index' : '10'}); /*Add a higher z-index value so this image stays on top*/ 
      $(this).find('img').addClass("hover").stop() /* Add class of "hover", then stop animation queue buildup*/
        .animate({
          marginTop: '-90px', /* The next 4 lines will vertically align this image */ 
          marginLeft: '-90px',
          top: '50%',
          left: '50%',
          width: '150px', /* Set new width */
          height: '150px', /* Set new height */
          padding: '30px',
          border: '0'
        }, 200); /* this value of "200" is the speed of how fast/slow this hover animates */

      } , function() {
        
    //	$(this).attr('src',''{'z-index' : '0'}); /* Set z-index back to 0 */
      $(this).css({'z-index' : '0'}); /* Set z-index back to 0 */
      $(this).find('img').removeClass("hover").stop()  /* Remove the "hover" class , then stop animation queue buildup*/
        .animate({
          marginTop: '0', /* Set alignment back to default */
          marginLeft: '0',
          top: '0',
          left: '0',
          padding: '0',
          border: '0',
          width: '100px', /* Set width back to default */
          height: '100px' /* Set height back to default */
        }, 400);
    });
      
      $("ul.thumb a").click( function() {  
        link = $(this).attr('href');
        link = link.substr(link.length - 2);
        var source = 'img/letters/' + link + '.jpg';
        $("#showcase").find('img').attr('src', source ); 
        return false;
      });
   }
   
  if($('#tabs').length > 0) {
    $("#tabs").slideDown( function () {
      $('#tabs').find('div').show();
      $("#tabs").tabs( { show: 1, selected: 0} );    
    });
   
  }

  $('table.table tr').each( function(){
    $(this).find('td:last').css('border-right', 'none');
  });
     
});

window.onload = function(){ 
  var flash_cookie = document.getElementById('atff');
  flash_cookie.parentNode.style.display = 'none';
} 