function showimage(image_index) {
	// Find the image to be shown, give it the 'between' state
	$(".productphotos ol").children("li").eq(image_index - 1).attr('class','action_img_between');

	// Find the image currently displayed, fade it out
	var blazzo = $(".productphotos ol li.action_img_show img");
	$(".productphotos ol li.action_img_show img").fadeOut("fast",
	function(){
		// Once faded out change the styles
		$(".productphotos ol li.action_img_show").attr('class','action_img_hide');
		$(".productphotos ol li.action_img_between").attr('class','action_img_show');
		blazzo.show();
	});
}

function createCookie(name,value,days) {
	var date = new Date();
	var expires = "";

	if (days) {
		date.setTime(date.getTime()+(days*24*60*60*1000));
		expires = "; expires="+date.toGMTString();
	}

	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	var c;
	var i;

	for(i=0; i < ca.length; i++) {
		c = ca[i];
		while (c.charAt(0)==' ') { c = c.substring(1,c.length); }
		if (c.indexOf(nameEQ) === 0) { return c.substring(nameEQ.length,c.length); }
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

$(document).ready(function(){
	
	$("#product #addReview").submit( function() {
		$.ajax({
			type: "POST",
			url: $(this).attr('action'),
			cache: false,
			data: $(this).serialize(),
			dataType: "html",
			success: function(html){
				var dialog = $("<div></div>").html(html).dialog({ width: 370, modal: true });
				reviewOverlayBindSubmit();
			}
		});
		
		return false;
	});
});

function reviewOverlayBindSubmit() {
	
	$("#ReviewAddForm .rating .star").rating();
	$("#ReviewAddForm").submit( function() {

		$.ajax({
			type: "POST",
			url: $(this).attr('action'),
			cache: false,
			data: $(this).serialize(),
			dataType: "html",
			success: function(data){

				$("#ReviewAddForm").parent().html(data);
				reviewOverlayBindSubmit();
			}
		});

		return false;			
	});

}


