var App = {
  
  Client: {
  
    isIphone: function() {
      return ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)));
    }
    
  },
  
  Forms: {
  
    init: function() {
      //show label values in form elements
	    $(":text").labelify({ text: "label" });
	    $("textarea").labelify({ text: "label" });
	    $("label").hide();
	    
	    //enable autogrowing textareas
	    $('textarea').css({fontSize: '12px', lineHeight: '16px'}).autogrow();
    }
  
  },
  
  Iphone: {
    
    init: function() {
      $.metadata.setType("class");
      $('.iphone ~ #screenshot-thumbnails a').click(function()
      {
        if ($(this).hasClass('image'))
        {
          image = document.createElement('img');
          image.src = $(this).metadata().src;
          $('.iphone').html(image);
        }
        if ($(this).hasClass('video'))
        {
          clone = $('.iphone').html($(this).clone())
          if (!App.Client.isIphone())
          {
            clone.children().media();
          }
        }
      });
      
      if (thumbnailIndex = parseInt(jQuery.url.attr("anchor")))
      {
        $('.iphone ~ #screenshot-thumbnails li:eq('+(thumbnailIndex-1)+') a').triggerHandler('click');
      }
      
      if (!App.Client.isIphone())
      {
        $('.iphone .video').media();
      }
    }
    
  },
  
  
  init: function()
  {
    App.Forms.init();
    App.Iphone.init();
  }

}

$(document).ready(function() {
  App.init();
});