var LoginBox = Class.create({	
	
	initialize: function() 
	{
		if (!$('loginOverlay')) return;
		
		this.error = $$('#loginOverlay p.error .message').first();
		
		this.loginForm = $$('form[name=loginOverlayForm]').first();		
		this.button = this.loginForm.select('input[type=image]').first();
		
		this.username = this.loginForm.select('input[name=username]').first();
		this.password = this.loginForm.select('input[name=password]').first();
		
		this.loginForm.onsubmit = function(event) {
			Event.stop(event);
			this.login();
		}.bindAsEventListener(this);		
		
		var dimensions = $('loginOverlay').getDimensions();
		window.loginbox = new app.lightbox('loginOverlay', dimensions.width, dimensions.height, { 
			lightbox: 'loginbox',
			before: function() {
				this.error.hide();
			}.bind(this)
		});
										
		$$('#loginOverlay .close a').first().onclick = function(e)
		{
			Event.stop(e);
			delete window.loginbox.after;
			window.loginbox.hide();
		}
		
		var dimensions = $('permissionOverlay').getDimensions();
		window.permissionbox = new app.lightbox('permissionOverlay', dimensions.width, dimensions.height, { lightbox: 'permissionbox' });		
		
		$$('#permissionOverlay .close a').first().onclick = function(e)
		{
			Event.stop(e);
			window.permissionbox.hide();
		}		
	},
	
	login: function()
	{
		if (this.pressed()) return;
	
		this.username = this.loginForm.select('input[name=username]').first();
		this.password = this.loginForm.select('input[name=password]').first();
	
		this.username.disabled = true;
		this.password.disabled = true;
	
		if (this.error.visible()) Effect.Fade(this.error);	
	
		var error = false;
		if (!this.username.value.strip() || this.username.value == this.username.defaultValue)
		{
			new Effect.Highlight(this.username);
			error = true;
		}
		if (!this.password.value.strip() || this.password.value == this.password.defaultValue)
		{
			new Effect.Highlight(this.password);
			error = true;
		}
		if (error) return;
		
		this.press();
		
		var callback = function(json)
		{
			this.unpress();
			this.password.value = '';
			this.username.disabled = false;
			this.password.disabled = false;
			
			if (json.success) {
				window.loginbox.hide();
			} else {
				Effect.Appear(this.error);
			}
		}.bind(this);
		
		var errorCallback = function()
		{
			this.unpress();
			this.password.value = '';
			this.username.disabled = false;
			this.password.disabled = false;				
			Effect.Appear(this.error);
		}.bind(this);
		
		var parameters = {
			username: this.username.value.strip(),
			password: this.password.value.strip()		
		};
		
		setTimeout(function() { 		
			app.jsonLoad('/login/', { 
				parameters: parameters,				
				callback: callback,
				errorCallback: errorCallback
			});
		}.bind(this), 500);
		
	},
	
	pressed: function()
	{
		return this.button.src.match(/\-on.(\w+)$/);
	},
	
	press: function()
	{
		this.button.src = this.button.src.replace(/(.*?)\.(\w+)$/, '$1-on.$2');		
	},
	
	unpress: function()
	{
		this.button.src = this.button.src.replace(/(.*?)-on\.(\w+)$/, '$1.$2');		
	}
	
});

