$(document).ready(function() {
   $("a.fancybox").fancybox( {
       width: 960,
      'titlePosition'  : 'inside'
     });
   init();
   animateSlider();
});

$elem = 0;
$totalElem = 0;
$elemOffset = 361;
$lastElemOffset = 0;

function init(){
  $('#banner_wrap').find('li').each(function(i){
    $lastElemOffset += jQuery(this, i).outerWidth(true); 
    $totalElem += 1;
  });
}


function animateSlider() {
  setTimeout(function() {
    $('#banner_wrap .wrapper').animate({"left": "-=240px"}, "slow", function(){ 
      if($totalElem == $elem){
          $lastElemOffset += 1680;
          $elem = 0;
      }
      
      $('#banner_wrap').find('li').each(function(i){
        var offset = $(this).offset();         
        if(offset.left <= $elemOffset){
          $(this).css("left", $lastElemOffset);

        }        
      });
      $elem += 1;
    });         
    
    animateSlider();
  }, 5000);
}


