$(document).ready(function() {
	var errors_count = 0;
	// Click on Links
	$("#logo").click(function() {
		window.location = "index";
	});
	$("#upload_button").click(function() {
		window.location = "photographer_account.php?task=imageupload";
	});
	$(".packages_area img").click(function() {
		window.location = "prices?price_chosen=" + $(this).attr("id");
	});
	$("#signup_button").click(function() {
		window.location = "choose_role";
	});
	$("#choose_role_button").click(function() {
		switch($("div.choose_role input[type='radio']:checked").val())
		{
			case "photographer":
				window.location = "registration.php?style=photographer";
				break;
			case "customer":
				window.location = "registrationlightbox.php?style=user";
				break;
			default:
			if ($("#choose_role_warning").length === 0) {
				$("div.choose_role").append('<p id="choose_role_warning">Please Choose Your Status</p>');
			}
		}
	});
	$("#forgot_password").click(function() {
		window.location = "forgot_password.php";
	});
	// Forms submit
	$("#signup_form input[type='password']").change(function() {
		$("#login_button").focus();
	})
	$("#search_form input[type='text']").change(function() {
		$("#search_button").focus();
	})
	$('input[type="image"]').click(function() {
		return check_price_submit($(this));
	});
	// Centralize right block ot the similar photos
	var photo_thumbnails_amount = $("div.photo_details_right div.similar_pictures table.photo_thumbnail_table").size();
	if (photo_thumbnails_amount > 0 && photo_thumbnails_amount < 4) {
		$("div.photo_details_right div.similar_pictures").css('width', 131 * photo_thumbnails_amount);
	}
	photo_thumbnails_amount = $("div.old_content table.photo_thumbnail_table").size();
	if (photo_thumbnails_amount > 0 && photo_thumbnails_amount < 6) {
		$("div.old_content").css('width', 131 * photo_thumbnails_amount);
	}

	function check_price_submit(object) {
		var error_message_html = "<span style='color:red'>Check price, please</span>";
		var parent = object.parent();
		if ($('input:radio[name=price_id]:checked').val() === undefined) {
			if (errors_count === 0) {
				errors_count++;
				if (parent.is("div")) {
					object.after("<br />" + error_message_html);
				} else if (parent.is("span")) {
					object.before(error_message_html);
				}
			}
			return false;
		} else {
			$("#submitBtn").trigger('click');
			return true;
		}
	}
});
