//preload the review star image.
	var pic = new Image(); 
	pic.src="/img/icons/starSmall.png";

	function showPic(num)
		{
		$(".bigImage").hide();
		$("#pic"+num).show();
		}
	
	function hideReview()
		{
		for(var i = 1; i < 6; i++)
			{
			$('#star'+i).css("background-image", "url(/img/icons/star_dotted.png)");
			}	
		$("#review_form").slideUp();
		$('#textStar').html("");	
		starHist = 0;
		}
	
	
	function cclick(value)
		{
	//	alert(value);
		$("#star"+value).blur();
	//	alert(value);
		for(var i = 1; i <= value; i++)
			{
			$('#star'+i).css("background-image", "url(/img/icons/starSmall.png)");
			}
	//	alert("for loop half done");
		for(var i = value+1; i < 6; i++)
			{
			$('#star'+i).css("background-image", "url(/img/icons/star_dotted.png)");
			}
		starHist = value;
	//	alert("starHist");
		$('#textStar').css("color", "#888888");
		if(value==1)
			{
			$('#textStar').css("color", "#e1958b");
			$('#textStar').html("Horrible!");
			}
		else if(value==2)
			$('#textStar').html("Ok");
		else if(value==3)
			$('#textStar').html("Good");
		else if(value==4)
			{
			$('#textStar').css("color", "#7dbc8c");
			$('#textStar').html("Very good");
			}
		else if(value==5)
			{
			$('#textStar').css("color", "#7dbc8c");
			$('#textStar').html("Brilliant!");
			}
		$("#review_form").slideDown();	
		}
		
	var starHist = 0;
	function s_hover(value)
		{
		//alert(value);
		if(value!=starHist)
			$("#textStar").css("color", "#cccccc");
		//alert("for loop1");
		for(var i = 1; i <= value; i++)
			{
			$('#star'+i).css("background-image", "url(/img/icons/starSmall.png)");
			}
		//alert("for loop2");
		for(var i = value+1; i < 6; i++)
			{
			$('#star'+i).css("background-image", "url(/img/icons/star_dotted.png)");
			}
		//alert("text");
		if(value==1)
			$('#textStar').html("Horrible!");
		else if(value==2)
			$('#textStar').html("Ok");
		else if(value==3)
			$('#textStar').html("Good");
		else if(value==4)
			$('#textStar').html("Very good");
		else if(value==5)
			$('#textStar').html("Brilliant!");			
		}

	function remove()
		{
		s_hover(starHist);
		if(starHist==0)
			$('#textStar').html("");
		else if(starHist==5||starHist==4)
			$('#textStar').css("color", "#7dbc8c");			
		else if(starHist==1)
			$('#textStar').css("color", "#e1958b");			
		else
			$('#textStar').css("color", "gray");
		}
	
	function submitReview()
		{
		var grade = starHist;
		var title = $("#title").val();
		var text = $("#text").val();
		var id = $("#id").val();
		var type = $("#type").val();
		var userName = $("#userName").val();
		if(userName=="")
			{
			alert("Please enter your name before continuing");
			}
		else
			{
			$.post('/ajax/users/save_review.php', {grade:grade,title:title,text:text,id:id,type:type,userName:userName}, function(data)
				{
				if(data==-1)//didnt work
					{
					alert("You have already reviewed this attraction");
					}
				else//did work, add the review inline!
					{
					//add the review as if it has been passed already...
					$('#new_review').hide();
					$('#new_review').html("<div style='width:700px;margin-top:16px;padding:10px;background-color:#eee;font-size:15px;'>Thank you for contributing to the TravelGround community!</div>");
					$('#new_review').slideDown("slow");
					}
				});			
			}
		}
	
	function saveReviewVote(review_id,vote)
		{
		$.post('/ajax/users/save_review_vote.php', {vote:vote,review_id:review_id}, function(data)
			{
			if(data==1)
				{
				$("#rev"+review_id).hide("slow");
				}
			else if(data==-1)
				{
				}
			});		
		}
	
	function vote(vote,url,num)
		{
		$('#thumb'+num).fadeOut("slow");
		$.post('/ajax/vote.php', {vote:vote,url:url}, function(data)
			{
			if(data==1)
				{
				//alert("Thank you for your input!");
				}
			else if(data==0)
				{
				}
			else
				{
				//alert("Thank you for your input!");
				}	
			});
		}

