$(document).ready(function() {
	$('#nav-menu #menu-header-navigation li:first').addClass('nav-first');
	var mjSubmitClicked = false;
	var mjStarRatingIndex=0;
	var mjlastClickedStar=0;
	for(mjStarRatingIndex=0; mjStarRatingIndex<=$('#select-hotel-rating div').length; ++mjStarRatingIndex ) {
		$('#star-rating-'+mjStarRatingIndex).mouseover(function() {
			var mjSingleStarIndex = $(this).attr('id').split("-");
			mjSingleStarIndex = mjSingleStarIndex[2];
			var mjStarDivs = 0;
			for(mjStarDivs = 0; mjStarDivs <= mjSingleStarIndex; ++mjStarDivs) {
				$('#star-rating-'+mjStarDivs).css({'backgroundPosition':'0px -16px'});
			}
		});
		$('#star-rating-'+mjStarRatingIndex).mouseout(function() {
			var mjSingleStarIndex = $(this).attr('id').split("-");
			mjSingleStarIndex = mjSingleStarIndex[2];
			var mjStarDivs = 0;
			if(mjlastClickedStar>0) {
			for(mjStarDivs = 0; mjStarDivs <= mjSingleStarIndex; ++mjStarDivs) {
				$('#star-rating-'+mjStarDivs).css({'backgroundPosition':'0px 0px'});
			}
			for(mjStarDivs = mjlastClickedStar+1; mjStarDivs <= 10; mjStarDivs++) {
				$('#star-rating-'+mjStarDivs).css({'backgroundPosition':'0px 0px'});
			}
			for(mjStarDivs = 1; mjStarDivs <= mjlastClickedStar; mjStarDivs++) {
				$('#star-rating-'+mjStarDivs).css({'backgroundPosition':'0px -32px'});
			}
			}
			else
			for(mjStarDivs = 0; mjStarDivs <= mjSingleStarIndex; ++mjStarDivs) {
				$('#star-rating-'+mjStarDivs).css({'backgroundPosition':'0px 0px'});
			}
		});
		$('#star-rating-'+mjStarRatingIndex).click(function() {
			var mjSingleStarIndex = $(this).attr('id').split("-");
			mjSingleStarIndex = mjSingleStarIndex[2];
			var mjStarDivs = 0;
			for(mjStarDivs = 0; mjStarDivs <= 10; ++mjStarDivs) {
				$('#star-rating-'+mjStarDivs).css({'backgroundPosition':'0px 0px'});
			}
			for(mjStarDivs = 0; mjStarDivs <= mjSingleStarIndex; ++mjStarDivs) {
				$('#star-rating-'+mjStarDivs).css({'backgroundPosition':'0px -32px'});
			}
			mjlastClickedStar = mjSingleStarIndex;
		});
	}
	/*
	$('#commentform').submit(function(event) {
		//event.preventDefault();
		//http://www.authlogin.us/bdp/wp-content/plugins/gd-star-rating/ajax.php?_ajax_nonce=4cd986e62f&vote_id=343&vote_value=7&vote_type=a&vote_tpl=10&vote_size=16
		var mjpostID = $('input[name="comment_post_ID"]').val();
		$.get(gdsr_cnst_ajax,{_ajax_nonce:gdsr_cnst_nonce,vote_id:mjpostID,vote_value:mjlastClickedStar,vote_type:'a',vote_tpl:10,vote_size:16});
		//$('#commentform').submit();
	});
	*/
	$('#commentform a#submit').click(function(event) {
		event.preventDefault();
		if(!mjSubmitClicked) {
			if(mjlastClickedStar==0) alert("Please, leave your rating");
			else if($('form#commentform input#author').val()=="") {alert("Please, enter your name"); $('form#commentform input#author').focus();}
			else if($('form#commentform input#email').val()=="") {alert("Please, enter your email"); $('form#commentform input#email').focus();}
			else if($('form#commentform textarea#comment').val()=="") {alert("Please, enter your review"); $('form#commentform textarea#comment').focus();}
			else {
				mjSubmitClicked = true;
				$('img#img-loader').show();
				var mjpostID = $('input[name="comment_post_ID"]').val();
				$.get(gdsr_cnst_ajax,{_ajax_nonce:gdsr_cnst_nonce,vote_id:mjpostID,vote_value:mjlastClickedStar,vote_type:'a',vote_tpl:10,vote_size:16},
				function() {
					$('#commentform').submit();
					$('img#img-loader').hide();
				});
			}
		}
	});
	/*
	$('.send-rating').click(function(event) {
	});
	*/
	$('ol.commentlist li div.reply a.btn-report').click(function(event) {
		event.preventDefault();
		$('div#report-respond').remove();
		var appendReport = '<div id="report-respond">';
		appendReport += '<h3 class="respond-title">Report This Comment</h3>';
		appendReport += '<div class="report-comment-reply">';
		appendReport += '<small><a style="" href="javascript:cancelReport();" id="report-comment-reply-link" rel="nofollow">Click here to cancel report.</a></small>';
		appendReport += '</div>';
		appendReport += '<label for="author">Name (required) </label>';
		appendReport += '<p class="report-p-field"><input type="text" size="22" id="reporter" name="reporter"></p>';
		appendReport += '<label for="email">Mail (required) </label>';
		appendReport += '<p class="report-p-field"><input type="text" size="22" id="reporter-email" name="reporter-email"></p>';
		appendReport += '<div class="report-textarea">';
		appendReport += '<div class="top"></div>';
		appendReport += '<div class="middle"><textarea tabindex="4" rows="9" cols="60" id="report" name="report"></textarea></div>';
		appendReport += '<div class="bottom"></div>';
		appendReport += '</div>';
		var commID = $(this).attr('name').split("-");
		commID = commID[3];
		appendReport += '<a id="submit" class="submit-report-'+commID+'" href="javascript:sendReport(\''+commID+'\');">Submit</a>';
		appendReport += '</div>';
		$(this).parent().parent().parent().after(appendReport);
	});
	$('div#report-respond a#submit').click(function(event) {
		event.preventDefault();
		var commID = $(this).attr('class').split("-");
		commID = commID[2];
		$.post('../report.php',{to:$('input#report_admin_email').val(),email:$('input#reporter-email').val(),name:$('input#reporter').val(),report:$('textarea#report').val(), commenttext:$('div.comment-'+commID+' div.commentmetadata p.comment-text').text(),commentid:commID});
	});
});
function sendReport(commID) {
	$.post($('input#report_js').val(),{to:$('input#report_admin_email').val(),email:$('input#reporter-email').val(),name:$('input#reporter').val(),report:$('textarea#report').val(), commenttext:$('div#comment-'+commID+' div.commentmetadata p.comment-text').text(),commentid:commID},function() {
		$('div#comment-'+commID+' div.commentmetadata').append('<p><b>Report is sent</b></p>');
		cancelReport();
	});
}
function cancelReport() {
	$('div#report-respond').remove();
}

