//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();
	
	});
	
	$('a.nominowner').click(function(e) {
		e.preventDefault();
		alert('You cannot nominate your own map.');
		return false;
	});
	
	//*
	$('#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();
		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();
		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) {			
		
		if ($('#pros').val().length<1 || $('#cons').val().length<1 || $('#overall').val().length<1) {
			alert('All fields are required to continue.');
			e.preventDefault();
		} else if (($('#pros').val() + $('#cons').val() + $('#overall').val()).length < 100) {
			alert('You must provide a more substantial review.');
			e.preventDefault();
		} else {
			//$('#reviewFormCont form').submit();
		}
		
	});
		
	
	$('#addComment a').click(function(e) {
		e.preventDefault();
		$('#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();
		//$("#slider").slider("value");
		
		$.post('/ajax_assorted.php', {'intent':'rate','value':$("#sliderToo").slider("value"),'map':$("#aj_mapID").html()}, function(data) {
			var str = window.location.href;
			if(data.valid) { window.location.href='details.php?file=' + $("#aj_mapID").html(); }
		}, 'json');
	});

	
	$('#embed-codes span#html').click(function(e) {
		$('span#code-label').text('HTML Code:');
		$('#switches span').removeClass('selected');
		$(this).addClass('selected');
		$('#embed-codes textarea').html($('#embed-codes #bbcode_str').html());
	});

	$('#embed-codes span#bbcode').click(function(e) {
		$('span#code-label').text('BBcode:');
		$('#switches span').removeClass('selected');
		$(this).addClass('selected');
		$('#embed-codes textarea').html($('#embed-codes #html_str').html());
	});

	$('#embed-codes textarea').click(function(e) {
		this.select();
	});



	$('.subcomment_reply a.reply').click(function(e) {
	
		e.preventDefault();
		
		$('#ratingWidget').hide();
		$('#reviewFormCont').hide();
		$('#commentFormCont').show();

		$('.commentCont').removeClass('reply-to');
		$(this).parent().parent().addClass('reply-to');

		if ($('#commentPanelThing #reply_to').length>0) {
			$('#commentPanelThing #reply_to').val($(this).attr('id').replace('rel',''));
			var comment = $(this).parents('.commentCont');
			$('#commentFormCont').addClass('in-reply').children('#reply-content').html('<div class="reply-avpanel">'+ comment.children('.avPanel').html() +'</div><div class="reply-message">'+comment.children('.commentPanel').html()+'</div>');
			$('#reply-content .reply-avpanel a:nth-child(2)').detach().prependTo('#reply-content .reply-message');
		} else {
			$('#commentPanelThing').append('<input type="hidden" name="reply_to" id="reply_to" value="'+$(this).attr('id').replace('rel','')+'">');
			var comment = $(this).parents('.commentCont');
			$('#commentFormCont').addClass('in-reply').prepend('<span id="in-reply-to">In reply to:</span><div id="reply-content"><div class="reply-avpanel">'+ comment.children('.avPanel').html() +'</div><div class="reply-message">'+comment.children('.commentPanel').html()+'</div></div>');
			$('#reply-content .reply-avpanel a:nth-child(2)').detach().prependTo('#reply-content .reply-message');
			
			$('<span/>', { id: 'cancel', text: 'Cancel'}).prependTo('#commentFormCont').click(function(e) {
				$('#commentFormCont').removeClass('in-reply').children('#reply-content').remove();
				$('#commentPanelThing #reply_to').add('#commentFormCont span#cancel').add('#in-reply-to').remove();
				$('.commentCont.reply-to').removeClass('reply-to');
			});
		
		}
		
		$('#commentPanelThing textarea').focus();
		
		$.scrollTo($('#commentFormCont'), 800);

	});	

	$('#add_screen_form form').submit(function() {
		$('#upl-throb').show();
		$('#add_screen_form input.button').attr('disabled','disabled').css({'color':'#384528'});
	});

	
});




/*
$(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;

}

}
//*/
