<!--

$(document).ready(function(){
    
    $('#votebox.rate img').one('click', function(){
        if (document.cookie.length > 0)
        {
            $rate = $(this).hasClass("down") ? "down" : "up";
            $key = $("#photokey").text();
            $('#votebox').load('/functions/ajax/ratephoto2.php', {'key':$key, 'tpe':'picture', 'rate':$rate}, function(){
                $("#votebox").addClass("rated");
                $("#votebox").removeClass("rate");
                $("#ratePhotoHeader").text("Thanks for rating!");
            });
        }
        else
        {
            alert('Sorry, you must have cookies enabled for this functionality');
        }
    });
    
    $("#votebox.rate img").hover(
      function () {
          if($(this).hasClass("up"))
              $("#ratePhotoHeader").text("I like this picture");
          else
              $("#ratePhotoHeader").text("I don't like this picture");
      },
      function () {
          if($(this).hasClass("rated"))
              $("#ratePhotoHeader").text("Rated");
          else
              $("#ratePhotoHeader").text("Rate this picture");
      }
    );
});
/*
function ajaxFunction(rating, key)
{
	var ajaxRequest;  // The variable that makes Ajax possible!
	
	try
	{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e)
	{
		// Internet Explorer Browsers
		try
		{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) 
		{
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e)
			{
				// Something went wrong
				//alert("Error creating Ajax object!");
				return false;
			}
		}
	}
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function()
	{
		if(ajaxRequest.readyState == 4)
		{
			//alert(ajaxRequest.responseText);
			if (!parseResponse(ajaxRequest.responseText))
				;
		}
	}
	
	var queryString = "/functions/ajax/ratephoto.htm?key=" + key + "&rate=" + rating;
	ajaxRequest.open("GET", queryString, true);
	ajaxRequest.send(null);
}


// Process ajax response
function parseResponse(response)
{
	if (response.length < 1) { return false; } 
	
	//Splits the response up in key pairs
  indx = 1;
	keypairs = new Object();
	while (response.indexOf('&') > -1)
	{
		keypairs[indx] = response.substring(0,response.indexOf('&'));
		response = response.substring((response.indexOf('&')) + 1);
		indx++;
	}
	//Go though key pairs
	for (indx in keypairs)
	{
		keyName = keypairs[indx].substring(0,keypairs[indx].indexOf('=')); // Left of '=' is name.
		keyValue = keypairs[indx].substring((keypairs[indx].indexOf('=')) + 1); // Right of '=' is value.
		processKeyPair(keyName, keyValue);
	}
	
	
	function processKeyPair(keyName, keyValue)
	{
		tag = keyName;
		txt = keyValue;
		switch (tag)
		{
			case 'up': 
				if (document.getElementById('cntPhotoRatedUp') != null)
					{	
						obj = document.getElementById('cntPhotoRatedUp');	
						obj.innerHTML = txt;
					}	
			break;
			
			case 'down': 
				if (document.getElementById('cntPhotoRatedDown') != null)
					{	
						obj = document.getElementById('cntPhotoRatedDown');	
						obj.innerHTML = txt;
					}	
			break;
			
			case 'rated':
				if (document.getElementById('ratePhotoHeader') != null)
					{	
						obj = document.getElementById('ratePhotoHeader');	
						obj.innerHTML = 'Thanks for rating!';
					}
				//Disable voting
				if (document.getElementById('imgRatePhotoUp') != null)
					{	
						obj = document.getElementById('imgRatePhotoUp');	
						action = 'off';
						if (txt == 'up') action = 'in';
						obj.innerHTML = "<img src=\"/img/thumbup_" + action + ".gif\" alt=\"Thumb up\" border=\"0\" width=\"28\" height=\"33\">";
					}
				if (document.getElementById('imgRatePhotoDown') != null)
					{	
						obj = document.getElementById('imgRatePhotoDown');	
						action = 'off';
						if (txt == 'down') action = 'in';
						obj.innerHTML = "<img src=\"/img/thumbdown_" + action + ".gif\" alt=\"Thumb up\" border=\"0\" width=\"28\" height=\"33\">";
					}
				
				
				break;
			
			case 'message': 
				if (txt == 'err')
				{
					if (document.getElementById('photoRating') != null)
					{	
						obj = document.getElementById('photoRating');	
						obj.innerHTML = 'sorry, an unexpected error occurred';
					}		
					alert('sorry, an unexpected error occurred');
				}
				else
				alert(txt);
			break;
		}
	}
}
*/
//-->
