/* File: /includes/js/framework/msgservice.js (Modified: 3. september 2010 12:30:56) */

var MsgService = {
	HttpChannel: Class.create({
		initialize: function (host, userid, auth, options) {
			this.options = Object.extend({
				timeout: 5000,
				onReady: Prototype.emptyFunction,
				onResponse: Prototype.emptyFunction,
				onError: Prototype.emptyFunction,
				frameSrc: 'http://{?Host?}/ajax/httpchannel.sys'
			}, options);
			this.host = host;
			this.frameSrc = this.options.frameSrc.replace('{?Host?}', this.host);
			this.userid = userid;
			this.auth = auth;
			this.retryCount = 0;
		},

		connect: function () {
			this.frame = new Element('iframe', { src: this.frameSrc }).setStyle({ display: 'none'	});
		this.frame.observe('load', this.initFrame.bind(this));
		document.body.appendChild(this.frame);
	},

	disConnect: function () {
		this.frame.location.contentWindow.replace('about:blank');
	},

	initFrame: function () {
		if (this.frame.contentWindow) {
			try {
				this.send = this.frame.contentWindow.send;
				this.frame.contentWindow.onresponse = this.handleResponse.bind(this);
				this.frame.contentWindow.onhttperror = this.handleError.bind(this);
				this.frame.contentWindow.setIOTimeout(this.options.timeout);
				this.frame.contentWindow.setCredentials(this.userid, this.auth);
				this.options.onReady();
			}
			catch (e) { }
		}
		else if (this.retryCount < 5) {
			this.retryCount++;
			setTimeout(this.initFrame.bind(this), 1000);
		}
	},

	handleResponse: function (response) {
		//			try{
		this.options.onResponse(response);
		//			}catch(e){alert(e + '\r\n' + response);}
	},

	handleError: function (status) {
		this.options.onError(status);
	}
}),


init: function (pollHost, cmdHost, userid, auth, initMsg, onReady) {
	this.onReady = onReady || Prototype.emptyFunction;
	this.initLog();
	this.initMsg = initMsg || [];
	this.sendlist = [];
	pollHost = [this.getUniqueID(), pollHost].join('a.');
	cmdHost = [this.getUniqueID(), cmdHost].join('b.');
	this.channel = {
		poll: new MsgService.HttpChannel(pollHost, userid, auth, {
			timeout: 55000,
			onReady: this.pollReady.bind(this),
			onResponse: this.pollResponse.bind(this),
			onError: this.pollError.bind(this)
		}),
		cmd: new MsgService.HttpChannel(cmdHost, userid, auth, { timeout: 5000, onReady: this.cmdReady.bind(this) })
	};
	this.connectionID = -1;
	this.initial = true;
	this.listeners = new Hash();
	this.loaded = true;
},

cmdReady: function () {
	while(this.sendlist.length > 0){
		this.send(this.sendlist.shift());
	}
	this.onReady();
},

initLog: function () {
	window.notifierLog = new MaxedArray(100);
	document.observe('keyup', function (e) {
		e = e || event;
		if (e.ctrlKey && e.shiftKey && e.keyCode == 76) {
			Arto.OpenPopup('/section/debug/NotifierLog.aspx', 'NotifierLog' + new Date().getTime(), { width: 750, height: 400 }, { scrollbars: 'no' });
		}
	});
},

getUniqueID: function () {
  var now = new Date();
  return now.getMinutes() + '' + now.getSeconds();
//	if (!this.uidkey) {
//		this.uidkey = new Date().getTime();
//	}
//	return this.uidkey++;
},

start: function () {
	this.channel.poll.connect();
	this.channel.cmd.connect();
},

stop: function () {
	this.channel.poll.disConnect();
	this.channel.cmd.disConnect();
},

send: function (obj) {
	if(this.channel.cmd && this.channel.cmd.send){
		this.channel.cmd.send(Object.toJSON(obj));
		this.log('Send', obj);
	}
	else{
		sendlist.push(obj);
	}
},

sendRaw: function (jsonStr) {
	this.channel.cmd.send(jsonStr);
},

poll: function () {
	var msgObj = {
		type: 'Init',
		initial: this.initial,
		connectionID: this.connectionID
	};
	if (this.initial && this.initMsg.length > 0) {
		msgObj.initMsgs = this.initMsg;
	}
	this.channel.poll.send(Object.toJSON(msgObj));
	this.log('Poll', msgObj);
	this.initial = false;
},

pollReady: function () {
	this.poll();
},

pollResponse: function (response) {
	var res = response.evalJSON(false);
	for (var i = 0; i < res.length; i++) {
		var obj = res[i];
		if (obj.type != 'Noop') {
			//				try{
			this.fire(obj.type, obj);
			//				}catch(e){alert(e + '\r\n' + Object.toJSON(obj));}
		}
		this.connectionID = obj.connectionID;
	}
	this.log('PollResponse', res);
	setTimeout(this.poll.bind(this), 1);
},

log: function (type, msg) {
	window.notifierLog.add({
		timestamp: new Date(),
		type: type,
		msg: msg
	});
},

observe: function (type, listener) {
	var typeListeners = this.listeners.get(type);
	if (!typeListeners) {
		typeListeners = new Array();
	}
	typeListeners[typeListeners.length] = listener;
	this.listeners.set(type, typeListeners);
},

fire: function (type, obj) {
	var typeListeners = this.listeners.get(type);
	if (typeListeners) {
		for (var i = 0; i < typeListeners.length; i++) {
			typeListeners[i](obj);
		}
	}
},

pollError: function (status) {
	setTimeout(this.poll.bind(this), 5000);
}

};

/* File: /includes/js/framework/Notifier/notifier.js (Modified: 3. september 2010 12:30:56) */

var Notifier = {};

/* File: /includes/js/framework/Notifier/Handler/notifier.basehandler.js (Modified: 3. september 2010 12:30:56) */

Notifier.BaseHandler = Class.create({
	initialize: function(obj, options) {
		this.options = Object.extend({
			width: '190px',
			height: '110px',
			timeout: 10000
		}, options);
		this.obj = obj;
		this.content = this.createContent();
	},

	createContent: function() {
		var content = new Element('div').setStyle({
			position: 'relative',
			width: this.options.width,
			height: this.options.height
		});

		content.appendChild(this.getContent());

		var href = this.getLinkHRef();
		if (href && !href.empty()) {
			var link = new Element('a', { href: href }).setStyle({
				position: 'absolute',
				top: '0px',
				left: '0px',
				width: this.options.width,
				height: this.options.height,
				zIndex: '10000'
			});
			var linkImg = new Element('img', { src: 'http://artogfx.cloud2.artodata.com/sitegfx/grafik/spacer.gif' }).setStyle({
				width: this.options.width,
				height: this.options.height,
				borderWidth: '0px'
			});
			link.appendChild(linkImg);
			content.appendChild(link);
		}

		return content;
	},

	show: function() {
		this.window = Notifier.WindowManager.createWindow(this.content, { timeout: this.options.timeout });
	},

	fade: function() {
		this.window.fade();
	},

	getProfileImage: function() {
		var userid = this.obj.userID || this.obj.friendID;
		return new Element('img', {
			src: Arto.GetProfileImagePath(userid, this.obj.userHasImage || this.obj.friendHasImage, new Date(), ProfileImageSize.Small)
		}).setStyle({
			width: '75px',
			height: '100px'
		});
	},

	getFormatedMessage: function(htmlEncode, length) {
		var msg = this.obj.message || this.obj.threadTitle;
		if (length > 0 && msg.length > length) {
			msg = msg.substr(0, length);
		}
		if (htmlEncode) {
			msg = msg.escapeHTML();
		}
		return msg;
	}
});

/* File: /includes/js/framework/Notifier/Handler/notifier.guestbookhandler.js (Modified: 3. september 2010 12:30:56) */

Notifier.GuestbookHandler = Class.create(Notifier.BaseHandler, {
	initialize: function($super, obj){
		$super(obj);
	},
	
	getContent: function(){
		var table = new Element('table');
    var tbody = new Element('tbody');
    var tr = new Element('tr');
    
    var imgCell = new Element('td').setStyle({
			verticalAlign: 'top',
			width: '75px',
			height: '100px'
    });
    imgCell.appendChild(this.getProfileImage());
    tr.appendChild(imgCell);
    
    var contentCell = new Element('td').setStyle({verticalAlign: 'top'});
    var msg = 'New message in your guestbook from' +  ' <b>' + this.obj.username + '</b>: ' + this.getFormatedMessage(true, 70);
    contentCell.update(msg);
    tr.appendChild(contentCell);
    
    tbody.appendChild(tr);
    table.appendChild(tbody);
    return table;
	},
	
	getLinkHRef: function(){
		return '/section/user/profile/guestbook/';
	},
	
	getHistoryLinkLabel: function(){
		return 'Gæstebogsbesked';
	},
	
	getHistoryInfo: function(){
		return 'besked fra ' + this.obj.username;
	}
});

/* File: /includes/js/framework/Notifier/Handler/notifier.battlecommenthandler.js (Modified: 3. september 2010 12:30:56) */

Notifier.BattleCommentHandler = Class.create(Notifier.BaseHandler, {
	initialize: function($super, obj) {
		$super(obj);
	},

	getContent: function() {
		var table = new Element('table');
		var tbody = new Element('tbody');
		var tr = new Element('tr');

		var contentCell = new Element('td').setStyle({ verticalAlign: 'top' });
		var msg = this.obj.username + ' has commented on a battle in which you participate: ' + this.getFormatedMessage(true, 50);
		contentCell.update(msg);
		tr.appendChild(contentCell);

		tbody.appendChild(tr);
		table.appendChild(tbody);
		return table;
	},

	getLinkHRef: function() {
		return '/section/battle/view.aspx?id=' + this.obj.battleID;
	},

	getHistoryLinkLabel: function() {
		return 'Comment to battle';
	},

	getHistoryInfo: function() {
		return 'comments from ' + this.obj.username;
	}
});

/* File: /includes/js/framework/Notifier/Handler/notifier.battleacceptedhandler.js (Modified: 3. september 2010 12:30:56) */

Notifier.BattleAcceptedHandler = Class.create(Notifier.BaseHandler, {
	initialize: function($super, obj) {
		$super(obj);
	},

	getContent: function() {
		var table = new Element('table');
		var tbody = new Element('tbody');
		var tr = new Element('tr');

		var contentCell = new Element('td').setStyle({ verticalAlign: 'top' });
		var msg = this.obj.username + ' has accepted your battle challenge, click here to go to your administration and start the battle.';
		contentCell.update(msg);
		tr.appendChild(contentCell);

		tbody.appendChild(tr);
		table.appendChild(tbody);
		return table;
	},

	getLinkHRef: function() {
		return '/section/battle/admin/';
	},

	getHistoryLinkLabel: function() {
		return 'Battle accepted';
	},

	getHistoryInfo: function() {
		return 'accepted battle from ' + this.obj.username;
	}
});

/* File: /includes/js/framework/Notifier/Handler/notifier.battlestartedhandler.js (Modified: 3. september 2010 12:30:56) */

Notifier.BattleStartedHandler = Class.create(Notifier.BaseHandler, {
	initialize: function($super, obj) {
		$super(obj);
	},

	getContent: function() {
		var table = new Element('table');
		var tbody = new Element('tbody');
		var tr = new Element('tr');

		var contentCell = new Element('td').setStyle({ verticalAlign: 'top' });
		var msg = 'The battle between ' + this.obj.compeditors + ' has started, click here to vote';
		contentCell.update(msg);
		tr.appendChild(contentCell);

		tbody.appendChild(tr);
		table.appendChild(tbody);
		return table;
	},

	getLinkHRef: function() {
		return '/section/battle/view.aspx?id=' + this.obj.battleID;
	},

	getHistoryLinkLabel: function() {
		return 'Battle started';
	},

	getHistoryInfo: function() {
		return 'started by ' + this.obj.username;
	}
});

/* File: /includes/js/framework/Notifier/Handler/notifier.battlestartedownhandler.js (Modified: 3. september 2010 12:30:56) */

Notifier.BattleStartedOwnHandler = Class.create(Notifier.BaseHandler, {
	initialize: function($super, obj) {
		$super(obj);
	},

	getContent: function() {
		var table = new Element('table');
		var tbody = new Element('tbody');
		var tr = new Element('tr');

		var contentCell = new Element('td').setStyle({ verticalAlign: 'top' });
		var msg = 'The battle against ' + this.obj.compeditors + ' has begun, click here to see status';
		contentCell.update(msg);
		tr.appendChild(contentCell);

		tbody.appendChild(tr);
		table.appendChild(tbody);
		return table;
	},

	getLinkHRef: function() {
		return '/section/battle/view.aspx?id=' + this.obj.battleID;
	},

	getHistoryLinkLabel: function() {
		return 'Battle started';
	},

	getHistoryInfo: function() {
		return 'started by ' + this.obj.username;
	}
});

/* File: /includes/js/framework/Notifier/Handler/notifier.battlechallangehandler.js (Modified: 3. september 2010 12:30:56) */

Notifier.BattleChallangeHandler = Class.create(Notifier.BaseHandler, {
	initialize: function($super, obj) {
		$super(obj);
	},

	getContent: function() {
		var table = new Element('table');
		var tbody = new Element('tbody');
		var tr = new Element('tr');

		var contentCell = new Element('td').setStyle({ verticalAlign: 'top' });
		var msg = this.obj.username + ' has challenged you to a battle, click here to participate!';
		contentCell.update(msg);
		tr.appendChild(contentCell);

		tbody.appendChild(tr);
		table.appendChild(tbody);
		return table;
	},

	getLinkHRef: function() {
		return '/section/battle/admin/';
	},

	getHistoryLinkLabel: function() {
		return 'Battle challenge';
	},

	getHistoryInfo: function() {
		return 'challenge from ' + this.obj.username;
	}
});

/* File: /includes/js/framework/Notifier/Handler/notifier.quickmessagehandler.js (Modified: 3. september 2010 12:30:56) */

Notifier.QuickMessageHandler = Class.create(Notifier.BaseHandler, {
	initialize: function($super, obj){
		$super(obj);
	},
	
	getContent: function(){
		var table = new Element('table');
    var tbody = new Element('tbody');
    var tr = new Element('tr');
    
    var imgCell = new Element('td').setStyle({
			verticalAlign: 'top',
			width: '75px',
			height: '100px'
    });
    imgCell.appendChild(this.getProfileImage());
    tr.appendChild(imgCell);
    
    var contentCell = new Element('td').setStyle({verticalAlign: 'top'});
    var msg = 'Ny besked i din postkasse fra <b>' + this.obj.username + '</b>: ' + this.getFormatedMessage(true, 70);
    contentCell.update(msg);
    tr.appendChild(contentCell);
    
    tbody.appendChild(tr);
    table.appendChild(tbody);
    return table;
	},
	
	getLinkHRef: function(){
		return '/section/user/profile/mail/';
	},
	
	getHistoryLinkLabel: function(){
		return 'Kvikbesked';
	},
	
	getHistoryInfo: function(){
		return 'besked fra ' + this.obj.username;
	}
});

/* File: /includes/js/framework/Notifier/Handler/notifier.forumhandler.js (Modified: 3. september 2010 12:30:56) */

Notifier.ForumHandler = Class.create(Notifier.BaseHandler, {
	initialize: function($super, obj){
		$super(obj);
	},
	
	getContent: function(){
		var table = new Element('table');
    var tbody = new Element('tbody');
    var tr = new Element('tr');
    
    var imgCell = new Element('td').setStyle({
			verticalAlign: 'top',
			width: '75px',
			height: '100px'
    });
    imgCell.appendChild(this.getProfileImage());
    tr.appendChild(imgCell);
    
    var contentCell = new Element('td').setStyle({verticalAlign: 'top'});
    var msg =  'Ny besked i forum tråden <b>' + this.getFormatedMessage(true, 100) + '</b>';
    contentCell.update(msg);
    tr.appendChild(contentCell);
    
    tbody.appendChild(tr);
    table.appendChild(tbody);
    return table;
	},
	
	getLinkHRef: function(){
		return '/section/forum/viewthread.aspx?last=true&id=' + this.obj.threadID;
	},
	
	getHistoryLinkLabel: function(){
		return 'Ny forum besked';
	},
	
	getHistoryInfo: function(){
		return 'forum besked fra ' + this.obj.username;
	}
});

/* File: /includes/js/framework/Notifier/Handler/notifier.friendapplicationhandler.js (Modified: 3. september 2010 12:30:56) */

Notifier.FriendApplicationHandler = Class.create(Notifier.BaseHandler, {
	initialize: function ($super, obj) {
		$super(obj);
	},

	getContent: function () {
		var table = new Element('table');
		var tbody = new Element('tbody');
		var tr = new Element('tr');

		var imgCell = new Element('td').setStyle({
			verticalAlign: 'top',
			width: '75px',
			height: '100px'
		});
		imgCell.appendChild(this.getProfileImage());
		tr.appendChild(imgCell);

		var contentCell = new Element('td').setStyle({ verticalAlign: 'top' });
		if (this.obj.message != "") {
			var msg = '' + this.obj.username + ' wants to be your friend: <br /> ' + this.getFormatedMessage(true, 100) + '';
		} else {
			var msg = '' + this.obj.username + ' wants to be your friend';
		}
		contentCell.update(msg);
		tr.appendChild(contentCell);

		tbody.appendChild(tr);
		table.appendChild(tbody);
		return table;
	},

	getLinkHRef: function () {
		return '/section/user/profile/friends/applications.aspx';
	},

	getHistoryLinkLabel: function () {
		return 'Venneansøgning';
	},

	getHistoryInfo: function () {
		return 'ansøgning fra ' + this.obj.username;
	}
});

/* File: /includes/js/framework/Notifier/Handler/notifier.friendlogonhandler.js (Modified: 3. september 2010 12:30:56) */

Notifier.FriendLogonHandler = Class.create(Notifier.BaseHandler, {
	initialize: function($super, obj){
		$super(obj);
	},
	
	getContent: function(){
		var table = new Element('table');
    var tbody = new Element('tbody');
    var tr = new Element('tr');
    
    var imgCell = new Element('td').setStyle({
			verticalAlign: 'top',
			width: '75px',
			height: '100px'
    });
    imgCell.appendChild(this.getProfileImage());
    tr.appendChild(imgCell);
    
    var contentCell = new Element('td').setStyle({verticalAlign: 'top'});
    var msg =  this.obj.friendName + ' er lige logget ind';
    contentCell.update(msg);
    tr.appendChild(contentCell);
    
    tbody.appendChild(tr);
    table.appendChild(tbody);
    return table;
	},
	
	getLinkHRef: function(){
		return '/section/user/profile/?id=' + this.obj.friendID;
	},
	
	getHistoryLinkLabel: function(){
		return 'Ven logget ind';
	},
	
	getHistoryInfo: function(){
		return this.obj.friendName + ' logget ind';
	}
});

/* File: /includes/js/framework/Notifier/Handler/notifier.spamhandler.js (Modified: 3. september 2010 12:30:56) */

Notifier.SpamHandler = Class.create(Notifier.BaseHandler, {
	initialize: function($super, obj){
		$super(obj);
	},
	
	getContent: function(){
		var table = new Element('table');
    var tbody = new Element('tbody');
    var tr = new Element('tr');
    
    var contentCell = new Element('td').setStyle({verticalAlign: 'top'});
    contentCell.update(this.obj.message);
    tr.appendChild(contentCell);
    
    tbody.appendChild(tr);
    table.appendChild(tbody);
    return table;
	},
	
	getLinkHRef: function(){
		return this.obj.link;
	},
	
	getHistoryLinkLabel: function(){
		return 'Arto informerer';
	},
	
	getHistoryInfo: function(){
		return 'besked fra Arto';
	}
});

/* File: /includes/js/framework/Notifier/Handler/notifier.gallerycommenthandler.js (Modified: 3. september 2010 12:30:56) */

Notifier.GalleryCommentHandler = Class.create(Notifier.BaseHandler, {
	initialize: function($super, obj){
		$super(obj);
	},
	
	getContent: function(){
		var table = new Element('table');
    var tbody = new Element('tbody');
    var tr = new Element('tr');
    
    var imgCell = new Element('td').setStyle({
			verticalAlign: 'top',
			width: '75px',
			height: '100px'
    });
    imgCell.appendChild(this.getProfileImage());
    tr.appendChild(imgCell);
    
    var contentCell = new Element('td').setStyle({verticalAlign: 'top'});
		var msg = '';
    switch(this.obj.type){
			case 'GalleryCommentOwner':
				msg = this.obj.username + ' har tilføjet en ny kommentar til dit billede <b>"' + this.obj.title + '"</b>: ' + this.getFormatedMessage(true, 50);
				break;
			case 'GalleryCommentFriend':
				msg = this.obj.username + ' har tilføjet en ny kommentar til billedet <b>"' + this.obj.title + '"</b>: ' + this.getFormatedMessage(true, 50);
				break;
    }
    contentCell.update(msg);
    tr.appendChild(contentCell);
    
    tbody.appendChild(tr);
    table.appendChild(tbody);
    return table;
	},
	
	getLinkHRef: function(){
		return 'javascript:Arto.ShowGalleryImage(' + this.obj.entryID + ');';
	},
	
	getHistoryLinkLabel: function(){
		return 'Galleri kommentar';
	},
	
	getHistoryInfo: function(){
		return 'kommentar fra ' + this.obj.username;
	}
});

/* File: /includes/js/framework/Notifier/Handler/notifier.chathandler.js (Modified: 3. september 2010 12:30:56) */

Notifier.ChatHandler = Class.create(Notifier.BaseHandler, {
	initialize: function($super, obj){
		$super(obj, {timeout:45000});
	},
	
	getContent: function(){
		var table = new Element('table');
    var tbody = new Element('tbody');
    var tr = new Element('tr');
    
    var contentCell = new Element('td').setStyle({verticalAlign: 'top'});
    contentCell.appendChild(document.createTextNode(this.obj.invitorName + ' vil gerne chatte med dig! - '));
    
    var acceptButton = new Element('input', {type:'button', 'class':'inputKnap','value':'Acceptér'});
    acceptButton.observe('click', this.chatAcceptClicked.bind(this));
    contentCell.appendChild(acceptButton);
    var declineButton = new Element('input', {type:'button', 'class':'inputKnap', 'value':'Afslå'});
    declineButton.observe('click', this.chatDeclineClicked.bind(this));
    contentCell.appendChild(declineButton);
    
    tr.appendChild(contentCell);
    
    tbody.appendChild(tr);
    table.appendChild(tbody);
    return table;
	},
	
	chatAcceptClicked: function(){
		Arto.OpenPopup('http://webnotifier.' + Arto.GetTopDomain() + '/section/notifier/messenger.aspx?response=' + this.obj.invitorID + '&remoteID=' + this.obj.chatID, 'quickChatWindow_' + this.obj.chatID.replace(/-/g, '_'), {width:600,height:400});
		//Arto.OpenPopup('/section/notifier/messenger.aspx?response=' + this.obj.invitorID + '&remoteID=' + this.obj.chatID, 'quickChatWindow_' + this.obj.chatID.replace(/-/g, '_'), {width:600,height:400});
		this.fade();
	},
	
	chatDeclineClicked: function(){
		this.fade();
	},
	
	getLinkHRef: function(){
		return null;
	}
	
});

/* File: /includes/js/framework/Notifier/Handler/notifier.quickstatuschangedhandler.js (Modified: 1. april 2009 09:14:07) */

Notifier.QuickStatusChangedHandler = Class.create(Notifier.BaseHandler, {
	initialize: function($super, obj) {
		$super(obj);
	},

	getContent: function() {
		var table = new Element('table');
		var tbody = new Element('tbody');
		var tr = new Element('tr');
		
		/*var imgCell = new Element('td').setStyle({
			verticalAlign: 'top',
			width: '75px',
			height: '100px'
		});
		imgCell.appendChild(this.getProfileImage());
		tr.appendChild(imgCell);*/

		var contentCell = new Element('td').setStyle({ verticalAlign: 'top' });
		var msg = this.obj.username + ' har ændret sin status til: "' + this.getFormatedMessage(true, 50) + '"';
		contentCell.update(msg);
		tr.appendChild(contentCell);

		tbody.appendChild(tr);
		table.appendChild(tbody);
		return table;
	},

	getLinkHRef: function() {
		return '/section/user/profile/mood/?tab=2&id=' + this.obj.userID;
	},

	getHistoryLinkLabel: function() {
		return 'Hurtig status';
	},

	getHistoryInfo: function() {
		return 'status fra ' + this.obj.username;
	}
});

/* File: /includes/js/framework/Notifier/Handler/notifier.quickstatuscommenthandler.js (Modified: 1. april 2009 09:14:07) */

Notifier.QuickStatusCommentHandler = Class.create(Notifier.BaseHandler, {
	initialize: function($super, obj) {
		$super(obj);
	},

	getContent: function() {
		var table = new Element('table');
		var tbody = new Element('tbody');
		var tr = new Element('tr');

		/*var imgCell = new Element('td').setStyle({
		verticalAlign: 'top',
		width: '75px',
		height: '100px'
		});
		imgCell.appendChild(this.getProfileImage());
		tr.appendChild(imgCell);*/

		var contentCell = new Element('td').setStyle({ verticalAlign: 'top' });
		var msg = this.obj.username + ' har kommenteret din status: "' + this.getFormatedMessage(true, 50) + '"';
		contentCell.update(msg);
		tr.appendChild(contentCell);

		tbody.appendChild(tr);
		table.appendChild(tbody);
		return table;
	},

	getLinkHRef: function() {
		return '/section/user/profile/mood/?tab=2&id=' + this.obj.sendTo + '&sid=' + this.obj.statusID;
	},

	getHistoryLinkLabel: function() {
		return 'Status kommentar';
	},

	getHistoryInfo: function() {
		return 'kommentar fra ' + this.obj.username;
	}
});

