	// Component slider functions

(function($){
	components = function() {
		  var xcurrentPosition = 0;
		  var xslideWidth = 591;
		  var xslides = $('.componentSlide');
		  var xnumberOfSlides = xslides.length;
		
		  // Remove scrollbar in JS
		  $('#componentSlidesContainer').css('overflow', 'hidden');
		
		  // Wrap all .slides with #slideInner div
		  xslides
			.wrapAll('<div class="componentSlideInner"></div>')
			// Float left to display horizontally, readjust .slides width
			.css({
			  'float' : 'left',
			  'width' : xslideWidth
			});
		
		  // Set #slideInner width equal to total width of all slides
		  $('.componentSlideInner').css('width', xslideWidth * xnumberOfSlides);
		
		  // Insert controls in the DOM
		  $('#componentContainer')
			.prepend('<a href="javascript:void(0);" class="componentControl" id="leftControlComponents">Clicking moves left</a>')
			.append('<a href="javascript:void(0);" class="componentControl" id="rightControlComponents">Clicking moves right</a>');
		
		  // Hide left arrow control on first load
		  xmanageControls(xcurrentPosition);
		
		  // Create event listeners for .controls clicks
		  $('.componentControl').bind('click', function(){
			// Determine new position
			xcurrentPosition = ($(this).attr('id')=='rightControlComponents') ? xcurrentPosition+1 : xcurrentPosition-1;
			
			// Hide / show controls
			xmanageControls(xcurrentPosition);
			
			// Move slideInner using margin-left
			$('.componentSlideInner').animate({
			  'marginLeft' : xslideWidth*(-xcurrentPosition)
			});
			
			// UK Flash Map - and Help Tip
			if(xcurrentPosition == 0) {
				$("#ukMap").fadeIn("slow");
				 
			} else {
				$("#ukMap").fadeOut("fast");
				$(".blink").hide();
			}
			
			// Ski Trail Flash Map 
			if(xcurrentPosition == 1) {
				$("#skiMap").fadeIn("slow");
				 
			} else {
				$("#skiMap").fadeOut("fast");
			}
			
			// Italy Flash Map
			if(xcurrentPosition == 2) {
				$("#italyMap").fadeIn("slow");
				 
			} else {
				$("#italyMap").fadeOut("fast");
			}
			
			// Filmtv Intro
			if(xcurrentPosition == 3) {
				$("#filmtvIntro").fadeIn("slow");
				 
			} else {
				$("#filmtvIntro").fadeOut("fast");
			}
			
		
		  });
		
		  // manageControls: Hides and Shows controls depending on currentPosition
		  function xmanageControls(xposition){
			// Hide left arrow if position is first slide
			if(xposition==0){ $('#leftControlComponents').hide() } else{ $('#leftControlComponents').show() }
			// Hide right arrow if position is last slide
			if(xposition==xnumberOfSlides-1){ $('#rightControlComponents').hide() } else{ $('#rightControlComponents').show() }
		  }	
  		
  	};
  })(jQuery);

