$(document).ready(function() {


  var counter = 0;
  var countsImg = ($('.posPic').length) - 1;
  
  $('#leftControl').css('display','none');
  
  
    slide = setInterval(function() {	
	
	  if (counter < countsImg) {
	  
	    counter = counter + 1;
            // alert(counter);
	
        $('#galleryPic').animate({"marginLeft" : "-=650"},600,'linear');
		
		$('#leftControl').css('display','block');
		
	  }else {
	    window.clearInterval(slide);
		$('#rightControl').css('display','none');
	  }
	  
    },6000);
	
	
 
  
  $('#rightControl').click(function() {
  
    window.clearInterval(slide);
  
    if (counter < countsImg) {
	  counter = counter + 1;
	  // $('#galleryPic img').attr('src','images/img_'+counter+'.jpg');
	  $('#galleryPic').animate({"marginLeft" : "-=650"},600,'linear');
	}
	
	if (counter != 0) {
	  $('#leftControl').css('display','block');
	}
	
	if (counter == countsImg) {
	  $('#rightControl').css('display','none');
	} 
    
  });


  $('#leftControl').click(function() {
  
    window.clearInterval(slide);
  
    if (counter <= countsImg && counter != 0) {
	  counter = counter - 1;
	  // $('#galleryPic img').attr('src','images/img_'+counter+'.jpg');
	  $('#galleryPic').animate({"marginLeft" : "+=650"},600,'linear');
	  
	  $('#rightControl').css('display','block');
	}
	
	if (counter == 0) {
	  $('#leftControl').css('display','none');
	}
    
  });
  
});