/* File: /includes/js/framework/Notifier/Handler/notifier.moodchangedhandler.js (Modified: 3. september 2010 12:30:56) */

Notifier.MoodChangedHandler = Class.create(Notifier.BaseHandler, {
	initialize: function($super, obj){
		$super(obj);
	},
	
	getContent: function(){
		var table = new Element('table');
    var tbody = new Element('tbody');
    var tr = new Element('tr');
    
   /* var imgCell = new Element('td').setStyle({
			verticalAlign: 'top',
			width: '75px',
			height: '100px'
    });
    imgCell.appendChild(this.getProfileImage());
    tr.appendChild(imgCell);*/
    
    var contentCell = new Element('td').setStyle({verticalAlign: 'top'});
    var msg = this.obj.username + ' has changed status to: "' + this.getFormatedMessage(true, 50) + '"';
    contentCell.update(msg);
    tr.appendChild(contentCell);
    
    tbody.appendChild(tr);
    table.appendChild(tbody);
    return table;
	},
	
	getLinkHRef: function(){
		return '/section/user/profile/mood/?tab=1&id=' + this.obj.userID;
	},
	
	getHistoryLinkLabel: function(){
		return 'Change of status';
	},
	
	getHistoryInfo: function(){
		return 'status from ' + this.obj.username;
	}
});

/* File: /includes/js/framework/Notifier/Handler/notifier.moodcommenthandler.js (Modified: 3. september 2010 12:30:56) */

Notifier.MoodCommentHandler = Class.create(Notifier.BaseHandler, {
	initialize: function($super, obj) {
		$super(obj);
	},

	getContent: function() {
		var table = new Element('table');
		var tbody = new Element('tbody');
		var tr = new Element('tr');

		/*var imgCell = new Element('td').setStyle({
			verticalAlign: 'top',
			width: '75px',
			height: '100px'
		});
		imgCell.appendChild(this.getProfileImage());
		tr.appendChild(imgCell);*/

		var contentCell = new Element('td').setStyle({ verticalAlign: 'top' });
		var msg = this.obj.username + ' has commented on the status: "' + this.getFormatedMessage(true, 50) + '"';
		contentCell.update(msg);
		tr.appendChild(contentCell);

		tbody.appendChild(tr);
		table.appendChild(tbody);
		return table;
	},

	getLinkHRef: function() {
		return '/section/user/profile/mood/?tab=1&id=' + this.obj.sendTo + '&day=' + this.obj.moodID;
	},

	getHistoryLinkLabel: function() {
		return 'Status comments';
	},

	getHistoryInfo: function() {
		return 'comments from ' + this.obj.username;
	}
});

/* File: /includes/js/framework/Notifier/Handler/notifier.matchinteresthandler.js (Modified: 3. september 2010 12:30:56) */

Notifier.MatchInterestHandler = Class.create(Notifier.BaseHandler, {
	initialize: function($super, obj) {
		$super(obj);
	},

	getContent: function() {
		var table = new Element('table');
		var tbody = new Element('tbody');
		var tr = new Element('tr');

		var contentCell = new Element('td').setStyle({ verticalAlign: 'top' });
		var msg = 'Somebody has shown interest in you, click here to see who it is!';
		contentCell.update(msg);
		tr.appendChild(contentCell);

		tbody.appendChild(tr);
		table.appendChild(tbody);
		return table;
	},

	getLinkHRef: function() {
		return '/section/love/?tabpage=1';
	},

	getHistoryLinkLabel: function() {
		return 'Another user is interested in you';
	},

	getHistoryInfo: function() {
		return 'Someone has shown interest in you';
	}
});

/* File: /includes/js/framework/Notifier/Handler/notifier.HistoryHandler.js (Modified: 3. september 2010 12:30:56) */

Notifier.HistoryHandler = Class.create(Notifier.BaseHandler, {
	initialize: function($super, messages){
		this.messages = messages;
		var height = this.messages.length > 3 ? this.messages.length * 30 + 30 : 110;
		$super({}, {height: height + 'px', timeout: 90000});
	},
	
	getContent: function(){
		var table = new Element('table');
    var tbody = new Element('tbody');
    var tr = new Element('tr');
    
    var contentCell = new Element('td').setStyle({verticalAlign: 'top'});
    contentCell.appendChild(new Element('div', {align:'center'}).setStyle({fontWeight:'bold',marginBottom:'5px'}).update('Notifier Historik'));
    for(var i = 0; i < this.messages.length; i++){
			var obj = this.messages.get(i);
			var handler = this.getHandler(obj);
			var elm = new Element('div').setStyle({marginBottom:'5px'});
			
			var link = new Element('a', {href: handler.getLinkHRef(obj)});
			link.appendChild(document.createTextNode(handler.getHistoryLinkLabel(obj)));
			elm.appendChild(link);
			
			var msg = new Element('div', {'class':'fontNote'}).update('- ' + handler.getHistoryInfo());
			elm.appendChild(msg);
			
			contentCell.appendChild(elm);
    }
    
    contentCell.appendChild(new Element('div', {
			'class': 'closeIcon cursorHand'
		}).setStyle({
			position: 'absolute',
			top: '5px',
			right: '5px'
    }).observe('click', this.closeClicked.bind(this)));
    
    tr.appendChild(contentCell);
    
    tbody.appendChild(tr);
    table.appendChild(tbody);
    return table;
	},
	
	closeClicked: function(){
		this.window.fade();
	},
	
	getHandler: function(obj){
		var handler = {};
		switch(obj.type){
			case 'ForumMessage':
				handler = new Notifier.ForumHandler(obj);
				break;
			case 'FriendApplication':
				handler = new Notifier.FriendApplicationHandler(obj);
				break;
			case 'FriendLogon':
				handler = new Notifier.FriendLogonHandler(obj);
				break;
			case 'GuestbookMessage':
				handler = new Notifier.GuestbookHandler(obj);
				break;
			case 'QuickMessage':
				handler = new Notifier.QuickMessageHandler(obj);
				break;
			case 'SpamMessage':
				handler = new Notifier.SpamHandler(obj);
				break;
			case 'GalleryCommentOwner':
				handler = new Notifier.GalleryCommentHandler(obj);
				break;
			case 'GalleryCommentFriend':
				handler = new Notifier.GalleryCommentHandler(obj);
				break;	
		}
		return handler;
	},
	
	getLinkHRef: function(){
		return null;
	}
});

/* File: /includes/js/framework/Notifier/Handler/notifier.achievementearnedhandler.js (Modified: 3. september 2010 12:30:56) */

Notifier.AchievementEarnedHandler = Class.create(Notifier.BaseHandler, {
	initialize: function ($super, obj) {
		$super(obj, { width: '300px' });
	},

	getContent: function () {
		var table = new Element('table');
		var tbody = new Element('tbody');
		var tr = new Element('tr');

		var imgCell = new Element('td', { align: 'center' }).setStyle({
			verticalAlign: 'top',
			position: 'relative',
			width: '98px',
			height: '84px'
		});
		var outerDiv = new Element('div').setStyle({
			position: 'relative',
			width: '98px',
			height: '84px'
		});
		var backgroundDiv = new Element('div').setStyle({
			position: 'absolute',
			zIndex: '50',
			width: '100%',
			height: '84px',
			background: 'transparent url(' + this.obj.trophyBackground + ') center center no-repeat'
		});
		var imageDiv = new Element('div').setStyle({
			position: 'absolute',
			zIndex: '100',
			width: '100%',
			height: '84px',
			background: 'transparent url(' + this.obj.achievementImage + ') center center no-repeat'
		});
		outerDiv.appendChild(backgroundDiv);
		outerDiv.appendChild(imageDiv);
		imgCell.appendChild(outerDiv);
		tr.appendChild(imgCell);

		var contentCell = new Element('td').setStyle({ verticalAlign: 'top' });
		var msg = 'You have gotten ' + this.obj.trophyName + ' in ' + this.obj.achievementName + '';
		contentCell.update(msg);
		tr.appendChild(contentCell);

		tbody.appendChild(tr);
		table.appendChild(tbody);
		return table;
	},

	getLinkHRef: function () {
		return '/section/user/profile/achievements/';
	},

	getHistoryLinkLabel: function () {
		return 'Achievements accepted';
	},

	getHistoryInfo: function () {
		return 'Accepted achievements from ' + this.obj.username;
	}
});

/* File: /includes/js/framework/Notifier/notifier.client.js (Modified: 3. september 2010 12:30:56) */

Notifier.Client = Class.create({
	initialize: function (service, options) {
		this.options = Object.extend({
			forum: { enabled: true, sound: 0 },
			friendApplication: { enabled: true, sound: 0 },
			friendLogon: { enabled: true, sound: 0 },
			guestbook: { enabled: true, sound: 0 },
			quickMessage: { enabled: true, sound: 0 },
			spam: { enabled: true, sound: 0 },
			galleryComment: { enabled: true, sound: 0 },
			chatInvite: { enabled: true, sound: 0 },
			moodComment: { enabled: true, sound: 0 },
			moodChanged: { enabled: true, sound: 0 },
			battleComment: { enabled: true, sound: 0 },
			battleAccepted: { enabled: true, sound: 0 },
			battleStarted: { enabled: true, sound: 0 },
			battleStartedOwn: { enabled: true, sound: 0 },
			battleChallange: { enabled: true, sound: 0 },
			matchInterest: { enabled: true, sound: 0 },
			achievementEarned: { enabled: true, sound: 0 },
			enabled: true
		}, options);
		this.service = service;
		this.listeners = new Hash();
		this.observers = new Hash();
		this.service.observe('Notification', this.handleNotification.bind(this));
		if (this.options.enabled) {
			this.setObservers();
		}
		this.messages = new MaxedArray(10);
	},

	handleNotification: function (obj) {
		var list = this.observers.get(obj.subType);
		if (list) {
			obj.basetype = obj.type;
			obj.type = obj.subType;
			for (var i = 0; i < list.length; i++) {
				list[i](obj);
			}
		}
	},

	observe: function (type, handler) {
		var list = this.observers.get(type);
		if (!list) {
			list = new Array();
		}
		list[list.length] = handler;
		this.observers.set(type, list);
	},

	setObservers: function () {
		this.observe('NotifierHistory', this.onHistory.bind(this));

		if (this.options.forum.enabled) {
			this.observe('ForumMessage', this.onMessage.bind(this, this.onForumMessage.bind(this), this.options.forum));
		}
		if (this.options.friendApplication.enabled) {
			this.observe('FriendApplication', this.onMessage.bind(this, this.onFriendApplication.bind(this), this.options.friendApplication));
		}
		if (this.options.friendLogon.enabled) {
			this.observe('FriendLogon', this.onMessage.bind(this, this.onFriendLogon.bind(this), this.options.friendLogon));
		}
		if (this.options.guestbook.enabled) {
			this.observe('GuestbookMessage', this.onMessage.bind(this, this.onGuestbookMessage.bind(this), this.options.guestbook));
		}
		if (this.options.quickMessage.enabled) {
			this.observe('QuickMessage', this.onMessage.bind(this, this.onQuickMessage.bind(this), this.options.quickMessage));
		}
		if (this.options.spam.enabled) {
			this.observe('SpamMessage', this.onMessage.bind(this, this.onSpamMessage.bind(this), this.options.spam));
		}
		if (this.options.galleryComment.enabled) {
			this.observe('GalleryCommentOwner', this.onMessage.bind(this, this.onGalleryComment.bind(this), this.options.galleryComment));
			this.observe('GalleryCommentFriend', this.onMessage.bind(this, this.onGalleryComment.bind(this), this.options.galleryComment));
		}
		if (this.options.chatInvite.enabled) {
			this.observe('LegacyChatInvite', this.onMessage.bind(this, this.onChatInvite.bind(this), this.options.chatInvite), true);
		}
		if (this.options.moodComment.enabled) {
			this.observe('MoodComment', this.onMessage.bind(this, this.onMoodComment.bind(this), this.options.moodComment));
		}
		if (this.options.moodChanged.enabled) {
			this.observe('MoodChanged', this.onMessage.bind(this, this.onMoodChanged.bind(this), this.options.moodChanged));
		}
		if (this.options.battleComment.enabled) {
			this.observe('BattleComment', this.onMessage.bind(this, this.onBattleComment.bind(this), this.options.battleComment));
		}
		if (this.options.battleAccepted.enabled) {
			this.observe('BattleAccepted', this.onMessage.bind(this, this.onBattleAccepted.bind(this), this.options.battleAccepted));
		}
		if (this.options.battleStarted.enabled) {
			this.observe('BattleStarted', this.onMessage.bind(this, this.onBattleStarted.bind(this), this.options.battleStarted));
		}
		if (this.options.battleStartedOwn.enabled) {
			this.observe('BattleStartedOwn', this.onMessage.bind(this, this.onBattleStartedOwn.bind(this), this.options.battleStartedOwn));
		}
		if (this.options.battleChallange.enabled) {
			this.observe('BattleChallange', this.onMessage.bind(this, this.onBattleChallange.bind(this), this.options.battleChallange));
		}
		if (this.options.matchInterest.enabled) {
			this.observe('MatchInterestNotification', this.onMessage.bind(this, this.onMatchInterest.bind(this), this.options.matchInterest));
		}
		if (this.options.achievementEarned.enabled) {
			this.observe('AchievementEarned', this.onMessage.bind(this, this.onAchievementEarned.bind(this), this.options.achievementEarned));
		}
	},

	showHistory: function () {
		if (this.messages.length > 0) {
			var handler = new Notifier.HistoryHandler(this.messages);
			handler.show();
		}
	},

	onHistory: function (obj) {
		this.messages.addRange(obj.messages);
	},

	onMessage: function (func, typeObj, obj, excludeFromHistory) {
		if (obj.notificationAge < 4000) {
			try {
				func(obj);
				this.playSound(typeObj.sound);
			}
			catch (e) {
				//alert(e);
			}
		}
		if (!excludeFromHistory) {
			this.messages.add(obj);
		}
	},

	onForumMessage: function (obj) {
		var handler = new Notifier.ForumHandler(obj);
		handler.show();
	},

	onFriendApplication: function (obj) {
		var handler = new Notifier.FriendApplicationHandler(obj);
		handler.show();
	},

	onFriendLogon: function (obj) {
		var handler = new Notifier.FriendLogonHandler(obj);
		handler.show();
	},

	onGuestbookMessage: function (obj) {
		var handler = new Notifier.GuestbookHandler(obj);
		handler.show();
	},

	onQuickMessage: function (obj) {
		var handler = new Notifier.QuickMessageHandler(obj);
		handler.show();
	},

	onSpamMessage: function (obj) {
		var handler = new Notifier.SpamHandler(obj);
		handler.show();
	},

	onGalleryComment: function (obj) {
		var handler = new Notifier.GalleryCommentHandler(obj);
		handler.show();
	},

	onChatInvite: function (obj) {
		var handler = new Notifier.ChatHandler(obj);
		handler.show();
	},

	onMoodComment: function (obj) {
		var handler = new Notifier.MoodCommentHandler(obj);
		handler.show();
	},

	onMoodChanged: function (obj) {
		var handler = new Notifier.MoodChangedHandler(obj);
		handler.show();
	},

	onBattleComment: function (obj) {
		var handler = new Notifier.BattleCommentHandler(obj);
		handler.show();
	},

	onBattleAccepted: function (obj) {
		var handler = new Notifier.BattleAcceptedHandler(obj);
		handler.show();
	},

	onBattleStarted: function (obj) {
		var handler = new Notifier.BattleStartedHandler(obj);
		handler.show();
	},

	onBattleStartedOwn: function (obj) {
		var handler = new Notifier.BattleStartedOwnHandler(obj);
		handler.show();
	},

	onBattleChallange: function (obj) {
		var handler = new Notifier.BattleChallangeHandler(obj);
		handler.show();
	},

	onMatchInterest: function (obj) {
		var handler = new Notifier.MatchInterestHandler(obj);
		handler.show();
	},

	onAchievementEarned: function (obj) {
		var handler = new Notifier.AchievementEarnedHandler(obj);
		handler.show();
	},

	playSound: function (sound) {
		if (sound && sound > 0) {
			SoundPlayer.play('/sounds/alerts/mp3/' + sound + '.mp3');
		}
	}
});

/* File: /includes/js/framework/Notifier/notifier.window.js (Modified: 3. september 2010 12:30:56) */

Notifier.Window = Class.create({
	initialize: function(content, options){
		this.options = Object.extend({
			timeout: 10000,
			className: 'notifyWindow',
			id: 'notifyWindow' + new Date().getTime(),
			onWindowDestroyed: Prototype.emptyFunction
		}, options);
		this.content = content;
		
		this.createWindow();
		document.body.appendChild(this.element);
		this.height = this.element.getHeight();
		
		this.windowClosingListener = this.windowClosing.bindAsEventListener(this);
		Event.observe(window, 'unload', this.windowClosingListener);
	},
	
	createWindow: function(){
		this.element = new Element('div', {'class':this.options.className, id: this.options.id});
		if(!Prototype.Browser.IE6){
			this.element.setStyle({
				position: 'fixed',
        right: '10px',
        /*display: 'none',*/
        zIndex: 10000
			});
			if(activeChat){
				this.element.setStyle({top: '5px'});
			}
			else{
				this.element.setStyle({bottom: '25px'});
			}
			var infobox = new InfoBox('', this.content, {disableHeader: true});
			this.element.appendChild(infobox.getInfoBox());
		}
	},
	
	windowClosing: function(){
		this.clearTimers();
		Event.stopObserving(window, 'unload', this.windowClosingListener);
		if(this.effect){
			this.effect.cancel();
		}
	},
	
	clearTimers: function(){
		if(this.timer){
			clearTimeout(this.timer);
		}
	},
	
	show: function(){
		if($(this.options.id)){
			if(activeChat){
				this.effect = new Effect.SlideDown(this.element);
			}
			else{
				this.effect = new Effect.BlindDown(this.element);
			}
			setTimeout(this.effectFinished.bind(this), 1000);
			this.timer = setTimeout(this.fade.bind(this), this.options.timeout);
		}
	},
	
	fade: function(){
		this.clearTimers();
		try {
			if($(this.options.id)){
					this.element.getInlineOpacity = function(){ return this.style.opacity || ''; };
					this.effect = new Effect.Fade(this.element);
			}
		}catch(e){alert(e);}
		this.timer = setTimeout(this.destroy.bind(this), 1000);
	},
	
	move: function(height){
		var offset = this.element.cumulativeOffset();
		this.element.setStyle({ position: 'absolute', top: offset.top + 'px', left: offset.left + 'px', bottom: '', right: '' });
		if(activeChat){
			this.effect = new Effect.Move(this.element, { x: offset.left, y: (offset.top + height + 10), mode: 'absolute' });
		}
		else{
			this.effect = new Effect.Move(this.element, { x: offset.left, y: (offset.top - height - 10), mode: 'absolute' });
		}
	},
	
	destroy: function(){
		this.clearTimers();
		this.element.remove();
		this.options.onWindowDestroyed(this);
	},
	
	effectFinished: function() {
		this.effect = null;
	}
});

/* File: /includes/js/framework/Notifier/notifier.windowManager.js (Modified: 3. september 2010 12:30:56) */

Notifier.WindowManager = {
	windows: new Array(),
	
	createWindow: function(content, options){
		options = Object.extend({onWindowDestroyed:this.windowDestroyed.bind(this)}, options);
		var win = new Notifier.Window(content, options);
		var windows = this.windows.reverse(false);
		for(var i = 0; i < windows.length; i++){
			if(!Prototype.Browser.IE6 && i < 2){
				windows[i].move(win.height);
			}
			else{
				windows[i].fade();
			}
		}
		win.show();
		this.windows.add(win);
		return win;
	},
	
	windowDestroyed: function(win){
		this.windows = this.windows.without(win);
	}
};

/* File: /includes/js/framework/Notifier/notifier.unreadhandler.js (Modified: 3. september 2010 12:30:56) */

Notifier.UnreadHandler = Class.create({
	initialize: function() {
		MsgService.observe('Notification', this.onMsg.bind(this));
	},

	onMsg: function(obj) {
		if (obj.subType == 'GuestbookMessageCount') {
			this.gbUpdate(obj);
		}
		else if (obj.subType == 'QuickMessageCount') {
			this.qmUpdate(obj);
		}
	},

	gbUpdate: function(obj) {
		if (obj.notificationAge < 3000) {
			if (obj.count > 0) {
				$('gbMsgCount').update(this.getNumberImage(obj.count));
			} else {
				$('gbMsgCount').update();
			}
			this.updateSession('gbupdate', obj.count);
		}
	},

	qmUpdate: function(obj) {
		if (obj.notificationAge < 3000) {
			if (obj.count > 0) {
				$('qmMsgCount').update(this.getNumberImage(obj.count));
			} else {
				$('qmMsgCount').update();
			}
			this.updateSession('qmupdate', obj.count);
		}
	},

	updateSession: function(m, count) {
		new Ajax.Request('/section/user/common/UnreadAjax.ashx', { parameters: { m: m, count: count} });
	},

	getNumberImage: function(number) {
		var OUrl = "http://artogfx.cloud2.artodata.com/sitegfx/design/2009/menunumbers/menu_tal_";
		if (number > 99) {
			OUrl += "100";
		}
		else {
			if (number < 10) {
				OUrl += '0';
			}
			OUrl += number;
		}
		OUrl += ".png";

		return "<img src=\"" + OUrl + "\" alt=\"\" style=\"border:0px;\" align=\"absmiddle\" />";
	}
});

/* File: /includes/js/framework/SilverlightMessage.js (Modified: 3. september 2010 12:30:56) */

var SilverlightMessage = {
	activeBox: null,

	isSilverlightInstalled: function (ver) {
		var version = ver || 3;
		if (Arto.isSilverlightInstalled(version)) {
			return true;
		} else {
			SilverlightMessage.show();
			return false;
		}
	},

	show: function () {
		if (!SilverlightMessage.activeBox) {
			SilverlightMessage.activeBox = new SilverlightMessageContent();
			$(document.body).insert(SilverlightMessage.activeBox);
		} else {
			SilverlightMessage.activeBox.reposition();
		}
	},

	hide: function () {
		if (SilverlightMessage.activeBox) {
			SilverlightMessage.activeBox.boxElement.remove();
			SilverlightMessage.activeBox = null;
		}
	}
}

var SilverlightMessageContent = Class.create({
	initialize: function () {
		this.options = {
			boxWidth: 600,
			offsetLeft: 25,
			offsetTop: 200
		};
	},

	toElement: function () {
		if (!this.boxElement) {
			var elmPos = this.getPosition();
			var infobox = new InfoBox('', this.getContent(), { width: '100%', altContent: this.getCloseImage(), className: 'shadowBox' });
			this.boxElement = new Element('div').setStyle({ width: this.options.boxWidth + 'px', position: elmPos.position, top: elmPos.top, left: elmPos.left }).insert(infobox.getInfoBox());
		}
		return this.boxElement;
	},

	getContent: function () {
		var elm = new Element('div').insert(
			new Element('div', { align: 'center' }).insert(
				new Element('img', { src: this.siteGfxUrl + '/silverlight/SilverlightLogo.png', alt: '' })
			)
		).insert(
			new Element('div').setStyle({ margin: '10px' }).update('You don\'t have Microsoft Silverlight installed. This is required to play games at Arto. Click the button below to install it.')
		).insert(
			new Element('div', { align: 'center' }).insert(this.getDownloadImage())
		);
		return elm;
	},

	getPosition: function () {
		var dim = document.viewport.getDimensions();
		var offsets = document.viewport.getScrollOffsets();
		var positions = { left: (dim.width < 970 ? this.options.offsetLeft : ((dim.width - 970) / 2) + this.options.offsetLeft), top: (dim.height > 600 ? offsets.top + this.options.offsetTop : 50) };
		return { position: 'absolute', top: positions.top + 'px', left: positions.left + 'px' };
	},

	reposition: function () {
		var pos = this.getPosition();
		this.boxElement.setStyle({ position: pos.position, left: pos.left, top: pos.top });
	},

	getDownloadImage: function () {
		return new Element('a', { href: 'http://go2.microsoft.com/fwlink/?LinkID=114576' }).update(
			new Element('img', { src: 'http://go2.microsoft.com/fwlink/?LinkID=108181', alt: '', border: 0 }).setStyle({ margin: '10px'})
		).observe('click', SilverlightMessage.hide);
	},

	getCloseImage: function () {
		return new Element('img', {
			src: 'http://artogfx.cloud2.artodata.com/sitegfx/grafik/kvikchat/window_close.png',
			'class': 'cursorHand'
		}).setStyle({
			width: '15px',
			height: '15px',
			borderWidth: '0px'
		}).observe('click', SilverlightMessage.hide);
	},

	siteGfxUrl: 'http://artogfx.cloud2.artodata.com/sitegfx'
});

/* File: /includes/js/okcheck.js (Modified: 3. september 2010 12:30:55) */

