// http://sixrevisions.com/tutorials/javascript_tutorial/create-a-slick-and-accessible-slideshow-using-jquery/

function initSlickSlider(){

  var relHash = ["intro","revenue","buzz","contact"];


  var currentPosition = 0;
  var slideWidth = 1140;
  var slides = $('.slide');
  var numberOfSlides = slides.length;
  
  var rIncOk = 1;
  var lIncOk = 1;

  // Remove scrollbar in JS
  $('#slidesContainer').css('overflow', 'hidden');

  // Wrap all .slides with #slideInner div
  slides
    .wrapAll('<div id="slideInner"></div>')
    // Float left to display horizontally, readjust .slides width
	.css({
      'float' : 'left',
      'width' : slideWidth
    });

  // Set #slideInner width equal to total width of all slides
  $('#slideInner').css('width', slideWidth * numberOfSlides);


  // Insert controls in the DOM
/*
  $('#slideshow')
    .prepend('<span class="control" id="leftControl"><]</span>')
    .append('<span class="control" id="rightControl">[></span>');
*/

  // Hide left arrow control on first load
  manageControls(currentPosition);

  // Create event listeners for controller clicks
  $('.navBar').children('li').add('.control')
    .bind('click', function(){
    // Determine new position
	/* currentPosition = ($(this).attr('id')=='rightControl') ? currentPosition+rIncOk : currentPosition-lIncOk; */

	if ($(this).attr('id')=='rightControl'){currentPosition = currentPosition+rIncOk}
	if ($(this).attr('id')=='leftControl'){currentPosition = currentPosition-lIncOk}
	
	//find out if an item on the nav bar was selected
	var navSel = ( $(this).attr('rel') );
	//get the index of the nav item
	var navIndex = ( $.inArray(navSel,relHash) );
	//if we found an index then set the current position to the index
	if (navIndex > -1){currentPosition = navIndex}

    $('#debugWin').html(currentPosition);
	// Hide / show controls
    manageControls(currentPosition);
    // Move slideInner using margin-left
    $('#slideInner').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){ $('#leftControl').fadeTo('fast',0);lIncOk = 0; } else{ $('#leftControl').fadeTo('fast',1);lIncOk = 1; }
		if(position==0){ $('#leftControl').hide();lIncOk = 0; } else{ $('#leftControl').show();lIncOk = 1; }
		// Hide right arrow if position is last slide
		//if(position==numberOfSlides-1){ $('#rightControl').fadeTo('fast',0); rIncOk = 0; } else{ $('#rightControl').fadeTo('fast',1);rIncOk = 1; }
		if(position==numberOfSlides-1){ $('#rightControl').hide(); rIncOk = 0; } else{ $('#rightControl').show();rIncOk = 1; }
		
		$('.navBar').children('li').removeClass('selectedTxtColor');
		$('li[rel='+relHash[position]+']').addClass('selectedTxtColor');

	}	
  
  
  
}





















