// sidebar slider: referenties

$(document).ready(function(refslide){

  var currentPosition = 0;
  var slideWidth = 294;
  var slides = $('.refslide');
  var numberOfSlides = slides.length;

  // Remove scrollbar in JS
  $('#refContainer').css('overflow', 'hidden');

  // Wrap all .slides with #slideInner div
  slides
    .wrapAll('<div id="refslideInner"></div>')
    // Float left to display horizontally, readjust .slides width
	.css({
      'float' : 'left',
      'width' : slideWidth
    });

  // Set #slideInner width equal to total width of all slides
  $('#refslideInner').css('width', slideWidth * numberOfSlides);

  // Insert controls in the DOM
  $('#refShow')
    .prepend('<span class="refcontrol" id="refleftControl">Clicking moves left</span>')
    .append('<span class="refcontrol" id="refrightControl">Clicking moves right</span>');

  // Hide left arrow control on first load
  manageControls(currentPosition);

  // Create event listeners for .controls clicks
  $('.refcontrol')
    .bind('click', function(){
    // Determine new position
	currentPosition = ($(this).attr('id')=='refrightControl') ? currentPosition+1 : currentPosition-1;
    
	// Hide / show controls
    manageControls(currentPosition);
    // Move slideInner using margin-left
    $('#refslideInner').animate({
      'marginLeft' : slideWidth*(-currentPosition)
    });
  });

  // manageControls: Hides and Shows controls depending on currentPosition
  function manageControls(position){
    // Hide left arrow if position is first slide
	if(position==0){ $('#refleftControl').hide() } else{ $('#refleftControl').show() }
	// Hide right arrow if position is last slide
    if(position==numberOfSlides-1){ $('#refrightControl').hide() } else{ $('#refrightControl').show() }
  }	
});

// sidebar slider: productfoto's

$(document).ready(function(profoslide){

  var currentPosition = 0;
  var slideWidth = 282;
  var slides = $('.profoslide');
  var numberOfSlides = slides.length;

  // Remove scrollbar in JS
  $('#profoContainer').css('overflow', 'hidden');

  // Wrap all .slides with #slideInner div
  slides
    .wrapAll('<div id="profoslideInner"></div>')
    // Float left to display horizontally, readjust .slides width
	.css({
      'float' : 'left',
      'width' : slideWidth
    });

  // Set #slideInner width equal to total width of all slides
  $('#profoslideInner').css('width', slideWidth * numberOfSlides);

  // Insert controls in the DOM
  $('#profoShow')
    .prepend('<span class="profocontrol" id="profoleftControl">Clicking moves left</span>')
    .append('<span class="profocontrol" id="proforightControl">Clicking moves right</span>');

  // Hide left arrow control on first load
  manageControls(currentPosition);

  // Create event listeners for .controls clicks
  $('.profocontrol')
    .bind('click', function(){
    // Determine new position
	currentPosition = ($(this).attr('id')=='proforightControl') ? currentPosition+1 : currentPosition-1;
    
	// Hide / show controls
    manageControls(currentPosition);
    // Move slideInner using margin-left
    $('#profoslideInner').animate({
      'marginLeft' : slideWidth*(-currentPosition)
    });
  });

  // manageControls: Hides and Shows controls depending on currentPosition
  function manageControls(position){
    // Hide left arrow if position is first slide
	if(position==0){ $('#profoleftControl').hide() } else{ $('#profoleftControl').show() }
	// Hide right arrow if position is last slide
    if(position==numberOfSlides-1){ $('#proforightControl').hide() } else{ $('#proforightControl').show() }
  }	
});
