jQuery(function(){
  
  // detect iphone and put iphone class in body tag
  if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)))
  {
    $('body').addClass('iphone');
  }

  // home hover help
  $('#home_columns a:not(.quick_download a)').hover(function(){
    $(this).closest('.home_column').addClass('hover');
  },function(){
    $(this).closest('.home_column').removeClass('hover');
  });
  

  // screenshot slideshow
  $('ul#screenshot_carousel.carousel').jcarousel({
    scroll: 1,
    initCallback: init_carousel,
    buttonNextCallback: next_callback,
    buttonPrevCallback: prev_callback
  })
  

  // drawer click behavior
  $('#app_screenshot.mac_interactive').click(toggle_drawer);
  
  $('a.drawer_open').click(toggle_drawer);

})



function toggle_drawer()
{
  var drawer = $('.mac_interactive .drawer');
  if(drawer.hasClass('open'))
    drawer.animate({'left':'25px'}, 400).removeClass('open');
  else
    drawer.animate({'left':'-276px'}, 400).addClass('open');
    
  return false;
}




function next_callback(carousel,button,disable)
{
  var button = $('.carousel_controls .next');
  
  if(disable)
  {
    button.removeClass('disabled');
  }
  else
  {
    button.addClass('disabled');
  }
}

function prev_callback(carousel,control,disable)
{
  var button = $('.carousel_controls .previous');
  
  if(disable)
  {
    button.removeClass('disabled');
  }
  else
  {
    button.addClass('disabled');
  }
}



// this method binds forward/next using generic
// class names, so it can be used for any carousel
function init_carousel(carousel)
{
  // binds next button
  $('.carousel_controls .next').bind('click', function(){
    carousel.next();
    return false;
  });
  
  
  // binds previous button 
  $('.carousel_controls .previous').bind('click', function(){
    carousel.prev();
    return false;
  });
}

