$(function() {
  $('div#featured.scrollable').scrollable().navigator({ navi: '#main_navi', keyboard: false });
  $('div#featured.scrollable').each(function() {
    var api = $(this).data('scrollable');
    api.begin();
  });
  
  $('.feedback > .tabs').tabs('.feedback > .quotes > div', { effect: 'fade', rotate: true });
  
  $('.feedback > .tabs').each(function() {
    var api = $(this).data('tabs');
    setInterval(function() {
      api.next();
    }, 8000);
  });
  
  $('a.overlay[rel]').overlay({ mask: { color: '#000', loadSpeed: 200, opacity: 0.7 } });
  
  $('a.overlay[rel="#lead-form"]').each(function() {
    var api = $(this).data('overlay');
    if (api) {
      api.onLoad(function() {
        _gaq.push(['_trackPageview', '/lead_funnel/open_form']);
      });
    }
  });
  
  $('#apps > .tabs').tabs('#apps > .items > div', { effect: 'fade', rotate: true, initialIndex: 0 });
  
  var tabs = $('#apps > .tabs').data('tabs');
  
  $('#apps').overlay({
      load: false,
      mask: { color: '#000', loadSpeed: 200, opacity: 0.7 }
  });

  $('.game a').click(function(e) {
    e.preventDefault();
    var api = $('#apps').data('overlay');
    $('#apps').data('title', this.rel);
    if (api) {
      api.load();
    }
  });
  
  $('#apps .thumb').hover(function() {
    var index = $('#apps .thumb').index(this)
    if (tabs.getIndex() != index) {
      tabs.click(index);
    }
  });
  
  $("a[rel='#video-overlay']").click(function() {
    var player = $('iframe#player').get(0);
    if (player) {    
      player.api('api_play');
    }
  });
  
  var api = $("a[rel='#video-overlay']").data('overlay');
  if (api) {
    api.onClose(function() {
      var player = $('iframe#player').get(0);
      if (player) {
        player.api('api_pause');
        player.api('api_seekTo', 0);
      }
    });
  }
  
  $('.thumb a').click(function(e) {
    e.preventDefault();
    var title = $('#apps').data('title');
    var api = $('#apps').data('overlay');
    if (api) {
      api.close();
      window.open(this.href + '/play/' + title + '/?utm_source=gtgnet');
    }
  });
  
  $('#thumbs .items').paginate({ page_size: 6, container: '<div class="page"/>' }).parent().scrollable();
  
  $('a.track[rel]').click(function() {
    _gaq.push(['_trackEvent', 'usage', 'click', this.rel]);
  });
  
  var ticker_opts = { date: new Date('1/29/2011'), amount: 78086.82 };
  $('p#ticker > span.amount').ticker(ticker_opts);
});

