$(document).ready(function(){
	hs.graphicsDir = '/images/highslide/';
    hs.outlineType = 'rounded-white';
    hs.outlineWhileAnimating = true;
	
	
	$('a.highslide').click(function() {
	   return hs.expand(this, { outlineType: 'rounded-white' });
	});
	
	$("#postComment").bind("click", function(){
		
		// var comment_name = $("input[name=comment_name]").val();
		var comment_comment = $("textarea[name=comment_comment]").val();
		var comment_code = $("input[name=comment_code]").val();
		$.ajax({
			type: "POST",
			url: "/checkCode.php",
			data: "code="+comment_code,
			success: function(html){
				if (html == 1){
					$("#codeError").hide();
				}else{
					$("#codeError").show();
				}
			}
		});
		/*
		if ( comment_name == "" ){
			$("#nameError").show();
		}else{
			$("#nameError").hide();
		}
		*/
		if ( comment_comment == "" ){
			$("#commentError").show();
		}else{
			$("#commentError").hide();
		}
		
		if ($("#codeError").css("display") == "none" && $("#commentError").css("display") == "none"){
			document.postComment.submit();
		}else {
			return false;
		}
		
	});
	
	$("#addComment").bind("click", function(){
		$("#commentsForm").slideDown("slow");
	});
	$("#displayComments").bind("click", function(){
		if ($("#commentsForm").css("display") == "none"){
			$("#commentsForm").slideDown("slow");
		}else{
			$("#commentsForm").slideUp("slow");
		}
	});
	
	
	
	$(".thumbsUp").bind("click", function(){
		var comment_id = $(this).attr("name");
		
		$.ajax({
			type: "POST",
			url: "/rateComment.php",
			data: "type=rateUp&comment_id="+comment_id
		});
		$.ajax({
			type: "POST",
			url: "/rateComment.php",
			data: "type=rating&comment_id="+comment_id,
			success: function(html){
				$("#c"+comment_id).empty();
				$("#c"+comment_id).append(html);
			}
		});
	});
	$(".thumbsDown").bind("click", function(){
		var comment_id = $(this).attr("name");
		$.ajax({
			type: "POST",
			url: "/rateComment.php",
			data: "type=rateDown&comment_id="+comment_id
		});
		$.ajax({
			type: "POST",
			url: "/rateComment.php",
			data: "type=rating&comment_id="+comment_id,
			success: function(html){
				$("#c"+comment_id).empty();
				$("#c"+comment_id).append(html);
			}
		});
	});

	$(".variousComm").fancybox({
		'width'				: '70%',
		'height'			: '85%',
        'autoScale'     	: false,
        'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe'
	});

	
	$(".pthumbsUp").bind("click", function(){
		var picture_id = $(this).attr("name");
		
		$.ajax({
			type: "POST",
			url: "/ratePicture.php",
			data: "type=rateUp&picture_id="+picture_id,
			success: function(html){
				//$(".imageMessage").hide();
				//$("#message"+picture_id).empty();
				//$("#message"+picture_id).append(html);
				if(html != ''){
					alert(html);
				}
				//$("#message"+picture_id).fadeIn();
			}
		});
		$.ajax({
			type: "POST",
			url: "/ratePicture.php",
			data: "type=rating&picture_id="+picture_id,
			success: function(html){
				$("#p"+picture_id).empty();
				$("#p"+picture_id).append(html);
			}
		});
	});
	$(".pthumbsDown").bind("click", function(){
		var picture_id = $(this).attr("name");
		$.ajax({
			type: "POST",
			url: "/ratePicture.php",
			data: "type=rateDown&picture_id="+picture_id,
			success: function(html){
				$("#message"+picture_id).empty();
				$("#message"+picture_id).append(html);
			}
		});
		$.ajax({
			type: "POST",
			url: "/ratePicture.php",
			data: "type=rating&picture_id="+picture_id,
			success: function(html){
				$("#p"+picture_id).empty();
				$("#p"+picture_id).append(html);
			}
		});
	});

});
