 /**
 * 	overlay class (uses jquery)
 * 	@author Ephigenia M. Eichner, modified by Martin Piske
 */
var overlay = {
	
	 opacity: 0.9
	,speed: 200
	
	,create: function() {
		$.showOverlay(this.speed, this.opacity).bind('click', function() {
			overlay.hide();
		});
		$('#__dimScreen').click(function() {
			overlay.hide();
		});
		$('#overlay-box .close').click(function() {
			overlay.hide();
		});
		overlay.autoCenter();
	}
	
	,autoCenter: function() {
		$('#overlay-box').css('left', ($(document.html).width() / 2) - ($('#overlay-box').width() / 2) + 'px');
	}

	/**
	 * 	Shows the overlay with the given content in it
	 *  @param string content
	 */
	,show: function(content) {
		if ($('#overlay-box').length == 0) {
			overlay.create();
			$(document.body).prepend('<div id="overlay-box">' + content + '</div>');
		} else {
			$('#overlay-box').html(content);
		}
		overlay.autoCenter();
		
		//hide the menu-selects
		$('#productSearchBar select').css('visibility','hidden');
		
	},
	
	/**
	 * 	Hides the overlay
	 */
	hide: function() {
		$.hideOverlay();
		//show the menu-selects again
		$('#productSearchBar select').css('visibility','visible');	
	}
	
	/**
	 *	Loads contents to the overlay from the passed url and params via ajax
	 * 	@param string url
	 * 	@param object params optional parameters for the axj request
	 */
	,load: function(url, params) {
		if (url.substr(0,1) != '/') {
			this.showMessage('No loading of external sources allowed.');
			return;
		}
		$.get(url, params, this.show); 
	}
	
	/**
	 *	Shows a plain message in the overlay with no overlay rendering
	 * 	@param string message
	 */
	,showMessage: function(message) {
		this.show(message);
	}
	
	/**
	 *	Shows layer for supermarket picture
	 */
	,showSupermarketPicture: function(id) {
		this.load('/supermarkt-foto/' + id);
	}
	/**
	 *	Shows layer for product picture
	 */
	,showProductPicture: function(id,source) {
		this.load('/produkt-foto/' + source + '/' + id);
	}
	
	

}