document.observe('dom:loaded', function() {
	setTimeout(function() {
		if (!window.orgAdsEnabled || Arto.GetParam("aidtest") == 'true' || Arto.GetParam("abtest") == 'true') {
			var body = new Element('div').setStyle({
				backgroundColor: 'red',
				color: 'white',
				padding: '10px'
			});
			var textMsg = 'Dear user,\n\nYou have chosen to install an \"adblock\" program and thus to block our ads.\n\nAds are our main source of income for the development and operating costs - we entirely depend on the ads.\n\nTherefore, this warning will be displayed on every page as long as you keep the that program installed. If you uninstall the program, the warning wil disappear permanently.\n\nIn case you installed the program because the ads slow down your computer, we recommend you start by trying the new generation of quick browsers like <a href=\"http://www.google.com/chrome\" target=\"_blank\" style=\"color: yellow\">Google Chrome</a> or <a href=\"http://www.apple.com/safari\" target=\"_blank\" style=\"color: yellow\">Safari</a>.\n\nIf you have any questions, you are welcome to <a href=\"JavaScript:openSupportWindow()\" style=\"color: yellow\">contact the support</a>.\n\nKind regards,\nArto';
			var isAidOnline = false;
			if (Arto.GetParam("aidtest") == 'true') {
				textMsg = 'Dear user,\n\nYou have chosen to install the programme AidOnline and thus block our publicity to the advantage of the publicity on which the firm behind AidOnline makes a profit.\n\nPublicity fees being our main source of income for the development and the operating costs, we entirely depend upon presentation of the publicity.\n\nYou have probably installed the programme with the best of intentions in order to support one or several of the humanitarian organisations who have agreed to participate in the project. Nevertheless, the ultimate consequence of this project will be closing down of Arto because we loose our source of income.\n\nTherefore, this warning will be displayed on every page as long as you keep the that programme installed. If you uninstall the programme, the warning wil disappear permanently.\n\nIf you have any questions, you are welcome to <a href=\"JavaScript:openSupportWindow()\" style=\"color: yellow\">contact the support</a>.\n\nKind regards,\nArto';
			}
			else {
				var banners = $$('#bannerWrapper');
				if (banners && banners.length > 0) {
					for (var i = 0; i < banners.length; i++) {
						var banner = banners[i];
						var imgs = banner.getElementsByTagName('img');
						if (imgs && imgs.length > 0) {
							var match = false;
							for (var ii = 0; ii < imgs.length; ii++) {
								var img = imgs[ii];
								if (img && img.src && img.src.match('https?://aoimages.')) {
									match = true;
									break;
								}
							}
							if (match) {
								textMsg = 'Dear user,\n\nYou have chosen to install the programme AidOnline and thus block our publicity to the advantage of the publicity on which the firm behind AidOnline makes a profit.\n\nPublicity fees being our main source of income for the development and the operating costs, we entirely depend upon presentation of the publicity.\n\nYou have probably installed the programme with the best of intentions in order to support one or several of the humanitarian organisations who have agreed to participate in the project. Nevertheless, the ultimate consequence of this project will be closing down of Arto because we loose our source of income.\n\nTherefore, this warning will be displayed on every page as long as you keep the that programme installed. If you uninstall the programme, the warning wil disappear permanently.\n\nIf you have any questions, you are welcome to <a href=\"JavaScript:openSupportWindow()\" style=\"color: yellow\">contact the support</a>.\n\nKind regards,\nArto';
								isAidOnline = true;
								break;
							}
						}
					}
				}
			}
			var text = new Element('div').update(textMsg.replace(/\n/g, '<br />'));
			body.insert(text);
			body.insert(
			new Element('div', { 'align': 'center' }).setStyle({ marginTop: '10px' }).insert(
				new Element('input', {
					'type': 'button',
					'value': 'Close warning',
					'class': 'inputKnap'
				}).observe('click', function() {
					if (window.adInformBox) {
						window.adInformBox.remove();
						window.adInformBox = null;
					}
				})
			)
		);

			var tImgSrc = isAidOnline ? '/trackers/redirect.asp?id=2' : '/trackers/redirect.asp?id=1';
			tImgSrc += '&updated=' + new Date().getTime();
			var tImg = new Element('img', { 'border': '0', src: tImgSrc });
			body.insert(tImg);


			var offsets = document.viewport.getScrollOffsets();
			var dim = document.viewport.getDimensions();
			var pos = {
				left: (dim.width / 2) - 200,
				top: offsets.top + 50
			};

			window.adInformBox = new Element('div').setStyle({
				position: 'absolute',
				top: pos.top + 'px',
				left: pos.left + 'px',
				zIndex: 9999
			});
			var infobox = new InfoBox('', body, { width: 400, disableHeader: true, useAltHeader: true, className: 'shadowBox' });
			window.adInformBox.insert(infobox.getInfoBox());
			document.body.appendChild(window.adInformBox);
		} 
	}, 1000);
});

/* File: /includes/js/framework/GameLib/game.client.js (Modified: 3. september 2010 12:30:56) */

var GameLib = {};
GameLib.Client = Class.create(Observable, {
	initialize: function (service, gameSettings) {
		this.service = service;
		this.service.observe('Game', this.handleMessages.bind(this));
		this.service.observe('Match', this.handleMatchMessages.bind(this));
		this.service.observe('MultiPlayer', this.handleMultiPlayerMessages.bind(this));
		this.settings = gameSettings;
	},

	handleMessages: function (obj) {
		this.fire(obj.subType, obj);
	},

	handleMatchMessages: function (obj) {
		this.fire('Match:' + obj.subType, obj);
	},

	handleMultiPlayerMessages: function (obj) {
		this.fire('MultiPlayer:' + obj.subType, obj);
	},

	beginQuickGameSearch: function (gametype, initial) {
		var msg = Object.extend(this.settings, {
			type: 'MatchReq',
			subType: 'BeginSearch',
			initial: initial,
			gameType: gametype
		});
		this.service.send(msg);
	},

	cancelGameSearch: function (gametype) {
		var msg = {
			type: 'MatchReq',
			subType: 'CancelSearch',
			gameType: gametype
		};
		this.service.send(msg);
	},

	declineInvite: function () {
		var msg = {
			type: invite.rejectType,
			subType: 'RejectGame'
		};
		this.service.send(msg);
	},

	setQuickGameAvailable: function (setting) {
		if (setting && setting.type) {
			this.service.send(setting);
		}
	},

	quickGameInviteAccepted: function () {
		var msg = {
			type: 'MatchReq',
			subType: 'AcceptGame'
		};
		this.service.send(msg);
	},

	quickGameInviteDeclined: function () {
		var msg = {
			type: 'MatchReq',
			subType: 'DeclineGame'
		};
		this.service.send(msg);
	},

	closeGame: function (gameInfo) {
		var msg = {
			recipient: gameInfo.ownerID,
			type: gameInfo.rejectType,
			subType: 'LeaveGame',
			gameID: gameInfo.gameID,
			userID: CurrentUser.id
		};
		this.service.send(msg);
	},

	timeout: function (invite) {
		var msg = {
			type: invite.rejectType,
			subType: 'TimeoutGame',
			recipient: invite.inviter,
			gameID: invite.gameID
		};
		this.service.send(msg);
	},

	startChat: function (userid, data) {
		var msg = {
			type: 'OpenChat',
			target: userid,
			session: 0,
			onlineStatus: 0,
			customData: data
		};
		this.service.send(msg);
	},

	joinGame: function (gameID) {
		var msg = {
			type: 'MultiPlayerCmd',
			subType: 'JoinGame',
			gameID: gameID,
			useQuickStart :true
		};
		this.service.send(msg);
	},

	launchGame: function(gameID){
		var msg = {
			type: 'MultiPlayerCmd',
			subType: 'LaunchGame',
			gameID: gameID
		};
		this.service.send(msg);
	},

	openGame: function (gameID, gameType, ante) {
		var msg = {
			type: 'MultiPlayerCmd',
			subType: 'OpenGame',
			gameID: gameID,
			gameType: gameType,
			useQuickStart :true,
			ante: ante
		};
		this.service.send(msg);
	},

	openGameKeepAlive: function (gameID, gameType) {
		var msg = {
			type: 'MultiPlayerCmd',
			subType: 'OpenGame',
			gameID: gameID,
			gameType: gameType,
			useQuickStart :true
		};
		this.service.send(msg);
	},

	removeGameFromList: function (gameID) {
		var msg = {
			type: 'MultiPlayerCmd',
			subType: 'CloseGame',
			gameID: gameID
		};
		this.service.send(msg);
	}
});

GameLib.Client.getInstance = function (gameSettings) {
	if (!this.instance) {
		this.instance = new GameLib.Client(MsgService, gameSettings);
	}
	return this.instance;
};

/* File: /includes/js/framework/GameLib/game.invitehandler.js (Modified: 3. september 2010 12:30:56) */

GameLib.InviteHandler = Class.create({
	initialize: function(settings, options) {
		this.options = Object.extend({
			width: 450
		}, options);
		this.settings = settings;
		this.client = GameLib.Client.getInstance();
		this.client.observe('Match:GameQuery', this.handleQuery.bind(this));
		this.client.observe('Match:Timeout', this.removeQuery.bind(this));
	},

	handleQuery: function(query) {
		if (this.activequery) {
			return;
		}

		this.optionsWrapper = new Element('div').setStyle({
			padding: '5px',
			backgroundColor: 'yellow'
		});
		this.optionsWrapper.update(this.getQueryOptions(query));

		var infobox = new InfoBox('', this.optionsWrapper, {
			disableHeader: true,
			className: 'shadowBox',
			width: this.options.width
		});
		var content = infobox.getInfoBox();

		var wrapper = new Element('div').setStyle({});

		var contentWrapper = new Element('div').setStyle({
			position: 'absolute',
			top: '0px',
			left: '0px',
			zIndex: '1000',
			width: (this.options.width) + 'px'
		}).update(content);

		var iframeHack = new Element('iframe', { src: '#', scrolling: 'no', frameborder: 0 }).setStyle({
			position: 'absolute',
			top: '0px',
			left: '0px',
			zIndex: '999',
			width: (this.options.width) + 'px'
		});

		var dim = document.viewport.getDimensions();
		var offsets = document.viewport.getScrollOffsets();

		var pos = {
			left: (dim.width / 2) - (this.options.width / 2),
			top: offsets.top + 120
		}

		wrapper.insert(contentWrapper);

		this.activequery = new Element('div').setStyle({
			position: 'fixed',
			right: '10px',
			bottom: '20px',
			width: this.options.width + 'px',
			height: '169px'
		}).insert(wrapper);

		document.body.appendChild(this.activequery);
		SoundPlayer.play('/sounds/alerts/mp3/37.mp3');
	},

	getQueryOptions: function(query) {
		var wrapper = new Element('div').setStyle({ 'padding': '10px', background: '#000000 url(http://artogfx.cloud2.artodata.com/sitegfx/gfx/ArtoGames/Mbg_onlinespill.jpg) top left', color: '#F9F5EA' });
		var acceptBtn = new ArtoButton('Yes', { buttonClass: 'LargeGreen', width: '100px', onClick: this.acceptClicked.bind(this, query) });
		var declineBtn = new ArtoButton('No', { buttonClass: 'LargeRed', width: '100px', onClick: this.declineClicked.bind(this, query) });
		var tempBtn = new ArtoButton('Do not disturb', { title: 'Deactivate invitations for 30 minutes', width: '100%', onClick: this.declineClicked.bind(this, query, true) });
		var imgSrc = query.thumbUrl;

		var label = new Element('div').update('You have been challenged to a game of ' + query.name + ', do you wish to participate?');
		wrapper.insert(label);

		this.ttl = query.timeoutIn;
		this.counterLabel = new Element('td').setStyle({ width: '50px', textAlign: 'center', verticalAlign: 'middle', fontSize: '30px' }).update(parseInt(this.ttl / 1000));
		this.counterTimoeut = setTimeout(this.updateCounter.bind(this), 100);
		this.flashTimeout = setTimeout(this.flash.bind(this), 200);

		var tabel = new Element('table').setStyle({width: '100%', marginTop: '5px'}).update(
			new Element('tbody').update(
				new Element('tr').update(
					new Element('td').update(
						new Element('img', { src: imgSrc }).setStyle({ borderWidth: '0px', width: '100px', height: '69px' })
					)
				).insert(
					new Element('td').setStyle({ verticalAlign: 'middle' }).update(
						new Element('table', { cellPadding: 0, cellSpacing: 0 }).update(
							new Element('tbody').update(
								new Element('tr').update(new Element('td').update(acceptBtn)).insert(new Element('td').update(declineBtn))
							).insert(
								new Element('tr').update(
									new Element('td', { colspan: 2 }).setStyle({ textAlign: 'center', paddingTop: '3px' }).update(tempBtn)
								)
							)
						)
					)
				).insert(this.counterLabel)
			)
		);
		wrapper.insert(tabel);
		return wrapper;
	},

	updateCounter: function() {
		this.ttl -= 100;
		if (this.ttl / 1000 >= 1) {
			this.counterLabel.update(parseInt(this.ttl / 1000));
			this.counterTimoeut = setTimeout(this.updateCounter.bind(this), 100);
		}
		else if (this.counterTimoeut) {
			clearTimeout(this.counterTimoeut);
			this.counterTimoeut = null;
		}
	},

	flash: function() {
		if (this.optionsWrapper.style.backgroundColor == 'yellow') {
			this.optionsWrapper.setStyle({ backgroundColor: 'red' });
		}
		else {
			this.optionsWrapper.setStyle({ backgroundColor: 'yellow' });
		}
		this.flashTimeout = setTimeout(this.flash.bind(this), 200);
	},

	acceptClicked: function(query) {
		Arto.OpenPopup('/section/artogames/quickgame.aspx?wait=true&gameid=' + query.gameType, 'ArtoChat' + new Date().getTime(), { width: 970, height: 552 }, { scrollbars: 'no' });
		this.removeQuery();
	},

	declineClicked: function(query, tempDisableInvites) {
		this.client.quickGameInviteDeclined(query);
		if (tempDisableInvites) {
			this.temporaryDisableInvites();
		}
		this.removeQuery();
	},

	temporaryDisableInvites: function() {
		this.settings.gameTypes = [];
		this.client.setQuickGameAvailable(this.settings);
		new Ajax.Request('/section/artogames/ArtoGamesAjax.ashx?m=tempdisableinvites');
	},

	removeQuery: function() {
		if (this.activequery) {
			this.activequery.remove();
		}
		this.activequery = null;

		if (this.counterTimoeut) {
			clearTimeout(this.counterTimoeut);
			this.counterTimoeut = null;
		}
	}
});

/* File: /includes/js/framework/GameLib/shadow/game.gamelistshadow.js (Modified: 3. september 2010 12:30:56) */

GameLib.GameListShadow = Class.create({
	initialize: function (options) {
		this.options = Object.extend({
			container: null,
			onGameAdded: Prototype.emptyFunction,
			onGameRemoved: Prototype.emptyFunction
		}, options);
		this.client = GameLib.Client.getInstance();
		this.gameList = new GameLib.GameList(this, options);
		this.setObservers();
	},

	setObservers: function () {
		this.client.observe('MultiPlayer:NewGame', this.handleNewUser.bind(this));
		this.client.observe('MultiPlayer:RemoveGame', this.handleRemoveUser.bind(this));
		this.client.observe('MultiPlayer:GameList', this.handleGameList.bind(this));
		this.client.observe('MultiPlayer:ClearList', this.handleClearList.bind(this));
	},

	handleNewUser: function (entry) {
		if (!entry.remove) {
			this.gameList.addEntry(entry);
			this.options.onGameAdded(this.gameList.getEntriesCount(), entry);
		} else {
			this.handleRemoveUser(entry);
		}
	},

	handleRemoveUser: function (entry) {
		this.gameList.removeEntry(entry);
		this.options.onGameRemoved(this.gameList.getEntriesCount(), entry);
	},

	handleGameList: function (obj) {
		this.gameList.processGameList(obj.games);
		this.options.onGameAdded(this.gameList.getEntriesCount());
	},

	handleClearList: function () {
		this.gameList.clearList();
	},

	handleOpenGame: function (typeID, ante) {
		//this.newGameDialog.close();
		this.gameList.openGamePopup(typeID, ante);
	},

	createGame: function () {
		if (!this.newGameDialog) {
			this.newGameDialog = new GameLib.NewGameSelector();
			this.newGameDialog.observe('OpenGame', this.handleOpenGame.bind(this));
		} else {
			this.newGameDialog.show();
		}
	},

	writePackageToDebug: function (obj, textColor) {
		if (window.dev) {
			var debugElm = $('debugDiv');
			if (debugElm) {
				debugElm.insert(new Element('div', { className: 'fontLille' }).setStyle({ color: textColor }).update(Object.toJSON(obj)));
			}
		}
	}
});

/* File: /includes/js/framework/GameLib/visual/game.gamelist.js (Modified: 3. september 2010 12:30:56) */

GameLib.GameList = Class.create(Observable, {
	initialize: function (shadowClass, options) {
		this.shadow = shadowClass;
		this.options = Object.extend({
			container: null
		}, options);
		this.options.container = $(this.options.container);
		this.entries = new GameLib.GameListEntries();
		this.client = GameLib.Client.getInstance();

		//this.client.observe('MultiPlayer:Invite', this.inviteAccepted.bind(this));
	},

	addEntry: function (entry) {
		var existingEntry = this.entries.get(entry.starterID);
		if (existingEntry) {
			this.removeEntry({ starterID: existingEntry.values.starterID, gameID: existingEntry.values.gameID });
		}
		var listEntry = new GameLib.GameListEntry(entry);
		listEntry.observe('JoinGame', this.handleJoinGame.bind(this))
		this.entries.set(listEntry);
		this.insertEntry(listEntry.Element);
	},

	removeEntry: function (gameEntry) {
		var entry = this.entries.get(gameEntry.starterID);
		if (entry && entry.values.gameID == gameEntry.gameID) {
			entry.Element.remove();
			this.entries.unset(gameEntry.starterID);
			if (this.entries.count() == 0) {
				this.options.container.update(new Element('div', { align: 'center' }).setStyle({ marginTop: '70px' }).update('There are no open games at the moment.'));
				this.options.container.insert(
					new Element('div', { align: 'center' }).insert(
						new Element('a', { href: 'JavaScript:void(0);' }).update('Start new game').observe('click', this.shadow.createGame.bind(this.shadow))
					)
				);
			}
		}
	},

	insertEntry: function (element) {
		if (this.entries.count() > 1) {
			this.options.container.insert({ top: element });
		} else {
			this.options.container.update(element);
		}
	},

	processGameList: function (games) {
		for (var i = 0; i < games.length; i++) {
			this.addEntry(games[i]);
		}
	},

	clearList: function () {
		var entries = this.entries.toList().values();
		for (var i = entries.length - 1; i >= 0; i--) {
			this.removeEntry(entries[i].values);
		}
	},

	handleJoinGame: function (id, userID, gameType, useQuickStart) {
		//		if(useQuickStart){
		//			this.client.joinGame(id);
		//		}
		//		else{
		var params = [];
		params.push('userid=' + userID);
		params.push('gametype=' + gameType);
		params.push('gameid=' + id);
		//}

		this.OpenPopup('/section/artogames/JoinGame.aspx?' + params.join('&'), 'JoinGame' + new Date().getTime(), { width: 985, height: 552 });
	},

	//	inviteAccepted: function (obj) {
	//		var params = [];
	//		params.push('gsid=' + obj.gameID);
	//		params.push('gameserver=' + obj.server);
	//		params.push('gametype=' + obj.game.iD);

	//		setTimeout(function (params) {
	//			location.href = PartnerGames.GetOrginialUrl() + '&' + params.join('&');
	//		} .curry(params), 100);
	//	},

	//	inviteAccepted: function (obj) {
	//		var params = [];
	//		if(obj.chatSessionID){
	//			params.push('sid=' + obj.chatSessionID);
	//		}
	//		params.push('game=true');
	//		params.push('gameid=' + obj.gameID);
	//		params.push('gameserver=' + obj.server);
	//		params.push('gametype=' + obj.game.iD);
	//		if(obj.userType != 'Arto'){
	//			params.push('disablechat=true');
	//		}

	//		var data = new Hash();
	//		data.set('windowState', 2);
	//		this.client.startChat(obj.inviter, data.toObject());

	//		setTimeout(function (params) {
	//			this.OpenPopup('/section/user/chat/ChatWindow.aspx?' + params.join('&'), 'ArtoChat' + new Date().getTime(), { width: 970, height: 552 });
	//			//location.href = '/section/user/chat/ChatWindow.aspx?' + params.join('&');
	//		} .curry(params), 100);
	//	},

	openGamePopup: function (typeID, ante) {
		if (SilverlightMessage.isSilverlightInstalled()) {
			var url = '/section/artogames/startgame.aspx?gametype=' + typeID;
			if (ante > 0) {
				url += '&ante=' + ante;
			}
			this.OpenPopup(url, 'OpenGamePopup', { width: 985, height: 552 });
		}
	},

	OpenPopup: function (url, name, dim, settings) {
		var winSettings = Object.extend({
			scrollbars: 'yes',
			status: 1,
			resizable: 1,
			toolbar: 'no'
		}, settings);
		var pos = {
			left: (screen.width) ? (screen.width - dim.width) / 2 : 0,
			top: (screen.height) ? (screen.height - dim.height) / 2 : 0
		};
		var features = 'height=' + dim.height + ',width=' + dim.width + ',top=' + pos.top + ',left=' + pos.left + ',scrollbars=' + winSettings.scrollbars + ',status=' + winSettings.status + ',resizable=' + winSettings.resizable + ',toolbar=' + winSettings.toolbar;
		return window.open(url, name, features);
	},

	getEntriesCount: function () {
		return this.entries.count();
	},

	debug: function (txt) {
		if (window.dev) {
			var debugElm = $('debugDiv');
			if (debugElm) {
				debugElm.insert(new Element('div', { className: 'fontLille' }).update(txt));
			}
		}
	},

	writePackageToDebug: function (obj, textColor) {
		if (window.dev) {
			var debugElm = $('debugDiv');
			if (debugElm) {
				debugElm.insert(new Element('div', { className: 'fontLille' }).setStyle({ color: textColor }).update(Object.toJSON(obj)));
			}
		}
	}
});

GameLib.GameListEntries = Class.create({
	initialize: function () {
		this.entries = new Hash();
	},

	get: function (starterID) {
		var gamelists = this.entries.values();
		var count = gamelists.length;
		for (var i = 0; i < count; i++) {
			var entry = gamelists[i].get(starterID);
			if (entry) {
				return entry;
			}
		}
		return null;
	},

	set: function (gameObject) {
		if (!this.entries.get(gameObject.values.gameType)) {
			this.entries.set(gameObject.values.gameType, new Hash());
		}
		this.entries.get(gameObject.values.gameType).set(gameObject.values.starterID, gameObject);
	},

	unset: function (starterID) {
		var entry = this.get(starterID);
		if (entry) {
			this.entries.get(entry.values.gameType).unset(starterID);
		}
	},

	toList: function () {
		var hash = new Hash();
		this.entries.each(function (pair) {
			hash = hash.merge(pair.value);
		});
		return hash;
	},

	getGameType: function (gameType) {
		var result = this.entries.get(gameType);
		if (!result) {
			result = new Hash();
		}
		return result;
	},

	getGameTypeIDs: function () {
		return this.entries.keys();
	},

	count: function () {
		var typeIDs = this.getGameTypeIDs();
		var result = 0;
		for (var i = 0; i < typeIDs.length; i++) {
			result += this.entries.get(typeIDs[i]).values().length;
		}
		return result;
	}
});

/* File: /includes/js/framework/GameLib/visual/game.gamelistentry.js (Modified: 3. september 2010 12:30:56) */

