$(function() {
	$('#show_login').click(function() {
		$('#loginFormContainer').toggle();
		return false;
	});

	$('#close_login').click(function() {
		$('#loginFormContainer').hide();
		return false;
	});

	$('#show_filter').click(function() {
		$('#filter').slideToggle();
		return false;
	});

	$('img[gallery=true]').click(function() {
		$('img[gallery=true]').each(function() {
			$(this).removeClass('current');
		});

		$(this).addClass('current');

		var container = $('#firstPhotoContainer').fadeTo(100, 0.2);

		var img = new Image();
		img.src = $(this).attr('medium');
		img.width = $(this).attr('mediumw');
		img.height = $(this).attr('mediumh');
		img.alt = '';

		$(img).load(function() {
			container.stop().empty().fadeTo(0, 1);
			$(this).appendTo(container);
		});

		$('#firstPhotoContainer').attr({
			href: $(this).attr('big'),
			bigw: $(this).attr('bigw'),
			bigh: $(this).attr('bigh')
		});

		return false;
	});

	$('#firstPhotoContainer').click(function() {
		viewImage(
			'/LT/viewImage.php?path='+$(this).attr('href'),
			'big',
			$(this).attr('bigw'),
			$(this).attr('bigh')
		);
		return false;
	});

	$('#photoSwitch').click(function() {
		$('#video').hide();
		$('#photo').show();
		$('#gallery').slideDown('fast');
		$('#photoSwitch').addClass('vkl');
		$('#videoSwitch').removeClass('vkl');
	});

	$('#videoSwitch').click(function() {
		$('#photo').hide();
		$('#gallery').slideUp('fast');
		$('#video').show();
		$('#videoSwitch').addClass('vkl');
		$('#photoSwitch').removeClass('vkl');
	});

	var viewImage = function(url, wnd_name, width, height) {
		var w = window.open(
			url,
			wnd_name,
			'width='+width+', height = '+height
			+', status = no, menubar = no, resizable = no, scrollbars = no, left = '
			+String((screen.width - width) / 2)+', top = '
			+String((screen.height - height) / 2)
		);
		w.focus();
		return w;
	};
});
