//makes sure the dom is ready
$(document).ready(function() {
	
	//variable that holds how many bikes are currently clicked for compare
	var clickedCount = 0;
	//array of all the bikes that are slected for comparison
	var bikes = Array();
	
	//listener for the compare clicks
	$(".bike_details .compare. .left_container").click(function () {
		
		//checks to see if it is already active
		if( $(this).hasClass( 'active' ) ){
			
			//it was active so where making it not active remove class
			$(this).removeClass( 'active' );
			
			//set the bike in the array for that click back to nothing
			bikes[clickedCount] = '';
			
			//there is one less clicked now so change the counter
			clickedCount--;
			
		}else{
			
			//if the click count is already 3 or greater 
			if( clickedCount >= 3 ){
				
				$.scrollTo("#header");
				
				$('.lineup_compare_container .red').show();
				
				$('.lineup_compare_container .red').fadeOut( 1000 );

//				$(".lineup_compare_container .left_container").animate({
//					 backgroundColor:'black', opacity: .5
//				    }, 1000, "linear" );
				
			}else{
			
				//one more is clicked so add it to the count
				clickedCount++;
			
				//set the bikes compare to active
				$(this).addClass( 'active' );
				
				//add that bikes name to the array
				bikes[clickedCount] = $(this).attr("rel");

				
			}
		}
	});
	
	//listen for the user to click the compare button
	$(".compare_link").click(function () {
			
		//if the slot is empty we pass in the word empty
		if( bikes[2] == '' ){
			
			//set array spot to word empty
			//this is how the compare functioned mimiking functionality
			bikes[2] = 'empty';
			
		}
		//if the slot is empty we pass in the word empty
		if( bikes[3] == '' ){
			
			//set array spot to word empty
			//this is how the compare functioned mimiking functionality
			bikes[3] = 'empty';
			
		}
		
		//open the compare in a new window
		window.location = "http://www.trekbikes.com/"+$(this).attr("country")+"/"+$(this).attr("lang")+"/bikes/compare/#/"+bikes[1]+","+bikes[2]+","+bikes[3];
		
		
	});
});
