//console.log('loaded');
$(function(){

	$('div.campaign #posterPane').mouseover(function() {
	
		$('#posterPane #campaignDetails').show();
		$('#posterPane img.poster').hide();
		$('#posterPane img.thumbnail').hide();
	
	});
	$('div.campaign #posterPane').mouseout(function() {
	
		$('#posterPane #campaignDetails').hide();
		$('#posterPane img.poster').show();
		$('#posterPane img.thumbnail').show();
	
	});

	//*
	$('#addCommentFake a').click(function(e) {
		e.preventDefault();
		$('#ratingWidget').toggle().html('<span class="err">You must be logged in to use this feature.</span>');
	})	//*/
	
	$('#addRatingFake a').click(function(e) {
		e.preventDefault();
		if ($(this).parent().hasClass('unrate')) {
			$('#ratingWidget').toggle().html('<span class="err">You must first play this map before rating it.</span>');
		} else {
			$('#ratingWidget').toggle().html('<span class="err">You must be logged in to use this feature.</span>');
		}
		$('#commentFormCont').hide();
		//$(this).attr('href', '/register.php');
	});

	//*
	$('#addRealRating a').click(function(e) {
	
		e.preventDefault();
		//console.log('working');
		if ($(this).parent().hasClass('disabled')) {
			$('#ratingWidget').toggle().html('<span class="err">You must be logged in to use this feature.</span>');
		} else {
		$('#ratingWidget').toggle();
		$('#commentFormCont').hide();
		
		$("#ratingWidget #sliderToo").slider({
			value:$("#sliderValueToo").html(),
			min: 1,
			max: 100,
			step: 1,
			slide: function(event, ui) {
				$("#sliderValueToo").text(ui.value);
			}
		});
		}
	});//*/
	
	window.inc = 0;
	
	$('#addRating a').click(function(e) {
	
		e.preventDefault();
		//console.log('working');
		if ($(this).parent().hasClass('ownertard')) {
			alert('You cannot review your own map.');
		} else {
			$('#reviewFormCont').toggle();
			$('#commentFormCont').hide();
			
			$("#reviewFormCont #slider").slider({
				value:$("#sliderValue").html(),
				min: 1,
				max: 100,
				step: 1,
				slide: function(event, ui) {
					$("#sliderValue").text(ui.value);
					$("#ratting").val(ui.value);
				}
			});
		}

	});


	$('#submitReview').click(function(e) {
		//console.log($("#slider").slider("value"));
		
		
		if ($('#pros').val().length<1 || $('#cons').val().length<1 || $('#overall').val().length<1) {
			alert('All fields are required to continue.');
		e.preventDefault();
		} else {
			console.log('saving');
			//console.log($('#reviewFormCont form'));
			//$('#reviewFormCont form').submit();
		}
		
	});
		
	
	$('#addComment a').click(function(e) {
	
		e.preventDefault();
		//console.log('working');
		
		$('#ratingWidget').hide();
		$('#reviewFormCont').hide();
		$('#commentFormCont').toggle();


	});	
	
	$('#vidIcon').click(function(e) {
		if (window.inc == 0) { $.get('/addviewvideo.php?id=' + $("#aj_mapID").html()); window.inc = 1; }
	});	
	
	
	//$("#sliderValue").val('$' + $("#slider").slider("value"));
	$('#commentWidget').hide();
	$('#saveRatingButton').click(function(e) {
		e.preventDefault();
		//console.log('saving');
		//console.log($("#slider").slider("value"));
		
		$.post('/ajax_assorted.php', {'intent':'rate','value':$("#sliderToo").slider("value"),'map':$("#aj_mapID").html()}, function(data) {
			//console.log(data);
			var str = window.location.href;
			if(data.valid) { window.location.href='details.php?file=' + $("#aj_mapID").html(); }
		}, 'json');
	});
		





	$('#reviewBox a.next').click(function(e) {
		e.preventDefault();
		if ($('#reviewBox .active').hasClass('last')) {
			$('#reviewBox .active').hide().removeClass('active');
			$('#reviewBox .first').show().addClass('active');
		} else {
			$('#reviewBox .active').hide().removeClass('active').next().show().addClass('active');
		}
	});

});







/*
$(function(event)) {


function addWatch(id, button) {
	
//&cmd=addwatchlist
//addWatch('.$file[id].',this)"></a>
	$.get("details.php?file=" + id + "", function(data){
	  $(button).addClass('watchLink_d').removeClass('watchLink');
	});

	return false;

}

}
//*/
