WindowOnline = function() {
	this.channel = "";
	this.host = document.location.host;
	this.onLoadStatus = false;
}
WindowOnline.prototype = {
	openWindow: function (options) {
		var defaults = {
			WindowTitle:        'Online Messenger',
			WindowPositionTop:  'center',
			WindowPositionLeft: 'center',
			WindowWidth:        400,
			WindowHeight:       460,
			WindowAnimation:    'easeOutBounce',
	        WindowResizable:      false,
	        //WindowDraggable:      false,
	        WindowMinimize:       false,
	        WindowMaximize:       false
	        //WindowClosable:       true,
		}
		var options = jQuery.extend(defaults, options);
		jQuery('#Firefoxapp').AeroWindow(options);
		if (this.channel != "") jQuery.cookie('c_channel', this.channel, { path: '/', expires: 5 });
	},
	createMessager: function() {
		var Firefoxapp = jQuery('#Firefoxapp');
		if (Firefoxapp.html() == "") {
			var line = '<iframe id="FirefoxIframe" onLoad="JavaScript:windowObj.setIframeUrl();" src="about:blank" width="100%" height="100%"  scrolling="no" style="border: 0px;overflow-y:hidden;overflow-x:hidden" frameborder="0"></iframe>';
			jQuery(line).appendTo(Firefoxapp);
		}
	},
	setIframeUrl: function() {
		// устанавливаем значение для Iframe
		if (this.onLoadStatus == false) {
			var FirefoxIframe = jQuery('#FirefoxIframe');
			FirefoxIframe.attr('src', 'http://zabroniryi.ru/realtime/messager.php?domain=' + this.host);
			this.onLoadStatus = true;
		}
	},
	channelTest: function() {
		this.channel = jQuery.cookie("c_channel");
		if (this.channel != "") {
			jQuery.getJSON('http://' + this.host + '/realtime/channel.php', {'channel': this.channel}, this.onChannelTestSuccess);
		}
	},
	onChannelTestSuccess: function(obj) {
		if (typeof obj == "object") {
			if (obj.success == "ok") {
				if (window_open == null) {
					windowObj.createMessager();
					windowObj.openWindow();//{WindowStatus: 'minimized'}
					window_open = 0;
				}
			} else {
				// удаляем куки
			}
		}
	},
	setChannel: function(val) {
		this.channel = val;
	}
}

// проверяем куку
var window_open = null; // статус открытия окна
var windowObj = new WindowOnline();

jQuery(document).ready(function()
{
	var channel = "";
	// создаем окно
	jQuery('#Firefoxicon').click(function() {
		if (window_open == null) {
			windowObj.createMessager();
			window_open = 0;
		}
		windowObj.openWindow();//{WindowStatus: 'minimized', WindowAnimation: 'easeInQuad'}
	});
	if (channel != "") {
		windowObj.createMessager();
		windowObj.openWindow();
		window_open = 0;
	} else {
		windowObj.channelTest();
	}
});