

/* tipsshow  slider script */

$(document).ready(function(){
  var tipscurrentPosition = 0;
  var tipsWidth = 829;
  var tips = $('.tips');
  var tipsnumberOfSlides = tips.length;

  // Remove scrollbar in JS
  $('#tipsContainer').css('overflow', 'hidden');

  // Wrap all .slides with #slideInner div
  tips
    .wrapAll('<div id="tipsInner"></div>')
    // Float left to display horizontally, readjust .slides width
	.css({
      'float' : 'left',
      'width' : tipsWidth
    });

  // Set #slideInner width equal to total width of all slides
  $('#tipsInner').css('width', tipsWidth * tipsnumberOfSlides);

  // Insert controls in the DOM
  $('#tipsshow')
    .prepend('<span class="tipscontrol" id="tipsleftControl"></span>')
    .append('<span class="tipscontrol" id="tipsrightControl"></span>');

  // Hide left arrow control on first load
  manageControls(tipscurrentPosition);

  // Create event listeners for .controls clicks
  $('.tipscontrol')
    .bind('click', function(){
    // Determine new position
	tipscurrentPosition = ($(this).attr('id')=='tipsrightControl') ? tipscurrentPosition+1 : tipscurrentPosition-1;
    
	// Hide / show controls
    manageControls(tipscurrentPosition);
    // Move slideInner using margin-left
    $('#tipsInner').animate({
      'marginLeft' : tipsWidth*(-tipscurrentPosition)
    });
  });

  // manageControls: Hides and Shows controls depending on currentPosition
  function manageControls(position){
    // Hide left arrow if position is first slide
	if(position==0){ $('#tipsleftControl').hide() } else{ $('#tipsleftControl').show() }
	// Hide right arrow if position is last slide
    if(position==tipsnumberOfSlides-1){ $('#tipsrightControl').hide() } else{ $('#tipsrightControl').show() }
  }	
});