GameLib.GameListEntry = Class.create(Observable, {
	initialize: function (values) {
		this.values = values;
		this.createGameButton();
		this.setDisplayPlayer();
		this.createElement();
	},

	createGameButton: function () {
		this.startGameButton = new ArtoButton('Play', { onClick: this.startGameOnClick.bind(this), buttonClass: 'Green' });
	},

	setDisplayPlayer: function () {
		var selectedPlayer = null;
		for (var i = 0; i < this.values.players.length; i++) {
			var player = this.values.players[i];
			if (player.isFriend) {
				selectedPlayer = player;
				break;
			} else if (player.isStarter) {
				selectedPlayer = player;
			}
		}
		this.displayPlayer = selectedPlayer;
	},

	createElement: function () {
		var elm = new Element('div', { className: 'borderTop' });
		var table = new Element('table', { cellpadding: 2, cellspacing: 1 }).setStyle({ width: '100%' }).insert(
			new Element('tbody').insert(
				new Element('tr').insert(
					new Element('td').setStyle({ width: '50px' }).update(this.getImage())
				).insert(
					new Element('td', { valign: 'top' }).insert(
						new Element('div').update(this.getUserProfileLink()).insert(this.getUserGenderAndAge())
					).insert(
						this.getInfoCell()
					)
				).insert(
					new Element('td', { align: 'right' }).setStyle({ width: '50px' }).update(this.startGameButton)
				)
			)
		);
		elm.update(table);
		this.Element = elm;
	},

	getInfoCell: function () {
		if (this.values.ante == 0) {
			return new Element('div', { className: 'fontLille' }).setStyle({ paddingTop: '2px' }).update(this.getNameRow());
		} else {
			return new Element('div').setStyle({ paddingTop: '2px' }).insert(
				new Element('table', { cellpadding: 0, cellspacing: 0, title: 'You have bet ' + this.values.ante + ' credits on this game.' }).insert(
					new Element('tbody').insert(
						new Element('tr').insert(
							new Element('td').insert(
								new Element('img', { src: 'http://artogfx.cloud2.artodata.com/sitegfx/gfx/credit_19x19.png', alt: '', align: 'middle', title: 'You have bet ' + this.values.ante + ' credits on this game.' })
							)
						).insert(
							new Element('td').update(this.values.ante).setStyle({ paddingLeft: '4px', fontWeight: 'bold' })
						)
					)
				)
			);
		}
	},

	getNameRow: function () {
		var result = '';
		if (!this.displayPlayer.firstName.startsWith('[?')) {
			result = this.displayPlayer.firstName + ' ' + this.displayPlayer.lastName;
		}
		return result;
	},

	getInfoText: function () {
		var result = 'Won: ';
		if (this.displayPlayer.won > 0) {
			result += Math.round((this.displayPlayer.won / (this.displayPlayer.won + this.displayPlayer.lost)) * 100) + "%";
		} else {
			result += '0%';
		}
		if ((this.values.maxPlayers - this.values.currentPlayers) > 1) {
			result += ' | <b>Seats: ' + (this.values.maxPlayers - this.values.currentPlayers) + '</b>';
		}
		return result;
	},

	getImage: function () {
		return new Element('img', { src: this.values.gameImage, alt: '', className: 'cursorHand' }).setStyle({ width: '50px', height: '35px' }).observe('click', this.startGameOnClick.bind(this));
	},

	getUserProfileLink: function () {
		var linkElm = null;
		if (this.displayPlayer.profileUrl.contains('arto.com')) {
			linkElm = new Element('a', { href: '/section/user/profile/?id=' + this.displayPlayer.id });
		} else {
			linkElm = new Element('a', { href: this.displayPlayer.profileUrl, target: "_Blank" });
		}
		return CallingCard.SetListeners(linkElm.setStyle({ paddingRight: '5px' }).update(this.displayPlayer.username), this.displayPlayer.id);
	},

	getUserGenderAndAge: function () {
		if (this.displayPlayer.gender == 'mand') {
			this.displayPlayer.gender = 'D';
		} else if (this.displayPlayer.gender == 'kvinde') {
			this.displayPlayer.gender = 'P';
		}
		var result = this.displayPlayer.gender;
		if (result.length > 1) {
			result += ' ';
		}
		if (this.displayPlayer.age > 0) {
			result += this.displayPlayer.age;
		}
		return result;
	},

	startGameOnClick: function () {
		if (SilverlightMessage.isSilverlightInstalled()) {
			if (!this.isInGame()) {
				var currentAmount = window.cc_inst.getCurrentAmount();
				if (currentAmount > this.values.ante || this.values.ante == 0) {
					this.fire('JoinGame', this.values.gameID, this.values.starterID, this.values.gameType);
				} else {
					new InsufficientFundsBox('You are trying to join a game playing for credits, but you don\'t have enough credits to join.');
				}
			} else {
				alert('You are already participating in this game.');
			}
		}
	},

	isInGame: function () {
		for (var i = 0; i < this.values.players.length; i++) {
			var player = this.values.players[i];
			if (player.id == CurrentUser.id) {
				return true;
			}
		}
		return false;
	}
});

/* File: /includes/js/framework/GameLib/visual/NewGameSelector.js (Modified: 3. september 2010 12:30:56) */

GameLib.NewGameSelector = Class.create(Observable, {
	initialize: function () {
		this.options = {
			boxWidth: 600,
			offsetLeft: 25,
			offsetTop: 160
		};
		new Ajax.Request('/section/artogames/artogamesajax.ashx?m=getgamesinfo', { onSuccess: this.generateBox.bind(this) });
	},

	generateBox: function (response) {
		var results = eval('(' + response.responseText + ')');
		var infobox = new InfoBox('Choose a game to start', this.getContent(results), { width: '100%', altContent: this.getCloseImage(), className: 'shadowBox' });
		this.boxElement = new Element('div').setStyle({ width: this.options.boxWidth + 'px', display: 'none' }).insert(infobox.getInfoBox());

		infobox.header.className = 'cursorHand';
		new Draggable(this.boxElement, {
			starteffect: Prototype.emptyFunction,
			endeffect: Prototype.emptyFunction,
			scroll: window, handle: infobox.header
		});

		document.body.appendChild(this.boxElement);
		this.show();
	},

	getContent: function (results) {
		var elm = new Element('div');
		for (var i = 0; i < results.length; i++) {
			var cls = i % 2 == 0 ? '' : 'tdSpeciel2';
			elm.insert(
				new Element('div', { className: cls }).update(
					this.getGameRow(results[i])
				)
			);
		}
		return elm;
	},

	getGameRow: function (game) {
		return new Element('table', { cellpadding: 2, cellspacing: 1 }).setStyle({ width: '100%' }).insert(
			new Element('tbody').insert(
				new Element('tr').insert(
					new Element('td').insert(
						new Element('div').setStyle({ float: 'right', marginTop: '20px', marginRight: '5px' }).insert(
							new ArtoButton('Start', { buttonClass: 'Green', onClick: this.showWagerBox.bind(this, game.ID) })
						)
					).insert(
						new Element('div').setStyle({ float: 'left' }).insert(
							new Element('img', { src: game.ThumbUrl, alt: '', className: 'cursorHand' }).setStyle({
								marginRight: '5px',
								width: '100px',
								height: '69px'
							}).observe('click', this.showWagerBox.bind(this, game.ID))
						)
					).insert(
						new Element('div').setStyle({ fontWeight: 'bold' }).update(game.Name)
					).insert(
						new Element('div').update(game.Description)
					)
				)
			)
		);
	},

	getPosition: function () {
		var dim = document.viewport.getDimensions();
		var offsets = document.viewport.getScrollOffsets();
		var positions = { left: (dim.width < 970 ? this.options.offsetLeft : ((dim.width - 970) / 2) + this.options.offsetLeft), top: offsets.top + this.options.offsetTop };
		return { position: 'absolute', top: positions.top + 'px', left: positions.left + 'px' };
	},

	getCloseImage: function () {
		return new Element('img', {
			src: 'http://artogfx.cloud2.artodata.com/sitegfx/grafik/kvikchat/window_close.png',
			'class': 'cursorHand'
		}).setStyle({
			width: '15px',
			height: '15px',
			borderWidth: '0px'
		}).observe('click', this.close.bind(this));
	},

	reposition: function () {
		var pos = this.getPosition();
		this.boxElement.setStyle({ position: pos.position, left: pos.left, top: pos.top });
	},

	close: function () {
		if (this.boxElement) {
			this.boxElement.hide();
		}
	},

	show: function () {
		if (this.boxElement) {
			this.reposition();
			this.boxElement.show();
		}
	},

	startGame: function (id, ante) {
		this.fire('OpenGame', id, ante);
	},

	showWagerBox: function (id) {
		this.close();
		this.wagerBox = new GameLib.WagerBox(id, this.startGame.bind(this));
	}
});

GameLib.WagerBox = Class.create({
	initialize: function (gameID, startGameMethod) {
		this.options = {
			boxWidth: 600,
			offsetLeft: 50,
			offsetTop: 200
		};
		//Hvis this.wagers ændres skal det også ændres i /section/artogames/StartGame.aspx.cs
		this.wagers = new Hash({ 1: 100, 2: 250, 3: 500, 4: 1000, 5: 5000 });

		this.onStartGame = startGameMethod;
		this.gameID = gameID;
		this.ante = 0;
		this.renderBox();
	},

	renderBox: function () {
		var infobox = new InfoBox('Do you want to bet credits on this game?', this.getContent(), { width: '100%', className: 'shadowBox', altContent: this.getCloseImage() });
		var pos = this.getPosition();

		this.boxElement = new Element('div').setStyle({
			width: this.options.boxWidth + 'px',
			position: pos.position,
			left: pos.left,
			top: pos.top,
			color: '#000000'
		}).insert(infobox.getInfoBox());
		infobox.header.style.cursor = 'move';
		new Draggable(this.boxElement, {
			starteffect: Prototype.emptyFunction,
			endeffect: Prototype.emptyFunction,
			scroll: window, handle: infobox.header
		});
		document.body.appendChild(this.boxElement);
	},

	createOptions: function (balance) {
		this.wagerOption0 = new Element('input', { type: 'radio', id: 'wagerOption0', value: 0, name: 'WagerOptions' }).observe('click', this.setAnte.bind(this));
		this.wagerOption1 = new Element('input', { type: 'radio', id: 'wagerOption1', value: this.wagers.get(1), name: 'WagerOptions', disabled: this.wagers.get(1) > balance }).observe('click', this.setAnte.bind(this));
		this.wagerOption2 = new Element('input', { type: 'radio', id: 'wagerOption2', value: this.wagers.get(2), name: 'WagerOptions', disabled: this.wagers.get(2) > balance }).observe('click', this.setAnte.bind(this));
		this.wagerOption3 = new Element('input', { type: 'radio', id: 'wagerOption3', value: this.wagers.get(3), name: 'WagerOptions', disabled: this.wagers.get(3) > balance }).observe('click', this.setAnte.bind(this));
		this.wagerOption4 = new Element('input', { type: 'radio', id: 'wagerOption4', value: this.wagers.get(4), name: 'WagerOptions', disabled: this.wagers.get(4) > balance }).observe('click', this.setAnte.bind(this));
		this.wagerOption5 = new Element('input', { type: 'radio', id: 'wagerOption5', value: this.wagers.get(5), name: 'WagerOptions', disabled: this.wagers.get(5) > balance }).observe('click', this.setAnte.bind(this));
	},

	getContent: function () {
		var accountBalance = window.cc_inst.getCurrentAmount();
		this.createOptions(accountBalance);

		var result = new Element('table', { cellpadding: 0, cellspacing: 0 }).insert(
			new Element('tbody').insert(
				new Element('tr').insert(
					new Element('td').insert(
						this.wagerOption0
					)
				).insert(
					new Element('td', { colspan: 3 }).insert(
						new Element('label', { 'for': 'wagerOption0' }).update('No thank you')
					)
				)
			).insert(
				new Element('tr').insert(
					new Element('td').insert(
						this.wagerOption1
					)
				).insert(
					new Element('td').insert(
						new Element('label', { 'for': 'wagerOption1' }).update('Yes, bet').setStyle({ textDecoration: (this.wagers.get(1) > accountBalance ? 'line-through' : 'none') })
					)
				).insert(
					new Element('td').insert(
						new Element('img', { src: 'http://artogfx.cloud2.artodata.com/sitegfx/gfx/credit_19x19.png', alt: '', align: 'middle' }).setStyle({ padding: '0px 4px 0px 4px' })
					)
				).insert(
					new Element('td').update(this.wagers.get(1)).setStyle({ textDecoration: (this.wagers.get(1) > accountBalance ? 'line-through' : 'none') })
				)
			).insert(
				new Element('tr').insert(
					new Element('td').insert(
						this.wagerOption2
					)
				).insert(
					new Element('td').insert(
						new Element('label', { 'for': 'wagerOption2' }).update('Yes, bet').setStyle({ textDecoration: (this.wagers.get(2) > accountBalance ? 'line-through' : 'none') })
					)
				).insert(
					new Element('td').insert(
						new Element('img', { src: 'http://artogfx.cloud2.artodata.com/sitegfx/gfx/credit_19x19.png', alt: '', align: 'middle' }).setStyle({ padding: '0px 4px 0px 4px' })
					)
				).insert(
					new Element('td').update(this.wagers.get(2)).setStyle({ textDecoration: (this.wagers.get(2) > accountBalance ? 'line-through' : 'none') })
				)
			).insert(
				new Element('tr').insert(
					new Element('td').insert(
						this.wagerOption3
					)
				).insert(
					new Element('td').insert(
						new Element('label', { 'for': 'wagerOption3' }).update('Yes, bet').setStyle({ textDecoration: (this.wagers.get(3) > accountBalance ? 'line-through' : 'none') })
					)
				).insert(
					new Element('td').insert(
						new Element('img', { src: 'http://artogfx.cloud2.artodata.com/sitegfx/gfx/credit_19x19.png', alt: '', align: 'middle' }).setStyle({ padding: '0px 4px 0px 4px' })
					)
				).insert(
					new Element('td').update(this.wagers.get(3)).setStyle({ textDecoration: (this.wagers.get(3) > accountBalance ? 'line-through' : 'none') })
				)
			).insert(
				new Element('tr').insert(
					new Element('td').insert(
						this.wagerOption4
					)
				).insert(
					new Element('td').insert(
						new Element('label', { 'for': 'wagerOption4' }).update('Yes, bet').setStyle({ textDecoration: (this.wagers.get(4) > accountBalance ? 'line-through' : 'none') })
					)
				).insert(
					new Element('td').insert(
						new Element('img', { src: 'http://artogfx.cloud2.artodata.com/sitegfx/gfx/credit_19x19.png', alt: '', align: 'middle' }).setStyle({ padding: '0px 4px 0px 4px' })
					)
				).insert(
					new Element('td').update(this.wagers.get(4)).setStyle({ textDecoration: (this.wagers.get(4) > accountBalance ? 'line-through' : 'none') })
				)
			).insert(
				new Element('tr').insert(
					new Element('td').insert(
						this.wagerOption5
					)
				).insert(
					new Element('td').insert(
						new Element('label', { 'for': 'wagerOption5' }).update('Yes, bet').setStyle({ textDecoration: (this.wagers.get(5) > accountBalance ? 'line-through' : 'none') })
					)
				).insert(
					new Element('td').insert(
						new Element('img', { src: 'http://artogfx.cloud2.artodata.com/sitegfx/gfx/credit_19x19.png', alt: '', align: 'middle' }).setStyle({ padding: '0px 4px 0px 4px' })
					)
				).insert(
					new Element('td').update(this.wagers.get(5)).setStyle({ textDecoration: (this.wagers.get(5) > accountBalance ? 'line-through' : 'none') })
				)
			)
		);

		this.wagerOption0.checked = true;

		return new Element('div').insert(
			new Element('div').update('You can bet Credits against other players - you can choose below how many Credits you wish to bet on you winning the game.<br />If you don\'t want to bet your Credits then simply press \"No Thank You\" and start the game.').setStyle({ margin: '5px 0px 5px 0px', padding: '0px 5px 0px 5px' })
		).insert(result).insert(
			new Element('div').insert(
				new ArtoButton('Start', { buttonClass: 'Green', onClick: this.startGame.bind(this) })
			).setStyle({ margin: '5px' })
		);
	},

	getPosition: function () {
		var dim = document.viewport.getDimensions();
		var offsets = document.viewport.getScrollOffsets();
		var positions = {
			left: (dim.width < 970 ? this.options.offsetLeft : ((dim.width - 970) / 2) + this.options.offsetLeft),
			top: offsets.top + this.options.offsetTop
		};
		return { position: 'absolute', top: positions.top + 'px', left: positions.left + 'px' };
	},

	setAnte: function () {
		var accountBalance = window.cc_inst.getCurrentAmount();
		if (this.wagerOption5.checked && accountBalance >= this.wagers.get(5)) {
			this.ante = this.wagers.get(5);
		}
		else if (this.wagerOption4.checked && accountBalance >= this.wagers.get(4)) {
			this.ante = this.wagers.get(4);
		}
		else if (this.wagerOption3.checked && accountBalance >= this.wagers.get(3)) {
			this.ante = this.wagers.get(3);
		}
		else if (this.wagerOption2.checked && accountBalance >= this.wagers.get(2)) {
			this.ante = this.wagers.get(2);
		}
		else if (this.wagerOption1.checked && accountBalance >= this.wagers.get(1)) {
			this.ante = this.wagers.get(1);
		} else {
			this.ante = 0;
		}
	},

	startGame: function () {
		this.onStartGame(this.gameID, this.ante);
		this.close();
	},

	getCloseImage: function () {
		return new Element('img', {
			src: 'http://artogfx.cloud2.artodata.com/sitegfx/grafik/kvikchat/window_close.png',
			'class': 'cursorHand'
		}).setStyle({
			width: '15px',
			height: '15px',
			borderWidth: '0px'
		}).observe('click', this.close.bind(this));
	},

	close: function () {
		if (this.boxElement) {
			this.boxElement.remove();
		}
	}
});

/* File: /includes/js/framework/ChatLib/ClientLib/chat.js (Modified: 3. september 2010 12:30:56) */

var ChatLib = {};
ChatLib.WindowState = { Maximized: 0, Minimized: 1, PopUped: 2 };
ChatLib.OnlineStatus = { Offline: -1, Online: 0, Buzy: 1, BRB: 2, Away: 3 };
var activeChat = false;

/* File: /includes/js/framework/ChatLib/ClientLib/chat.client.js (Modified: 3. september 2010 12:30:56) */

ChatLib.Client = Class.create({
	initialize: function(service, currentUser) {
		this.service = service;
		this.user = currentUser;
		this.setObservers();
		this.setListeners();
		this.manager = new ChatLib.SessionManager(this, this.listeners);
		this.autoMessages = new Hash();
	},

	setObservers: function() {
		this.service.observe('ChatError', this.handleError.bind(this));
		this.service.observe('ChatMessage', this.handleMessage.bind(this));
		this.service.observe('ChatUser', this.handleUser.bind(this));
		this.service.observe('ChatSession', this.handleSession.bind(this));
		this.service.observe('UserState', this.handleSessionList.bind(this));
		this.service.observe('ChatCustomDataUpdate', this.handleState.bind(this));
		//		this.service.observe('RequestChatUser', this.sendUserInfo.bind(this));
		this.service.observe('ChatInvite', this.handleRequest.bind(this));
		this.service.observe('ChatResponse', this.handleResponse.bind(this));
		this.service.observe('RemoveUser', this.handleUserRemove.bind(this));
		this.service.observe('CloseSession', this.handleSessionClose.bind(this));
		this.service.observe('ChatIsTyping', this.handleIsTyping.bind(this));
		this.service.observe('ChatUserInfo', this.handleUserInfo.bind(this));
		
		this.service.observe('WebcamInvite', this.handleWebcamInvite.bind(this));
		this.service.observe('WebcamAccept', this.handleWebcamAccepted.bind(this));
		this.service.observe('WebcamDecline', this.handleWebcamDeclined.bind(this));
	},

	addInviteListener: function(listener) { this.listeners.invite[this.listeners.invite.length] = listener; },
	addInviteResponseListener: function(listener) { this.listeners.inviteResponse[this.listeners.inviteResponse.length] = listener; },
	addMessageListener: function(listener) { this.listeners.message[this.listeners.message.length] = listener; },
	addSessionListener: function(listener) { this.listeners.session[this.listeners.session.length] = listener; },
	addStateChangedListener: function(listener) { this.listeners.stateChanged[this.listeners.stateChanged.length] = listener; },
	addUserListener: function(listener) { this.listeners.user[this.listeners.user.length] = listener; },
	addUserRemovedListener: function(listener) { this.listeners.user[this.listeners.user.length] = listener; },
	addSessionCloseListener: function(listener) { this.listeners.sessionClose[this.listeners.sessionClose.length] = listener; },
	addIsTypingListener: function(listener) { this.listeners.isTyping[this.listeners.isTyping.length] = listener; },
	
	addWebcamInviteListener: function(listener) { this.listeners.webcamInvite[this.listeners.webcamInvite.length] = listener; },
	addWebcamAcceptedListener: function(listener) { this.listeners.webcamAccepted[this.listeners.webcamAccepted.length] = listener; },
	addWebcamDeclinedListener: function(listener) { this.listeners.webcamDeclined[this.listeners.webcamDeclined.length] = listener; },

	setListeners: function() {
		this.listeners = {
			invite: new Array(),
			inviteResponse: new Array(),
			message: new Array(),
			session: new Array(),
			stateChanged: new Array(),
			user: new Array(),
			userRemoved: new Array(),
			sessionClose: new Array(),
			isTyping: new Array(),
			webcamInvite: new Array(),
			webcamAccepted: new Array(),
			webcamDeclined: new Array()
		};
	},

	notifyListeners: function(listeners, obj, arg1, arg2, arg3) {
		for (var i = 0; i < listeners.length; i++) {
			listeners[i](obj, arg1, arg2, arg3);
		}
	},

	handleError: function(obj) {
		//TODO: Evt. implementer noget fejlhåndtering (eller bare ignorer?)
	},

	handleMessage: function(obj) {
		this.manager.setMessage(obj.session, obj);
	},

	handleResponse: function(obj) {
		if (obj.session) {
			this.manager.setSession(obj.session);
		}
		this.notifyListeners(this.listeners.inviteResponse, obj);
	},

	handleRequest: function(obj) {
		this.sendResponse(obj);
	},

	handleSession: function(obj) {
		this.manager.setSession(obj);
		for (var i = 0; i < obj.participants.length; i++) {
			var user = obj.participants[i];
			var autoMsg = this.autoMessages.get(user.id);
			if (autoMsg) {
				this.sendMessage(obj.id, autoMsg);
				this.autoMessages.unset(user.id);
			}
		}
	},
	notifyNewSession: function(session) {
		this.notifyListeners(this.listeners.session, session);
	},

	handleSessionList: function(obj) {
		try {
			this.manager.setSessions(obj.sessionList.sessions);
			this.manager.setGenerelState(obj.customData);
		} catch (e) { alert(e); };
	},

	handleState: function(obj) {
		//try{
		this.manager.setState($H(obj.customData));
		//}catch(e){alert(e);};
	},

	handleUser: function(obj) {
		this.manager.setUser(obj.session, obj);
	},

	handleUserRemove: function(obj) {
		//TODO: Fjern bruger fra sessionen/chatten
	},

	handleSessionClose: function(obj, keepObj) {
		if (!keepObj) {
			this.manager.destroySession(obj.session);
		}
		this.notifyListeners(this.listeners.sessionClose, obj.session);
	},

	handleIsTyping: function(obj) {
		this.manager.isTyping(obj.session, obj);
	},

	handleUserInfo: function(obj) {
		try {
			this.manager.updateUserInfo(obj);
		} catch (e) { /*alert(e);*/ }
	},
	
	handleWebcamInvite: function(obj){
		this.notifyListeners(this.listeners.webcamInvite, obj);
	},
	
	handleWebcamAccepted: function(obj){
		this.notifyListeners(this.listeners.webcamAccepted, obj);
	},
	
	handleWebcamDeclined: function(obj){
		this.notifyListeners(this.listeners.webcamDeclined, obj);
	},

	leave: function(sid) {
		this.service.send({ type: 'ChatDepart', session: sid });
	},

	closeChat: function(sid) {
		this.service.send({ type: 'CloseChat', session: sid }, true);
	},

	sendMessage: function(sid, msg) {
		this.service.send({ type: 'ChatMessage', session: sid, message: msg });
	},

	sendResponse: function(request) {
		this.service.send({ type: 'ChatResponse', session: request.session, inviter: request.sender, response: 1 });
	},
	
	sendWebcamInvite: function(sid, publishID){
		this.service.send({type: 'WebcamInvite', session: sid, publishID: publishID});
	},
	
	sendWebcamAccepted: function(sid, publishID){
		this.service.send({type: 'WebcamAccept', session: sid, publishID: publishID});
	},
	
	sendWebcamDeclined: function(sid, pubid){
		this.service.send({type: 'WebcamDecline', session: sid, publishID: pubid});
	},

	setCustomData: function(data) {
		this.service.send({ type: 'ChatSetCustomData', customData: data });
	},

	setUserInfo: function(userInfo) {
		this.service.send(userInfo);
	},

	invite: function(targetUser, status, message, customData) {
		status = status || 0;
		if (message) {
			this.autoMessages.set(targetUser, message);
		}
		this.service.send({ type: 'OpenChat', target: targetUser, session: 0, onlineStatus: status, customData: customData });
	},

	sendUserInfo: function(obj) {
		//		this.service.send(Object.extend({type:'ChatUser'}, CurrentUser));
	},

	notifyTyping: function(timeout, session, userid) {
		this.service.send({ type: 'ChatIsTyping', isTyping: timeout, session: session, userID: userid });
	}
});

ChatLib.Client.getInstance = function(){
	if(!this.instance){
		this.instance = new ChatLib.Client(MsgService, CurrentUser);
	}
	return this.instance;
};

/* File: /includes/js/framework/ChatLib/ClientLib/chat.sessionmanager.js (Modified: 3. september 2010 12:30:56) */

ChatLib.SessionManager = Class.create({
	initialize: function(client, listeners) {
		this.client = client;
		this.listeners = listeners;
		this.sessions = new Hash();
	},

	destroySession: function(sid) {
		this.sessions.unset(sid);
	},

	isTyping: function(sid, obj) {
		var session = this.sessions.get(sid);
		if (session) {
			session.isTyping(obj);
		}
	},

	setMessage: function(sid, msg) {
		var session = this.sessions.get(sid);
		if (session) {
			session.setMessage(msg);
		}
	},

	setSession: function(session) {
		var newSession = this.sessions.get(session.id);
		var sessionExists = typeof newSession != 'undefined';
		if (!sessionExists) {
			newSession = new ChatLib.Session(this.client, session, this.listeners);
			this.sessions.set(newSession.id, newSession);
			this.client.notifyListeners(this.listeners.session, newSession);
		}
		else {
			var currentState = parseInt(newSession.getStateValue('windowState'));
			if (currentState == ChatLib.WindowState.PopUped) {
				try {
					self.focus();
				} catch (e) { }
			}
			else {
				var data = newSession.state;
				data.set('windowState', ChatLib.WindowState.Maximized);
				this.client.setCustomData(data.toObject());
			}
		}
	},

	setSessions: function(sessions) {
		this.sessions = new Hash();
		for (var i = 0; i < sessions.length; i++) {
			var session = sessions[i];
			this.setSession(session);
		}
	},

	setGenerelState: function(state) {
		this.state = $H(state);
	},

	setState: function(state) {
		var cuid = state.get('cuID');
		var sessions = this.sessions.each(function(pair) {
			if (pair.value.getStateValue('cuID') == cuid) {
				pair.value.setState(state);
				throw $break;
			}
		});
	},

	setUser: function(sid, user) {
		var session = this.sessions.get(sid);
		if (session) {
			session.setUser(user);
		}
	},

	updateUserInfo: function(info) {
		var session = this.sessions.get(info.session);
		if (session) {
			session.updateUserInfo(info);
		}
	}

});

