$(document).ready(function(){
  
  $('#header-wrapper').css('background-position', '50% 1000px'); 
  $('body').addClass('js');


  $("#iphone-controls a").hide();
  
/*    
    var eq = $(this).parent().prevAll().length;
    $('.tabs li').removeClass('active');
    $('.tabs li:eq('+eq+')').addClass('active');
  
    window.currentControl = eq;
    window.controlTimer = clearInterval(window.controlTimer);
    window.controlTimer = setInterval(nextControl, 4000)  
    return false;
  });
  
*/  
  
    /*
    $("#iphone-controls a").click(function(){
      var eq = $(this).parent().prevAll().length;
      /*
      $(".tabs").css("left", "-"+eq*291+"px");
      window.currentControl = eq;
      */
    /*
      offset = abs((eq-window.controlOffset)*291);
      $(".tabs").css("left", offset+"px");      
      
      if (window.controlTimer) clearInterval(window.controlTimer);
      window.controlTimer = setInterval(nextControl, 4000);
      return false;
    });
    */
    
    window.controlTimer = setInterval(nextControl, 4000);
    window.controlOffset = 0;
    
    var hash = location.href.substr(location.href.indexOf("#"));    
    if (hash == "#pressure") { window.controlOffset = 1; }
    if (hash == '#temperature') { window.controlOffset = 2; }
    if (hash == "#forecast") { window.controlOffset = 3; }
    if (hash == "#world") { window.controlOffset = 4; }
    if (hash == "#all") { window.controlOffset = 0; }
    window.currentControl = window.controlOffset *1;
    
    $('.tabs li:eq('+window.currentControl+')').addClass('active');
    
    function nextControl(){
    
      window.currentControl = window.currentControl + 1;
      if (window.currentControl > 4) window.currentControl = 0;    
      
      $('.tabs li').removeClass('active');
      $('.tabs li:eq('+window.currentControl+')').addClass('active');      
    /*
      window.currentControl = window.currentControl + 1;
      if (window.currentControl > 4) window.currentControl = 0;
      offset = abs((window.currentControl-window.controlOffset)*291);
      $(".tabs").css("left", offset+"px");
    */
    }
    
    function abs (n) {
      return ((n<0) ? n*-1 : n*-1);
    }
});
window.onload = function(){
  $('#header-wrapper')
    .animate({
      backgroundPosition: '(50% 0px)'
    },1500, 'easeOutQuad');
}