var ContactSearch = Class.create({	
	
	initialize: function(section, args) 
	{
		this.contacts = [];
		this.remove = [];
		
		args = args || {};
		this.callback = args.callback;
		
		if (!section) return;

		try
		{
			this.section = $(section);		
			this.contactList = this.section.select('.list').first();
			this.field = this.section.select('input').first();		
			this.chooser = $('contactsChooser');
		} catch(e) { return; }

		this.contactList.select('.user').each(function(user) {
			var id = user.id.substr(this.section.id.length);
			if (this.contacts.indexOf(id) != -1) return;

			this.contacts.push(id);					
			this.remove = this.remove.without(id);
			this.setupContact(user, id);
		}.bind(this));

		this.field.onkeydown = function(e) {
			this.selectPrevious(e);
		}.bindAsEventListener(this);
		
		this.field.onkeypress = function(e) {
			this.selectPrevious(e);
		}.bindAsEventListener(this);
		
		Event.observe(document, 'keydown', this.deleteSelected.bindAsEventListener(this));
		Event.observe(document, 'keypress', this.deleteSelected.bindAsEventListener(this));
		Event.observe(document, 'click', this.clearSelected.bindAsEventListener(this));
				
		this.section.select('.field').first().onclick = function(e) {
			if (!Event.element(e).hasClassName('user'))
				this.field.focus();
		}.bindAsEventListener(this);
				
		var callback = function(x, entry) 
		{ 
			var params = { ids: this.contacts.toString() };
			return entry + '&' + $H(params).toQueryString();
		}.bind(this);
		
		new Ajax.Autocompleter(this.field, this.chooser, '/search/user/', { 
			paramName: 'user',
			callback: callback,
			parameters: $H({ excludeUser: args.excludeUser }).toQueryString(),
			updateElement: function(li) { this.addContact(li) }.bind(this)
		});		
	},
	
	empty: function()
	{
		return (this.contacts == 0);
	},
	
	setupContact: function(user, id)
	{
		if (!user) return;
		
		var del = user.select('a.delete').first();
		if (del) del.onclick = this.deleteCurrent.bindAsEventListener(this, id);
		user.onclick = this.selectCurrent.bindAsEventListener(this);		
	},
	
	addContact: function(li)
	{
		var id = li.id.substr(6);
		if (this.contacts.indexOf(id) != -1) return;
		
		var name = li.select('.name').first();
		this.contacts.push(id);
		this.remove = this.remove.without(id);		
		this.contactList.insert('<div id="'+this.section.id+id+'" class="user">'+name.innerHTML.stripTags()+' <a class="delete" href="#">X</a></div>');

		var user = this.contactList.select('.user').last();
		this.setupContact(user, id);
		
		if (this.callback) this.callback(li);
		
		this.field.value = '';
		this.field.focus();		
	},
	
	selectCurrent: function(e)
	{
		if (this.selected)
			this.selected.removeClassName('selected');

		var user = Event.element(e);
		this.selected = user;
		
		user.addClassName('selected');
		this.field.blur();		
	},
	
	deleteCurrent: function(e, id)
	{
		Event.stop(e);
		this.contacts = this.contacts.without(id);
		if (this.remove.indexOf(id) == -1) this.remove.push(id);
		Event.element(e).parentNode.remove();
		this.field.focus();		
	},
	
	selectPrevious: function(e)
	{
		var keycode = e.charCode || e.keyCode;
		var input = Event.element(e);

		if (keycode && keycode == 8 && input.value == '')
		{
			var user = this.contactList.select('div.user').last();
			if (user)
			{
				this.selected = user;
				
				user.addClassName('selected');
				this.field.blur();				
			}
			Event.stop(e);
		}
	},
	
	deleteSelected: function(e)
	{
		var keycode = e.charCode || e.keyCode;

		if (keycode && (keycode == 8) && !(Event.element(e) && Event.element(e).value))
		{
			Event.stop(e);

			if (this.selected) {
				if (!this.selected.select('a.delete').first()) return;

				var id = this.selected.id.substr(this.section.id.length);						
				this.contacts = this.contacts.without(id);
				if (this.remove.indexOf(id) == -1) this.remove.push(id);

				this.selected.remove();						
				delete this.selected;
				this.field.focus();
			}			
		}			
	},
	
	clearSelected: function(e)
	{
		if (this.selected && Event.element(e) != this.selected)
		{
			this.selected.removeClassName('selected');
			delete this.selected;
		}
	}	
});

var Panel = Class.create({	
	
	initialize: function(panel, options)
	{
		this.start(panel, options);
	},
	
	start: function(panel, options)
	{		
		this.options = options || {};
		
		this.panel = $(panel);
		if (!this.panel) return;

		this.button = $(this.options.button) || $(this.panel.id+'Chooser');
		this.on = this.options.on || 'on';
		
		this.button.onclick = function(e) {
			Event.stop(e);

			if (!this.visible()) {
				this.open();
			}
			else {
				this.close();
			}
		}.bindAsEventListener(this);		
		
		Event.observe(document, 'click', function(e) { 
			var x = Event.element(e);
			if (x == this.panel || x.descendantOf(this.panel)) return;
			if (this.visible()) this.close();
		}.bindAsEventListener(this));	
		
		if (this.onInit) this.onInit(); // FOR CHILD CLASSES
		if (this.options.onInit) this.options.onInit(); // RUNTIME
	},

	open: function()
	{
		this.panel.show();
		if (this.options.on !== false)
			this.button.addClassName(this.on);

		if (this.onOpen) this.onOpen(); // FOR CHILD CLASSES
		if (this.options.onOpen) this.options.onOpen(); // RUNTIME
	},

	close: function()
	{
		Effect.Fade(this.panel, { duration: 0.2 });
		if (this.options.on !== false)		
			this.button.removeClassName(this.on);	

		if (this.onClose) this.onClose(); // FOR CHILD CLASSES			
		if (this.options.onClose) this.options.onClose(); // RUNTIME
	},
	
	visible: function()
	{
		return this.panel.visible();
	}
});

