//Add Vehicle to the Comparison Queue
function AddToComparison(p_sVIN, p_sThumbnailImg)
{
	//If this is will be the 1st vehicle in the Queue, show the comparison block
	if ($('#ComparisonQueue li').length == 0)
		$('#ComparisonQueue').attr('style','visibility: display;');				


	$('#ComparisonVehicleList').prepend('<li><span class="RemoveCompare"><a id="CompareVehicle_' + p_sVIN + '" href="javascript:RemoveFromComparison(\'' + p_sVIN + '\');" title="Remove ' + p_sVIN + ' from Comparison" class="tipster">Remove ' + p_sVIN + ' from Comparison</a></span><img src="' + p_sThumbnailImg + '" width="50" height="37" alt="' + p_sVIN + '" /></li>');
	
	//Set up the remove from Comparison Queue function for the New Item
	$('#CompareVehicle_' + p_sVIN).click(function() {
		$(this).parents('li:eq(0)').hide('slow',  function () {
	       $(this).remove();

   		   //If there are no more items, hide the comaparison block
			if ($('#ComparisonQueue li').length == 0)
				$('#ComparisonQueue').hide(300);					
		 });
	});
		
	//initiates the tipster for the New item
	$('#CompareVehicle_' + p_sVIN).tooltip({
		track: true,
		delay: 0,
		showURL: false,
		fade: 250,
		left: -5,
		top: 20
	});			
}	

//Add Vehicle to comparison Queue by showing Image Animation
function AddToComparisonAnimation(p_sImageID, p_sVIN, p_sImageContainerDiv, p_iAnimationDuration)
{
	$.ajax({
		   type: "POST",
		   url: "/Inventory/AddToComparisonProc.asp",
		   data: "VIN=" + p_sVIN,
	       success: function(p_sThumbnailImg) {
		   		//The vehicle was added to the comparison Queue.  Transfer the vehicle image to the comparison queue.
				if (p_sThumbnailImg != '')
				{
					//If this is will be the 1st vehicle in the Queue, show the comparison block
					if ($('#ComparisonQueue li').length > 0)
						$('#ComparisonQueue').attr('style','visibility: display;');				

					var $mainImage = $('#' + p_sImageID);

					//clone mainImage to the document for the animation
					var $animationImage = $mainImage.clone().appendTo('body');
					$animationImage.css({ 'visibility': 'visible', 'display': 'block' });					
					
					//move $animationImage to position
					//also big z-index, make sure to edit this to something that works with the page
					$animationImage
					  .css('position', 'absolute')
					  .css('left', $('#' + p_sImageContainerDiv).offset().left)
					  .css('top', $('#' + p_sImageContainerDiv).offset().top)
					  .css('zIndex', 1000);		
					  
					//animate the $animationImage to the position of the comparison queue and add new item to the queue
					$animationImage.animate( { 'top': $('#ComparisonQueue').offset().top+10, 'left': $('#ComparisonQueue').offset().left, 'width': '50px', 'height': '37px'  }, p_iAnimationDuration, function(){
					   $animationImage.remove();
					   
						$('#ComparisonVehicleList').prepend('<li><span class="RemoveCompare"><a id="CompareVehicle_' + p_sVIN + '" href="javascript:RemoveFromComparison(\'' + p_sVIN + '\');" title="Remove ' + p_sVIN + ' from Comparison" class="tipster">Remove ' + p_sVIN + ' from Comparison</a></span><img src="' + p_sThumbnailImg + '" width="50" height="37" alt="' + p_sVIN + '" /></li>');
	
						//Set up the remove from Comparison Queue function for the New Item
						$('#CompareVehicle_' + p_sVIN).click(function() {
							$(this).parents('li:eq(0)').hide('slow',  function () {
						       	$(this).remove();

					   		   	//If there are no more items, hide the comaparison block
								if ($('#ComparisonQueue li').length == 0)
									$('#ComparisonQueue').hide(300);					
							});
						});
		
						//initiates the tipster for the New item
					    $('#CompareVehicle_' + p_sVIN).tooltip({
							track: true,
							delay: 0,
							showURL: false,
							fade: 250,
							left: -5,
							top: 20
						});								   
					   					   					   
					});	 //end of animationImage.animate
				} // end of IF
				else if ($('#ComparisonQueue li').length == 4)
				{
					alert("You currently have the maximum number of vehicles in the queue.\nPlease delete a vehicle before you add another.");
				}
		   } // end of success function
	});		
}

//Remove vehicle from the Comparison Queue
function RemoveFromComparison(p_sVIN)
{
	$.ajax({
	   type: "POST",
	   url: "/Inventory/RemoveFromComparison.asp",
	   data: "VIN=" + p_sVIN + "&AJAX=1"
	});	
	if ($('#ComparisonQueue li').length == 2)
		$('#ComparisonQueue').attr('style','visibility: hidden;');		
}

