$(document).ready(function() {
	// Submit the search form if a tag was clicked.
	$(".search_tag").livequery("click", function() {
		$(this).parent().submit();
	});
	
	// Close facebox
	$(".close").livequery("click", function() {
		$(document).trigger("close.facebox");
		
		var url = document.location.href.split("/");
		if (url.length >= 6) {
			if (url[5] != "edit") {
				scrollWin($("#ad-shadow"));
			}
		} else {
			scrollWin($("#ad-shadow"));
		}
	});
	
	$("#search_input").focus(function() {
		if ($(this).val() == "albums or images") {
			$(this).val("");
		}
	});
	
	$("div").mouseover(function() {
		if ($(this).parent().attr("class") == "album-container") {
			if (!$(this).parent().children(".album-options-left").is(":visible")) {
				$(this).parent().children(".album-options-left").show();
			}
			
			if (!$(this).parent().children(".album-options-right").is(":visible")) {
				$(this).parent().children(".album-options-right").show();
			}
			
			if (!$(this).parent().children(".album-options-right-pop").is(":visible")) {
				$(this).parent().children(".album-options-right-pop").show();
			}
			
			if (!$(this).parent().children(".album-options-right-friend").is(":visible")) {
				$(this).parent().children(".album-options-right-friend").show();
			}
			
			if (!$(this).parent().children(".album-options-left-mvi").is(":visible")) {
				$(this).parent().children(".album-options-left-mvi").show();
			}
			
			if (!$(this).parent().children(".album-options-right-mvi").is(":visible")) {
				$(this).parent().children(".album-options-right-mvi").show();
			}
			
			if (!$(this).parent().children(".album-options-left-mpi").is(":visible")) {
				$(this).parent().children(".album-options-left-mpi").show();
			}
			
			if (!$(this).parent().children(".album-options-right-mpi").is(":visible")) {
				$(this).parent().children(".album-options-right-mpi").show();
			}
		}
	});
	
	$(".album-container").mouseout(function() {
		$(".album-options-left").hide();
		$(".album-options-right").hide();
		$(".album-options-right-pop").hide();
		$(".album-options-right-friend").hide();
		$(".album-options-left-mvi").hide();
		$(".album-options-right-mvi").hide();
		$(".album-options-left-mpi").hide();
		$(".album-options-right-mpi").hide();
		$(".exif").hide();
	});
	
	$("#all_tags_link").livequery("click", function() {
		$(".ajax-loader-photos").show();
	});
	
	$(".close_image").livequery("click", function() {
		$(".ajax-loader-photos").hide();
	});
});

function scrollWin(element){
	$('html, body').animate(
		{scrollTop: element.offset().top},
		750
	);
}