/* File: /includes/js/framework/ChatLib/ClientLib/chat.session.js (Modified: 3. september 2010 12:30:56) */

ChatLib.Session = Class.create({
	initialize: function(client, session, listeners) {
		this.client = client;
		this.messages = new Array();
		this.users = new Hash();
		this.state = new Hash();
		this.userStates = new Hash();
		this.setSession(session);
		this.listeners = listeners;
		this.userInfoListeners = new Array();
	},

	addMessage: function(uid, msg) {
		this.client.sendMessage(this.id, { user: uid, message: msg });
	},

	addUserInfoChangedListener: function(listener) {
		this.userInfoListeners[this.userInfoListeners.length] = listener;
	},

	isTyping: function(obj) {
		this.client.notifyListeners(this.listeners.isTyping, obj);
	},

	getStateValue: function(key) {
		return this.state.get(key);
	},

	getUserInfo: function(userid) {
		return this.userInfos.get(userid);
	},

	updateUserInfo: function(info) {
		this.userInfos.set(info.userID, info);
		this.userInfoChanged(info);
	},

	userInfoChanged: function(info) {
		for (var i = 0; i < this.userInfoListeners.length; i++) {
			this.userInfoListeners[i](info);
		}
	},

	setStateValue: function(key, value) {
		this.state.set(key, value);
		this.client.changeState(this.id, this.state);
	},

	getUser: function(userid) {
		return this.users.get(userid);
	},

	leave: function() {
		this.client.leave(this.id);
	},

	close: function() {
		this.client.closeChat(this.id);
	},

	getMessage: function(id) {
		var msg;
		for (var i = 0; i < this.messages.length; i++) {
			msg = this.messages[i];
			if (msg.id == id) {
				return msg;
			}
		}
		return null;
	},

	setMessage: function(message) {
		var oldMsg = this.getMessage(message.id);
		var newMsg = new ChatLib.Message(this.client, this, message);
		var updated = false;
		for (var i = 0; i < this.messages.length; i++) {
			var msg = this.messages[i];
			if (msg.id == newMsg.id) {
				this.messages[i] = newMsg;
				updated = true;
				break;
			}
		}
		if (!updated) {
			this.messages[this.messages.length] = newMsg;
		}

		if (oldMsg == null) {
			this.client.notifyListeners(this.listeners.message, newMsg);
		}
	},

	setSession: function(session) {
		this.id = session.id;
		this.publishID = session.publishID;
		if (session.customData) {
			this.state = $H(session.customData);
		}
		if (session.userInfos) {
			this.userInfos = $H(session.userInfos);
		}
		if (session.participants) {
			for (var i = 0; i < session.participants.length; i++) {
				var user = session.participants[i];
				if (user.id == CurrentUser.id) {
					user = Object.extend({userType: user.userType}, CurrentUser);
					this.users.set(user.id, user);
				}
				else {
					this.setUserInfo(user.id, user);
				}
			}
		}
		if (session.messages) {
			for (var i = 0; i < session.messages.length; i++) {
				var msg = new ChatLib.Message(this.client, this, session.messages[i]);
				this.messages[this.messages.length] = msg;
			}
		}
		if (session.gameInvite) {
			this.gameInvite = session.gameInvite;
		}
		if(session.webcamInvite){
			this.webcamInvite = session.webcamInvite;
		}
	},

	setState: function(state) {
		this.state = $H(state);
		this.state.each(function(pair) {
			if (pair.key.startsWith('user')) {
				this.setUser(pair.value.evalJSON(false));
			}
		} .bind(this));
		this.client.notifyListeners(this.listeners.stateChanged, this.state, this);
	},

	setStateValue: function(key, value) {
		this.state.set(key, value);
		this.client.changeState(this.id, this.state);
	},

	setUser: function(user) {
		user.session = this.id;
		this.users.set(user.id, user);
		this.client.notifyListeners(this.listeners.user, user);
	},

	setUserInfo: function(userid, cUser) {
		var userStr = this.getStateValue('user' + userid);
		var user = null;
		if (userStr && !userStr.empty()) {
			var user = userStr.evalJSON(false);
			if (user) {
				user.userType = cUser.userType;
				this.users.set(userid, user);
			}
		}
		if (!user) {
			this.users.set(userid, { id: userid, userType: cUser.userType});
			new Ajax.Request('/section/chat/ChatAjax.ashx?m=getuser&id=' + userid, { onSuccess: this.handleUserData.bind(this) });
		}
	},

	handleUserData: function(response) {
		var obj = response.responseText.evalJSON(false);
		if (obj) {
			var state = this.state;
			var user = Object.toJSON(obj);
			state.set('user' + obj.id, Object.toJSON(obj));
			this.client.setCustomData(state);
		}
	}
});

/* File: /includes/js/framework/ChatLib/ClientLib/chat.message.js (Modified: 3. september 2010 12:30:56) */

ChatLib.Message = Class.create({
	initialize: function(client, session, message){
		this.client = client;
		this.id = message.id;
		this.message = message.message;
		this.rawMessage = message.rawMessage;
		this.user = session.getUser(message.userID);
		this.time = message.writtenTime;
		this.session = session;
	}
});

/* File: /includes/js/framework/ChatLib/ClientLib/chat.shadowmanager.js (Modified: 3. september 2010 12:30:56) */

ChatLib.ShadowManager = {
	init: function(initShadows) {
		if (typeof initShadows == 'undefined') {
			initShadows = true;
		}
		if (initShadows) {
			this.TaskBar = new ChatLib.TaskBarShadow();
			this.FriendList = new ChatLib.FriendListShadow();
			this.Game = new ChatLib.GameShadow();
		}
		this.windows = new Hash();
	},

	addChatWindow: function(id, obj) {
		this.windows.set(id, obj);
	},

	getChatWindow: function(id) {
		return this.windows.get(id);
	},

	removeChatWindow: function(id) {
		this.windows.unset(id);
	}
};

/* File: /includes/js/framework/ChatLib/ClientLib/chat.visualmanager.js (Modified: 3. september 2010 12:30:56) */

ChatLib.VisualManager = {
	init: function(){
		this.windows = new Hash();
	},
	
	addChatWindow: function(id, obj){
		this.windows.set(id, obj);
	},

	getChatWindow: function(id){
		return this.windows.get(id);
	},
	
	removeChatWindow: function(id){
		this.windows.unset(id);
	}
};

/* File: /includes/js/framework/ChatLib/Shadow/ChatWindowShadow.js (Modified: 3. september 2010 12:30:56) */

ChatLib.ChatWindowShadow = Class.create(Observable, {
	initialize: function(session) {
		/* session = {id, users, messages} */
		this.session = session;

		this.chatClient = ChatLib.Client.getInstance();
		this.chatClient.addMessageListener(this.onNewMessage.bind(this));
		this.chatClient.addUserListener(this.onUserUpdate.bind(this));
		this.chatClient.addStateChangedListener(this.customDataChanged.bind(this));
		this.chatClient.addIsTypingListener(this.isTyping.bind(this));
		this.chatClient.addSessionCloseListener(this.onClose.bind(this));
		this.chatClient.addWebcamInviteListener(this.onWebcamInvite.bind(this));
		this.chatClient.addWebcamAcceptedListener(this.onWebcamAccepted.bind(this));
		this.chatClient.addWebcamDeclinedListener(this.onWebcamDeclined.bind(this));

		this.gameClient = GameLib.Client.getInstance();
		this.gameClient.observe('Invite', this.onGameInvite.bind(this));
	},

	removeWindow: function() {
		this.chatClient.handleSessionClose({ session: this.session.id }, true);
	},

	customDataChanged: function(data) {
		if (this.session.getStateValue('cuID') == data.get('cuID')) {
			this.fire('customDataChanged', data);
		}
	},

	onNewMessage: function(msg) {
		if (this.session.id == msg.session.id) {
			this.fire('newMessage', msg);
			if (msg.user.id != CurrentUser.id && CurrentUser.chatSound > 0) {
				SoundPlayer.play('/sounds/alerts/mp3/' + CurrentUser.chatSound + '.mp3');
			}
		}
	},

	onGameInvite: function(invite) {
		if (this.session.id == invite.chatSessionID) {
			if (CurrentUser.chatSound > 0) {
				SoundPlayer.play('/sounds/alerts/mp3/' + CurrentUser.chatSound + '.mp3');
			}
		}
	},
	
	onWebcamInvite: function(invite){
		if(invite.session == this.session.id){
			this.fire('WebcamInvite', invite);
		}
	},
	
	onWebcamAccepted: function(obj){
		if(obj.session == this.session.id){
			this.fire('WebcamInviteAccepeted', obj);
		}
	},
	
	onWebcamDeclined: function(obj){
		if(obj.session == this.session.id){
			this.fire('WebcamInviteDeclined', obj);
		}
	},

	onUserUpdate: function(user) {
		this.fire('userUpdate', user);
	},

	notifyTyping: function(timeout) {
		this.chatClient.notifyTyping(timeout, this.session.id, CurrentUser.id);
	},

	sendMessage: function(message) {
		this.chatClient.sendMessage(this.session.id, message);
	},

	StartTyping: function(message) {

	},

	isTyping: function(obj) {
		this.fire('isTyping', obj);
	},

	destroy: function() {
		//this.session = null;
	},

	close: function() {
		this.session.close();
	},

	onClose: function(sid) {
		if (this.session.id == sid) {
			this.fire('onClose');
		}
	},

	popup: function(session, withWebcam) {
		if (withWebcam) {
			this.startWebcam(session);
		}
		data = session.state;
		data.set('windowState', ChatLib.WindowState.PopUped);
		this.chatClient.setCustomData(data.toObject());
	},

	startWebcam: function(session) {
		this.chatClient.sendWebcamInvite(session.id, session.publishID);
	},
	
	acceptWebcamInvite: function(session){
		this.chatClient.sendWebcamAccepted(session.id, session.publishID);
	},
	
	declineWebcamInvite: function(session, pubid){
		this.chatClient.sendWebcamDeclined(session.id, pubid);
	},

	minimize: function(session) {
		data = session.state;
		data.set('windowState', ChatLib.WindowState.Minimized);
		data.set('minimizedTime', new Date().getTime());
		this.chatClient.setCustomData(data.toObject());
	},

	attach: function(session) {
		data = session.state;
		data.set('windowState', ChatLib.WindowState.Maximized);
		this.chatClient.setCustomData(data.toObject());
	},

	isMinimized: function() {
		return this.session.getStateValue('windowState') == ChatLib.WindowState.Minimized;
	}
});

/* File: /includes/js/framework/ChatLib/Shadow/FriendListShadow.js (Modified: 3. september 2010 12:30:56) */

ChatLib.FriendListShadow = Class.create({
	initialize: function() {
		MsgService.observe('UserOffline', this.handleUserOffline.bind(this));
	},

	handleUserOffline: function(id) {
	},

	InviteUser: function(userid, status) {
		ChatLib.Client.getInstance().invite(userid, status);
	}
});

/* File: /includes/js/framework/ChatLib/Shadow/GameShadow.js (Modified: 3. september 2010 12:30:56) */

ChatLib.GameShadow = Class.create({
	initialize: function() {
	},

	SelectGame: function(userid, status) {
		var windows = ChatLib.VisualManager.windows.values(); //TODO fix AEK
		for (var i = 0; i < windows.length; i++) {
			if (windows[i].user.id == userid) {
				windows[i].gameClicked();
				return;
			}
		}
		var data = new Hash();
		data.set('windowState', ChatLib.WindowState.PopUped);
		ChatLib.Client.getInstance().invite(userid, status, null, data.toObject());
		
		var width = 970;
		var height = 552;
		this.gamePopup = Arto.OpenPopup('/section/user/chat/chatwindow.aspx?userid=' + userid + '&game=true', 'ArtoChat' + new Date().getTime(), { width: width, height: height }, { scrollbars: 'no' });
	},

	StartGame: function(userid, gameType) {
		var windows = ChatLib.VisualManager.windows.values(); //TODO fix AEK
		for (var i = 0; i < windows.length; i++) {
			if (windows[i].user.id == userid) {
				windows[i].startGameClicked(gameType);
				return;
			}
		}
		var data = new Hash();
		data.set('windowState', ChatLib.WindowState.PopUped);
		ChatLib.Client.getInstance().invite(userid, null, null, data.toObject());

		var width = 970;
		var height = 552;
		this.gamePopup = Arto.OpenPopup('/section/user/chat/chatwindow.aspx?gametype=' + gameType + '&userid=' + userid + '&game=true', 'ArtoChat' + new Date().getTime(), { width: width, height: height }, { scrollbars: 'no' });
	}

});

/* File: /includes/js/framework/ChatLib/Shadow/TaskBarShadow.js (Modified: 3. september 2010 12:30:56) */

ChatLib.TaskBarShadow = Class.create({
	initialize: function() {
		this.ChatClientlib = ChatLib.Client.getInstance();
		this.ChatClientlib.addSessionListener(this.StartChat.bind(this));
		this.ChatClientlib.addStateChangedListener(this.StateChanged.bind(this));
		this.ChatClientlib.addUserRemovedListener(this.UserRemoved.bind(this));
		this.ChatClientlib.addMessageListener(this.NewMessage.bind(this));
		this.ChatClientlib.addSessionCloseListener(this.EndChat.bind(this));
		this.ChatClientlib.addUserListener(this.onUserUpdate.bind(this));

		//		this.ChatWindowShadowDict = new Object();

		this.TaskBar = new ChatLib.TaskBar();
		this.TaskBar.observe('TaskBar:CloseTab', this.closeTab.bind(this));
		this.TaskBar.observe('TaskBar:closeAllClicked', this.closeAllClicked.bind(this));
		this.TaskBar.observe('TaskBarTab:Minimize', this.minimize.bind(this));
		this.TaskBar.observe('TaskBarTab:Maximize', this.maximize.bind(this));
		this.TaskBar.observe('TaskBarTab:LastMsgUpdate', this.updateLastMsg.bind(this));

		this.TaskBarElement = $("taskbar_" + this.TaskBar.Handle);
	},

	closeTab: function(sid) {
		this.ChatClientlib.closeChat(sid);
	},

	onUserUpdate: function(user) {
		this.TaskBar.setUser(user.session, user);
	},

	StartChat: function(session) {
		var chatWin = ChatLib.ShadowManager.getChatWindow(session.id);
		if (!chatWin) {
			var windowState = session.getStateValue('windowState');
			if (parseInt(windowState) != ChatLib.WindowState.PopUped) {
				var shadowWin = new ChatLib.ChatWindowShadow(session);
				ChatLib.ShadowManager.addChatWindow(session.id, shadowWin);
				this.TaskBarElement.fire("taskbarshadow:StartChat", { session: session, win: shadowWin });
				if (windowState != ChatLib.WindowState.Minimized) {
					this.minimizeWindows(session.id);
				}
			}
			else {
				//alert(session.id);
				//CookieManager.setValue('ArtoChat', 'win' + session.id, new Date().getTime());
				this.monitorPopupTimer = setTimeout(this.monitorPopup.bind(this, session), 5000);
			}
		}
	},

	updateLastMsg: function(session) {
		data = session.state;
		data.set('lastMsgTime', new Date().getTime());
		this.ChatClientlib.setCustomData(data.toObject());
	},

	EndChat: function(session) {
		var win = ChatLib.ShadowManager.getChatWindow(session);
		if (win) {
			win.destroy();
			ChatLib.ShadowManager.removeChatWindow(session);
		}
		this.TaskBarElement.fire("taskbarshadow:EndChat", session);
	},

	UserRemoved: function(session) {
		this.TaskBarElement.fire("taskbarshadow:FriendRemoved", session);
	},

	NewMessage: function(message) {
		var win = ChatLib.ShadowManager.getChatWindow(message.session.id);
		if(win){
			this.TaskBarElement.fire('taskbarshadow:NewMessage', { message: message, windowVisible: win.IsVisible });
		}
	},

	StateChanged: function(state, session) {
		var newState = parseInt(state.get('windowState'));
		if (newState == ChatLib.WindowState.Maximized) {
			var win = ChatLib.ShadowManager.getChatWindow(session.id);
			if (!win) {
				this.ChatClientlib.notifyNewSession(session);
			}
			else {
				this.minimizeWindows(session.id);
			}
		}
		else if (newState == ChatLib.WindowState.PopUped) {
			CookieManager.setValue('ArtoChat', 'win' + session.id, 'KeepAlive');
			this.monitorPopupTimer = setTimeout(this.monitorPopup.bind(this, session), 1000);
		}
	},

	minimizeWindows: function(except) {
		var wins = ChatLib.ShadowManager.windows.values();
		for (var i = 0; i < wins.length; i++) {
			var win = wins[i];
			if (!win.isMinimized() && win.session.id != except) {
				win.minimize(win.session);
			}
		}
	},

	FriendIsTyping: function(sid) {
		this.TaskBarElement.fire("taskbarshadow:FriendIsTyping", sid);
		setTimeout(this.FriendStoppedTyping.bind(this, sid), 5000);
	},

	FriendStoppedTyping: function(sid) {
		this.TaskBarElement.fire("taskbarshadow:FriendStoppedTyping", sid);
	},

	minimize: function(session) {
		data = session.state;
		data.set('windowState', ChatLib.WindowState.Minimized);
		data.set('minimizedTime', new Date().getTime());
		this.ChatClientlib.setCustomData(data.toObject());
	},

	maximize: function(session) {
		data = session.state;
		data.set('windowState', ChatLib.WindowState.Maximized);
		var tab = this.TaskBar.TaskBarTabs.get(session.id);
		if (tab) {
			tab.removeHighlighting();
		}
		this.ChatClientlib.setCustomData(data.toObject());
	},

	closeAllClicked: function() {
		var wins = ChatLib.ShadowManager.windows.values();
		for (var i = 0; i < wins.length; i++) {
			var win = wins[i];
			if (parseInt(win.session.getStateValue('windowState')) != ChatLib.WindowState.PopUped) {
				this.closeTab(win.session.id);
			}
		}
	},

	monitorPopup: function(session) {
		var value = CookieManager.getValue('ArtoChat', 'win' + session.id);
		if (value && value == 'KeepAlive') {
			this.monitorPopupTimer = setTimeout(this.monitorPopup.bind(this, session), 1000);
		}
		else if (value == 'FakeClose') {
			var cookieKey = 'win' + session.id;
			CookieManager.removeValue('ArtoChat', cookieKey);
			clearTimeout(this.monitorPopupTimer);
			var game = CookieManager.getObject('ArtoGame', cookieKey);
			if (game) {
				GameLib.Client.getInstance().closeGame(game);
				var game = CookieManager.getObject('ArtoGame', cookieKey);
				CookieManager.removeValue('ArtoGame', cookieKey);
			}
		}
		else if (value) {
			var cookieKey = 'win' + session.id;
			CookieManager.removeValue('ArtoChat', cookieKey);

			var game = CookieManager.getObject('ArtoGame', cookieKey);
			if (game) {
				GameLib.Client.getInstance().closeGame(game);
				var game = CookieManager.getObject('ArtoGame', cookieKey);
				CookieManager.removeValue('ArtoGame', cookieKey);
			}

			this.monitorPopupTimer = null;
			
			var now = new Date().getTime();
			if(session.lastMessage && now - session.lastMessage.getTime() <= 1000){
				data = session.state;
				data.set('windowState', ChatLib.WindowState.Maximized);
				var partnerUserID = -1;
				var tmpUserIDs = session.users.keys();
				for (var i = 0; i < tmpUserIDs.length; i++) {
					partnerUserID = tmpUserIDs[i];
					if (partnerUserID != CurrentUser.id) {
						break;
					}
				}
				this.ChatClientlib.invite(partnerUserID, null, null, data.toObject());
				//this.ChatClientlib.setCustomData(data.toObject());
			}
			else{
				session.close();
			}
		}
		else {
			var now = new Date().getTime();
			if(session.lastMessage && now - session.lastMessage.getTime() <= 1000){
				data = session.state;
				data.set('windowState', ChatLib.WindowState.Maximized);
				var partnerUserID = -1;
				var tmpUserIDs = session.users.keys();
				for (var i = 0; i < tmpUserIDs.length; i++) {
					partnerUserID = tmpUserIDs[i];
					if (partnerUserID != CurrentUser.id) {
						break;
					}
				}
				this.ChatClientlib.invite(partnerUserID, null, null, data.toObject());
			}
			else{
				//alert('monitorPopup:else:close');
				session.close();
			}
			//session.close();
		}
	}

});

/* File: /includes/js/framework/ChatLib/Visual/chat.timestamp.js (Modified: 3. september 2010 12:30:56) */

ChatLib.Timestamp = Class.create({
	initialize: function(time){
		this.time = time.toLocaleDate();
		this.now = new Date();
	},
	
	_isToday: function(){
		return this.now.getYear() == this.time.getYear() && this.now.getMonth() == this.time.getMonth() && this.now.getDate() == this.time.getDate();
	},
	
	getDate: function(){
		var date = CurrentUser.dateFormat.replace(/-yyyy/ig, '').replace(/\/yyyy/ig, '');
		var month = this.time.getMonth() + 1;
		var day = this.time.getDate();
		date = date.replace(/dd?/ig, day);
		date = date.replace(/mm/ig, month);
		date = date.replace(/-/ig, '/');
		return date;
	},
	
	getTime: function(){
		var time = '';
		var hours = this.time.getHours();
		var minutes = this.time.getMinutes();
		var localeTime = this.time.toLocaleTimeString();
		if(localeTime.endsWith('PM')){
			if(hours > 12){
				hours = hours - 12;
			}
			time += hours.toPaddedString(2) + ":" + minutes.toPaddedString(2) + '&nbsp;PM';
		}
		else if(localeTime.endsWith('AM')){
			time += hours.toPaddedString(2) + ":" + minutes.toPaddedString(2) + '&nbsp;AM';
		}
		else{
			time += hours.toPaddedString(2) + ":" + minutes.toPaddedString(2);
		}
		return time;
	},
	
	toString: function(){
		var hours = this.time.getHours().toPaddedString(2);
		var minutes = this.time.getMinutes().toPaddedString(2);
		var time = this.getTime();
		if(this._isToday()){
			return time;
		}
		else{
			var month = this.time.getMonth();
			var day = this.time.getDate();
			return this.getDate() + '&nbsp;' + time;
		}
	}
});

/* File: /includes/js/framework/ChatLib/Visual/ChatAdvertisementPanel.js (Modified: 3. september 2010 12:30:56) */

ChatLib.ChatAdvertisementPanel = Class.create({
	initialize: function(container, loadBanner, large) {
		this.useIFrame = true;
		this.large = large;

		if (!this.useIFrame) {
			this.orgDocWrite = document.write;
			this.orgError = window.onerror;
			inFIF = true;
		}

		this.container = container;
		this.Height = 65;
		this.user = CurrentUser;
		this.wrapper = new Element('div', { id: 'adWrapper' }).setStyle({ padding: '0px', margin: '0px' });
		this.container.insert(this.wrapper);
		//this.container.insert(this.wrapper);

		if (loadBanner) {
			if (window.loaded) {
				this._loadBanner(60);
			}
			else {
				Event.observe(window, 'load', this._loadBanner.bind(this, 60));
			}
		}
	},

	_getBanner: function() {
		if (this.useIFrame) {
			var elm = new Element('iframe', {
				'marginwidth': '0',
				'marginheight': '0',
				'framespacing': '0',
				'frameborder': 'no',
				'scrolling': 'no'
			});
			if (this.large) {
				elm.setStyle({ width: '728px', height: '90px' });
			}
			else {
				elm.setStyle({ width: '234px', height: '60px' });
			}
			return elm;
		}
		else {
			return new Element('script', { type: 'text/javascript' });
		}
	},

	_getUrl: function(refreshTime) {
		if (this.useIFrame) {
			var url = ChatWindowBanner;
			if (this.large && parseInt(refreshTime) > 0) {
				url += '&refresh=' + refreshTime;
			}
			url += '&cb=' + new Date().getTime();
			url += this.user.gender ? '&gender=female' : '&gender=male';
			url += '&age=' + this.user.age;
			url += '&zip=' + this.user.zipCode;
			url += '&country=' + this.user.country;
			return url;
		}
		else {
			var url = 'http://adserver.adtech.de/addyn/3.0/739/2016487/0/4/ADTECH;loc=100;target=_blank;key=key1+key2+key3+key4;grp=[group];misc=' + new Date().getTime();
			url += this.user.gender ? '&kvgender=female' : '&kvgender=male';
			url += '&kvage=' + this.user.age;
			url += '&kvzip=' + this.user.zipCode;
			url += '&kvcountry=' + this.user.country;
			return url;
		}
	},

	_loadBanner: function(refreshTime) {
		if (!this.useIFrame) {
			window.__ADTECH_CODE__ = '';
			var oldElm = $('DIV_2016487');
			var oldElm2 = $('DIV2_2016487');
			if (oldElm) {
				oldElm.update();
				oldElm.remove();
				if (oldElm2) {
					oldElm2.update();
					oldElm2.remove();
				}
			}
		}

		if (this.banner) {
			try {
				this.banner.remove();
			} catch (e) { }
		}

		this.banner = this._getBanner();
		this.wrapper.update(this.banner);
		this.banner.src = this._getUrl(refreshTime);

		if (!this.useIFrame) {
			this.loopCount = 0;
			window.onerror = function() { return true };
			setTimeout(this._updateContent.bind(this, window.__ADTECH_CODE__), 200);
		}
	},

	_updateContent: function(content) {
		if (content && !content.empty()) {
			document.write = this.orgDocWrite;
			window.onerror = this.orgError;
			this.wrapper.update(content);
		}
		else if (this.loopCount < 10) {
			this.loopCount++;
			setTimeout(this._updateContent.bind(this, window.__ADTECH_CODE__), 200);
		}
	},

	reload: function(refreshTime) {
		this._loadBanner(refreshTime);
	},

	resize: function(width, height) {
	}
});

