var $hp_slides=['mk3','groupe','cannes','drone','figaro','fff'];
 
rnd=0;
listLi = "";
lastList = new Array(3);

function goLeft(){
  if (pos > 0){
    pos = pos -1;
    posleft = posleft - 594;
    $('ul.gallery img').animate({left:"-"+posleft + "px"},1400,'easeInOutCirc',function(){}); 
  }
  checkArrows();
}
function checkArrows(){
  if (pos == 0){
	$('#leftArrow').animate({  opacity: 0.25  }, 2000);
  }
  else{
	$('#leftArrow').animate({  opacity: 1 }, 2000);
  }
  if (pos < nbSlide -1){
    $('#rightArrow').animate({  opacity: 1 }, 2000);
  }
  else{
      $('#rightArrow').animate({  opacity: 0.25  }, 2000);
  }
}

function goRight(){
  if (pos < nbSlide -1){
    pos = pos +1;
    posleft = posleft + 594;
    $('ul.gallery img').animate({left:"-" + posleft + "px"},1400,'easeInOutCirc',function(){}); 
  }
  checkArrows();
}
function resetList(){
  
  $('#gallerywidget-3 ul').fadeOut(1000,function(){
  $('#gallerywidget-3 li').remove();
  listLi = "";
  for (i = 0 ; i < 3 ; i++){
    while (rnd == lastList[0] || rnd == lastList[1] || rnd == lastList[2])
        rnd = Math.floor(Math.random() * icons.length);
    listLi = listLi + icons[rnd].innerHTML;
    lastList[i] = rnd;
  }
  precWidth = 0;
  $('#gallerywidget-3 ul').html(listLi);
  /*$('#gallerywidget-3 img').each(function(index) {
          if (index == 1)
	$(this).css("left", (parseInt(precWidth) + parseInt(5)) + "px");
      if (index>1){
	$(this).css("float", "right");
	$(this).css("position", "relative");
      }
      precWidth = $(this).css("width").substring(0,$(this).css("width").length-2);
    $(this).css("left", (parseInt(i) + parseInt(5)) + "px");
  });*/
  $('#gallerywidget-3 ul').fadeIn(2000);
  $("#gallerywidget-3 a").attr("href", "javascript:resetList();")

  });
}
//#mobile,#hachette,#groupe,#contact,#references
$(document).ready(
  function(){ 
    $(window).bind('resize',function(){
     window.location.href = window.location.href;
    });
    icons = $('#gallerywidget-3 li');
    resetList();
    if ($('ul.gallery').length && ('#gallery-1').length){
      $("<div id=\"leftArrow\"><a href=\"javascript:goLeft()\"><img src=\"/wp-content/themes/videozoom/images/left_arrow.png\"></a></div><div id=\"rightArrow\"><a href=\"javascript:goRight()\"><img src=\"/wp-content/themes/videozoom/images/right-arrow.png\"></a></div>").insertAfter('.single');
    }
    posleft=0;
    nbPic = $('#scroll-pane').find('img').size();
    nbSlide = Math.ceil(nbPic / 12);
    pos=0;
    
    if ($("#rightArrow").length > 0 && $('#leftArrow').length > 0){
	    $('#leftArrow').css('margin-left','-75px');
    	    //$('#leftArrow').offset({'left':$('#gallery-1 ul').offset().left -390}) ;
	    
	    //$('#rightArrow').offset({'left':$('#gallery-1 li').offset().left +605}) 

    }
    
   $('#groupe').hide();
    $('#figaro').hide();
    $('#mk3').hide();
    $('#drone').hide();
    $('#cannes').hide();
    $('#rmc').hide();
    $('#fff').hide();
    
    $('#groupe').css('left','0','top','0');
    $('#figaro').css('left','0','top','0');
    $('#mk3').css('left','0','top','0');
    $('#drone').css('left','0','top','0');
    $('#cannes').css('left','0','top','0');
    $('#rmc').css('left','0','top','0');
    $('#fff').css('left','0','top','0');
    
    init_slideshow();checkArrows();
  });

function handle(e){
  e.data.elem.html(e.frameCount);
}
function hp_show_slide(slide_number,first_animation){
  $x = "-110%";
  $y = "0%"; 
  if ($k != 5)
	$next_slide=$('#'+$hp_slides[$k+1]);
  else
  	$next_slide=$('#'+$hp_slides[0]);
  
  $current_slide=$('#'+$hp_slides[$k]);
  
  $current_slide.unbind('frame');
 
  $current_slide.find('img.text').animate({left:$x,top:$y},1000,'easeInQuint',function(){});
  $current_slide.find('img.pic').animate({left:$x,top:$y},1500,'easeInQuint',function(){});
  $current_slide.find('img.more').animate({left:$x,top:$y},1700,'easeOutBack',function(){}); 

  $window_width=$(document).width();
  $(window).resize(function(){$window_width=$(document).width();})
  $next_slide.show();
  $next_slide.css('left','0','top','0').css('width',$window_width).find('img').show().css('left','100%','top','0%');
  $next_slide.find('img.text').animate({left:'0%',top:'0%'},2400,'easeOutQuart',
				  function(){
				    $next_slide.bind('frame',{frameDuration:1500})
				  });
  $next_slide.find('img.pic').animate({left:'0%',top:'0%'},1600,'easeOutQuart',
				  function(){
				    $next_slide.bind('frame',{frameDuration:1500})
				  });
  $next_slide.find('img.more').animate({left:'0%',top:'0%'},1900,'easeOutQuart',
				  function(){
				    $next_slide.bind('frame',{frameDuration:1500})
				  });
  $current_slide=$next_slide;
  $k++;
  if ($k == 6)
  	$k=0;
  setTimeout("hp_show_slide()",7000);
}

var $k=0;
function init_slideshow(key){
  $('#cannes,#drone,#groupe,#figaro,#mk3,#fff,#rmc').jparallax({mouseport:$('body'),frameDuration:0,xparallax:true,yparallax:true},
				   {xtravel:'0px',ytravel:'0px'},
				   {xtravel:'20px',ytravel:'0px'},
				   {xtravel:'40px',ytravel:'20px'}
				  );
  hp_show_slide(0,true);
}


