$(document).ready(function(){

  
  
  //
  // Project image transitions
  //------------------------------------------------------------------------------------------------
  var total = $(".our_work .images img").length
  var ipp = parseInt( $(".our_work .images").attr("data-ipp") );
  var duration = parseInt( $(".our_work .images").attr("data-duration") );
  
  if(!ipp) {
    ipp = 6
  }
  if(!duration) {
    duration = 600
  }
  var offset = 0;
  var pageTimer;
   
  showPage();
  
  if(total > ipp) {    
    window.pageTimer = setInterval(function(){offset = (offset+ipp >= total) ? 0 : offset+ipp; showPage()}, 4000)
  }

  function showPage() {
    // Hide all images
    $(".our_work .images img").hide();

    $(".our_work .images img").slice(offset, offset + ipp).each(function(index, item){
      setTimeout(function() {
        $(item).fadeIn(duration);
      }, 100+index*200)
    });
    
  }

  

  //
  // Project Info Panel Toggle
  //------------------------------------------------------------------------------------------------

  $(".our_work .moreinfo").toggle( 
    function(){ 
      $(".our_work .info").animate({width: 648}, 500); 
      clearInterval( window.pageTimer); 
      return false; 
    }, 
    function(){ 
      $(".our_work .info").animate({width: 0}, 500); 
      return false; 
    }
  );
  $(".our_work .close").click(function(){
    $(".our_work .moreinfo").click();
  }) 


  //
  // Text Scroller
  //------------------------------------------------------------------------------------------------
  $(".our_work .info .description").jScrollPane();
  



  //
  // Subnav highlight
  //------------------------------------------------------------------------------------------------
  var locationPath = location.pathname.split("/")
  $("#subnav a").each(function(index, item){
    var itemPath = $(item).attr("href").split("/")
    if(itemPath[2] == locationPath[2]) {
      $(item).addClass("selected");
    }    
  });



})