/* File: /includes/js/framework/ChatLib/Visual/ChatWindow.js (Modified: 3. september 2010 12:30:56) */

ChatLib.ChatWindow = Class.create(Observable, {
	initialize: function (width, height, shadowWin, user, tabXpos, session, isPopupWindow, gameInviteID) {
		this.sid = session.id;
		this.session = shadowWin.session;
		this.session.addUserInfoChangedListener(this.userInfoChanged.bind(this));

		this.windowState = parseInt(this.session.getStateValue('windowState'));
		this.isPopup = this.windowState == ChatLib.WindowState.PopUped || isPopupWindow;
		this.visible = this.windowState != ChatLib.WindowState.Minimized;
		this.gameActive = this.session.activeGame ? true : false;

		this.orgDim = { width: width, height: height };

		var partnerUserID = -1;
		var tmpUserIDs = this.session.users.keys();
		for (var i = 0; i < tmpUserIDs.length; i++) {
			partnerUserID = tmpUserIDs[i];
			if (partnerUserID != CurrentUser.id) {
				break;
			}
		}
		this.partnerUserID = partnerUserID;
		var userInfo = session.getUserInfo(partnerUserID);
		this.partnerOnlineStatus = parseInt(userInfo.status);
		this.playbackID = userInfo.playbackID;
		this.user = user;
		this.shadow = shadowWin;
		this.shadow.observe('newMessage', this.onNewMessage.bind(this));
		this.shadow.observe('userUpdate', this.onUserUpdate.bind(this));
		this.shadow.observe('customDataChanged', this.customDataChanged.bind(this));
		this.shadow.observe('isTyping', this.isTyping.bind(this));
		this.shadow.observe('onClose', this.onClose.bind(this));
		this.shadow.observe('WebcamInvite', this.onWebcamInvite.bind(this));
		this.shadow.observe('WebcamInviteAccepeted', this.onWebcamInviteAccepted.bind(this));
		this.shadow.observe('WebcamInviteDeclined', this.onWebcamInviteDeclined.bind(this));

		this.WindowFrame = new ChatLib.WindowFrame(tabXpos, this.isPopup, this.visible, width, this.session.activeWebcam || this.gameActive);
		this.WindowFrame.observe('CloseClicked', this.closeClicked.bind(this));
		this.WindowFrame.observe('PopupClicked', this.popupClicked.bind(this));
		this.WindowFrame.observe('CollapseClicked', this.collapseClicked.bind(this));
		this.WindowFrame.observe('AttachClicked', this.attachClicked.bind(this));
		this.WindowFrame.setUsername(user);

		this.gameClient = GameLib.Client.getInstance();
		this.gameClient.observe('Invite', this.handleGameInvite.bind(this));
		this.gameClient.observe('ClearInvite', this.handleClearGame.bind(this));

		this.Handle = this.WindowFrame.Handle;
		this.Content = this.WindowFrame.Content;
		if (this.session.activeWebcam || this.gameActive) {
			var dim = {
				width: document.viewport.getWidth() - width,
				height: height - 90
			};

			var loadBanner = true;

			if (this.gameActive) {
				this.GameContent = this.WindowFrame.ExtraContent;
				var gameToLoad = null;
				if (this.session.gameType && !this.session.gameType.empty()) {
					gameToLoad = { id: this.session.gameID, server: this.session.gameServer, type: this.session.gameType, matchGame: this.session.matchGame };
					loadBanner = false;
				}
				this.GamePanel = new ChatLib.GamePanel(this.session, userInfo.userID, gameToLoad, { width: width, height: 150 }, gameInviteID, user); // new ChatLib.WebcamPanel(this.session, dim);
				this.GamePanel.observe('SilverlightDownload', this.stopClose.bind(this));
				this.GamePanel.observe('RefreshBanner', this.refreshBanner.bind(this));
				this.GameContent.insert(this.GamePanel);
				if (this.session.activeWebcam) {
					this.WebcamContent = this.WindowFrame.Content;
					this.WebcamPanel = new ChatLib.WebcamPanel(this.session, { width: width, height: 150 }, this.partnerUserID); ;
					this.WebcamContent.insert(this.WebcamPanel);
				}
			}
			else if (this.session.activeWebcam) {
				this.WebcamContent = this.WindowFrame.ExtraContent;
				//this.WebcamPanel = new ChatLib.WebcamPanel(this.session, dim);
				this.WebcamPanel = new ChatLib.WebcamPanel(this.session, { width: width, height: 150 }, partnerUserID);
				this.WebcamContent.insert(this.WebcamPanel);
			}
			this.advertisementPanel = new ChatLib.ChatAdvertisementPanel(this.WindowFrame.AdContent, this.visible && loadBanner, true);
		}
		else {
			//this.advertisementPanel = new ChatLib.ChatAdvertisementPanel(this.Content, this.visible, false);
		}
		this.ChatInfoPanel = new ChatLib.ChatInfoPanel(this, user, this.session.activeWebcam, this.gameActive);
		this.MessagePanel = new ChatLib.MessagePanel(this, this.session, user);
		this.StatusBarPanel = new ChatLib.StatusBarPanel(this, user);
		this.InputPanel = new ChatLib.InputPanel(this, this.partnerOnlineStatus != ChatLib.OnlineStatus.Offline && user.userType == 'Arto', user);

		this.ChatInfoPanel.observe('WebcamClicked', this.webcamClicked.bind(this));
		this.ChatInfoPanel.observe('GameClicked', this.gameClicked.bind(this));
		this.MessagePanel.observe('WebcamAccepted', this.webcamAccepted.bind(this));
		this.MessagePanel.observe('WebcamDeclined', this.webcamDeclined.bind(this));
		this.MessagePanel.observe('RejectGameInvite', this.gameInviteRejected.bind(this));
		this.MessagePanel.observe('AcceptGameInvite', this.gameInviteAccepted.bind(this));
		this.StatusBarPanel.observe('SmileyClicked', this.smileyClicked.bind(this));
		this.StatusBarPanel.observe('BoldClicked', this.boldClicked.bind(this));
		this.StatusBarPanel.observe('ItalicClicked', this.italicClicked.bind(this));
		this.StatusBarPanel.observe('UnderlinedClicked', this.underlineClicked.bind(this));
		this.StatusBarPanel.observe('ColorChanged', this.textColorChanged.bind(this));

		for (var i = 0; i < shadowWin.session.messages.length; i++) {
			this.onNewMessage(shadowWin.session.messages[i]);
		}

		if (session.gameInvite && (!this.session.gameID || this.session.gameID.empty())) {
			this.handleGameInvite(session.gameInvite);
		}

		if (session.webcamInvite) {
			this.onWebcamInvite(session.webcamInvite);
		}

		if (this.isPopup) {
			setTimeout(this.onWindowResize.bind(this), 1);
		}
		else {
			//			if (width == this.orgDim.width) {
			//				if (document.location.href.indexOf("/section/user/chat/chatwindow.aspx") > 0) {
			//					window.location.href = window.location.href + "&reloaded=1&debug=" + width + "x" + this.orgDim.width;
			//				} 
			//			}
			this.resize(width, height);
		}
		if (!this.visible) {
			this.hide();
		}

		if (this.isPopup) {
			Event.observe(window, 'resize', this.onWindowResize.bind(this));
			Event.observe(window, 'beforeunload', this.onWindowClose.bindAsEventListener(this));
			this.orgDocDim = document.viewport.getDimensions();
			this.setAlive();

			if (this.session.activeWebcam) {
				if (!this.session.playbackid || this.session.playbackid == '') {
					setTimeout(function () { this.shadow.startWebcam(this.session); } .bind(this), 100);
				}
				else {
					setTimeout(function () { this.shadow.acceptWebcamInvite(this.session); } .bind(this), 100);
				}
			}
		}
	},

	customDataChanged: function (data) {
		var newWinState = data.get('windowState');
		if (newWinState) {
			this.setState(parseInt(newWinState));
		}
	},

	setState: function (newState) {
		if (newState != this.windowState) {
			switch (parseInt(newState)) {
				case ChatLib.WindowState.Maximized:
					if (this.windowState == ChatLib.WindowState.PopUped) {
						if (window.name.startsWith('ArtoChat')) {
							try {
								CookieManager.setValue('ArtoChat', 'win' + this.sid, 'FakeClose');
								//CookieManager.removeValue('ArtoChat', 'win' + this.sid);
								this.dying = true;
								window.close();
							} catch (e) { }
						}
					}
					else {
						this.show(parseInt(this.WindowFrame.WindowRoot.style.right));
						this.fire('ChatWindow:Maximized', this.sid);
					}
					break;
				case ChatLib.WindowState.Minimized:
					this.hide();
					break;
				case ChatLib.WindowState.PopUped:
					this.shadow.removeWindow();
					break;
			}
			this.windowState = newState;
		}
	},

	isTyping: function (obj) {
		this.StatusBarPanel.isTyping(obj);
	},

	smileyClicked: function () {
		this.InputPanel.insertSmiley();
	},

	boldClicked: function () {
		this.InputPanel.switchBold();
	},

	italicClicked: function () {
		this.InputPanel.switchItalic();
	},

	underlineClicked: function () {
		this.InputPanel.switchUnderlined();
	},

	textColorChanged: function (color) {
		this.InputPanel.setColor(color);
	},

	userInfoChanged: function (userInfo) {
		if (userInfo.userID != CurrentUser.id) {
			if (this.partnerOnlineStatus != userInfo.status) {
				if (userInfo.status > ChatLib.OnlineStatus.Offline && this.partnerOnlineStatus == ChatLib.OnlineStatus.Offline) {
					this.InputPanel.enableInput();
					this.MessagePanel.removeMessage(this.userOfflineSysMessage);
				}
				else if (this.partnerOnlineStatus > ChatLib.OnlineStatus.Offline) {
					this.InputPanel.disableInput();
					var user = this.session.getUser(userInfo.userID);
					this.userOfflineSysMessage = this.MessagePanel.addSystemMessage(new Date(), '' + user.username + ' is not on line any longer');
				}
			}
			this.partnerOnlineStatus = userInfo.status;
			if (this.chatRequest != userInfo.chatRequest) {
				if (!this.session.activeWebcam) {
					//if (this.user.username) {
					//this.MessagePanel.showWebcamOption(this.user.username, userInfo.playbackID);
					//}
				}
				else {
					//alert(Object.toJSON(userInfo));
					//this.WebcamPanel.startPlayback(userInfo.playbackID)
				}
			}
			this.playbackID = userInfo.playbackID;
		}
	},

	onWebcamInvite: function (invite) {
		if (!this.session.playbackid || this.session.playbackid == '') {
			this.MessagePanel.showWebcamOption(this.user.username, invite.publishID);
		}
	},

	onWebcamInviteAccepted: function (obj) {
		//alert('onWebcamInviteAccepted: ' + obj.publishID);
		//alert('onWebcamInviteAccepted' + obj.publishID);
		this.WebcamPanel.startPlayback(obj.publishID)
	},

	onWebcamInviteDeclined: function (obj) {
		this.MessagePanel.addSystemMessage(new Date(), 'Your webcam application has been declined!');
	},

	toggle: function (xpos) {
		this.WindowFrame.toggle(xpos, this.MessagePanel);
	},

	hide: function () {
		this.WindowFrame.hide();
		this.visible = false;
	},

	show: function (xpos, ignoreBanner) {
		this.WindowFrame.show(xpos, this.MessagePanel);
		this.visible = true;
		if (!ignoreBanner && this.advertisementPanel) {
			this.advertisementPanel.reload();
		}
	},

	move: function (xpos) {
		this.WindowFrame.move(xpos);
	},

	destroy: function () {
		try {
			this.WindowFrame.destroy();
			this.ChatInfoPanel.destroy();
			this.MessagePanel.destroy();
			this.InputPanel.destroy();
			this.StatusBarPanel.destroy();
		} catch (e) { }
	},

	onWindowResize: function () {
		var dim = document.viewport.getDimensions();
		var diff = this.orgDocDim.width - dim.width;
		if (diff > 0) {
			if (Prototype.Browser.IE) {
				if (this.resizeTimer) {
					clearTimeout(this.resizeTimer);
				}
				this.resizeTimer = setTimeout(function () {
					try {
						window.resizeBy(diff, 0);
					}
					catch (e) { }
				}, 100);
			}
			else {
				window.resizeBy(diff, 0);
			}
		}
		else {
			this.resize(dim.width, dim.height);
		}
	},

	resize: function (width, height) {
		this.WindowFrame.resize(width, height, this.orgDim.width);

		this.Width = this.WindowFrame.InnerWidth;
		this.Height = this.WindowFrame.InnerHeight;
		//Resize child controls
		if (!this.session.activeWebcam && !this.gameActive && this.advertisementPanel) {
			this.advertisementPanel.resize(this.Width, 60);
		}
		else {
			if (this.gameActive) {
				this.GamePanel.resize(width - this.orgDim.width, this.Height + this.WindowFrame.Top.getHeight() + 1 - 90);
				this.Width = this.orgDim.width;
			}
			if (this.session.activeWebcam) {
				if (!this.gameActive) {
					this.WebcamPanel.resize(width - this.orgDim.width, this.Height + this.WindowFrame.Top.getHeight() + 1 - 90);
					this.Width = this.orgDim.width;
				}
				else {
					//this.WebcamPanel.resize();
					//TODO: Resize webcam samtidig med spil
				}
			}
		}
		this.ChatInfoPanel.resize(this.Width, 58);
		if (this.isPopup) {
			this.InputPanel.resize(this.Width - 3, 70);
		}
		else {
			this.InputPanel.resize(this.Width, 45);
		}
		this.StatusBarPanel.resize(this.Width, 18);
		var msgPanelHeight = this.Height - this.ChatInfoPanel.Height - this.InputPanel.Height - this.StatusBarPanel.Height;
		if (!this.session.activeWebcam && !this.gameActive && this.advertisementPanel) {
			msgPanelHeight = msgPanelHeight - this.advertisementPanel.Height;
		}
		this.MessagePanel.resize(this.Width, msgPanelHeight - 2);
	},

	onNewMessage: function (message) {
		this.MessagePanel.addUserMessage(message.time, message.user, message);
		this.session.lastMessage = new Date();
		this.WindowFrame.newMessage();

		if (message.user.id != CurrentUser.id) {
			this.StatusBarPanel.setLastMessage(new ChatLib.Timestamp(message.time));
			if (window.loaded && message.rawMessage) {
				if (window.isInFocus) {
					CookieManager.setValue('ArtoChat', 'lfm', new Date().getTime());
				}
				else {
					var last = parseInt(CookieManager.getValue('ArtoChat', 'lfm'));
					var now = new Date().getTime();
					if (now - last > 500) {
						if (window.newChatMessageTimer) {
							clearTimeout(window.newChatMessageTimer);
						}
						this.titleLoop = 0;
						this.updateTitle('' + message.user.username + ': ' + message.rawMessage + '');
					}
				}
			}
		}
	},

	updateTitle: function (msg) {
		var last = parseInt(CookieManager.getValue('ArtoChat', 'lfm'));
		var now = new Date().getTime();
		if ((window.isInFocus && this.titleLoop <= 120) || (now - last < 500)) {
			document.title = window.orgDocTitle;
			CookieManager.setValue('ArtoChat', 'lfm', new Date().getTime());
		}
		else if (this.titleLoop > 120) {
			document.title = msg;
			Event.observe(window, 'focus', function () { document.title = window.orgDocTitle; });
		}
		else {
			document.title = document.title == msg ? ' ' : msg;
			this.titleLoop++;
			window.newChatMessageTimer = setTimeout(this.updateTitle.bind(this, msg), 500);
		}
	},

	onUserUpdate: function (user) {
		if (this.user.id == user.id) {
			this.WindowFrame.setUsername(user);
			this.ChatInfoPanel.setProfileImage(user);
			this.ChatInfoPanel.setName(user);
			this.MessagePanel.setUsername(user);
			this.user = user;
		}
	},

	addUserMessage: function (message) {
		this.shadow.sendMessage(message);
	},

	addSystemMessage: function (timestamp, message) {
		this.MessagePanel.addSystemMessage(timestamp, message);
	},

	closeClicked: function () {
		this.shadow.close();
	},

	onClose: function () {
		if (this.isPopup) {
			//window.close();
		}
	},

	notifyTyping: function (timeout) {
		this.shadow.notifyTyping(timeout);
	},

	popupClicked: function (width, height) {
		Arto.OpenPopup('/section/user/chat/chatwindow.aspx?sid=' + this.sid, 'ArtoChat' + this.sid, { width: width, height: height }, { scrollbars: 'no' });
		this.shadow.popup(this.session, false);
	},

	webcamClicked: function (playback) {
		if (this.isPopup) {
			if (this.session.activeWebcam) {
				if (!this.session.playbackid || this.session.playbackid == '') {
					this.shadow.startWebcam(this.session);
				}
				else {
					this.shadow.acceptWebcamInvite(this.session);
				}
			}
			if (this.gameActive) {
				this.WebcamContent = this.WindowFrame.Content;
				var width = this.orgDim.width - this.WindowFrame.FrameLeft.getWidth();
				var height = width / 4 * 3;
				this.WebcamPanel = new ChatLib.WebcamPanel(this.session, { width: width, height: height }, this.partnerUserID, true); ;
				this.WebcamContent.insert({ top: this.WebcamPanel });
				//this.WebcamPanel.resize(this.orgDim.width, this.WindowFrame.Top.getHeight() + 1 - 90);

				if (!playback) {
					this.shadow.startWebcam(this.session);
				}
				else {
					this.session.playbackid = playback;
					this.shadow.acceptWebcamInvite(this.session);
				}

				this.session.activeWebcam = true;

				this.MessagePanel.resize(this.MessagePanel.Width, this.MessagePanel.Height - height);
			}
			else {
				var height = document.viewport.getHeight() - 60 + 90;
				window.resizeTo(986, 637);
				var game = this.gameActive ? '&game=true' : '';
				this.closeBlocked = true;
				location.href = '/section/user/chat/chatwindow.aspx?sid=' + this.sid + '&webcam=true' + game + '&playback=' + playback;
			}
		}
		else if (!this.webcamPopup || this.webcamPopup.closed) {
			var width = 970;
			var height = 552;  //this.WindowFrame.WindowRoot.getHeight() - 60 + 90;
			this.webcamPopup = Arto.OpenPopup('/section/user/chat/chatwindow.aspx?sid=' + this.sid + '&webcam=true' + '&playback=' + playback, 'ArtoChat' + this.sid, { width: width, height: height }, { scrollbars: 'no' });
			this.closeBlocked = true;
			this.shadow.popup(this.session);
		}
		else if (!this.webcamPopup.closed) {
			this.webcamPopup.focus();
		}
	},

	webcamAccepted: function (playbackid) {
		this.webcamClicked(playbackid);
	},

	webcamDeclined: function (playbackid) {
		this.shadow.declineWebcamInvite(this.session, playbackid);
	},

	gameClicked: function (extraparams) {
		extraparams = extraparams || '';
		if (this.GamePanel && this.GamePanel.activeGame) {
			if (Prototype.Browser.IE) {
				this.closeBlocked = true;
			}
			this.GamePanel.showGameOptions();
		}
		else if (this.isPopup) {
			if (this.GamePanel) {
				//this.closeBlocked = true;
				this.GamePanel.showGameOptions();
			}
			else {
				//this.shadow.startWebcam(this.session, true);
				var height = 525;  //document.viewport.getHeight() - 60 + 90;
				window.resizeTo(986, 637);
				var webcam = this.session.activeWebcam ? '&webcam=true' : '';
				this.closeBlocked = true;
				location.href = '/section/user/chat/chatwindow.aspx?sid=' + this.sid + '&game=true' + webcam + extraparams;
			}
		}
		else if (!this.gamePopup || this.gamePopup.closed) {
			var width = 970;  //728 + 0;
			var height = 552;  //490;  //this.WindowFrame.WindowRoot.getHeight() - 60 + 90;
			this.closeBlocked = true;
			this.gamePopup = Arto.OpenPopup('/section/user/chat/chatwindow.aspx?sid=' + this.sid + '&game=true' + extraparams, 'ArtoChat' + this.sid, { width: width, height: height }, { scrollbars: 'no' });
			//CookieManager.setValue('ArtoChat', 'win' + this.sid, 'KeepAlive');
			this.shadow.popup(this.session, false);
		}
		else if (!this.gamePopup.closed) {
			this.gamePopup.focus();
		}
	},

	startGameClicked: function (game) {
		var width = 970;  //728 + 0;
		var height = 552;  //490;  //this.WindowFrame.WindowRoot.getHeight() - 60 + 90;
		this.closeBlocked = true;
		this.shadow.popup(this.session, false);
		this.gamePopup = Arto.OpenPopup('/section/user/chat/chatwindow.aspx?sid=' + this.sid + '&game=true&gameType=' + game, 'ArtoChat' + this.sid, { width: width, height: height }, { scrollbars: 'no' });
		//CookieManager.setValue('ArtoChat', 'win' + this.sid, 'KeepAlive');
	},

	handleGameInvite: function (invite) {
		if (invite.chatSessionID == this.sid) {
			this.MessagePanel.showGameOption(invite);
			this.session.lastMessage = new Date();
			this.gameInviteTimer = setTimeout(function (invite) {
				this.gameClient.timeout(invite);
				this.gameInviteTimer = null;
			} .bind(this, invite), 3600000);
		}
	},

	handleClearGame: function (invite) {
		if (invite.chatSessionID == this.sid) {
			this.MessagePanel.clearInvite(invite);
			if (this.gameInviteTimer) {
				clearTimeout(this.gameInviteTimer);
			}
		}
	},

	gameInviteRejected: function (invite) {
		this.gameClient.declineInvite(invite);
		if (this.gameInviteTimer) {
			clearTimeout(this.gameInviteTimer);
		}
	},

	gameInviteAccepted: function (invite) {
		if (this.gameInviteTimer) {
			clearTimeout(this.gameInviteTimer);
		}
		if (this.GamePanel) {
			if (this.GamePanel.activeGame) {
				//alert('gameInviteAccepted:Close');
				this.GamePanel.closeGame(this.sid);
			}
			this.GamePanel.loadGame({
				type: invite.game.iD,
				id: invite.gameID,
				server: invite.server
			});
		}
		else {
			this.gameClicked('&gameid=' + invite.gameID + '&gameserver=' + invite.server + '&gametype=' + invite.game.iD);
		}
	},

	collapseClicked: function () {
		this.shadow.minimize(this.session);
	},

	attachClicked: function () {
		this.closeBlocked = true;
		//CookieManager.removeValue('ArtoChat', 'win' + this.sid);
		this.dying = true;
		this.shadow.attach(this.session);
	},

	stopClose: function () {
		this.closeBlocked = true;
	},

	onWindowClose: function (e) {
		if (this.GamePanel) {
			//alert('onWindowClose:Close');
			this.GamePanel.closeGame(this.sid);
		}
		if (!this.closeBlocked) {
			var value = CookieManager.getValue('ArtoChat', 'win' + this.sid)
			if (value) {
				CookieManager.setValue('ArtoChat', 'win' + this.sid, 'Close');
			}
		}
		else {
			this.closeBlocked = false;
		}
	},

	refreshBanner: function (refreshTime) {
		if (this.advertisementPanel) {
			this.advertisementPanel.reload(refreshTime);
		}
	},

	setAlive: function () {
		//if (!this.dying) {
		CookieManager.setValue('ArtoChat', 'win' + this.sid, 'KeepAlive');
		//CookieManager.setValue('ArtoChat', 'win' + this.sid, new Date().getTime());
		//setTimeout(this.setAlive.bind(this), 500);
		//}
	}
});

/* File: /includes/js/framework/ChatLib/Visual/WindowFrame.js (Modified: 3. september 2010 12:30:56) */

