/**
 * Favorites Scripts
 */

	function addFavorites(item_id, item_type_id)
	{
		// build array of the params to pass via ajax
		var params = { 
			'a': 'add',
			item_id: 		item_id,
			item_type_id: 	item_type_id
		};
			
		// ajax request to add movie
		$.get("favorites.php?a=add", params, function(msg) {
			if(msg == "success")
			{
				$("#favoritesRemove_" + item_type_id + "_" + item_id).show();
				$("#favoritesAdd_" + item_type_id + "_" + item_id).hide();
			}
			else
			{
				//alert(': item:'+item_id+' type:'+item_type_id);
			}

		});	
	}

	function removeFavorites(item_id, item_type_id)
	{
		// build array of the params to pass via ajax
		var params = { 
			item_id: 		item_id,
			item_type_id: 	item_type_id
		};
		
		// ajax request to remove movie
		$.get("favorites.php?a=remove", params, function(msg) {
			if(msg == "success")
			{			
				$("#favoritesRemove_" + item_type_id + "_" + item_id).hide();
				$("#favoritesAdd_" + item_type_id + "_" + item_id).show();
			}
			else
			{
				//alert('Remove Fail');
			}
		});
	}

/**
 * Ratings Scripts
 */

	var currentStarSet		= "";
	var currentStarSettings	= new Object();
	currentStarSettings[1]	= "";
	currentStarSettings[2]	= "";
	currentStarSettings[3]	= "";
	currentStarSettings[4]	= "";
	currentStarSettings[5]	= "";
	
	function ratingStarOver(starSet, num)
	{
		//	Local vars
		var i	= 0;
		var img	= null;
		
		//	If working on a new star set, move the old one back to its
		//	original settings before proceeding
		if( currentStarSet != "" &&
			currentStarSet != starSet )
		{
			for( i = 1; i <= 5; i++ )
			{
				img		= document.getElementById( currentStarSet + '_' + i );
				img.src	= currentStarSettings[ i ];
			}
		}
		
		//	If working on a new star set, save the new settings for the
		//	current set
		if( currentStarSet != starSet )
		{
			//	Save the new current
			currentStarSet	= starSet;
			
			for( i = 1; i <= 5; i++ )
			{
				img					= document.getElementById( starSet + '_' + i );
				currentStarSettings[ i ]	= img.src;
			}
		}
		
		//	Swap out the necessary images to the rollover
		for( i = 1; i <= 5; i++ )
		{
			img		= document.getElementById(starSet+'_'+i);
			
			if( i <= num )
					img.src	= ratingStarSelected;
			else	img.src	= ratingStarZero;
		}
	}
	function ratingStarOut(starSet, num)
	{
		//	Local vars
		var i	= 0;
		var img	= null;
		
		//	Swap out the un-included stars back to their original src
		for( i = 5; i > 0; i-- )
		{
			img		= document.getElementById( starSet + '_' + i );
			img.src	= currentStarSettings[ i ];
		}
	}
	function rateItem(starSet, num, item_id, item_type_id)
	{
		// build array of the params to pass via ajax
		var params = { 
			item_id: 		item_id,
			item_type_id: 	item_type_id,
			num: 			num
		};
		
		var ratingDiv	= document.getElementById(starSet+'_DIV');
		
		ratingDiv.innerHTML	= "Saving...";
		
		var newStars	= "";
		
		for( var i = 1; i <= 5; i++ )
		{
			currentStarSettings[ i ]	= ( i <= num ? ratingStarSelected : ratingStarZero );
			newStars					+= '<a href="javascript:rateItem(\'' + starSet + '\', ' + i + ', ' + item_id + ', ' + item_type_id +')" onMouseOver="ratingStarOver(\'' + starSet + '\',' + i + ')" onMouseOut="ratingStarOut(\'' + starSet + '\',' + i + ')"><img id="' + starSet + '_' + i + '" src="' + ( i <= num ? ratingStarSelected : ratingStarZero ) + '" border="0" /></a>';
		}
		
		ratingDiv.innerHTML	= newStars;
				
		// ajax request to remove movie
		$.get( "/ratings.php?a=add", params );
		
	}