Panel.editor = Class.create(Panel, {
	
	initialize: function(panel, options)
	{	
		this.options = options || {};
		
		this.editor = this.options.editor;
		this.start(panel, this.options);
	},
	
	onOpen: function()
	{
		this.__onOpen();
	},
	
	onClose: function()
	{
		this.__onClose();
	},
	
	__onOpen: function()
	{
		if (!this.editor) return;

		this.editor.bookmark = this.editor.selection.getBookmark();
		this.editor.selection.moveToBookmark(this.editor.bookmark);
	},
	
	__onClose: function()
	{
		if (!this.editor) return;

		this.editor.selection.moveToBookmark(this.editor.bookmark);
		this.editor.bookmark = null;	
	}
});

Panel.editor.link = Class.create(Panel.editor, {	

	onInit: function()
	{
		this.input = this.panel.select('input').first();
		this.edit = this.panel.select('.edit').first();
		this.save = this.panel.select('.save').first();
		this.cancel = this.panel.select('.cancel').first();
		
		this.input.onkeyup = function(e) {
			var keycode = e.charCode || e.keyCode;
			if (keycode == 13 || keycode == 10 || keycode == 3)
			{
				this.link();
				return;
			}
			var esc = window.event ? 27 : e.DOM_VK_ESCAPE;	      
			if (keycode == esc)
			{
				this.close();
				return;
			}
		}.bindAsEventListener(this);		
		
		this.input.onkeydown = function(e) {
			var keycode = e.charCode || e.keyCode;
			if (keycode == 13 || keycode == 10 || keycode == 3)
			{
				Event.stop(e);
				return;
			}			
		}.bindAsEventListener(this);
		
		this.save.onclick = this.edit.onclick = function(e) {
			Event.stop(e);
			this.link();
		}.bindAsEventListener(this)
		
		this.cancel.onclick = function(e) {
			Event.stop(e);
			this.unlink();
		}.bindAsEventListener(this)
	},

	onOpen: function()
	{
		this.__onOpen();		
		this.input.focus();
		this.input.value = this.input.value;		
		
		if (this.input.value && this.input.value != this.input.defaultValue)
		{ 
			this.save.hide();
			this.edit.show();
			this.cancel.show();			
		}
		else
		{
			this.save.show();
			this.edit.hide();	
			this.cancel.hide();						
		}
	},

	fill: function(x)
	{
		if (this.halt) return;
		this.input.value = '';
		if (x && x.href) this.input.value = x.href;	
		if (this.visible())
		{
			this.save.hide();
			this.edit.show();
			this.cancel.show();			
		}
	},

	clear: function()
	{
		if (this.halt) return;		
		this.input.value = '';		
		this.input.value = this.input.defaultValue;
		if (this.visible())
		{		
			this.save.show();
			this.edit.hide();	
			this.cancel.hide();	
		}
	},

	unlink: function()
	{
		this.editor.selection.moveToBookmark(this.editor.bookmark);		
		var node = this.editor.dom.getParent(this.editor.selection.getNode(), 'A');
		if (node)
		{
			this.editor.execCommand("UnLink", false);
		}
		
		new Effect.Highlight(this.input, { afterFinish: function() {
			this.close();
		}.bind(this) });				
	},

	link: function()
	{
		this.input.value = this.input.value.strip();
		if (this.input.value == '' || this.input.value == this.input.defaultValue) return;
		this.input.value = this.input.value.replace(/^http:\/\/(\w+:\/\/)/, '$1');
		if (!this.input.value.match(/^\w+:\/\//)) this.input.value = 'http://' + this.input.value;
		
		this.halt = true;
		this.editor.selection.moveToBookmark(this.editor.bookmark);
		var node = this.editor.dom.getParent(this.editor.selection.getNode(), 'A');

		var target = this.input.value.match(/\.ics$/) ? '' : '_blank';

        // VIMEO HANDLING
        var found = this.input.value.match(/vimeo\.com\/([0-9]+)$/);
        if (found) 
        {                
			var span = this.editor.dom.get('vimeo'+found[1]);
			if (span)
			{
				alert('This video has already been placed. To place it somewhere else, first delete it from the edit area using your backspace or delete keys.');
				return;			
			}
        
			var html = '<span id="vimeo'+found[1]+'" class="player">[VIMEO='+found[1]+']</span>';
			var ref = this.editor.selection.getNode();

			if (!ref || Prototype.Browser.Gecko)
			{
				this.editor.execCommand('mceInsertContent', false, '<p>'+html+'</p>');
			}
			else
			{
				var p = this.editor.dom.insertAfter(this.editor.dom.create('p'), ref);
				this.editor.dom.setHTML(p, html);			
			}

			var span = this.editor.dom.get('vimeo'+found[1]);
			new Vimeo(span, found[1], this.editor);
        }
        
        // NORMAL LINK HANDLING
        else
        {
    		if (!node)
    		{
    			this.editor.execCommand("CreateLink", false, this.input.value);	
    			node = this.editor.dom.getParent(this.editor.selection.getNode(), 'A');
    			this.editor.dom.setAttribs(node, {
    				target : target
    			});
    		}
    		else
    		{
    			this.editor.dom.setAttribs(node, {
    				href : this.input.value,
    				target : target
    			});
    		}        
        }


		this.halt = false;	
		this.fill(node);
		
		new Effect.Highlight(this.input, { afterFinish: function() {
			this.close();
		}.bind(this) });		
	}
});

var Toggle = Class.create({	

	initialize: function(where, type)
	{
		switch(where) { 
			case 'article': case 'user': case 'topic': break;
			default: return;
		}		

		switch(type) { 
			case 'recommend': case 'bookmark': break;
			default: return;
		}

		this.button = $(type);
		this.buttonBottom = $(type+'Bottom');		
		
		if (!this.button) return;
		
		this.type = type;		
		this.where = where;
		this.halt = false;	
		
		this.classes = { on: type+'On', loading: type+'Loading' };
				
		this.loading =
		{
			show: function() {
				this.button.addClassName(this.classes.loading);
				this.button.removeClassName(this.classes.on);

				if (this.buttonBottom) {
					this.buttonBottom.addClassName(this.classes.loading);
					this.buttonBottom.removeClassName(this.classes.on);		
				}
			}.bind(this),

			hide: function() {
				this.halt = false;
				this.button.removeClassName(this.classes.loading);
				if (this.buttonBottom)
					this.buttonBottom.removeClassName(this.classes.loading);		
			}.bind(this)
		}
			
	},

	callback: function(json)
	{
		if (json.on)
		{
			this.button.addClassName(this.classes.on);				
			if (this.buttonBottom)
				this.buttonBottom.addClassName(this.classes.on);				
		}
		else
		{
			this.button.removeClassName(this.classes.on);				
			if (this.buttonBottom)
				this.buttonBottom.removeClassName(this.classes.on);				
		}
	},

	toggle: function(id)
	{	
		if (this.halt) return;
		this.halt = true;
		
		var url = this.button.hasClassName(this.classes.on) ? 'un'+this.type : this.type;
		
		app.jsonLoad('/'+url+'/'+this.where+'/'+id+'/', { 
			loading: this.loading,
			callback: this.callback.bind(this)
		});
	}

});

var FormProcess = Class.create({	

	initialize: function(form) 
	{
	  if (location.search.match(/\?forceReload\=/)) location.href = location.pathname + location.hash;
    
		this.halt = false;
		this.loading = $('loading');
		this.form = $$('form#'+form).first();
		if (!this.form) return;
		
		this.form.getElements().each(function(x) {
			Event.observe(x, 'focus', function() {
				this.form.select('.error').each(function(y) {
					if (y.visible()) new Effect.Fade(y);
				})
			}.bindAsEventListener(this));
		}.bind(this));
	},
	
	callback: function(json)
	{
		if (json.error)
		{
			var error = this.form.select('.error.'+json.error).first();
			if (error) error.show();
		}
		
		if (json.success)
		{
			if (json.url) 
			{
			  var pieces = json.url.split('#');
		    location.href = json.url;
		    if (pieces[0] == location.pathname)
          location.href = pieces[0] + '?forceReload=' + Math.random() + (pieces[1] ? '#'+pieces[1] : '');
			}
		}
	},
	
	validate: function()
	{
		if (!this.form) return false;
		
		var parameters = {};

		this.form.getElements().each(function(x) {
				parameters[x.name] = x.value.strip();
				if (x.type == 'text' || x.type == 'textarea')
				{	
					if (!parameters[x.name] || (!x.hasClassName('active') && parameters[x.name] == x.defaultValue))
					{
						if (!x.hasClassName('optional'))
						{
							new Effect.Highlight(x);
							parameters = false;
							throw $break;							
						}
						parameters[x.name] = '';
					}						
				}
		});
				
		return parameters;
	},
	
	submit: function()
	{				
		var parameters = this.validate();		
		if (parameters === false) return;
		
		if (this.halt) return;
		this.halt = true;		
		
		Position.clone(this.form, this.loading);			
		this.loading.show();
				
		app.jsonLoad(this.form.action, {
			loading: this.loading,
			parameters: parameters,
			keepLoading: true,
			callback: this.callback.bind(this),
			commonCallback: function() { this.halt = false; }.bind(this)
		});
	}
	
});

var Paging = Class.create({
	
	initialize: function(url, block)
	{
		this.halt = false;
		
		this.url = url;
		this.block = block;
		this.container = $(block+'Container');
		this.paging = $(block+'PagingContainer');
		
		this.loading = $('loading');	
		this.section = '';
	},
	
	callback: function(json)
	{
		if (json.html !== undefined)
			this.container.update(json.html);

		if (json.paging !== undefined)
			this.paging.update(json.paging);
	},
	
	select: function(section)
	{
		this.section = section;
		this.page(1);
	},
	
	page: function(page)
	{		
		if (this.halt) return;
		this.halt = true;
				
		Position.clone(this.container, this.loading);
		this.loading.show();
				
		app.jsonLoad(this.url, { 
			loading: this.loading,
			callback: this.callback.bind(this),
			commonCallback: function() { this.halt = false; }.bind(this),
			parameters: { block: this.block, page: page, section: this.section }
		});
	}
});

window.paging = {};

var Folder = Class.create({
	
	initialize: function(folder)
	{
		this.folder = $(folder)
		if (!this.folder) return;
		
		this.isFolder = true;
		
		try {
			this.wrapper = this.folder.select('.wrapper').first();
			this.titles = this.folder.select('.titles .dropzone').first();
			if (this.wrapper.hasClassName('videos'))
				this.type = 'videos';
			if (this.wrapper.hasClassName('images'))
				this.type = 'images';			
		} catch(e) {}
		
		if (this.titles) {
			Droppables.add(this.titles, { 	
				onHover: this.onHover.bind(this), 
				onDrop: this.onDrop.bind(this),
				hoverclass: 'hover'
			});
			Droppables.drops.each(function(drop) {
				if (drop.element == this.titles) {
					this.drop = drop;			
				    throw $break;
				}
			}.bind(this));

			this.folder.select('.titles .delete a').each(function(y) {
				y.onclick = this.remove.bindAsEventListener(this);
			}.bind(this));
		}
		
		this.arrow = this.folder.select('.expandCollapse a').first();		
		if (this.arrow) {
			this.arrow.onclick = this.toggle.bindAsEventListener(this);
		}
	},

	remove: function(e)
	{
		Event.stop(e);
		if (window.edit && window.edit.removeFolder)
			window.edit.removeFolder(this);
	},

	onDrop: function(element)
	{
		if (!this.wrapper || !element || !element.id || !Sortable.sortables[this.wrapper.id]) return;
		
		if (this.elementType(element) == this.type)
		{
			if (this.isClosed()) this.open();
	        element.parentNode.removeChild(element);
			this.wrapper.insert({ top: element });		
		}
	},

	onHover: function(element)
	{
		var type = this.elementType(element);
		
		if (this.drop)
		{
			if (type == this.type)
				this.drop.hoverclass = 'hover';
			else
				this.drop.hoverclass = 'denied';
		}
		
	    Element.addClassName(this.drop.element, this.drop.hoverclass);

		if (this.drop.hoverclass == 'denied') return;

		this.timeout = setTimeout(function() {
			if (this.titles.hasClassName('hover'))
				if (this.isClosed()) this.open();
		}.bind(this), 500);
	},

	elementType: function(element)
	{
		if (element.hasClassName('videos'))
			return 'videos';
		if (element.hasClassName('images'))
			return 'images';			
		return '';
	},

	toggle: function(e)
	{
		Event.stop(e);
		if (this.isClosed()) this.open();
		else this.close();
	},
	
	isEmpty: function()
	{
		return this.wrapper.childElements().length > 0 ? false : true;
	},
	
	isClosed: function()
	{
		return this.folder.hasClassName('closed');
	},
	
	open: function()
	{
		this.folder.removeClassName('closed');
	},
	
	close: function()
	{
		if (this.timeout)
		{
			clearTimeout(this.timeout);
			this.timeout = false;
		}
		this.folder.addClassName('closed');		
	}
});


var Video = Class.create({
	
	initialize: function(player, pid, width, height, ed, comDiv)
	{
		if (!player || !player.id || !pid) return;		

		if (Prototype.Browser.Gecko)
			if (ed) ed.getDoc().designMode = 'Off';

		var w = (parseInt(width, 10) || 320); // + 2;
		var h = (parseInt(height, 10) || 240) + 32;

		var so = new SWFObject("http://content.bitsontherun.com/staticfiles/videoplayer.swf", player.id+'swf', w, h, "8.0.0.0");
		so.addParam("quality", "high");
		so.addParam("scale", "noscale");
		so.addParam("salign", "tl");
		so.addParam("menu", "true");
		so.addParam("bgcolor", "dddddd");
		so.addParam("wmode", "transparent");				        			    			
		so.addParam("allowFullScreen", "true");
		so.addParam("allowScriptAccess", "always");
		
		so.addVariable("playlist","none");
		so.addVariable("repeat","none");
		so.addVariable("autostart","false");
		so.addVariable("dock","false");
		so.addVariable("frontcolor","000000");
		so.addVariable("image","http://content.bitsontherun.com/thumbs/"+pid+"-640.jpg");
		so.addVariable("stretching","uniform");
		so.addVariable("ping.script","http://content.bitsontherun.com/pings/");
		so.addVariable("height", h);
		so.addVariable("width", w);
		so.addVariable("lightcolor","000000");
		so.addVariable("controlbar","bottom");
		so.addVariable("backcolor","dddddd");		
		so.addVariable("displayclick","play");
		so.addVariable("backcolor","ffffff");
		so.addVariable("skin","http://content.bitsontherun.com/skins/VFgGj89b.swf");
		so.addVariable("playlistsize","200");
		so.addVariable("file","http://content.bitsontherun.com/jwp/"+pid+".xml");

		so.write(player);		

		if (Prototype.Browser.Gecko)
			if (ed) {	
				setTimeout(function() {
					ed.getDoc().designMode = 'On';
				}, 1000);
			}
	}	
});

var Vimeo = Class.create({
	
	initialize: function(player, pid, ed)
	{
		if (!player || !player.id || !pid) return;		

		if (Prototype.Browser.Gecko)
			if (ed) ed.getDoc().designMode = 'Off';

		var w = 560;
		var h = 312;

		var so = new SWFObject("http://vimeo.com/moogaloop.swf?clip_id="+pid+"&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1", player.id+'swf', w, h, "8.0.0.0");
		so.addParam("quality", "high");
		so.addParam("scale", "noscale");
		so.addParam("salign", "tl");
		so.addParam("menu", "true");
		so.addParam("bgcolor", "dddddd");
		so.addParam("wmode", "transparent");				        			    			
		so.addParam("allowFullScreen", "true");
		so.addParam("allowScriptAccess", "always");
		
		so.addVariable("height", h);
		so.addVariable("width", w);

		so.write(player);		

		if (Prototype.Browser.Gecko)
			if (ed) {	
				setTimeout(function() {
					ed.getDoc().designMode = 'On';
				}, 1000);
			}
	}	
});

window.windowOnload.push(function() {	
	new LoginBox();
});

var PreloadImages = [
	'/img/articles/comments-media-on.gif',
	'/img/articles/comments-revisions-on.gif',
	'/img/articles/comments-saving.gif',
	'/img/articles/comments-style-bg.png',
	'/img/articles/comments-style-body.gif',
	'/img/articles/comments-style-heading.gif',
	'/img/articles/comments-style-subheading.gif',
	'/img/articles/article-bg-right.gif',
	'/img/articles/drawer-footer.gif',
	'/img/articles/comment-divider.gif',
	'/img/articles/file-drawer-bottom.gif',
	'/img/articles/view-revert-divider.gif',
	'/img/articles/publisher-bg.gif',
	'/img/articles/comments-quote-on.gif',
	'/img/articles/comments-bullet-on.gif',
	'/img/articles/comments-underline-on.gif',
	'/img/articles/comments-italics-on.gif',
	'/img/articles/comments-bold-on.gif',
	'/img/global/nav/home-on.png',
	'/img/global/nav/articles-on.png',
	'/img/global/nav/networks-on.png',
	'/img/global/nav/groups-on.png',
	'/img/global/nav/publish-on.png',
	'/img/global/nav/admin-on.png',
	'/img/global/nav/support-on.png',
	'/img/global/nav/faq-on.png',
	'/img/global/nav/register-on.png',	
	'/img/global/nav/members-on.png',	
	'/img/global/nav/expo-on.png',					
	'/img/global/nav/home.png',
	'/img/global/nav/articles.png',
	'/img/global/nav/networks.png',
	'/img/global/nav/groups.png',
	'/img/global/nav/publish.png',
	'/img/global/nav/admin.png',
	'/img/global/nav/support.png',
	'/img/global/nav/faq.png',	
	'/img/global/nav/register.png',	
	'/img/global/nav/members.png',	
	'/img/global/nav/expo.png',			
	'/img/global/loading.gif',
	'/img/global/paging-prev.gif',
	'/img/global/paging-next.gif',
	'/img/global/paging-bg.gif',
	'/img/global/bookmark.gif',
	'/img/global/bookmarked.gif',	
	'/img/articles/expand.gif',
	'/img/articles/expanded.gif',
	
	'/img/articles/login-on.gif',
	'/img/articles/text-largest.gif',
	'/img/articles/text-largest-on.gif',
	'/img/articles/text-medium.gif',
	'/img/articles/text-medium-on.gif',
	'/img/articles/text-smallest.gif',
	'/img/articles/text-smallest-on.gif',
	'/img/articles/bookmark.gif',
	'/img/articles/bookmarking.gif',	
	'/img/articles/bookmarked.gif',
	'/img/articles/editing.gif',
	'/img/articles/replying.gif',
	'/img/articles/recommend-comment.gif',
	'/img/articles/recommended-comment.gif',
	'/img/articles/recommend.gif',
	'/img/articles/recommending.gif',
	'/img/articles/recommended.gif',
	'/img/articles/contents-on.gif',
	'/img/articles/contents-dropdown-bg.png',
	'/img/articles/contents-dropdown-bottom.png',
	'/img/articles/comments-link-on.gif',
	'/img/articles/link-bg.png',
	'/img/articles/remove-link.gif',
	'/img/articles/create-link.gif',
	'/img/articles/edit-link.gif',
	'/img/articles/annotating.gif',
	'/img/articles/annotate-process-bg.png',
	'/img/articles/annotate-drag.png',
	'/img/articles/annotation-bullet.gif',
	'/img/articles/annotate-add.gif',
	'/img/articles/annotate-bg-bottom.png',
	'/img/articles/annotate-bg-top.png',
	'/img/articles/add-annotation.gif',
	'/img/articles/folder-icon-drop.gif',
	'/img/articles/folder-icon-nodrop.gif',

	'/img/profiles/add-colleague.gif',
	'/img/profiles/adding-colleague.gif',
	'/img/profiles/your-colleague.gif',
	'/img/profiles/follow.gif',
	'/img/profiles/following.gif',
	'/img/profiles/follow-pressed.gif',	
	'/img/global/less-blueonblue.gif'
];


