$(document).ready(function(){
  $('#noGallery a').lightBox();
  $('#Gallery a').lightBox();
  $('#noGalleryIphonePlat a').lightBox();
  var currentPosition = 0;
  var slideWidth = 250;
  var slides = $('.slide');
  var numberOfSlides = slides.length;
  var urlname = window.location.pathname.split("/")[1];
  var position = 0;
  var aantalElementen = 4;
  

  //swap tussen iphone en android
  setInterval('swapImages()', 4000);  

  //prev		
  $('#prev').css('visibility', 'hidden');
  
  // Scrollbar wegdoen in js
  $('#slidesContainer').css('overflow', 'hidden');


  // Wrap all .slides
  slides
    .wrapAll('<div id="slideInner"></div>')
	.css({
      'float' : 'left',
      'width' : slideWidth
    });


  $('#slideInner').css('width', slideWidth * numberOfSlides);
  
  //next images
  $('#next')
    .bind('click', function(){
    // Determine new position
	if(currentPosition != slides.length -1){
		currentPosition = currentPosition +1;
	    // Move slideInner using margin-left
	    $('#slideInner').animate({
	      'marginLeft' : slideWidth*(-currentPosition)
	    });	
		check();
	}
  });
  
  //prev images
    $('#prev')
    .bind('click', function(){
    // Determine new position
	if(currentPosition != 0){
		currentPosition = currentPosition -1;
    // Move slideInner using margin-left
    $('#slideInner').animate({
      'marginLeft' : slideWidth*(-currentPosition)
    });	
	check();
	}
  });
  
	//functie die berekent op welke pagina de applicatie zich bevind in slidebarCases
		$( ".othercases a" ).each( function(){
			position++;
			if(urlname == $(this).attr("rel")){
				var positieLijst = Math.ceil(position/ aantalElementen);
				currentPosition = positieLijst -1;
			    $('#slideInner').animate({
			      'marginLeft' : slideWidth*(-currentPosition)
			    });	
				check();
			}
		});
		
//functie er voor zorgt da next en prev op de juist momenten worden getoond		
function check(){
 	if (currentPosition != slides.length - 1) {
		$('#next').css('visibility', 'visible');
	}else{
		$('#next').css('visibility', 'hidden');
	}
	
	if (currentPosition != 0) {
		$('#prev').css('visibility', 'visible');
	}else{
		$('#prev').css('visibility', 'hidden');
	}
 }

});

//functie voor de iphone en android images
function swapImages(){
      var $active = $('#Gallery .active');
      var $next = ($('#Gallery .active').next().length > 0) ? $('#Gallery .active').next() : $('#Gallery img:first');
	  
      $active.fadeOut("slow",function(){
      		$active.removeClass('active');
      });
	  $next.fadeIn("slow").addClass('active');
    }