ChatLib.WindowFrame = Class.create(Observable, {
	initialize: function(xpos, isPopup, visible, width, enableExtraContent) {
		this.typingDelay = 500;
		this.isPopup = isPopup;
		this.Handle = parseInt(Math.random() * (Math.pow(2, 32)));
		this.width = width;
		this.enableExtraContent = enableExtraContent;
		//var OFrame = "<div class='window' id='window_" + this.Handle + "'>";
		var OFrame = "<table style='position:absolute;top:0px;left0px;width: 100%;z-index:1000;' cellspacing='0' cellpadding='0' id='chatWindow_" + this.Handle + "' >";
		OFrame += "<tr><td colspan='2' class='frametop' id='window_frametop_" + this.Handle + "'></td></tr>";
		OFrame += "<tr>";
		OFrame += "<td class='frameleft' id='window_frameleft_" + this.Handle + "'></td>";
		OFrame += "<td class='framecontent' id='window_framecontent_" + this.Handle + "' valign='top'>";

		var popupIcon = '/grafik/kvikchat/window_expand.png';
		if (this.isPopup) {
			popupIcon = '/grafik/kvikchat/window_attach.png';
		}

		OFrame += " <div id='window_top_" + this.Handle + "' style='z-index:1000;'>";
		OFrame += "     <table class='top contentBoxHeaderBackgroundAltNotTransparent' cellspacing='0' cellpadding='0' style='width: 100%;'>";
		OFrame += "       <tr>";
		OFrame += "         <td><a id='chatUsernameCell_" + this.Handle + "'>Opponent</a><span id='chatTypingSpan_" + this.Handle + "'></span></td>";
		OFrame += "         <td align='right'><img src='http://artogfx.cloud2.artodata.com/sitegfx/grafik/kvikchat/window_colapse.png' class='cursorHand' id='chatCollapse_" + this.Handle + "' /><img src='" + popupIcon + "' class='cursorHand' id='chatMax_" + this.Handle + "' />" + (!this.isPopup ? "<img src='http://artogfx.cloud2.artodata.com/sitegfx/grafik/kvikchat/window_close.png' id='chatClose_" + this.Handle + "' style='width:15px;height:15px;border-width:0px;' class='cursorHand' />" : "") + "</td>";
		OFrame += "       </tr>";
		OFrame += "     </table>";
		OFrame += " </div>";

		OFrame += " <div class='content' id='window_content_" + this.Handle + "' style='z-index:1000;'></div>";

		OFrame += "</td>";
		OFrame += "<td class='frameright' id='window_frameright_" + this.Handle + "'></td>";
		OFrame += "</tr>";
		OFrame += "<tr><td colspan='3' class='framebottom' id='window_framebottom_" + this.Handle + "'></td></tr>";
		OFrame += "</table>";

		if (enableExtraContent) {
			//			OFrame = '<table cellpadding="0" cellspacing="0"><tr><td>' + OFrame + '</td>';
			//			OFrame += '<td style="vertical-align:top;" id="webcamPanel_' + this.Handle + '"></td>';
			//			OFrame += '</tr></table>';
		}

		this.WindowRoot = new Element('div', { 'class': 'window', id: 'window_' + this.Handle }).setStyle({ 'display': 'none' }); // $('window_' + this.Handle);
		if (!enableExtraContent) {
			this.WindowRoot.update(OFrame);
		}
		if (!this.isPopup) {
			this.iframeHack = new Element('iframe', { src: 'about:blank', scrolling: 'no', frameborder: 0 }).setStyle({ position: 'absolute', top: '0px', left: '0px', zIndex: '999' });
			this.WindowRoot.insert(this.iframeHack);
			this.WindowRoot.setStyle({ bottom: '23px' });
		}
		else {
			this.WindowRoot.setStyle({ bottom: '0px' });
		}



		if (enableExtraContent) {
			var newTable = new Element('table', { 'cellpadding': 0, 'cellspacing': 0 }).setStyle({ 'height': '100%', 'width': '100%' });
			var newTbody = new Element('tbody');
			var newRow = new Element('tr');
			var newContent = new Element('td', { id: 'contentCell', rowSpan: 2 }).setStyle({ verticalAlign: 'top', backgroundColor: '#AC956B', width: '245px' });
			newContent.update(OFrame);
			newRow.insert(newContent);
			this.ExtraContent = new Element('td', { align: 'right' }).setStyle({ verticalAlign: 'top', backgroundColor: '#AC956B' });
			newRow.insert(this.ExtraContent);
			newTbody.insert(newRow);

			var adrow = new Element('tr');
			this.AdContent = new Element('td', { align: 'center', id: 'adContainer', 'class': 'chatAdContainer' }).setStyle({ textAlign: 'center' });
			adrow.insert(this.AdContent);
			newTbody.insert(adrow)
			newTable.insert(newTbody);

			this.WindowRoot.update(newTable);

			/*

			var newTable = new Element('table', { 'cellpadding': 0, 'cellspacing': 0 });
			var newTbody = new Element('tbody');
			var newRow = new Element('tr');
			var newContent = new Element('td', { verticalAlign: 'top' });
			newRow.insert(newContent);
			this.ExtraContent = new Element('td', { align: 'right' }).setStyle({ verticalAlign: 'top' });
			newRow.insert(this.ExtraContent);
			newTbody.insert(newRow);
			var adrow = new Element('tr');
			this.AdContent = new Element('td', { colspan: 2, align: 'center' });
			adrow.insert(this.AdContent);
			newTbody.insert(adrow)
			newTable.insert(newTbody);

			//this.WindowRoot.update(newTable);
			this.Content.update(newTable);
			this.Content = newContent;
			//this.WebcamContent = $('webcamPanel_' + this.Handle);
			
			*/
		}
		document.body.appendChild(this.WindowRoot);
		this.Content = $('window_content_' + this.Handle);

		if (enableExtraContent) {
			this.MainContentWindow = $('chatWindow_' + this.Handle);
		}

		this.Top = $('window_top_' + this.Handle);
		this.FrameContent = $('window_framecontent_' + this.Handle);
		this.FrameTop = $('window_frametop_' + this.Handle);
		this.FrameBottom = $('window_framebottom_' + this.Handle);
		this.FrameRight = $('window_frameright_' + this.Handle);
		this.FrameLeft = $('window_frameleft_' + this.Handle);
		this.CloseButton = $('chatClose_' + this.Handle);
		this.PopupButton = $('chatMax_' + this.Handle);
		this.CollapseButton = $('chatCollapse_' + this.Handle);
		this.UsernameCell = $('chatUsernameCell_' + this.Handle);
		this.TypingElm = $('chatTypingSpan_' + this.Handle);

		if (enableExtraContent) {
			this.FrameRight.setStyle({ width: '0px' });
			this.FrameBottom.setStyle({ height: '0px' });
		}

		if (this.CloseButton) {
			this.CloseButton.observe('click', this.closeClicked.bind(this));
		}
		this.PopupButton.observe('click', this.popupClicked.bind(this));
		this.CollapseButton.observe('click', this.collapseClicked.bind(this));

		if (this.isPopup) {
			this.CollapseButton.hide();
		}

		setTimeout(function(visible) {
			if (typeof this.visible == 'undefined' || visible == true) {
				this.WindowRoot.show()
			}
			var xPosMax = document.viewport.getWidth() - this.width;
			if (xpos > xPosMax) {
				xpos = xPosMax;
			}
			this.WindowRoot.setStyle({ right: xpos + 'px' });
			//this.WindowRoot.setStyle({ left: xpos + 'px' });
		} .bind(this, visible), 1);

		//new Draggable(this.WindowRoot, { handle: this.Top, snap: this.snapHandler.bind(this) });
	},

	toggle: function(xPos, msgPanel) {
		if (this.WindowRoot.visible()) {
			this.hide();
		}
		else {
			this.show(xPos, msgPanel);
		}
	},

	hide: function() {
		this.WindowRoot.hide();
		this.visible = false;
	},

	show: function(xpos, msgPanel) {
		var xPosMax = document.viewport.getWidth() - this.width;
		if (xpos > xPosMax) {
			xpos = xPosMax;
		}
		this.WindowRoot.setStyle({ right: xpos + 'px' });
		//this.WindowRoot.setStyle({ left: xpos + 'px' });
		this.WindowRoot.show();
		this.visible = true;
		msgPanel.scrollToBottom();
	},

	move: function(xpos) {
		this.WindowRoot.setStyle({ right: (xpos + 2) + 'px' });
	},

	destroy: function() {
		this.WindowRoot.remove();
	},

	isTyping: function(obj) {
		var timeout = obj.isTyping;
		if (this.isTypingTimer) {
			clearTimeout(this.isTypingTimer);
		}
		this.isTypingTimer = setTimeout(this.handleTyping.bind(this, timeout - this.typingDelay), this.typingDelay);
	},

	handleTyping: function(timeout) {
		if (this.TypingElm.innerHTML == '.....') {
			this.TypingElm.update('.');
		}
		else {
			this.TypingElm.innerHTML += '.';
		}
		if (timeout <= 0) {
			this.isTypingTimer = null;
			this.TypingElm.update();
		}
		else {
			this.isTypingTimer = setTimeout(this.handleTyping.bind(this, timeout - this.typingDelay), this.typingDelay);
		}
	},

	newMessage: function() {
		if (this.isTypingTimer) {
			clearTimeout(this.isTypingTimer);
			this.isTypingTimer = null;
			this.TypingElm.update();
		}
	},

	setUsername: function(user) {
		if(user.username){
			var onlineInfo = Arto.GetOnlineInfo(user.online, user.onlineStatus);
			this.UsernameCell.update();
			this.UsernameCell.appendChild(onlineInfo.icon);
			var link = new Element('a', { href: '/section/user/profile/?id=' + user.id, target: 'hovedside' }).setStyle({ marginLeft: '3px' }).update(user.username);
			this.UsernameCell.appendChild(link);
		}
	},

	resize: function(width, height, orgWidth) {
		this.width = width;
		var extrawidth = this.enableExtraContent ? 0 : 0;
		this.WindowRoot.setStyle({ width: (width + extrawidth) + "px", height: (height) + "px" });
		//this.WindowRoot.style.width = (width + extrawidth) + "px";
		//this.WindowRoot.style.height = (height) + "px";
		if (!this.isPopup) {
			this.WindowRoot.setStyle({ bottom: '49px' });
			this.iframeHack.setStyle({ width: (width) + 'px', height: height + 'px' });
			setTimeout(function() {
				this.iframeHack.setStyle({ width: this.WindowRoot.getWidth() + 'px', height: (this.WindowRoot.getHeight() + 23) + 'px' });
			} .bind(this), 1);
		}
		else {
			this.WindowRoot.setStyle({ bottom: '0px' });
		}
		this.Width = orgWidth || width;
		this.Height = height;
		this.InnerWidth = this.Width - this.FrameRight.getWidth() - this.FrameLeft.getWidth();
		//if (Prototype.Browser.IE) {
			this.InnerWidth = this.InnerWidth - 2;
		//}
		this.InnerHeight = this.Height - this.FrameTop.getHeight() - this.FrameBottom.getHeight() - this.Top.getHeight();

		if (this.enableExtraContent) {
			this.InnerWidth = this.InnerWidth; // -728;  //484;
			this.InnerHeight = this.InnerHeight;
		}

		this.Top.style.width = this.InnerWidth + "px";
		this.Content.style.width = this.InnerWidth + "px";
		this.Content.style.height = this.InnerHeight + "px";

		if (this.MainContentWindow && orgWidth) {
			this.MainContentWindow.setStyle({ width: orgWidth + 'px' });
		}
	},

	//	snapHandler: function(x, y, obj) {
	//		this.boundary = $(document.body).getWidth() - $(obj.element).getWidth();

	//		this.friendBoxBoundary = {
	//			x: this.boundary - 320,
	//			y: 520
	//		};

	//		x = x < 0 ? 0 : (x > this.boundary ? this.boundary : x);
	//		y = y < 0 ? 0 : y;

	//		if (x >= this.friendBoxBoundary.x && y < this.friendBoxBoundary.y) {
	//			x = this.friendBoxBoundary.x;
	//		}
	//		return [x, y];
	//	},

	closeClicked: function() {
		this.fire('CloseClicked', this);
	},

	getWidth: function() {
		return this.WindowRoot.getWidth();
	},

	getHeight: function() {
		return this.WindowRoot.getHeight();
	},

	popupClicked: function() {
		if (this.isPopup) {
			this.fire('AttachClicked');
		}
		else {
			this.fire('PopupClicked', this.WindowRoot.getWidth(), this.WindowRoot.getHeight());
		}
	},

	collapseClicked: function() {
		this.fire('CollapseClicked');
	}
});

/* File: /includes/js/framework/ChatLib/Visual/ChatInfoPanel.js (Modified: 3. september 2010 12:30:56) */

ChatLib.ChatInfoPanel = Class.create(Observable, {
	initialize: function(chatwindow, user, webcamEnabled, gameEnabled) {
		this.ChatWindow = chatwindow;
		this.Handle = chatwindow.Handle;

		this.webcamEnabled = webcamEnabled
		this.gameEnabled = gameEnabled
		this.user = user;

		this.uid = new Date().getTime();

		var img = Arto.GetProfileImagePath(user.id, user.gotPicture, user.pictureUpdatedTime, ProfileImageSize.Small);
		//var img = Arto.GetProfileImagePath(user.id, user.gotPicture, new Date(), ProfileImageSize.Small);
		var target = this.ChatWindow.isPopup ? " target='_blank'" : "";

		var OFrame = "<table style='width: 100%;' class='chatInfo' cellspacing='3' cellpadding='1'>";
		OFrame += "<tr>";
		OFrame += "<td style='width:33px;'><a href='/section/user/profile/?id=" + user.id + "'" + target + "><img src='" + img + "' style='width: 33px; height: 44px;border-width:0px;' id='profileImage_" + this.uid + "' /></a></td>";
		OFrame += "<td style='vertical-align:top;padding-left:2px;' id='func_" + this.uid + "'></td>";
		OFrame += "</tr>";
		OFrame += "</table>";

		this.element = document.createElement("div");
		this.element.innerHTML = OFrame;
		this.ChatWindow.Content.appendChild(this.element);
		this.element = $(this.element);

		this.profileImage = $('profileImage_' + this.uid);
		this.functions = $('func_' + this.uid);
		var tmpName = '';
		if(user.userType == 'Arto'){
			if (user.firstname) {
				tmpName = user.firstname + ' ' + user.lastname;
			}
		}
		else{
			tmpName = 'Opponent';
		}
		this.name = new Element('div').setStyle({ marginTop: '0px', color: '#AC9778', fontSize: '14px' }).update(tmpName);
		this.functions.appendChild(this.name);

		var webcamLabel = this.webcamEnabled ? 'Stop webcam' : 'Start webcam';
		var gameLabel = this.gameEnabled ? 'Choose game' : 'Start game';
		var buttons = new Element('table', { cellPadding: 0, cellSpacing: 0 }).setStyle({ marginTop: '15px' }).update(
			new Element('tbody').update(
				new Element('tr').insert(
					new Element('td').insert(
						this.getButtonElm('http://artogfx.cloud2.artodata.com/sitegfx/grafik/kvikchat/onlinechat_webcam.png', webcamLabel, this.startWebcamClicked.bind(this))
					)
				).insert(
					new Element('td').setStyle({ paddingLeft: '8px' }).insert(
						this.getButtonElm('http://artogfx.cloud2.artodata.com/sitegfx/grafik/kvikchat/onlinechat_games.png', gameLabel, this.startGameClicked.bind(this))
					)
				)
			)
		);
		this.functions.insert(buttons);
	},

	getButtonElm: function(imgSrc, linkText, handler) {
		return new Element('table', { cellPadding: 0, cellSpacing: 0 }).update(
			new Element('tbody').update(
				new Element('tr').insert(
					new Element('td').update(
						new Element('img', { src: imgSrc }).setStyle({ width: '15px', height: '15px', borderWidth: '0px' })
					)
				).insert(
					new Element('td').setStyle({ paddingLeft: '3px' }).update(
						new Element('a', { href: 'JavaScript:void(0);' }).setStyle({ fontSize: '10px' }).update(linkText).observe('click', handler)
					)
				)
			)
		);
	},

	startWebcamClicked: function() {
		//alert('Kommer senere...');
		if(this.user.userType == 'Arto'){
			this.fire('WebcamClicked');
		}
		else{
			alert('Kommer senere...');
		}
	},

	startGameClicked: function() {
		if(this.user.userType == 'Arto'){
			this.fire('GameClicked');
		}
		else{
			alert('Kommer senere...');
		}
	},

	setName: function(user) {
		this.name.update(user.firstname + ' ' + user.lastname);
	},

	setProfileImage: function(user) {
		this.profileImage.src = Arto.GetProfileImagePath(user.id, user.gotPicture, user.pictureUpdatedTime, ProfileImageSize.Small);
	},

	destroy: function() {
		this.element.remove();
	},

	resize: function(width, height) {
		this.Height = height;
		this.Width = width;
		this.element.setStyle({
			'height': this.Height + "px",
			'width': this.Width + "px"
		});
	}
});

/* File: /includes/js/framework/ChatLib/Visual/InputPanel.js (Modified: 3. september 2010 12:30:56) */

ChatLib.InputPanel = Class.create({
	initialize: function(chatwindow, enabled, user) {
		this.enabled = enabled;
		this.user = user;

		this.ChatWindow = chatwindow;
		this.Handle = this.ChatWindow.Handle;
		var OFrame = "<table style='width: 100%' cellspacing='0' cellpadding='0'>";
		OFrame += "<tr>";
		OFrame += "<td></td>";
		OFrame += "<td align='center' valign='middle'><textarea id='InputPanel_InputField_" + this.Handle + "'></textarea></td>";
		OFrame += "</tr>";
		OFrame += "</table>";

		this.element = document.createElement("div");
		this.element.innerHTML = OFrame;
		this.ChatWindow.Content.appendChild(this.element);
		this.element = $(this.element);

		this.InputField = $('InputPanel_InputField_' + this.Handle);
		this.InputField.observe("keydown", this.onkeydown.bindAsEventListener(this));
		this.InputField.observe("keyup", this.onkeyup.bindAsEventListener(this));

		if (!this.enabled) {
			this.InputField.disabled = true;
		}

	},

	destroy: function() {
		this.element.remove();
	},

	switchBold: function() {
		if(this.user.userType != 'Arto'){
			return;
		}
		if (this.isbold) {
			this.InputField.setStyle({ fontWeight: '' });
			this.isbold = false;
		}
		else {
			this.InputField.setStyle({ fontWeight: 'bold' });
			this.isbold = true;
		}
		this.InputField.focus();
	},

	switchItalic: function() {
		if(this.user.userType != 'Arto'){
			return;
		}
		if (this.isitalic) {
			this.InputField.setStyle({ fontStyle: '' });
			this.isitalic = false;
		}
		else {
			this.InputField.setStyle({ fontStyle: 'italic' });
			this.isitalic = true;
		}
		this.InputField.focus();
	},

	switchUnderlined: function() {
		if(this.user.userType != 'Arto'){
			return;
		}
		if (this.isunderlined) {
			this.InputField.setStyle({ textDecoration: '' });
			this.isunderlined = false;
		}
		else {
			this.InputField.setStyle({ textDecoration: 'underline' });
			this.isunderlined = true;
		}
		this.InputField.focus();
	},

	setColor: function(color) {
		if(this.user.userType != 'Arto'){
			return;
		}
		this.InputField.setStyle({ color: '#' + color });
		this.color = color;
		this.InputField.focus();
	},

	insertSmiley: function() {
		if(this.user.userType != 'Arto'){
			return;
		}
		Arto.OpenSmileyPopup(this.InputField.id, this.Handle);
	},

	enableInput: function() {
		this.InputField.disabled = false;
	},

	disableInput: function() {
		this.InputField.disabled = true;
	},

	resize: function(width, height) {
		this.Height = height;
		this.Width = width;
		this.element.setStyle({
			'height': this.Height + "px",
			'width': this.Width + "px"
		});
		this.InputField.setStyle({
			'width': (this.Width - 4) + "px",
			'height': (this.Height - 1) + "px"
		});
	},

	onkeydown: function(event) {
		if(this.user.userType != 'Arto'){
			return;
		}
		if (event.keyCode == 13 && !this.ieEventFired) {
			if (event.ctrlKey || event.altKey || event.shiftKey) {
				this.InputField.value += "\n";
				Event.stop(event);
				return false;
			}
			else {
				var msg = this.getMessage();
				if (!msg.empty()) {
					this.lastIsTyping = null;
					this.ChatWindow.addUserMessage(this.getMessage());
					this.InputField.value = '';
					setTimeout(function() { this.InputField.value = ''; } .bind(this), 10); //Hack to prevent new line in inputfield
				}
				Event.stop(event);
				return false;
			}
		}
		else {
			var now = new Date().getTime();
			if (!this.lastIsTyping || (now - this.lastIsTyping) >= 5000) {
				this.lastIsTyping = now;
				this.ChatWindow.notifyTyping(30000);
			}
			return true;
		}
	},

	onkeyup: function(e) {
		if(this.user.userType != 'Arto'){
			return;
		}
		if (this.lastIsTyping && this.InputField.value.empty()) {
			this.lastIsTyping = null;
			this.ChatWindow.notifyTyping(0);
		}
	},

	getMessage: function() {
		var msg = this.InputField.value;
		if (msg && !msg.empty()) {
			if (this.isbold) {
				msg = '<b>' + msg + '</b>';
			}
			if (this.isitalic) {
				msg = '<i>' + msg + '</i>';
			}
			if (this.isunderlined) {
				msg = '<u>' + msg + '</u>';
			}
			if (this.color) {
				msg = '[color:#' + this.color + ']' + msg + '[/color]';
			}
		}
		return msg;
	}
});

/* File: /includes/js/framework/ChatLib/Visual/MessagePanel.js (Modified: 3. september 2010 12:30:56) */

ChatLib.MessagePanel = Class.create(Observable, {
	initialize: function(chatwindow, session, user) {
		this.session = session;
		this.messageElements = new Hash();
		this.messages = new Array();

		this.ChatWindow = chatwindow;
		this.Handle = chatwindow.Handle;
		var OFrame = "<table style='width: 100%;' cellspacing='0' cellpadding='0'>";
		OFrame += "<tr>";
		OFrame += "<td><div id='Console_" + this.Handle + "' class='console'></div></td>";
		OFrame += "</tr>";
		OFrame += "</table>";

		this.element = document.createElement("div");
		this.element.innerHTML = OFrame;
		this.ChatWindow.Content.appendChild(this.element);
		this.element = $(this.element);

		this.Console = $('Console_' + this.Handle);

		if(user && user.userType != 'Arto'){
			this.addSystemMessage(new Date(), 'The chat is not currently supported against this apponent');
		}
	},

	destroy: function() {
		this.element.remove();
	},

	resize: function(width, height) {
		this.Height = height;
		this.Width = width;
		this.element.setStyle({
			'height': this.Height + "px",
			'width': (this.Width) + "px"
		});
		this.Console.setStyle({
			'height': this.Height + "px",
			'width': (this.Width) + "px"
		});
	},

	scrollToBottom: function() {
		setTimeout(function() { this.Console.scrollTop = this.Console.scrollHeight } .bind(this), 1);
	},

	addUserMessage: function(timestamp, user, message, options) {
		if (message.message) {
			var msgElm = this.getMsgElm(message, user, timestamp, options);
			this.Console.appendChild(msgElm.table);
			this.scrollToBottom();

			var arr = this.messageElements.get(user.id);
			if (!arr) {
				this.messageElements.set(user.id, new Array());
			}
			this.messageElements.get(user.id).add({ username: msgElm.name });

			this.messages.add(message);

			if (this.messages.length >= 10 && !this.moreLinkAdded) {
				this.moreElm = new Element('div', { 'class': 'watchMore' }).update(
				new Element('a', { href: 'javascript:void(0);' }).update('See more...').observe('click', this.moreClicked.bind(this))
			);
				this.Console.insert({ top: this.moreElm });
				this.moreLinkAdded = true;
			}
		}
	},

	getMsgElm: function(message, user, timestamp, options) {
		var opt = Object.extend({
			'class': 'message',
			msgClass: 'messageContent',
			usernameClass: 'fontNote messageUsername',
			timestampClass: 'fontNote messageTimestamp'
		}, options);

		var msgTable = new Element('table', { id: 'chatMessage_' + message.id, 'class': opt['class'], 'cellPadding': 0, 'cellSpacing': 0 });
		var msgBody = new Element('tbody');

		var infoRow = new Element('tr');
		var nameCell = new Element('td', { 'class': opt.usernameClass }).update(user.username);
		infoRow.appendChild(nameCell);
		var timeCell = new Element('td', { 'class': opt.timestampClass }).update(new ChatLib.Timestamp(timestamp));
		infoRow.appendChild(timeCell);
		msgBody.appendChild(infoRow);

		var msgRow = new Element('tr');
		var msgCell = new Element('td', { 'class': opt.msgClass, 'colspan': 2 }).update(message.message);
		msgRow.appendChild(msgCell);
		msgBody.appendChild(msgRow);

		msgTable.appendChild(msgBody);
		return { table: msgTable, name: nameCell };
	},

	moreClicked: function() {
		var params = {
			m: 'getmessages',
			session: this.session.id,
			message: this.messages[0].id
		};
		new Ajax.Request('/section/chat/ChatAjax.ashx', {
			parameters: params,
			onSuccess: this.handleOldMessages.bind(this)
		});
	},

	handleOldMessages: function(response) {
		var messages = response.responseJSON;
		if (messages) {
			this.moreElm = this.moreElm.remove();
			var chosenID = this.messages[0].id;

			this.messages.reverse();
			for (var i = messages.length - 1; i > 0; i--) {
				var msg = messages[i];
				this.Console.insert({ top: this.getMsgElm(msg, this.session.getUser(msg.userID), msg.writtenTime).table });
				this.messages[this.messages.length] = msg;
			}
			this.messages.reverse();

			setTimeout(function(chosenID) {
				var elm = $('chatMessage_' + chosenID);
				if (elm) {
					elm.scrollIntoView();
				}
			} .bind(this, messages[messages.length - 1].id), 1);

			if (messages.length >= 10) {
				this.Console.insert({ top: this.moreElm });
			}
		}
	},

	setUsername: function(user) {
		var messages = this.messageElements.get(user.id);
		if (messages) {
			messages.each(function(msg) {
				msg.username.update(user.username);
			});
		}
	},

	addSystemMessage: function(timestamp, message) {
		var id = new Date().getTime();
		message = '<b>' + message + '</b>';
		
		var elm = new Element('div', {id: 'chatMessage_' + id}).update(message);
		this.Console.insert(elm);
		if(this.gameOptions){
			setTimeout(function() { this.gameOptions.scrollIntoView(); } .bind(this), 1);
		}
//		this.addUserMessage(timestamp, { id: 13610, username: 'Arto' }, { id: id, message: message }, { usernameClass: 'systemName' });
		return id;
	},

	removeMessage: function(id) {
		var elm = $('chatMessage_' + id);
		if (elm) {
			elm.remove();
		}
	},

	showGameOption: function(invite) {
		if (this.gameOptions) {
			this.gameOptions.remove();
			this.gameOptions = null;
		}
		var yesButton = new ArtoButton('Yes', {
			buttonClass: 'Green',
			onClick: this.gameYesClicked.bind(this, invite),
			url: 'javascript:void(0);'
		});
		var noButton = new ArtoButton('No', {
			buttonClass: 'Red',
			onClick: this.gameNoClicked.bind(this, invite),
			url: 'javascript:void(0);'
		});
		this.gameOptions = new Element('table', { 'cellpadding': '0', 'cellspacing': '0' }).insert(
			new Element('tbody').insert(
				new Element('tr').insert(
					new Element('td').insert(
						new Element('img', { src: invite.game.thumbUrl }).setStyle({ width: '80px', height: '56px', marginLeft: '5px' })
					)
				).insert(
					new Element('td').setStyle({ verticalAlign: 'top' }).insert(
						new Element('table').insert(
							new Element('tbody').insert(
								new Element('tr').insert(
									new Element('td', { 'colspan': '2' }).update('Would you like to play? :-)')
								)
							).insert(
								new Element('tr').insert(
									new Element('td').update(yesButton)
								).insert(
									new Element('td').update(noButton)
								)
							)
						)
					)
				)
			)
		);
		this.Console.insert(this.gameOptions);
		setTimeout(function() { this.gameOptions.scrollIntoView(); } .bind(this), 1);
	},

	clearInvite: function(invite) {
		if (this.gameOptions) {
			this.gameOptions.remove();
			this.gameOptions = null;
		}
	},

	gameYesClicked: function(invite) {
		this.gameOptions.remove();
		this.gameOptions = null;
		this.fire('AcceptGameInvite', invite);
	},

	gameNoClicked: function(invite) {
		this.gameOptions.remove();
		this.gameOptions = null;
		this.fire('RejectGameInvite', invite);
	},

	showWebcamOption: function(username, playbackid) {
		if (this.webcamOption) {
			this.webcamOption.remove();
			this.webcamOption = null;
		}
		var yesButton = new ArtoButton('Yes', {
			buttonClass: 'Green',
			onClick: this.webcamYesClicked.bind(this, playbackid),
			url: 'javascript:void(0);'
		});
		var noButton = new ArtoButton('No', {
			buttonClass: 'Red',
			onClick: this.webcamNoClicked.bind(this, playbackid),
			url: 'javascript:void(0);'
		});
		this.webcamOption = new Element('table', { 'cellpadding': '0', 'cellspacing': '0' }).insert(
			new Element('tbody').insert(
				new Element('tr').insert(
					new Element('td').update('A webcam chat has been started with you. Would you like to participate?')
				)
			).insert(
				new Element('tr').insert(
					new Element('td').insert(
						new Element('table').insert(
							new Element('tbody').insert(
								new Element('tr').insert(
									new Element('td').update(yesButton)
								).insert(
									new Element('td').update(noButton)
								)
							)
						)
					)
				)
			)
		);
		this.Console.insert(this.webcamOption);
		setTimeout(function() { this.webcamOption.scrollIntoView(); } .bind(this), 1);
	},

	webcamYesClicked: function(playbackid) {
		this.fire('WebcamAccepted', playbackid);
		this.webcamOption.remove();
	},

	webcamNoClicked: function(playbackid) {
		this.fire('WebcamDeclined', playbackid);
		this.webcamOption.remove();
	}
});

