
/**
 * NameRobot JavaScript BrowserCheck
 *
 * Copyright NameRobot
 */

if (typeof _nr == 'undefined') {
	var _nr = {};
};

_nr.browsercheck =
{
	check : function()
	{
		// Internet Explorer 8
		if (_ptools._Browser.isMSIE8) {
			return true;
		};

		if (_ptools._Browser.isMSIE9) {
			return true;
		};

		if (_ptools._Browser.isFirefox) {
			return true;
		};

		if (_ptools._Browser.isOpera) {
			return true;
		};

		if (_ptools._Browser.isSafari) {
			return true;
		};

		if (_ptools._Browser.isChrome) {
			return true;
		};

		return false;
	},

	open : function()
	{
		_nr.background.show();

		if (!$('browserCheckWindow'))
		{
			var oDiv = document.createElement('div');
			oDiv.id  = 'browserCheckWindow';

			document.body.appendChild( oDiv );
		};

		if (!$('browserCheckWindowBackground'))
		{
			var oDivbg = document.createElement('div');
			oDivbg.id  = 'browserCheckWindowBackground';

			oDivbg.style.width    = window.screen.width +'px';
			oDivbg.style.height   = window.screen.height +'px';
			oDivbg.style.position = 'fixed';
			oDivbg.style.zIndex   = 999;
			oDivbg.style.top      = 0;
			oDivbg.style.left     = 0;
			oDivbg.style.backgroundColor = '#000';

			document.body.appendChild( oDivbg );
		};

		if ($('browserCheckWindow').offsetTop < 20) {
			$('browserCheckWindow').style.top = '20px';
		};

		$('browserCheckWindow').set('opacity', 0);

		new Fx.Morph($('browserCheckWindow'), {
			duration   : 500,
			transition : Fx.Transitions.Quad.easeOut,
			onComplete : function()
			{
				_Ajax.asyncPost('ajax_get_nr_browser', function(result)
				{
					if (!$('browserCheckWindow')) {
						return;
					};

					$('browserCheckWindow').innerHTML = result;

					$('browser_btn_close').appendChild(
						new _ptools.Button({
							text    : 'schließen',
							width   : 120,
							onclick : function()
							{
								_nr.browsercheck.close();
							}
						}).create()
					);
				}, {
					project : _Project.name
				});
			}
		}).start({
			opacity : 1
		});
	},

	close : function()
	{
		if ($('browserCheckWindowBackground'))
		{
			$('browserCheckWindowBackground').parentNode.removeChild(
				$('browserCheckWindowBackground')
			);
		};

		new Fx.Morph($('browserCheckWindow'), {
			duration   : 500,
			transition : Fx.Transitions.Quad.easeOut,
			onComplete : function()
			{
				_nr.background.hide();
				//window.location = '/';
			}
		}).start({
			opacity : 0
		});
	}
};
