/**
 * * * Carousel object
 * Carousel.left = initial LEFT css property of the sliding container.
 * Carousel.links = array of carousel carousel items
 * Carousel.numImages = number of items that can be simultaenously visible in the carousel.
 * Carousel.imageWidth = width of each item in the carousel.
 * Carousel.maxLeft = the farthest the carousel container can slide to the left, default is set to 0.
 * Carousel.minLeft() = the farthest the carousel container can slide to the right.
 * Carousel.noRight = flag that prevents the carousel from sliding to the right when true.
 * Carousel.noLeft = flag that prevents the carousel from sliding to the left when true, default is set to 0.
 * * *

 * * * Carousel Markup * * *
 	<div id="sponsorsCarouselContainer">
    <div id="sponsorsLeftArrow" class="inactive"></div>	
    <div class="mask">
    	<div id="sponsorsScrollStrip">
			<!--<a> tags here-->
			<a><img /></a>
			<a><img /></a>
			<a><img /></a>
			<a><img /></a>
			<!--end <a> tags -->
		</div>
    </div>
    <div id="sponsorsRightArrow"></div>
</div>
 * * *
 */


$(function(){
	$('#sponsorsRightArrow').removeClass('inactive');
	var Carousel = {
		left : parseInt($('div#sponsorsCarouselContainer div#sponsorsScrollStrip').css('left')) || 0,
		links : $('div#sponsorsCarouselContainer div#sponsorsScrollStrip a'),
		numImages : 6,
		imageWidth : 153,
		oneRow : function(){return this.numImages * this.imageWidth;},
		maxLeft : 0,
		minLeft : function(){return this.maxLeft - (this.links.length * this.imageWidth - this.oneRow())},
		noRight : false,
		noLeft : true
		};
		
	$('div#sponsorsCarouselContainer div#sponsorsRightArrow').click(
		function(event){
			if(Carousel.noRight === true){
				return false;
			}
			else if(Carousel.left - Carousel.oneRow() < Carousel.minLeft()){
				Carousel.left = Carousel.minLeft();
			}
			else{
				Carousel.left -= Carousel.oneRow();
			}
			$('div#sponsorsScrollStrip').animate(
				{'left' : Carousel.left}, 1250,'swing',
				function(){
					Carousel.noLeft = false;
					$('div#sponsorsLeftArrow').removeClass('inactive');
					if(Carousel.left === Carousel.minLeft()){
						Carousel.noRight = true;
						$('div#sponsorsRightArrow').addClass('inactive');
					}
				}
			);
		}							  
	)
	
	$('div#sponsorsCarouselContainer div#sponsorsLeftArrow').click(
		function(event){
			if(Carousel.noLeft === true){
				return false;
			}
			else if(Carousel.left + Carousel.oneRow() > Carousel.maxLeft){
				Carousel.left = Carousel.maxLeft;
			}
			else{
				Carousel.left += Carousel.oneRow();	
			}
			$('div#sponsorsScrollStrip').animate(							 
				{'left' : Carousel.left}, 1250,'swing',
				function(){
					Carousel.noRight = false;
					$('div#sponsorsRightArrow').removeClass('inactive');
					if(Carousel.left === Carousel.maxLeft){
						Carousel.noLeft = true;
						$('div#sponsorsLeftArrow').addClass('inactive');
					}	
				}
			);
		}							  
); //end large carousel
	

//small carousel

var Carousel_small = {
		left : parseInt($('div#companiesLandingCarouselContainer div#sponsorsScrollStrip').css('left')) || 0,
		links : $('div#companiesLandingCarouselContainer div#sponsorsScrollStrip a'),
		numImages : 4,
		imageWidth : 153,
		oneRow : function(){return this.numImages * this.imageWidth;},
		maxLeft : 0,
		minLeft : function(){return this.maxLeft - (this.links.length * this.imageWidth - this.oneRow())},
		noRight : false,
		noLeft : true
		};
		
	$('div#companiesLandingCarouselContainer div#sponsorsRightArrow').click(
		function(event){
			if(Carousel_small.noRight === true){
				return false;
			}
			else if(Carousel_small.left - Carousel_small.oneRow() < Carousel_small.minLeft()){
				Carousel_small.left = Carousel_small.minLeft();
			}
			else{
				Carousel_small.left -= Carousel_small.oneRow();
			}
			$('div#sponsorsScrollStrip').animate(
				{'left' : Carousel_small.left}, 1250,'swing',
				function(){
					Carousel_small.noLeft = false;
					$('div#sponsorsLeftArrow').removeClass('inactive');
					if(Carousel_small.left === Carousel_small.minLeft()){
						Carousel_small.noRight = true;
						$('div#sponsorsRightArrow').addClass('inactive');
					}
				}
			);
		}							  
	)
	
	$('div#companiesLandingCarouselContainer div#sponsorsLeftArrow').click(
		function(event){
			if(Carousel_small.noLeft === true){
				return false;
			}
			else if(Carousel_small.left + Carousel_small.oneRow() > Carousel_small.maxLeft){
				Carousel_small.left = Carousel_small.maxLeft;
			}
			else{
				Carousel_small.left += Carousel_small.oneRow();	
			}
			$('div#sponsorsScrollStrip').animate(							 
				{'left' : Carousel_small.left}, 1250,'swing',
				function(){
					Carousel_small.noRight = false;
					$('div#sponsorsRightArrow').removeClass('inactive');
					if(Carousel_small.left === Carousel_small.maxLeft){
						Carousel_small.noLeft = true;
						$('div#sponsorsLeftArrow').addClass('inactive');
					}	
				}
			);
		}							  
); 

$('#videoRightArrow').removeClass('inactive');
var Carousel_video = {
		left : parseInt($('div#videoCarouselContainer div#videoScrollStrip').css('left')) || 0,
		links : $('div#videoCarouselContainer div#videoScrollStrip a'),
		numImages : 4,
		imageWidth : 60,
		oneRow : function(){return this.numImages * this.imageWidth;},
		maxLeft : 0,
		minLeft : function(){return this.maxLeft - (this.links.length * this.imageWidth - this.oneRow())},
		noRight : false,
		noLeft : true
		};
	
	$('div#videoCarouselContainer div#videoRightArrow').click(
		function(event){
			if(Carousel_video.noRight === true){
				return false;
			}
			else if(Carousel_video.left - Carousel_video.oneRow() < Carousel_video.minLeft()){
				
				Carousel_video.left = Carousel_video.minLeft();
			}
			else{
				Carousel_video.left -= Carousel_video.oneRow();
			}
			$('div#videoScrollStrip').animate(
				{'left' : Carousel_video.left}, 1250,'swing',
				function(){
					Carousel_video.noLeft = false;
					$('div#videoLeftArrow').removeClass('inactive');
					if(Carousel_video.left === Carousel_video.minLeft()){
						Carousel_video.noRight = true;
						$('div#videoRightArrow').addClass('inactive');
					}
				}
			);
		}							  
	)
	
	$('div#videoCarouselContainer div#videoLeftArrow').click(
		function(event){
			if(Carousel_video.noLeft === true){
				return false;
			}
			else if(Carousel_video.left + Carousel_video.oneRow() > Carousel_video.maxLeft){
				Carousel_video.left = Carousel_video.maxLeft;
			}
			else{
				Carousel_video.left += Carousel_video.oneRow();	
			}
			$('div#videoScrollStrip').animate(							 
				{'left' : Carousel_video.left}, 1250,'swing',
				function(){
					Carousel_video.noRight = false;
					$('div#videoRightArrow').removeClass('inactive');
					if(Carousel_video.left === Carousel_video.maxLeft){
						Carousel_video.noLeft = true;
						$('div#videoLeftArrow').addClass('inactive');
					}	
				}
			);
		}							  
); 	
  
  
  
});//end DOMReady