/* File: /includes/js/framework/ChatLib/Visual/StatusBarPanel.js (Modified: 3. september 2010 12:30:56) */

ChatLib.StatusBarPanel = Class.create(Observable, {
	initialize: function(chatwindow, user) {
		this.typingDelay = 500;
		this.ChatWindow = chatwindow;
		this.Handle = chatwindow.Handle;
		this.user = user;

		var OFrame = "<table style='width: 100%' cellspacing='0' cellpadding='0' class='statusBar'>";
		OFrame += "<tr>";
		OFrame += "<td id='StatusLabel_" + this.Handle + "' align='left'></td>";
		OFrame += "<td id='ChatFunctions_" + this.Handle + "' align='right'></td>";
		OFrame += "</tr>";
		OFrame += "</table>";

		this.element = document.createElement("div");
		this.element.innerHTML = OFrame;
		this.ChatWindow.Content.appendChild(this.element);
		this.element = $(this.element);

		this.StatusLabel = $('StatusLabel_' + this.Handle);
		this.functions = $('ChatFunctions_' + this.Handle);
		this.setLabel();
		this.setFunctions();

		if (!window.colorChanged) {
			window.colorChanged = Prototype.emptyFunction;
		}
	},

	setLabel: function() {
		this.label = new Element('div', { 'class': 'chatStatusLabel', title: 'Last message received' });
		this.StatusLabel.insert(this.label);
	},

	setFunctions: function() {
		this.functions.insert(
			new Element('div').insert(
				this.getFunctionElm('/grafik/kvikchat/txtedit_emoticons.png', 'Insert smiley', this.smileyClicked.bind(this), true)
			).insert(this.getPipe()).insert(
				this.getFunctionElm('/grafik/kvikchat/txtedit_bold.png', 'Cool', this.boldClicked.bind(this), true)
			).insert(this.getPipe()).insert(
				this.getFunctionElm('/grafik/kvikchat/txtedit_italic.png', 'Italics', this.italicClicked.bind(this), true)
			).insert(this.getPipe()).insert(
				this.getFunctionElm('/grafik/kvikchat/txtedit_underline.png', 'Underlined', this.underlineClicked.bind(this), true)
			).insert(this.getPipe()).insert(
				this.getFunctionElm('/grafik/kvikchat/txtedit_color.png', 'Change colour', this.colorClicked.bind(this), false)
			)
		);
	},

	getFunctionElm: function(imgSrc, title, handler, withMargin) {
		var result = new Element('img', { src: imgSrc, 'class': 'cursorHand', title: title }).setStyle({
			width: '10px',
			height: '10px',
			borderWidth: '0px'
		}).observe('click', handler);
		if (withMargin) {
			result.setStyle({ marginRight: '3px' });
		}
		return result;
	},

	getPipe: function() {
		return new Element('span').setStyle({ color: '#C6B08B', marginRight: '3px', fontSize: '16px' }).update('|');
	},

	smileyClicked: function() {
		if(this.user.userType != 'Arto'){
			return;
		}
		this.fire('SmileyClicked');
	},

	boldClicked: function() {
		if(this.user.userType != 'Arto'){
			return;
		}
		this.fire('BoldClicked');
	},

	italicClicked: function() {
		if(this.user.userType != 'Arto'){
			return;
		}
		this.fire('ItalicClicked');
	},

	underlineClicked: function() {
		if(this.user.userType != 'Arto'){
			return;
		}
		this.fire('UnderlinedClicked');
	},

	colorClicked: function() {
		if(this.user.userType != 'Arto'){
			return;
		}
		if (!this.popwin || this.popwin.closed) {
			var params = '';
			if (this.color) {
				params = '?color=' + this.color;
			}
			this.popwin = Arto.OpenPopup('/section/common/ColorPicker.aspx' + params, this.Handle, { width: 280, height: 270 });
			this.setPopWinHandler();
		}
		else {
			this.popwin.focus();
		}
	},

	setPopWinHandler: function() {
		var pageReady = false;
		try {
			pageReady = this.popwin && this.popwin.UpdateOpener;
		}
		catch (e) { }
		if (pageReady) {
			this.popwin.UpdateOpener = function(input) {
				this.color = input;
				this.fire('ColorChanged', input);
			} .bind(this);
		}
		else {
			setTimeout(this.setPopWinHandler.bind(this), 100);
		}
	},

	destroy: function() {
		this.element.remove();
	},

	isTyping: function(obj) {
		var timeout = obj.isTyping;
		if (this.isTypingTimer) {
			clearTimeout(this.isTypingTimer);
		}
		if (!this.label.innerHTML.startsWith('writing')) {
			this.lastMsg = this.label.innerHTML;
		}
		this.handleTyping(timeout);
		//this.isTypingTimer = setTimeout(this.handleTyping.bind(this, timeout - this.typingDelay), this.typingDelay);
	},

	handleTyping: function(timeout) {
		if (this.label.innerHTML == 'writing.....' || this.label.innerHTML == this.lastMsg) {
			this.label.update('writing');
		}
		else {
			this.label.innerHTML += '.';
		}
		if (timeout <= 0) {
			this.isTypingTimer = null;
			this.label.update(this.lastMsg);
			this.last = 'Last message received';
		}
		else {
			this.isTypingTimer = setTimeout(this.handleTyping.bind(this, timeout - this.typingDelay), this.typingDelay);
		}
	},

	setLastMessage: function(date) {
		if (this.isTypingTimer) {
			clearTimeout(this.isTypingTimer);
			this.isTypingTimer = null;
		}
		this.label.update(date);
	},

	resize: function(width, height) {
		this.Height = height;
		this.Width = width;
		this.element.setStyle({
			'height': this.Height + "px",
			'width': this.Width + "px"
		});
	}
});

/* File: /includes/js/framework/ChatLib/Visual/TaskBar.js (Modified: 3. september 2010 12:30:56) */

ChatLib.TaskBar = Class.create(Observable, {
	initialize: function() {
		this.TaskBarFrame = new ChatLib.TaskBarFrame();
		this.TaskBarFrame.observe('closeAllClicked', this.closeAllClicked.bind(this));

		this.Handle = this.TaskBarFrame.Handle;

		//this.TaskBarTabs = new Array();
		this.TaskBarTabs = new Hash();

		this.TaskBarElement = $("taskbar_" + this.Handle);
		this.TaskBarElement.observe("taskbarshadow:StartChat", this.startChat.bindAsEventListener(this));
		this.TaskBarElement.observe("taskbarshadow:EndChat", this.endChat.bindAsEventListener(this));
		this.TaskBarElement.observe("taskbarshadow:FriendIsTyping", this.friendIsTyping.bindAsEventListener(this));
		this.TaskBarElement.observe("taskbarshadow:FriendStoppedTyping", this.friendStoppedTyping.bindAsEventListener(this));
		this.TaskBarElement.observe("taskbarshadow:FriendRemoved", this.friendRemoved.bindAsEventListener(this));
		this.TaskBarElement.observe("taskbarshadow:NewMessage", this.newMessage.bindAsEventListener(this));
		
		this.gameClient = GameLib.Client.getInstance();
		this.gameClient.observe('Invite', this.handleGameInvite.bind(this));

		document.body.appendChild(new Element('div').setStyle({ height: this.TaskBarElement.getHeight() + 'px' }));
	},

	// Event handlers
	startChat: function(event) {
		var session = event.memo.session;
		var shadowWin = event.memo.win;
		var user = '';
		for (var i = 0; i < session.users.values().length; i++) {
			var tmpUser = session.users.values()[i];
			if (tmpUser.id != CurrentUser.id) {
				user = tmpUser;
				break;
			}
		}
		if (this.TaskBarTabs.keys().length == 0) {
			this.TaskBarFrame.show();
			setTimeout(function() { activeChat = true; }, 1);
		}
		var tab = this.addTab(session.id, user, "black", shadowWin);
		this.organizeTabs();
		var window = new ChatLib.ChatWindow(244, 360, shadowWin, user, tab.getXPos(), session);
		if (parseInt(session.getStateValue('windowState')) == ChatLib.WindowState.Minimized) {
			var minTime = parseInt(session.getStateValue('minimizedTime'));
			if (minTime > 0) {
				var lastMsgTime = parseInt(session.getStateValue('lastMsgTime'));
				if (lastMsgTime > 0) {
					if (lastMsgTime > minTime) {
						tab.setHighlightColor();
					}
				}
			}
		}
		//window.observe('ChatWindow:Minimize', this.minimizeWindow.bind(this));
		window.observe('ChatWindow:Maximize', this.minimizeWindows.bind(this));
		ChatLib.VisualManager.addChatWindow(session.id, window);
		tab.window = window;
		//this.minimizeWindows(session.id);
	},

	organizeTabs: function() {
		var tabs = this.TaskBarTabs.values();
		var barWidth = this.TaskBarFrame.getWidth() - 6;
		var tabWidth = (barWidth / tabs.length).floor() - 11;
		tabs.invoke('resize', tabWidth, tabs.length, this.TaskBarFrame.getWidth());
	},

	organizeWindows: function() {
		var tabs = this.TaskBarTabs.values();
		for (var i = 0; i < tabs.length; i++) {
			var tab = tabs[i];
			var win = ChatLib.VisualManager.getChatWindow(tab.sid);
			if (win) {
				win.move(tab.getXPos());
			}
		}
	},

	endChat: function(event) {
		var session = event.memo;
		this.removeTab(session);
		var win = ChatLib.VisualManager.getChatWindow(session);
		if (win) {
			win.destroy();
			ChatLib.VisualManager.removeChatWindow(session);
		}
		if (this.TaskBarTabs.keys().length == 0) {
			this.TaskBarFrame.hide();
			setTimeout(function() { activeChat = false; }, 1);
		}
		else {
			this.organizeWindows();
		}
	},
	
	handleGameInvite : function(invite) {
		try {
			var tab = this.TaskBarTabs.get(invite.chatSessionID);
			if (tab) {
				var winShadow = ChatLib.ShadowManager.getChatWindow(invite.chatSessionID);
				if (winShadow.isMinimized()) {
					tab.highlight();
				}
			}
		} catch (ex) {
			alert(ex.message);
		}
	},

	setUser: function(sid, user) {
		var tab = this.TaskBarTabs.get(sid);
		if (tab) {
			tab.setUsername(user);
		}
	},

	friendIsTyping: function(event) {
		var session = event.memo;
		var tab = this.TaskBarTabs.get(session.id);
		tab.startBlink();
	},

	friendStoppedTyping: function(event) {
		var session = event.memo;
		var tab = this.TaskBarTabs.get(session.id);
		tab.stopBlink();
	},

	friendRemoved: function(event) {
		var session = event.memo;
	},

	newMessage: function(event) {
		var message = event.memo.message;
		var tab = this.TaskBarTabs.get(message.session.id);
		if (tab) {
			var win = ChatLib.VisualManager.getChatWindow(message.session.id);
			var winShadow = ChatLib.ShadowManager.getChatWindow(message.session.id);
			var tab = this.TaskBarTabs.get(message.session.id);
			if (win && winShadow && tab) {
				if (!this.hasOpenWindow() && !winShadow.isMinimized()) {
					win.show(tab.getXPos());
					this.minimizeWindows(message.session.id);
				}
				else if (winShadow.isMinimized()) {
					tab.highlight();
					this.fire('TaskBarTab:LastMsgUpdate', message.session);
				}
			}
		}
	},

	hasOpenWindow: function() {
		var wins = ChatLib.VisualManager.windows.values();
		for (var i = 0; i < wins.length; i++) {
			if (wins[i].visible) {
				return true;
			}
		}
		return false;
	},

	addTab: function(sid, user, color, shadowWin) {
		if (this.TaskBarTabs.get(sid) != null) {
			return;
		}
		var element = $('taskbar_' + this.TaskBarFrame.Handle);

		var NewTaskBarTab = new ChatLib.TaskBarTab(element, user, color, sid);
		NewTaskBarTab.observe('Tab:Clicked', this.tabClicked.bind(this));
		NewTaskBarTab.observe('Tab:CloseClicked', this.closeTab.bind(this));
		element = $('taskbartab_' + NewTaskBarTab.Handle);
		this.TaskBarTabs.set(sid, NewTaskBarTab);

		return NewTaskBarTab;
	},

	closeTab: function(sid) {
		this.fire('TaskBar:CloseTab', sid);
	},

	tabClicked: function(sid, xPos, win) {
		if (win.visible) {
			this.fire('TaskBarTab:Minimize', win.session);
		}
		else {
			this.fire('TaskBarTab:Maximize', win.session);
		}
		//win.toggle(xPos);
		//this.minimizeWindows(sid);
	},

	minimizeWindows: function(except) {
		var wins = ChatLib.VisualManager.windows.values();
		for (var i = 0; i < wins.length; i++) {
			var win = wins[i];
			if (win.sid != except) {
				win.hide();
			}
		}
	},

	closeAllClicked: function() {
		this.fire('TaskBar:closeAllClicked');
	},

	removeTab: function(sid) {
		var tab = this.TaskBarTabs.get(sid);
		if (tab) {
			var element = tab.element;
			if (element) {
				element.remove();
				this.TaskBarTabs.unset(sid);
				this.organizeTabs();
			}
		}
	}
});

/* File: /includes/js/framework/ChatLib/Visual/TaskBarFrame.js (Modified: 3. september 2010 12:30:56) */

ChatLib.TaskBarFrame = Class.create(Observable, {
	initialize: function() {
		this.Handle = parseInt(Math.random() * (Math.pow(2, 32)));
		var OFrame = "<div class='taskbar' id='taskbarWrapper_" + this.Handle + "'>";
		OFrame += "<div class='taskbarElm contentBoxHeaderBackgroundAltNotTransparent' id='taskbar_" + this.Handle + "'>";
		OFrame += "<table style='width: 100%' cellspacing='0' cellpadding='0'>";
		OFrame += "<tr><td colspan='3' class='frametop' id='taskbar_frametop_" + this.Handle + "'></td></tr>";
		OFrame += "</table>";
		OFrame += "</div>";
		OFrame += "</div>";

		this.wrapper = new Element("div").setStyle({ display: 'none' });
		this.wrapper.innerHTML = OFrame;
		document.body.appendChild(this.wrapper);

		this.dummy = new Element('div').setStyle({ width: '100%', height: this.wrapper.getHeight() + 'px', display: 'none' });
		document.body.appendChild(this.dummy);

		this.element = $('taskbar_' + this.Handle);
		this.tWrapper = $('taskbarWrapper_' + this.Handle);

		this.iframeHack = new Element('iframe', { src: 'about:blank', scrolling: 'no', frameborder: 0 }).setStyle({ position: 'absolute', top: '0px', left: '0px', zIndex: '999', height: this.wrapper.getHeight(), width: this.wrapper.getWidth() });
		this.tWrapper.insert(this.iframeHack);

		this.element.insert(
			new Element('div', { 'class': 'closeAllTab' }).update(
				new Element('img', { src: 'http://artogfx.cloud2.artodata.com/sitegfx/grafik/kvikchat/window_close.png', title: 'Close all' }).setStyle({
					width: '15px',
					height: '15px',
					borderWidth: '0px'
				})
			).observe('click', this.closeAllClicked.bind(this))
		);

		this.Content = $('taskbar_content_' + this.Handle);
		this.Top = $('taskbar_top_' + this.Handle);
		this.FrameContent = $('taskbar_framecontent_' + this.Handle);
		this.FrameTop = $('taskbar_frametop_' + this.Handle);
		this.FrameBottom = $('taskbar_framebottom_' + this.Handle);
		this.FrameRight = $('taskbar_frameright_' + this.Handle);
		this.FrameLeft = $('taskbar_frameleft_' + this.Handle);
	},

	getWidth: function() {
		return this.tWrapper.getWidth();
	},

	show: function() {
		this.wrapper.show();
		this.dummy.setStyle({ height: this.wrapper.getHeight() + 'px' });
		this.dummy.show();
		this.iframeHack.setStyle({ width: this.wrapper.getWidth() + 'px', height: (this.tWrapper.getHeight()) + 'px' });
	},

	closeAllClicked: function() {
		this.fire('closeAllClicked');
	},

	hide: function() {
		this.wrapper.hide();
		this.dummy.hide();
	}
});

/* File: /includes/js/framework/ChatLib/Visual/TaskBarTab.js (Modified: 3. september 2010 12:30:56) */

ChatLib.TaskBarTab = Class.create(Observable, {
	initialize: function(Taskbarframe, user, Color, sid, options) {
		this.sid = sid;
		this.user = user;
		this.options = Object.extend({
			width: 150
		}, options);
		this.width = this.options.width;

		this.Handle = parseInt(Math.random() * (Math.pow(2, 32)));
		this.Color = Color;
		this.blinkEffect = null;
		this.Taskbarframe = Taskbarframe;
		this.element = new Element("div");
		this.Taskbarframe.appendChild(this.element);
		this.drawTab();
	},

	drawTab: function() {
		this.nameCell = new Element('td').update(this.user.username);
		var closeCell = new Element('td', { align: 'right' }).update(
			new Element('img', { src: 'http://artogfx.cloud2.artodata.com/sitegfx/grafik/kvikchat/window_close.png', 'class': 'cursorHand' }).setStyle({
				width: '15px',
				height: '15px',
				borderWidth: '0px'
			}).observe('click', this.closeClicked.bindAsEventListener(this))
		);

		this.tab = new Element('table', { cellPadding: 0, cellSpacing: 0, 'class': 'tab' }).setStyle({
			color: this.Color,
			fontWeight: 'bold',
			width: this.options.width + 'px'
		}).update(
			new Element('tbody').update(new Element('tr').insert(this.nameCell).insert(closeCell))
		).observe('click', this.clicked.bind(this));

		this.element.insert(this.tab);
	},

	closeClicked: function(e) {
		this.fire('Tab:CloseClicked', this.sid);
		Event.stop(e);
	},

	resize: function(newWidth) {
		if (newWidth <= this.options.width) {
			this.tab.setStyle({ width: newWidth + 'px' });
			this.width = width;
		}
	},

	getXPos: function() {
		//dev.title(document.viewport.getWidth() - this.tab.cumulativeOffset().left);
		return document.viewport.getWidth() - this.tab.cumulativeOffset().left - this.width;
		//return this.tab.cumulativeOffset().left;
	},

	setUsername: function(user) {
		if (user.id == this.user.id) {
			this.nameCell.update(user.username);
			this.user = user;
		}
	},

	updateText: function(newText) {
		this.nameCell.update(newText);
	},

	updateColor: function(newColor) {
		this.tab.setStyle({ color: newColor });
	},

	updateBackgroundColor: function(newColor) {
		this.tab.setStyle({ backgroundColor: newColor });
	},

	startBlink: function() {
		if (this.blinkEffect == null) {
			this.blinkEffect = new Effect.Pulsate(this.element, { pulses: 100000, duration: 100000, from: 0.5 });
		}
	},

	stopBlink: function() {
		if (this.blinkEffect != null) {
			this.blinkEffect.cancel();
			Effect.Appear(this.element);
			this.blinkEffect = null;
		}
	},

	highlight: function() {
		this.setHighlightColor();
		new Effect.Pulsate(this.tab);
	},

	setHighlightColor: function() {
		this.updateBackgroundColor('#FFDA61');
	},

	removeHighlighting: function() {
		this.updateBackgroundColor('');
	},

	clicked: function() {
		this.fire('Tab:Clicked', this.sid, this.getXPos(), this.window);
	}
});


try {
RegTr("13088");
RegTr("16601");
RegTr("15966");
RegTr("15967");
RegTr("16653");
RegTr("16654");
RegTr("16655");
RegTr("16544");
RegTr("15970");
RegTr("15971");
RegTr("16842");
RegTr("15970");
RegTr("15971");
RegTr("16615");
RegTr("16616");
RegTr("16617");
RegTr("20271");
RegTr("20272");
RegTr("13089");
RegTr("13090");
RegTr("13091");
RegTr("13092");
RegTr("13093");
RegTr("13094");
RegTr("17975");
RegTr("17976");
RegTr("17977");
RegTr("19969");
RegTr("19970");
RegTr("19971");
RegTr("20135");
RegTr("16228");
RegTr("16230");
RegTr("16230");
RegTr("16229");
RegTr("18215");
RegTr("18216");
RegTr("18217");
RegTr("18218");
RegTr("18211");
RegTr("20181");
RegTr("20243");
RegTr("20139");
RegTr("20585");
RegTr("20586");
RegTr("20140");
RegTr("20141");
RegTr("20587");
RegTr("20182");
RegTr("20187");
RegTr("20188");
RegTr("20588");
RegTr("20589");
RegTr("20590");
RegTr("20591");
RegTr("20592");
RegTr("20593");
RegTr("20594");
RegTr("20595");
RegTr("20596");
RegTr("12671");
RegTr("18420");
RegTr("12672");
RegTr("20359");
RegTr("20357");
RegTr("18418");
RegTr("18419");
RegTr("16943");
RegTr("16944");
RegTr("20358");
RegTr("13101");
RegTr("16945");
RegTr("16946");
RegTr("16947");
RegTr("16945");
RegTr("16946");
RegTr("18348");
RegTr("13102");
RegTr("13103");
RegTr("13104");
RegTr("13105");
RegTr("13106");
RegTr("13107");
RegTr("13108");
RegTr("13109");
RegTr("13110");
RegTr("13111");
RegTr("13112");
} catch (e) {}
