$(document).ready(function() {
	
	//Image previews
	$(".thumbPreview").hover(
		function(){
			var hoverElem = $(this);
			var imagePreview = parseInt($(this).find("span").html());
			var pos = hoverElem.position();
			imagePreview = $("#preview-"+imagePreview);
			imagePreview.css("top",(pos.top)+"px").css("left",((pos.left-imagePreview.width())-10)+"px").show();
		},
		function(){
			var hoverElem = $(this);
			var imagePreview = parseInt($(this).find("span").html());
			imagePreview = $("#preview-"+imagePreview);
			imagePreview.hide();
		}
	);
	
	//Character limiter on client box
	var maxCharacters = 300;
	function limitChars(textid, limit, infodiv) {
		toggleSubmitButton();
		var text = $('#'+textid).val();
		var textlength = text.length;
		if(textlength > limit) {
			$('#' + infodiv).html('You cannot write more then '+limit+' characters!');
			$('#'+textid).val(text.substr(0,limit));
			return false;
		} else {
			$('#' + infodiv).html('You have '+ (limit - textlength) +' characters left.');
			return true;
		}
	}
	if ($('#client').length > 0) {
		limitChars('client', maxCharacters, 'chCounter');
		$('#client').keyup(function(){limitChars('client', maxCharacters, 'chCounter');});
	}
	
});