/* Displaying hiding comments so we don't scroll too much*/
function displayMoreComments(){
		$('#moreComments').fadeIn('slow',
				function(){
			$('#showMoreContent').html("<a href='javascript:void(0);' onclick='hideMoreComments()'>Hide Older Comments</a>");
			$("#moreComments").scrollTo(2000); //Speed
			});	
}
function hideMoreComments(){
	$('#moreComments').fadeOut('slow',
			function(){
		$('#showMoreContent').html("<a href='javascript:void(0);' onclick='displayMoreComments()'>Show Older Comments</a>");
		$("#imageCaptionText").scrollTo(2000); //Speed
		});	
}

$(function goToComment(){
	var commentDiv = jQuery.url.attr("anchor");
	if(commentDiv != undefined){
		$("#"+commentDiv).scrollTo(2000);
	}
});
/* Reporting an image*/
function reportImage(){
	$.ajax({
		beforeSend:function(){
		$('#imageContainer').prepend("<div id='loadingNotice' style='text-align:center'><h1>Reporting this image</h1> It will be unpublished until moderated<br /><img src='/assets/ajax-loader.gif' /></div>");
		},
		type:"POST",
		url:siteroot+'/bin/handlers/report.image.handler.php',
		data: "imageid="+$('#imageid').val()+"&name="+$('#name').val()+"&email="+$('#email').val()+"&reason="+$('#reason').val(),
		success: function(){
			window.location.reload(true);
		}
	});
}
function displayReportImageForm(){
	$("#reportFormDialog").show();
	$("#reportFormDialog").dialog({
		bgiframe: true,
		height: 300,
		width:350,
		modal: true,
		draggable: true
	});
}

$('#report-image').button()
.click(function() {
	reportImage();
});

$('#reportImageLink').click(function(){
	displayReportImageForm(imageId);
});
/*validate the image report data*/
$.validator.setDefaults({
	submitHandler: function() {$('#submit').disable();$("#form").submit(); }
});
 
$().ready(function() {
	// validate signup form on keyup and submit
	$("#reportImageForm").validate({
		
		rules: {
			name: {
				required: true,
				minlength: 2
			},
			email: {
				required: true,
				email: true
			},
			reason:"required"
		},
		messages: {
			name: {
				required: "Please enter a name for your image",
				minlength: "Your name must consist of at least 2 characters"
			},
			email: {
				required: "We need an email address",
				email: "Please enter a valid email address"
			},
			reason :"We need a description for your entry",
		}
	});

});


/* repositioning the image so it sits right in the middle of the div tag*/

function displayImage(){
	var containerWidth = parseFloat($('#centeredImageWrapper').width() / 2);
	var realImageWidth = parseFloat($('#imageContainer').width());
	var imageWidth = parseFloat($('#imageContainer').width() / 2);
	var imagePaddingLeft = $('#imageContainer').css('padding-left');
	var leftPadding = parseFloat(imagePaddingLeft.substr(0, imagePaddingLeft.length - 2));
	var leftMargin = (containerWidth - imageWidth);
	if($('#imageContainer').width() < 580){
		$('#imageContainer').css('margin-left',(leftMargin-leftPadding)+'px');
	}else{
		$('#imageContainer').css('width', $('#imageContainer').width()+'px');// set the width first so that auto margins work
		$('#imageContainer').css('margin-left','auto');
		$('#imageContainer').css('margin-right','auto');
	}
	$('#imageComments').width($('#imageContainer').width()+ 20);
	//$('#imageComments').css('margin-left',(leftPadding)+'px');
	$('#imageComments').css('margin-left','auto');
	$('#imageComments').css('margin-right','auto');
	$('#uploaderInfo').width($('#imageContainer').width()+ 20);
	//$('#uploaderInfo').css('margin-left',(leftPadding)+'px');
	$('#uploaderInfo').css('margin-left','auto');
	$('#uploaderInfo').css('margin-right','auto');
	
	//$('#socialBar').css('margin-left',(leftPadding)+'px');
	$('#socialBar').css('margin-left','auto');
	$('#socialBar').css('margin-right','auto');
	
	//$('#singleImageName').height($('#topSocialBar').height());
	$('#singleImageName').width($('#centeredImageWrapper').width());
	
	// caption stuff
	$('#imageCaptionText').width($('#imageContainer').width()+ 20);
	$('#imageCaptionText').css('margin-left',(leftMargin-leftPadding)+'px');
	$('#uploaderInfo').width($('#imageContainer').width()+ 20);
	$('#uploaderInfo').css('margin-left',(leftMargin-leftPadding)+'px');
	$('#imageContainer').fadeIn('slow');
}
