$(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;
	});

	$('a[wop=true]').click(function() {
		var id = $(this).attr('id');
		var width = $(this).attr('width');
		var height = $(this).attr('height');
		openWindow(this.href, id, width, height);
		return false;
	});

	$('#addtofav').click(function() {
		var title = $(this).attr('favtitle');
		addToFavorites(document.location.href, title);
	});

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

		return w;
	};

	var viewImage = function(path, title, width, height) {
		var id = 'view_image_'+url;
		var url = '/LT/viewImage.php?path='+path+'&title='+title;
		var w = window.open(
			url,
			id,
			'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;
	};

	var addToFavorites = function(url, title) {
		if(!url) url = location.href;

		if(!title) title = document.title;

		//Gecko
		if((typeof window.sidebar == "object") && (typeof window.sidebar.addPanel == "function")) window.sidebar.addPanel (title, url, "");

		//IE4+
		else if(typeof window.external == "object") window.external.AddFavorite(url, title);

		//Opera7+
		else if(window.opera && document.createElement) {
			var a = document.createElement('A');
			if (!a) return false; //IF Opera 6
			a.setAttribute('rel','sidebar');
			a.setAttribute('href',url);
			a.setAttribute('title',title);
			a.click();
		}

		else return false;

		return true;
	};
});
