/*
----------------------------------------------
 Oink Custom JavaScript
 Developed by Ollie Bettany / I Am Human
 Created: 11/01/2011
----------------------------------------------
*/
  
  $(function () {
    $(".work ul li").hover(function () {
      $(this).toggleClass('current');
    });

    var switch_speed = (window.location.pathname == '/about') ? 5000 : 2500;
    
    $(".featuresub").tabs(".features > li", {
      // enable "cross-fading" effect
      effect: 'fade',
      fadeOutSpeed: 1000,

      // start from the beginning after the last tab
      rotate: true,
      
      onBeforeClick: function(e, i){
        if($('.features > li:eq(' + i + ') > img').length > 0){
          var rel = $('.features > li:eq(' + i + ') img').attr('rel');
        } else if($('.features > li:eq(' + i + ')').hasClass('video')){
          var rel = 'video';
        }
        
        $("ul.asset-types li[rel!='" + rel + "']").removeClass('current')
        $("ul.asset-types li[rel='" + rel + "']").addClass('current')
        $('video').trigger('pause');
        return true
      },
      
      onClick: function(e, i){
        $.cookie('tabs-' + window.location.pathname, i, { expires: 1 });
        if($('.features > li:eq(' + i + ')').hasClass('video')){
          $(".featuresub").data("slideshow").stop();
          $('.features > li:eq(' + i + ') video').trigger('play');
          $(".pause").removeClass('show');
          $(".play").addClass('show');
        }
      }
      
    // use the slideshow plugin. It accepts its own configuration
    }).slideshow({autoplay: true, autopause: false, interval: switch_speed});

    //$('a.backward').click(function(e){ api.prev(); e.preventDefault() });
    //$('a.forward').click(function(e){ api.next(); e.preventDefault() });
    
    $(".gridsub").tabs(".work > li", {
      // enable "cross-fading" effect
      effect: 'fade',
      fadeOutSpeed: 1000,

      // start from the beginning after the last tab
      rotate: true,
      
      initialIndex: ($.cookie('tabs-' + window.location.pathname) === null) ? 0 : parseInt($.cookie('tabs-' + window.location.pathname)),
      
      onClick: function(e, i){
        $.cookie('tabs-' + window.location.pathname, i, { expires: 1 });
      }
    }).slideshow();
    
    $(".play").click(function () {
      $(".featuresub").data("slideshow").play();
      $(this).removeClass('show');
      $(".pause").addClass('show');
    });
    $(".pause").click(function () {
      $(".featuresub").data("slideshow").stop();
      $(this).removeClass('show');
      $(".play").addClass('show');
    });

    $('video').click(function(e){
      if($(this).attr('paused')){
        $(this).trigger('play')
      } 

      $(".featuresub").data("slideshow").stop();
      $(".pause").removeClass('show');
      $(".play").addClass('show');

      e.stopPropagation();
    })
    
  });

