function bindEvent(name) {
	$("#" + name).bind("mouseenter",function() {
		$("#" + name).animate({"width": "+=15px"},"normal");
 	 }).bind("mouseleave",function() { 
 		$("#" + name).animate({"width": "-=15px"},"normal");
  });
}
function zoom_image( img, width, height ) { 
	var url = (typeof(img)=='string'?img:img.src);
	var left = parseInt((screen.availWidth/2) - (width/2));
	var top = parseInt((screen.availHeight/2) - (height/2)) - 20;
	var windowFeatures = "width=" + width + ",height=" + height +
		",resizable=yes,left=" + left + ",top=" + top +
		"screenX=" + left + ",screenY=" + top + ",scrollbars=yes";
	new_window=window.open(url, "", windowFeatures);
	return false;
}

/* legioners section */
function disable_all()
{
	var $div = $('#page_overlay');
	if (!$div.length) {
		$('<div>').appendTo('body').height($(document).height()).width($(document).width()).css({
			'background-color': '#000000',
			'opacity': '0.5',
			'position': 'fixed',
			'left': 0,
			'top': 0,
			'z-index': 1
		})
		.attr('id', 'page_overlay');
	}
	$div.show();
}
function enable_all()
{
	$('#page_overlay').hide();
}
function legioner(id) {
	disable_all();
	$( '#legioner' ).html( '&nbsp;' ).load( '/life/legionaries/legioner/id' + id);
	$( '#legioner' ).stop(true, true).fadeIn("slow");
}
function legioner_close() {
	enable_all();
	$( '#legioner' ).stop(true, true).hide();
}
function addPhotoClickHandlers() {
    $(".photo").click( function() { legioner(this.id) });
    legioner_pattern = /^#id=\d+$/  
    if (legioner_pattern.test(location.hash)) {
    	legioner(location.hash.match(/(?!#id=)\d+/g));
    }
}

/* Check comment form for errors */
function validateform() {
	return $("#commentForm").validate({
		rules: {
			name: "required",
		    email: {
		    	required: true,
		    	email: true
		    },
		    url: {
		        required: false,
		        url: true
		    },
		    comment: "required",
		    captcha_1: {
		        required: true,
		        rangelength: [4, 4]
		    }
		},
		messages: {
			name: gettext("Please enter your name"),
			email: {
				required: gettext("Please enter your email"),
				email: gettext("Please enter a valid email address")
			},
			url: {
				url: gettext("Please enter a valid URL address")
			},
			comment: {
				required: gettext("Please enter your comment")
			},
			captcha_1: {
				required: gettext("Please enter what you see on the picture"),
				rangelength: gettext("Word has to consist of 4 characters")
			} 
		}
	});
}

/* Check where there are errors in the comment form */
function testform() {
	return validateform().form()
}