// Overlay Class
// author: kschewe@lynet.de
Overlay = function() {
	this.init();
}

$.extend(Overlay.prototype, {
	// object variables
	backdrop: {},
	container: {},
	content: {},
	target: {},

	init: function() {
		// do initialization here
		var obj = this;
		this.backdrop = $('<div></div>');
		this.backdrop.css({position: 'absolute', zIndex: 10000, left: '0px', top: '0px'});
		this.backdrop.addClass('backdrop');
		this.backdrop.hide();
		$(document.body).append(this.backdrop);
		this.container = $('<div></div>');
		this.container.css({position: 'absolute', zIndex: 10001, left: '0px', top: '0px'});
		this.container.addClass('overlay');
		this.container.hide();
		$(document.body).append(this.container);
		var toolbar = $('<div></div>');
		toolbar.addClass('toolbar');
		var button = $('<a href="javascript:void(0);"><img class="pngfix" src="/images/close_btn.png" width="37" height="37" style="border: 0 none;" alt="Schließen" title="Schließen"/></a>');
		button.bind('mousedown', function(){ $(this).blur();obj.hide();return false; });
		toolbar.append(button);
		this.container.append(toolbar);
		this.content = $('<div></div>');
		this.container.append(this.content);
   },

   set: function(markup) {
   	// set container content
   	this.content.html(markup);
   },
   
	show: function(target, left, top) {
		//$(document.body).css({overflow: 'hidden'});
		if(window.getSelection) {
			window.getSelection().removeAllRanges();
		}
		this.target = target;
		// show overlay
		this.backdrop.width($(document.body).width());
		this.backdrop.height($(document).height());
		this.backdrop.show();
		var x = $(window).width()/2 - this.container.width() / 2;
		if (left != null) {
			x = left;
		}
		var y = ($(window).height()/2 - this.container.height() / 2) + $(window).scrollTop();
		if (top != null) {
			y = top;
		}
		this.container.css({left: x+'px', top: y+'px'});
		this.container.show();
		//this.container.fadeIn('fast');// slow | fast
   },
   
	hide: function() {
		// hide overlay
		this.container.hide();
		//this.container.fadeOut('fast');
		this.backdrop.hide();
		var video = this.container.find('.video');
		video.html('');
		//this.backdrop.fadeOut('fast');
		if (this.target) {
			this.target.focus();
		}
		//$(document.body).css({overflow: 'auto'});
   }
});

