$(document).ready(function(){
  
  // Change App Store URL based on device detection
  var iPadUrl = "http://itunes.apple.com/us/app/skygrid/id364187929?mt=8";
  var iPhoneUrl = "INSERT iTUNES URL TO iPHONE APP HERE";

  var isiPad = navigator.userAgent.match(/iPad/i) != null;
  var isiPhone = navigator.userAgent.match(/iPhone/i) != null;
  
  if (isiPad) {
    $('#footer a img').parent().attr('href', iPadUrl);
    $('#promo').attr('href', 'ipad.html');
  }
  
  if (isiPhone) {
    $('#footer a img').parent().attr('href', iPhoneUrl);
    $('#promo').attr('href', 'iphone.html');
  }

  // Allow elements with the class "clickable" to be, well, clickable..
  $(".clickable").click(function(event) {
    event.preventDefault();
    window.location = $(this).attr("href");
  });
  
  // Subtlely animate the promo image on the homepage.
  $("#promo").css({'opacity' : '.4'});
  $("#promo").animate({ opacity: 1 }, 1000, 'swing' );
  
  // Create the lightbox for the iPad page
  $('body#ipad div.screenshot a').fancyZoom({
    scaleImg: true, 
    closeOnClick: true,
    directory: 'assets/img/fancyzoom',
    width:950,
    height: 752
  });
  
  // Create the lightbox for the iPhone page
  $('body#iphone div.screenshot a').fancyZoom({
    scaleImg: true, 
    closeOnClick: true,
    directory: 'assets/img/fancyzoom',
    width:320,
    height: 480
  });

  // Create the lightbox for the Android page
  $('body#android div.screenshot a').fancyZoom({
    scaleImg: true,
    closeOnClick: true,
    directory: 'assets/img/fancyzoom',
    width:320,
    height: 480
  });

  // Subtlely animate the image on the ipad page.
  $("div.screenshot img").css({'opacity' : '.4'});
  $("div.screenshot img").animate({ opacity: 1 }, 1000, 'swing' );
  $("#skygrid-ipads").css({'opacity' : '.4'});
  $("#skygrid-ipads").animate({ opacity: 1 }, 1000, 'swing' );
  
  // Team grid
  if ($('#team-grid li[title]').length > 0) {
    
    $("#team-grid li").css({'opacity' : '.4'});
    $("#team-grid li").animate({ opacity: 1 }, 1000, 'swing' );
    
    $('#team-grid li[title]').qtip({
      position: {
         corner: {
            target: 'bottomLeft',
            tooltip: 'topRight'
         }
      },
      style: {
        width: 230,
        border: {
           width: 7,
           radius: 5,
           color: '#ccc'
        },
        name: 'light', 
        tip: true 
      }, 
      show: { delay: 1 } 
    });
  }
  
  // Timeline
  if ($('#timeline li a').length > 0) {
    $('#timeline li a[title]').qtip({
      position: {
         corner: {
            target: 'bottomRight',
            tooltip: 'topLeft'
         }
      },
      style: {
        border: {
           width: 7,
           radius: 5,
           color: '#ccc'
        },
        name: 'light', 
        tip: true 
      }, 
      show: { delay: 1 } 
    });
    
  }
  
});

