$mytyInlineLogin = {
	settings : {
		url : null,
		data : {},
		background_opacity : 0.8,
		opacity : 1,
		animationDuration : 1000,
		automaticClose : false,
		showTime : 4000
	},

	callbacks : {
		oncomplete : function() {}
	},

	init : function(settings, callbacks) {
		this.configure(settings,callbacks);
		this.create();

		$(window).scroll(function(){ $scrollPos = _getScroll(); $mytyInlineLogin.centerLayer(); });
		$(window).resize(function(){ $mytyInlineLogin.centerLayer(); $mytyInlineLogin.resizeOverlay(); });
	},

	configure : function(settings,callbacks) {
		this.settings = jQuery.extend(this.settings,settings);
		this.callbacks = jQuery.extend(this.callbacks,callbacks);
	},

	// Code erzeugen
	create : function() {
		var injectedCode = '<div class="mytyOverlay" id="il-overlay"/><div class="il-container" style="display:none;"><a href="javascript:;" class="il-close"/><div class="il-content"/>';
		$('body').append(injectedCode);
		$il_overlay = $('#il-overlay');
		$il_overlay.css('z-index','10010').css('opacity',0).hide();
		$il_container = $('div.il-container');
		$il_container.css('z-index','10011').fadeTo(1, 0, function(){ $il_container.hide(); });
		$il_content = $('div.il-content');
		$('a.il-close').click( function() {$mytyInlineLogin.close();} );
		this.resizeOverlay();
	},

	centerLayer : function() {
		if($.browser.opera) {
			windowHeight = window.innerHeight;
			windowWidth = window.innerWidth;
		}else{
			windowHeight = $(window).height();
			windowWidth = $(window).width();
		};
		ilWidth = $il_container.width();
		ilHeight = $il_container.height();
		var projectedTop = (windowHeight/2) + $scrollPos['scrollTop'] - (ilHeight/2);
		if(projectedTop < 0) projectedTop = 0;
		$il_container.css({
			'top': projectedTop,
			'left': (windowWidth/2) + $scrollPos['scrollLeft'] - (ilWidth/2)
		});
	},

	resizeOverlay : function() {
		$('div.mytyOverlay').css({
			'height':$(document).height(),
			'width':$(window).width()
		});
	},

	show : function() {
		this.loadContents();
		$il_overlay.show().fadeTo(this.settings.animationDuration,this.settings.background_opacity);
	},

	loadContents : function() {
		$il_content.load(this.settings.url,this.settings.data,function() {
			$mytyInlineLogin.loadCallback();
			try { this.callbacks.oncomplete; } catch(e) {}
		});
	},

	loadCallback : function() {
		this.centerLayer();
		$il_container.show();
		$il_container.fadeTo(this.settings.animationDuration, this.settings.opacity);
		if (this.settings.automaticClose==true) {
			window.setTimeout( function() { $mytyInlineLogin.close(); }, this.settings.showTime);
		}
	},

	close : function(callback) {
		$il_overlay.fadeTo(this.settings.animationDuration, 0, function() { $il_overlay.hide(); });
		$il_container.fadeTo(this.settings.animationDuration, 0, function(){ if (typeof callback!='undefined') { callback(); } $il_container.hide(); });
	}
}

if (typeof _getScroll == 'undefined') {
	function _getScroll() {
		if (self.pageYOffset) {
			scrollTop = self.pageYOffset;
			scrollLeft = self.pageXOffset;
		} else if (document.documentElement && document.documentElement.scrollTop) {	 // Explorer 6 Strict
			scrollTop = document.documentElement.scrollTop;
			scrollLeft = document.documentElement.scrollLeft;
		} else if (document.body) {// all other Explorers
			scrollTop = document.body.scrollTop;
			scrollLeft = document.body.scrollLeft;
		}
		return {scrollTop:scrollTop,scrollLeft:scrollLeft};
	}
}

$(function() {
	try {
		$scrollPos = _getScroll();
		/*$mytyInlineLogin.init({ url:(("https:" == document.location.protocol) ? "https" : "http")+'://www.sansibar.de/templates/rl2009/scripts/login.ajax.php'});*/
		$mytyInlineLogin.init({ url:document.location.protocol+'//'+document.location.hostname+'/templates/rl2009/scripts/login.ajax.php'}); 
	} catch(e) {
		if (typeof console != 'undefined') {
			console.log(e);
		} else {
		}
	}
});