/**
 * @fileoverview CTFluoroscopy.com main website script
 *
 * <pre>
 * Copyright(c) 2003-2007 by BWin Technologies Ltd.
 * http://www.bwintech.com
 * Quay House, South Esplanade, St. Peter Port
 * GY1 4EJ Guernsey, CI, UK
 * All rights reserved.
 * </pre>
 */
// Voor de taal van de pagina.
var TAAL = "NL";
var UNIQUEUSERNAME = false;

window.NL_class = undefined;
window.DE_class = undefined;
window.UK_class = undefined;

// Center the 800x600 wrapper on the page
function windowResize(){
	$("wrapper").style.left =
		(document.body.clientWidth > ($("wrapper").clientWidth + 2)) ?
			Math.floor((document.body.clientWidth - $("wrapper").clientWidth) / 2) : 0;

	$("wrapper").style.top =
		(document.body.clientHeight > ($("wrapper").clientHeight + 2)) ?
			Math.floor((document.body.clientHeight - $("wrapper").clientHeight) / 2) : 0;
}

function enableDiv(divId){
	var infos = document.getElementsByClassName("infoText");

	infos.each(function(obj, indx, arr){
		if(arr[indx].style.display == "block"){
			TRACE(0, "enableDiv: Just hidden [" + arr[indx].id + "]");
			arr[indx].style.display = "none";
		}
	});

	$(divId).style.display = "block";
}

function overWrite(targetObject, srcObject){
	for(var obj in srcObject){
		if(targetObject[obj] === undefined){ continue; }

		targetObject[obj] = srcObject[obj];
	}

	return targetObject;
}

function changeLang(newLang){

	$("wrapper").filters[0].Apply();

	window.NL_class.display = "none";
	window.DE_class.display = "none";
	window.UK_class.display = "none";

	TAAL = newLang;
	window[TAAL + "_class"].display = "block";

	$("wrapper").filters[0].Play();
}


/******************************************************************************
	BWin Classes
******************************************************************************/

// The BWin user class. When a user logs in this will create a neat user object
// for us so we can always verify the user.
var $User = Class.create(function(userName, userHash, serverHash){
	// Set our log in information correctly
	this.userName = userName;
	this.userHash = userHash;
	this.serverHash = serverHash;

	// Add a little time stamp
	this.loginTime = (new Date()).getTime();
	this.loginDate = Date();

	// Output some info on what just happend
	TRACE(0, "BWin.user: User succesfully created details;\n" +
		"    user name: " + this.userName + "\n" +
		"    user hash: " + this.userHash + "\n" +
		"    server hash: " + this.serverHash + "\n" +
		"    login time: " + this.loginTime + "\n" +
		"    login date: " + this.loginDate );
});

Object.extend($User.prototype, {
	userName:	null,
	userHash:	null,
	serverHash:	null,

	loginTime:	null,
	loginDate:	null
});

// The $Site class will give us a object with in there a complete site.
var $Site = Class.create(function(domainName){
	this.domain = domainName;
	this.pagesDirty = [];

	// Get the page tree from the server and stick it in the Pages collection
	// same goes for the menu wich are saved in a diffrent blob ofcourse. But
	// we'll let the server worry about that.
	/*BWin.request(
		window.document.location.protocol +	"//" + window.document.location.host + window.document.location.pathname + "getSiteTree.lee",
		{	Site: this,
			onSuccess: function(){
				this.options.Site.Pages = Object.fromChars(this.transport.responseText);
			},
			onFailure: function(){
				// Well the server had no tree for us wich is rather pecular actually sicne there always should
				// be one. But for the heck of it lets just start with a clean slate.
				TRACE(0, "$Site: Unable to get site tree for [" + this.options.Site.domain + "]");

				// Creating a tree here. And adding the Root node.
				this.options.Site.Pages = new RelationalTree(BWinSTL.map({ fn: function(a,b) { return parseInt(a) < parseInt(b); } }));
				this.options.Site.Pages.insert(-1, {first: 0, second: new RelNode(0, {name: this.options.Site.domain, type: "Domain"}) } );
			}
		});*/

	// No we are going to do the same for the menus collection
	/*BWin.request(
		window.document.location.protocol +	"//" + window.document.location.host + window.document.location.pathname + "getMenuTree.lee",
		{	Site: this,
			onSuccess: function(){
				this.options.Site.Menus = Object.fromChars(this.transport.responseText);
			},
			onFailure: function(){
				// Somehow we didn't get anything this means that this is eiter a new site or something
				// is really wrong. Anyway we are going to create a nice little menu collection now so
				// we can contieu what ever we were doing.
				TRACE(0, "$Site: Unable to get menu collection for [" + this.options.Site.domain + "]");

				this.options.Site.Menus = new $Menus({});
			}
		});*/

	this.Pages = new RelationalTree(BWinSTL.map({ fn: function(a,b) { return parseInt(a) < parseInt(b); } }));
	this.Pages.insert(-1, {first: 0, second: new RelNode(0, {name: this.domain, type: "Domain"}) } );

	this.Menus = new $Menus({});
});

Object.extend($Site.prototype, {

	domain:	null,
	Pages:	null,
	Menus:	null,

	// For editing purposes.
	treeDirty: false,
	pagesDitry: null,

	getPageById: function(pageId){ return this.Pages.find(pageId); }
});

// The Menus collection is always a pretty important part of a site and even a page
// so we need a good solid class for it to function properly.
var $Menus = Class.create(function(parentCollection){
	if(!parentCollection){
		parentCollection = {}; }

	// we don't want to carry over the prototyped functions right =P
	Object.protectedExtend(this, parentCollection);
});

Object.extend($Menus.prototype, {
	getMenu: function(menuId){
		if(!menuId){
			this.__error(".getMenu: No menuId given.");
			return undefined;
		}
		return this[menuId];
	},

	addMenu: function(menuId, menu){
		if(!menuId || !menu){
			// Can't do anything without the arguments...
			this.__error(".addMenu: Invalid arguments.");
			return undefined;
		}

		return (this[menuId] = menu);
	},

	removeMenu: function(menuId){
		if(!menuId || !this.getMenu(menuId)){
			this.__error(".removeMenu: Can't remove [" + menuId + "]");
			return;
		}

		delete(this[menuId]);
	},

	__error: function(errMessage){
		// Can't anything if we don't know what it is called.
		try{
			TRACE(0, BWin.CurrentSite.domain + "." + BWin.CurrenctPage.nodeId + errMessage);
		}catch(err){
			try{
				TRACE(0, BWin.CurrentSite.domain + errMessage);
			}catch(errr){
				TRACE(0, "$Menus: _PANIC_ No CurrentSite this error isn't even possible! message:[[" + errMessage + "]]");
		}	}
	}
});

// A general type of menu so the sliding menu and context menu and any kind of menu
// has the same type of abstract.
var $menuItem = Class.create(function(menuId, content){
	this.items = [];
	this.content = content;
	this.menuId = menuId;
});

Object.extend($menuItem.prototype, {
	items:		null,
	content:	null,

	level:		-1,
	menuId:		null,

	addItem: function(content, insertBefore){
		var tMenuItem = new $menuItem(this.menuId, content);
		tMenuItem.level = this.level + 1;

		if(insertBefore && insertBefore.isType() == "number"){
			this.items.splice(insertBefore, insertBefore - 1, tMenuItem);
		}else{
			this.items.push(tMenuItem);
		}

		return tMenuItem;
	},

	removeItem: function(itemIndex){
		this.items.splice(itemIndex, itemIndex - 1);
	}
});

// We now need a proper page class. The pages can also contain methods and properties and what not.
var $Page = Class.create(function(pagePath){
	this.name = pagePath;
});

Object.extend($Page.prototype, {
	html:	null,
	name:	null
});

// The BWin object this is where all the magic really really happens.
var BWin = {
	// Our really sexy site collection
	Sites: {},

	// These properties will be set when pages and sites are added in the mix
	CurrentSite: null,
	CurrentPage: null,

	// The user object, since we didn't log in were NULL.
	user: new $User(null, null, null),

	//*************************************************************************
	//	Some Mehtods for handeling Sites
	//*************************************************************************
	addSite: function(domainName){
		if(!domainName){
			// Can't add anything if we don't know what it is going to be called.
			TRACE(0, "BWin.addSite: Unable to add Site without domain.");
		}else if(BWin.getSite(domainName)){
			// Can't add something that is already there
			TRACE(0, "BWin.addSite: Site [" + domainName + "] already excited.");
			return BWin[domainName];
		}

		// We appearently we need to create a new site...
		BWin.Sites[domainName] = new $Site(domainName);

		// Return the site
		return BWin[domainName];
	},

	removeSite: function(domainName){
		if(!BWin.getSite(domainName)){
			TRACE(0, "BWin.removeSite: [" + domainName + "] unavailable.");
			return;
		}

		delete(BWin[domainName]);
	},

	setCurrentSite: function(domainName){
		if(!BWin.getSite(domainName)){
			TRACE(0, "BWin.removeSite: [" + domainName + "] unavailable.");
			return;
		}

		// Reurn our sites
		return (BWin.CurrentSite = BWin.Sites[domainName]);
	},

	getSite: function(domainName){
		if(!domainName){
			// Can't find something if we don't know what we are looking for
			TRACE(0, "BWin.getSite: Can't get site no domain name specified.");
			return undefined;
		}

		// If the site is not actually there "undefined" will be returned.
		return BWin.Sites[domainName];
	},

	// This is sort of a mock up function not out on the final design etc yet.
	setCurrentPage: function(pageId){
		if(!pageId){
			TRACE(0, "BWin.setCurrentPage: Unable to set page without ID.");
			return;
		}

		var tPage = BWin.CurrentSite.Pages.find(pageId);

		if(!tPage){
			TRACE(0, "BWin.setCurrentPage: Page was not found.");
			return;
		}

		return (BWin.CurrentPage = tPage);
	},

	// Login method
	initUser: function(userName, userHash, loginMessage){
		$("FluoroscopyMenu_0").innerHTML = "My account";
		
		BWin.user = new $User(userName, userHash, null);

		//BWin.requestCode("./?id=48898"); // MD5 hashing for iEditor
		//BWin.requestCode("./?id=49140"); // slidingMenu
		//BWin.requestCode("./?id=49136", function(){
			/*BWin.iEditor = new IconEditorConstruct();*/
		//	BWin.iEditor.injectTextIcons();
		//	BWin.iEditor.iconsOn();
		//});
		
		

		BWin.requestCode("./?id=49362", function(){
			if($("chatSendButton") && $("chatTextBox")){
				initChat(); }
		});

		BWin.requestCode("./?id=49505", function(){
			Object.extend(BWin, {
				Class: "BWin",
				xHttp: null,
				url: "./",
				createElement: function(type, parnt) {
					var el = null;

					if (window.self.document.createElementNS)
						// use the XHTML namespace; IE won't normally get here unless
						// _they_ "fix" the DOM2 implementation.
						el = window.self.document.createElementNS("http://www.w3.org/1999/xhtml", type);
					else
						el = window.self.document.createElement(type);

					if (typeof parnt != "undefined")
						parnt.appendChild(el);

					if (BWin.is_ie)
						el.setAttribute("unselectable", true);

					if (BWin.is_gecko)
						el.style.setProperty("-moz-user-select", "none", "");

					return el;
				}
			});
		});

		BWin.write = function(pageId, element, onComplete){
			if(!element || !pageId){
				// we got some bad arguments here, abort the mission, over. *kuughrrrh*
				TRACE(0, "BWin.write: Invalid arguments.");
				return;
			}

			if(onComplete === undefined){
				onComplete = function(){ return undefined; }; }

			// When a write is done directly after a init it is possible that not all the scripts are loaded yet
			try{ destroyChat(); }catch(ERR){ }

			var page = BWin.CurrentSite.Pages.find(pageId);

			if(element.className.match(/[0-9]{5}/gi)){
				element.className = element.className.replace(/[0-9]{5}/gi, pageId.toString());
			}else{
				element.className += " " + pageId.toString();
			}

			if(!page.html){
				BWin.request(
					"./?id=" + pageId.toString(),
					{	htmlElement: element,
						pageNode: page,
						asynchronus: false,
						writeComplete: onComplete,
						onSuccess: function(){
							this.options.htmlElement.innerHTML = this.transport.responseText;
							this.options.pageNode.html = this.transport.responseText;

							this.options.writeComplete();
						},
						onFailure: function(){
							TRACE(0, "BWin.write: Unable to request blob with id [" + this.page.nodeId + "]");
						}
					});
			}else{
				element.innerHTML = page.html;
				onComplete();
			}

			Event.observers.each(function(obj, indx, arr){
				if(arr[indx] && arr[indx][0].parentElement == null){
					Event._destroy(indx); }
			});
		};
	},

	//*************************************************************************
	//	Genral methods that keep everything runnign smoooth
	//*************************************************************************
	request: function(url, options){ return new Ajax.Request(url, options); },
	requestCode: function(url, onComplete){
		if(!onComplete){ onComplete = function(){ return; }; }
		return BWin.request(url, {
			_onComplete: onComplete,
			onSuccess: function(){
				window.execScript(this.transport.responseText);
				this.options._onComplete.call(this);
			}
		});
	},

	write: function(pageId, element, onComplete){
		if(!element || !pageId){
			// we got some bad arguments here, abort the mission, over. *kuughrrrh*
			TRACE(0, "BWin.write: Invalid arguments.");
			return;
		}

		if(onComplete === undefined){
			onComplete = function(){ return undefined; }; }

		var page = BWin.CurrentSite.Pages.find(pageId);

		if(element.className.match(/[0-9]{5}/gi)){
			element.className = element.className.replace(/[0-9]{5}/gi, pageId.toString());
		}else{
			element.className += " " + pageId.toString();
		}

		if(!page.html){
			BWin.request(
				"./?id=" + pageId.toString(),
				{	htmlElement: element,
					pageNode: page,
					asynchronus: false,
					writeComplete: onComplete,
					onSuccess: function(){
						this.options.htmlElement.innerHTML = this.transport.responseText;
						this.options.pageNode.html = this.transport.responseText;

						this.options.writeComplete();
					},
					onFailure: function(){
						TRACE(0, "BWin.write: Unable to request blob with id [" + this.page.nodeId + "]");
					}
				});
		}else{
			element.innerHTML = page.html;
			onComplete();
		}

		Event.observers.each(function(obj, indx, arr){
			if(arr[indx] && arr[indx][0].parentElement == null){
				Event._destroy(indx); }
		});
	}
};

/******************************************************************************
	Context menu Class
******************************************************************************/
var ContextMenu = {
	contextMenuTimeout: null,

	newContextMenu: function(menu, element){
		if(!menu || !element){
			TRACE(0, "ContextMenuRendering: Invalid arguments.");
			return;
		}

		Event.init(element, "contextmenu",
		// Generate a function here, out of thin air
		"if(event.ctrlKey){ return; } ContextMenu.displayMenu('" + menu.menuId + "'); return false; " , true);
	},

	displayMenu: function(menuId){
		var outerDiv = document.createElement("div");
		var middleDiv = document.createElement("div");
		var innerDiv = document.createElement("div");

		var menu = BWin.CurrentSite.Menus.getMenu(menuId);

		// WE have to attach the menu to the body. Some nodes can't have children.
		document.body.appendChild(outerDiv);

		outerDiv.appendChild(middleDiv);
		middleDiv.appendChild(innerDiv);

		// Setting stuff for the outer div
		outerDiv.id = menu.menuId;

		outerDiv.style.position = "absolute";
		outerDiv.style.left = event.clientX - 10;
		outerDiv.style.top = event.clientY - 10;

		// setting a temp over flow
		outerDiv.style.overflow = "auto";

		// Border neatness
		outerDiv.style.borderTop = "1px solid threedlightshadow";
		outerDiv.style.borderLeft = "1px solid threedlightshadow";
		outerDiv.style.borderBottom = "1px solid threeddarkshadow";
		outerDiv.style.borderRight = "1px solid threeddarkshadow";

		// Setting stuff for the middle div
		middleDiv.style.position = "absolute";
		middleDiv.style.left = "0px";
		middleDiv.style.top = "0px";

		middleDiv.style.width = "100%";
		middleDiv.style.height = "100%";

		middleDiv.style.borderTop = "1px solid threedhighlight";
		middleDiv.style.borderLeft = "1px solid threedhighlight";
		middleDiv.style.borderBottom = "1px solid threedshadow";
		middleDiv.style.borderRight = "1px solid threedshadow";

		// Inner div
		innerDiv.style.position = "absolute";
		innerDiv.style.left = "0px";
		innerDiv.style.top = "0px";

		innerDiv.style.width = "100%";
		innerDiv.style.height = "100%";

		innerDiv.style.background = "menu";
		innerDiv.style.padding = "1px";

		for(var n = 0; n < menu.items.length; n++){
			var menuItem = document.createElement("div");

			// The settings for the menu items
			menuItem.style.paddingLeft = "16px";
			menuItem.style.paddingRight = "16px";
			menuItem.style.paddingTop = "3px";
			menuItem.style.paddingBottom = "3px";
			menuItem.style.fontFamily = "Tahoma";
			menuItem.style.fontSize = "11px";
			menuItem.style.color = "menutext";
			menuItem.style.cursor = "default";

			menuItem.innerHTML = menu.items[n].content.html;

			innerDiv.appendChild(menuItem);

			Event.init(menuItem, "mouseenter", ContextMenu.onMouseOverItem, true);
			Event.init(menuItem, "mouseout", ContextMenu.onMouseOutItem, true);
			Event.init(menuItem, "click", menu.items[n].content.onClick, true);
		}

		Event.init(outerDiv, "mouseenter", ContextMenu.onMouseOverMenu, true);
		Event.init(outerDiv, "mouseleave", ContextMenu.onMouseLeaveMenu, true);

		// We are going to prevent a context menu on a context menu...
		Event.init(outerDiv, "contextmenu", function(){ return false; }, true);

		outerDiv.style.width = outerDiv.scrollWidth + 4;
		outerDiv.style.height = outerDiv.scrollHeight + 4;

		outerDiv.style.overflow = "visible";
	},

	onMouseOverItem: function(){
		event.srcElement.style.background = "activecaption";
		event.srcElement.style.color = "captiontext";
	},
	onMouseOutItem: function(){
		event.srcElement.style.background = "menu";
		event.srcElement.style.color = "menutext";
	},

	onMouseOverMenu: function(){
		if(ContextMenu.contextMenuTimeout !== null){
			clearTimeout(ContextMenu.contextMenuTimeout); }
	},
	onMouseLeaveMenu: function(){
		ContextMenu.ContextMenuTimeout = setTimeout("ContextMenu.contextMenuTimeout = null; $('" + event.srcElement.id + "').removeNode(true);", 10);
	}
};

/******************************************************************************
	Sliding menu Class
******************************************************************************/
var SlidingMenu = {
	slidingMenuInstances: { },

	newSlidingMenu: function(menu, menuOptions){
		if(
			menuOptions.isType() != "object" 		||	menuOptions.menu.isType() != "object"	||
			menuOptions.bar.isType() != "object"	||	menuOptions.items.isType() != "object"
		){
			TRACE(0, "SlidingMenu: Invalid agruments missing menu options");
			return;
		}else if(!menu /*|| menu.isType() != "object"*/){
			TRACE(0, "SlidingMenu: Invalid arguments missing menu");
			return;
		}else if(SlidingMenu.slidingMenuInstances[menu.menuId]){
			TRACE(0, "SlidingMenu: [" + menu.menuId + "] is already renderd");
			return;
		}

		// Well this is actually a singleton but we need to remember some stuff with this type of menu,
		// how far to slide, the speed etc etc. It can't be predefined. Same goes for all the funky
		// colour combinations.
		SlidingMenu.slidingMenuInstances[menu.menuId] = menuOptions;

		var iFrame = document.createElement("iframe");

		// Setting some iFrame options
		iFrame.id = menu.menuId + "_iFrame";
		iFrame.name = menu.menuId + "_iFrame";

		iFrame.frameBorder = 0;
		iFrame.marginWidth = 0;
		iFrame.marginHeight = 0;

		iFrame.scrolling = "no";
		iFrame.allowTransparency = true;
		iFrame.style.background = "transparent";

		iFrame.src = "about:blank";

		// And now finally appending it to the page
		document.body.appendChild(iFrame);

		menuOptions.targetWindow = iFrame;

		// Adding some style to the menuIframe
		//Object.extend(iFrame.style, menuOptions.menu);
		overWrite(iFrame.style, menuOptions.menu);

		if(!iFrame.contentWindow && iFrame.contentWindow.document.readyState != "complete"){
			SlidingMenu.displayMenu(menu.menuId);
		}else{
		// sticking a event to our newly created sliding menu iFrame
			Event.init(iFrame, "readystatechange",
				function(){
					if(event.srcElement.readyState != 'complete'){ return; }

					// Calling the displayMenu function with our ID, wich will lead it to the appropeate styles
					// and other options.
					SlidingMenu.displayMenu(event.srcElement.id.substring(0, event.srcElement.id.indexOf("_iFrame")));

					// destroying the event, we dont want to "redisplay" the menu every time an image is doen loading.
					Event.destroy($(event.srcElement.id), "readystantechange");
				}, true);
		}
	}, // newSlidingMenu()

	displayMenu: function(menuId){
		// Testing if we got the right arguments. It has to be a valid menuId
		if(!menuId || !SlidingMenu.slidingMenuInstances[menuId]){
			TRACE(0, "SlidingMenu.displayMenu: Unable to render menu, invalid menuId");
			return;

		// This should actually be fixed pretty soon. Pages can have menu collections aswell...
		}else if(!BWin.CurrentSite.Menus.getMenu(menuId)){
			TRACE(0, "SlidingMenu.displayMenu: No menu found for [" + menuId + "]");
			return;
		}

//	try{ // adding a little safty here...
		// Setting some short cuts and creating the neccesary elements.
		var sMenu = SlidingMenu.slidingMenuInstances[menuId];
		var menu = BWin.CurrentSite.Menus.getMenu(menuId);

		// Setting the body transparent
		sMenu.targetWindow.contentWindow.document.body.style.background = "transparent";

		var container = sMenu.targetWindow.contentWindow.document.createElement("div");
		var slider = sMenu.targetWindow.contentWindow.document.createElement("div");
		var bar = sMenu.targetWindow.contentWindow.document.createElement("div");

		// Setting some options
		container.id = "container";
		container.className = menu.menuId;

		slider.id = "slider";
		slider.className = menu.menuId;

		bar.id = "bar";
		bar.className = menu.menuId;

		// Set overflow to auto so when the objects are done rendering we van adjust it to the proper size
		sMenu.targetWindow.contentWindow.document.body.style.overflow = "auto";

		// Patching all the elements together
		sMenu.targetWindow.contentWindow.document.body.appendChild(container);
		container.appendChild(slider);
		container.appendChild(bar);

		// Setting the styles of the HTML elements

		// Container settings.
		container.style.background = "transparent";
		container.style.padding = 0;
		container.style.margin = 0;
		container.style.zIndex = 0;

		container.style.position = "absolute";

		// Depending on how the menu is positioned
		switch(sMenu.position){
			case "top":
				container.style.left = 0;
				container.style.top = -(sMenu.items.height);
				break;
			case "right":
				container.style.left = sMenu.items.width;
				container.style.top = 0;
				break;
			case "bottom":
				container.style.left = 0;
				container.style.top = sMenu.items.height;
				break;
			case "left":
				container.style.left = -(sMenu.items.width);
				container.style.top = 0;
				break;
			default:
				TRACE(0, "[" + sMenu.position + "] is a invalid position.");
				//throw({message: "[" + sMenu.position + "] is a invalid position."});
				break;
		}

		// slider settings

		slider.style.padding = 0;
		slider.style.margin = 0;

		slider.style.position = "absolute";

		slider.style.left = 0;
		slider.style.top = 0;

		// Setting the bar properties
		bar.style.position = "absolute";
		switch(sMenu.position){
			case "top":
				bar.style.left = 0;
				bar.style.top = sMenu.items.height;
				break;
			case "right":
				bar.style.left = sMenu.items.width;
				bar.style.top = 0;
				break;
			case "left":
			case "bottom":
				bar.style.left = 0;
				bar.style.top = 0;
				break;
		}

		bar.innerHTML = sMenu.barHTML;
		bar.unselectable = "on";

		// before we are going to add the items to the menu we are going to set some sexy styles
		overWrite(slider.style, sMenu.slider);
		overWrite(bar.style, sMenu.bar);

		// Now we are going to add the itmes =)
		menu.items.each(function(obj, indx, arr){
			var tDiv = sMenu.targetWindow.contentWindow.document.createElement("div");

			// Setting some style options here.
			tDiv.style.position = "absolute";

			switch(sMenu.position){
				case "top":
					tDiv.style.height = sMenu.items.width;
					tDiv.style.left = sMenu.items.width * indx;
					tDiv.style.top = 0;
					break;
				case "bottom":
					tDiv.style.height = sMenu.items.width;
					tDiv.style.left = sMenu.items.width * indx;
					tDiv.style.top = sMenu.bar.height;
					break;
				case "right":
					tDiv.style.height = sMenu.items.height;
					tDiv.style.left = 0;
					tDiv.style.top = sMenu.items.height * indx;
					break;
				case "left":
					tDiv.style.height = sMenu.items.height;
					tDiv.style.left = sMenu.bar.width;
					tDiv.style.top = sMenu.items.height * indx;
					break;
			}

			//Object.extend(tDiv.style, sMenu.items);
			overWrite(tDiv.style, sMenu.items);

			tDiv.innerHTML = arr[indx].content.html;
			tDiv.id = menu.menuId + "_" + (indx + 1).toString();
			tDiv.unselectable = "on";

			slider.appendChild(tDiv);

			for(var eventFunc in arr[indx].content){
				if(
					eventFunc.substr(0, 2) == "on"	&&
					eventFunc.charAt(2) === eventFunc.charAt(2).toUpperCase()
				){
					Event.init(tDiv, eventFunc.substr(2).toLowerCase(), arr[indx].content[eventFunc], true);
				}
			}
		});

		Event.init(container, "mouseover", "SlidingMenu.slideOut('" + menu.menuId + "');", true);
		Event.init(container, "mouseleave", "SlidingMenu.slideIn('" + menu.menuId + "');", true);

		Event.init($(menu.menuId + "_iFrame"), "readystatechange",
			function(){
				SlidingMenu.resizeIFrame(event.srcElement.id.substring(0, event.srcElement.id.indexOf("_iFrame")));
			}, true);

		SlidingMenu.resizeIFrame(menu.menuId);
	}, // displayMenu()

	resizeIFrame: function(menuId){
		// This function will resize the iFrame to the proper size.
		var sMenu = SlidingMenu.slidingMenuInstances[menuId];
		var menu = BWin.CurrentSite.Menus.getMenu(menuId);

		if(sMenu.targetWindow.contentWindow.document.readyState != "complete"){ return; }

		var container = sMenu.targetWindow.contentWindow.document.getElementById("container");
		var slider = sMenu.targetWindow.contentWindow.document.getElementById("slider");
		var bar = sMenu.targetWindow.contentWindow.document.getElementById("bar");

		var body = sMenu.targetWindow.contentWindow.document.body;

		//sMenu.targetWindow.width = sMenu.targetWindow.document.body.scrollWidth;
		//sMenu.targetWindow.height = sMenu.targetWindow.document.body.scrollHeight;

		switch(sMenu.position){
			case "left":
			case "right":
				bar.style.height = body.scrollHeight;
				slider.style.height = body.scrollHeight;
				container.style.width =
					(isNaN(sMenu.items.width) ? 0 : sMenu.items.width) +
					(isNaN(sMenu.bar.width) ? 0 : sMenu.bar.width);
				container.style.height = body.scrollHeight;
				break;
			case "top":
			case "bottom":
				bar.style.width = body.scrollWidth;
				slider.style.width = body.scrollWidth;
				container.style.width = body.scrollWidth;
				container.style.height =
					(isNaN(sMenu.items.height) ? 0 : sMenu.items.height) +
					(isNaN(sMenu.bar.height) ? 0 : sMenu.bar.height);
				break;
		}

		body.style.overflow = "hidden";

		sMenu.targetWindow.style.width = parseInt(container.style.width) + 2;
		sMenu.targetWindow.style.height = parseInt(container.style.height) + 2;

	},

	__move: function(menuId, InOut, side, plus, condtion){
		var sMenu = SlidingMenu.slidingMenuInstances[menuId];
		var container = sMenu.targetWindow.contentWindow.document.getElementById("container");

		if(condtion){
			clearTimeout(sMenu.Moving);
			sMenu.Moving = setTimeout("SlidingMenu." + (InOut === true ? "slideIn" : "slideOut") + "('" + menuId + "')", sMenu.slideSpeed);

			if(plus){
				container.style[side] = parseInt(container.style[side]) + 5;
			}else{
				container.style[side] = parseInt(container.style[side]) - 5;
			}
		}else{
			clearTimeout(sMenu.Moving);
		}
	},

	slideOut: function(menuId){
		var sMenu = SlidingMenu.slidingMenuInstances[menuId];
		var container = sMenu.targetWindow.contentWindow.document.getElementById("container");

		switch(sMenu.position){
			case "top":
				SlidingMenu.__move(menuId, false, "top", true, (parseInt(container.style.top) < 0));
				break;
			case "right":
				SlidingMenu.__move(menuId, false, "left", false, (parseInt(container.style.left) < parseInt(container.style.width)));
				break;
			case "bottom":
				SlidingMenu.__move(menuId, false, "top", false, (parseInt(container.style.top) > 0));
				break;
			case "left":
				SlidingMenu.__move(menuId, false, "left", true, (parseInt(container.style.left) < 0));
				break;
		}
	},

	slideIn: function(menuId){
		var sMenu = SlidingMenu.slidingMenuInstances[menuId];
		var container = sMenu.targetWindow.contentWindow.document.getElementById("container");

		switch(sMenu.position){
			case "top":
				SlidingMenu.__move(menuId, true, "top", false, (parseInt(container.style.top) > -sMenu.items.height));
				break;
			case "right":
				SlidingMenu.__move(menuId, true, "left", true, (parseInt(container.style.left) > parseInt(container.style.width)));
				break;
			case "bottom":
				SlidingMenu.__move(menuId, true, "top", true, (parseInt(container.style.top) < sMenu.items.height));
				break;
			case "left":
				SlidingMenu.__move(menuId, true, "left", false, (parseInt(container.style.left) < -sMenu.items.width));
				break;
		}

		return false;
	}
};


function menu_onMouseenter(){
	// The item is clicked so we are going to do nothing here...
	if(Element.hasClassName(event.srcElement, "blauw") === "blauw"){
		Event.stopBubble();
		return;
	}

	// it appears we have a normal item here, lets h4x0r some names
	Element.replaceClassName(event.srcElement, "blauwText", "blauwText");
	Element.replaceClassName(event.srcElement, "geel", "wit");
}

function menu_onMouseleave(){
	// The item is clicked so we are going to do nothing here...
	if(Element.hasClassName(event.srcElement, "blauw") === "blauw"){
		Event.stopBubble();
		return;
	}

	// it appears we have a normal item here, lets h4x0r some names
	Element.replaceClassName(event.srcElement, "blauwText", "blauwText");
	Element.replaceClassName(event.srcElement, "wit", "geel");
}

function menu_onMouseclick(){
	var container = $("topMenu");
	for(var n = 0; n < container.children.length; n++){
		// return all the items to normal again
		if(container.children[n].id == event.srcElement.id){ continue; }
		Element.replaceClassName(container.children[n], "witText", "blauwText");
		Element.replaceClassName(container.children[n], "blauw", "geel");
	}

	// Set the new clicked item
	Element.replaceClassName(event.srcElement, "blauwText", "witText");
	Element.replaceClassName(event.srcElement, "wit", "blauw");
}



var FluoroscopyLeftMenu = {

	// This function also renders the menu. Pretty simple...
	newFluoroscopyLeftMenu: function(menu, targetElement){
		if(!menu || !targetElement){
			TRACE(0, "FluoroscopyLeftMenu: Invalid arguments");
			return;
		}

		menu.items.each(function(obj, indx, arr){
			var tDiv = document.createElement("div");

			tDiv.id = "FluoroscopyLeftMenu_" + indx.toString();
			tDiv.className = indx === 0 ? "leftMenuItem witText blauw lichtBlokje" : "leftMenuItem blauwText creme donkerBlokje";
			tDiv.innerHTML = arr[indx].content.html;

			tDiv.style.top = (targetElement.children.length * 40);

			if(targetElement.style.height){
				targetElement.style.height = parseInt(targetElement.style.height) + 40;
			}else{
				targetElement.style.height = 40;
			}

			targetElement.appendChild(tDiv);

			Event.init(tDiv, "mouseenter", FluoroscopyLeftMenu.onMouseenter, true);
			Event.init(tDiv, "mouseleave", FluoroscopyLeftMenu.onMouseleave, true);
			Event.init(tDiv, "click", arr[indx].content.onClick, true);
			Event.init(tDiv, "click", FluoroscopyLeftMenu.onMouseclick, true);

		});
	},

	onMouseenter: function(){
		// The item is clicked so we are going to do nothing here...
		if(Element.hasClassName(event.srcElement, "blauw") === "blauw"){
			Event.stopBubble();
			return;
		}

		// it appears we have a normal item here, lets h4x0r some names
		Element.replaceClassName(event.srcElement, "blauwText", "blauwText");
		Element.replaceClassName(event.srcElement, "creme", "wit");
		Element.replaceClassName(event.srcElement, "donkerBlokje", "lichtBlokje");
	},
	onMouseleave: function(){
		// The item is clicked so we are going to do nothing here...
		if(Element.hasClassName(event.srcElement, "blauw") === "blauw"){
			Event.stopBubble();
			return;
		}

		// it appears we have a normal item here, lets h4x0r some names
		Element.replaceClassName(event.srcElement, "blauwText", "blauwText");
		Element.replaceClassName(event.srcElement, "wit", "creme");
		Element.replaceClassName(event.srcElement, "lichtBlokje", "donkerBlokje");
	},
	onMouseclick: function(){
		var container = $("LeftMenuContainer");
		for(var n = 0; n < container.children.length; n++){
			// return all the items to normal again
			if(container.children[n].id == event.srcElement.id){ continue; }
			Element.replaceClassName(container.children[n], "witText", "blauwText");
			Element.replaceClassName(container.children[n], "blauw", "creme");
			Element.replaceClassName(container.children[n], "lichtBlokje", "donkerBlokje");
		}

		// Set the new clicked item
		Element.replaceClassName(event.srcElement, "blauwText", "witText");
		Element.replaceClassName(event.srcElement, "wit", "blauw");
	}
};

var ArchiveItems = {

	// This function also renders the menu. Pretty simple...
	newArchiveItems: function(){
		$('leftMenuContainer').innerHTML = "<div id='spineMenu' class='spineMenu'><img id='procSpine' src='./?id=49221'></div>";
			document.getElementsByClassName("(green|red)[0-9]*").each(function(obj,indx,arr){
				Event.init(arr[indx], "mouseenter", ArchiveItems.onMouseenter, true);
				Event.init(arr[indx], "mouseleave", ArchiveItems.onMouseleave, true);
				Event.init(arr[indx], "click", ArchiveItems.onMouseclick, true);
				$('spineMenu').appendChild(spineDot(arr[indx].id) );
			});

		$('spineMenu').style.left = '510px';
	},

	onMouseenter: function(){
		showSpineDot(event.srcElement.id);
		event.srcElement.style.color = '95336b';
		event.srcElement.style.cursor = 'hand';
	},
	onMouseleave: function(){
		hideSpineDot(event.srcElement.id);
		event.srcElement.style.color = '';
		event.srcElement.style.cursor = '';
	},
	onMouseclick: function(){
		dotId = event.srcElement.id;
		if ( dotId > 49214 ) {
			$("content").innerHTML = $('leftMenuContainer').innerHTML;
			$('leftMenuContainer').innerHTML = '';
			$('spineMenu').style.left = '345px';

			BWin.write(event.srcElement.id, $("leftMenuContainer"));
		}

		//ProcTitleItems.newProcTitleItems(event.srcElement.id, actualProcName);
	}
};

function spineDot( id ){
	//x = left y = top
	var someDot = new Image();
	var coords = dotLookup[id];

	if(coords[0] == 'red') {
		someDot.src = './?id=49242';
	}else if (coords[0] == 'green'){
		someDot.src = './?id=49240';
	}
	someDot.id = "dot_" + id;
	someDot.className = 'spineDot';
	someDot.style.top = (coords[2]-12) + "px";
	someDot.style.left = (coords[1]-12) + "px";
	someDot.style.display = 'none';
	return someDot;
}

function showSpineDot( id )
{
	var someDot = $("dot_" + id);
	someDot.style.display = 'block';
}

function hideSpineDot( id )
{
	var someDot = $("dot_" + id);
	someDot.style.display = 'none';
}

function testErrOutput(objErrors){
	var message = objErrors.generalError + '<br />';
	
	if (objErrors.fieldErrors) {
		for (var ii = 0; ii < objErrors.fieldErrors.length; ii++)
			message += (ii + 1) + ': Field "' + objErrors.fieldErrors[ii].field.name + '" ' + objErrors.fieldErrors[ii].errorMessage + "<br />";
	}
	
	var outputDiv = document.getElementById("errOutput");
	
	if(outputDiv != null){
		outputDiv.innerHTML = message;
		outputDiv.style.display = "block";
	}
}

function myOnSuccess() {
	$("errOutput").style.display = "block";
	$("errOutput").innerHTML = "\
	<p>\
	Your registration has been successfull. Please check your email for\
	a confimation message. The confirmation email will contain an\
	activation link wich you will need to follow to activate your account.\
	</p>";
};

function myDebug(message){
	var debugContainer = document.getElementById("debugContainer");
	if(debugContainer == null){
		debugContainer = document.createElement("div");
		debugContainer.id = "debugContainer";
		var st = debugContainer.style;
		st.position = "absolute";
		st.top = "0";
		st.right = "0";
		st.width = "500px";
		st.height = "100px";
		st.overflow = "scroll";
		st.backgroundColor = "#EEEEEE";
		st.fontSize = "small";
		document.body.appendChild(debugContainer);
	}

	debugContainer.innerHTML += message.replace(/&/g, '&amp;').replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/\n/g, "<br />") + "<br />";
}

function initLoginRegPage(){
	if(BWin.user.userName === null){
		BWin.Form.Validator.addDataType(
			'bwFormPassword',
			'Password',
			null,
			"Passwords are not the same.",
			"Please verify your password.",
			function(password) {
				if( $('password1').value == password ){
					$('Password').value = hex_md5(password);
					return true;
				} else {
					return false;
				}
			}
		);
	
		// Run this to auto-activate all "bwForm" class forms in the document.
		BWin.Form.setupAll({
			showErrors: 'afterField',
			showErrorsOnSubmit: true,
			submitErrorFunc: testErrOutput,
			asyncSubmitFunc: myOnSuccess,
			//ajaxDebugFunc: myDebug,
			theme: "Winxp2",
			themeId: "49943"
		});

		Event.init($("userNameBox"), "keypress",
			function(){
	 			if(event.keyCode == 0x0D){ $("userPassBox").focus(); }
			}, true);
	
		Event.init($("userPassBox"), "keypress",
			function(){
	 			if(event.keyCode == 0x0D){ $("loginButton").fireEvent("onclick"); }
			}, true);

		Event.init($("loginButton"), "click",
			function(){
				new Ajax.Request(
					"./ctf_login.lee?auth=" + $("userNameBox").value + "," + hex_md5($("userNameBox").value + hex_md5($("userPassBox").value)),
				{	method: "get",
					onSuccess: function(){
						if(this.transport.responseText == "OK"){
							BWin.initUser(
								$("userNameBox").value,
								hex_md5($("userNameBox").value + $("userPassBox").value),
								this.transport.responseText
							);

							$('FluoroscopyMenu_2').click();
						} // if(OK)
					} // onSuccess()
				}); // Ajax Request
			}, true);
	}else{
		// Just some HTML hacking here
		var loginHeader = document.getElementsByClassName("loginHeader")[0];
		var loginBox = $("loginContainer");
				
		loginHeader.parentNode.removeChild(loginHeader);
		loginBox.parentNode.removeChild(loginBox);
/*
		// Do some stuff with the boxes =)
		$("username").value = BWin.user.userName;
		$("username").disabled = true;
		$("username").style.backgroundColor = "#D4D0C8";
		
		$("email").disabled = true;
		$("email").style.backgroundColor = "#D4D0C8";	
		
		$("verifyemail").disabled = true;
		$("verifyemail").style.backgroundColor = "#D4D0C8";
		
		$("regButton").value = "Save";
		
		document.getElementsByClassName("regHeader")[0].style.left = "10px";
		document.getElementsByClassName("regHeader")[0].innerText = "My account";
		$("regContainer").style.left = "10px";

		// We will need to request some information from the server to fill in the
		// registration boxes.
		new Ajax.Request( "./ctf_userman.lee?getUser=" + BWin.user.userName + "&time=" + (new Date).getTime(), {
			method: "get",
			onSuccess: function(){
				function $v(elId){ return $(elId).value; }
				function $c(elId){ return $(elId).checked; }
				if(this.transport.responseText != ""){
					(new Function("this.profile = " + this.transport.responseText)).call(BWin.user);
					
					$("username").value		= BWin.user.profile.user;
					$("name").value			= BWin.user.profile.name;
					$("firstname").value	= BWin.user.profile.firstName;
					$("title").value		= BWin.user.profile.title;
					$("occupation").value	= BWin.user.profile.occupation;
					$("institute").value	= BWin.user.profile.hospital;
					$("address").innerText	= BWin.user.profile.hospitalAddress;
					$("phonenumber").value	= BWin.user.profile.phoneNumber;
					
					$("infiltrations").checked	= BWin.user.profile.infiltration; 
					$("neurolysis").checked		= BWin.user.profile.neurolysis;   
					$("nucleoplasty").checked	= BWin.user.profile.nucleoplasty; 
					$("vertebroplasty").checked	= BWin.user.profile.vertebrolasty;
					$("biopsiesAndDrainages").checked = BWin.user.profile.biopsisAndDrainages; 					
				}
			}
		});
		
		Event.init($("regButton"), "click",
			function(){
				if(!BWin.user.profile){ return; }
				new Ajax.Request(
					"./ctf_userman.lee?Username=" + Crypto.base64.encodeString(BWin.user.userName, Crypto.base64.urlSafeBase64, 1) + "&time=" + (new Date).getTime(),
					{	method: "post",
						postBody: (function(){
							return "time=" + (new Date()).getTime().toString() +
								(($("password").value !== "" || $("verifypassword").value.toString() != $("password").value.toString()) ? "&Password="	+ hex_md5($("password").value) : "") +
								($("name").value		!= BWin.user.profile.name 			? "&Name=" 		+ Crypto.base64.encodeString($("name").value, Crypto.base64.urlSafeBase64, 1)		: "") +
								($("firstname").value	!= BWin.user.profile.firstName		? "&FirstName="	+ Crypto.base64.encodeString($("firstname").value, Crypto.base64.urlSafeBase64, 1)	: "") +
								($("title").value		!= BWin.user.profile.title			? "&Title="		+ Crypto.base64.encodeString($("title").value, Crypto.base64.urlSafeBase64, 1)		: "") +
								($("occupation").value	!= BWin.user.profile.occupation 	? "&Occupation="+ Crypto.base64.encodeString($("occupation").value, Crypto.base64.urlSafeBase64, 1)	: "") +
								($("institute").value	!= BWin.user.profile.hospital		? "&Hospital="	+ Crypto.base64.encodeString($("institute").value, Crypto.base64.urlSafeBase64, 1)	: "") +
								($("address").innerText	!= BWin.user.profile.hospitalAddress? "&HospitalAddress=" + Crypto.base64.encodeString($("address").innerText, Crypto.base64.urlSafeBase64, 1) : "") +
								($("phonenumber").value	!= BWin.user.profile.phoneNumber	? "&Phonenumber=" + Crypto.base64.encodeString($("phonenumber").value, Crypto.base64.urlSafeBase64, 1) : "") +
								
								($("infiltrations").checked	!= BWin.user.profile.infiltration	? "&Int_infil="	+ ($("infiltrations").checked	? "1" : "0") : "") +
								($("neurolysis").checked	!= BWin.user.profile.neurolysis		? "&Int_neuro="	+ ($("neurolysis").checked		? "1" : "0") : "") +
								($("nucleoplasty").checked	!= BWin.user.profile.nucleoplasty	? "&Int_nucleo="+ ($("nucleoplasty").checked	? "1" : "0") : "") +
								($("vertebroplasty").checked!= BWin.user.profile.vertebrolasty	? "&Int_verte="	+ ($("vertebroplasty").checked	? "1" : "0") : "") +
								($("biopsiesAndDrainages").checked != BWin.user.profile.biopsisAndDrainages ? "&Int_biop="	+ ($("biopsiesAndDrainages").checked ? "1" : "0") : "");
						})(),
						onSuccess: function(){ 
							BWin.user.postBody = this.options.postBody;
							BWin.user.responseQuery = this.transport.responseText; 
						}
					});
			}, true);
*/	}		
} // initLoginRegPage

function initForum(){
	var main = $("forumContainer");

	//buttn = new $TextButton(null, isAdmin, "as admin", "as user");
	//buttn.addListenr(function(){isAdmin = !isAdmin; currentForum.redraw();}, null);
	//main.appendChild(buttn.buttonView.span);

	// add button link
	//var buttn = new $TextButton(null, true, "Directory", null);
	//buttn.addListenr(function(){window.location="?id=49382";}, null);
	//main.appendChild(buttn.buttonView.span);

	currentForum = new $ForumPage(null, FORUMID, main);

	// load forumdata
	RemotePersistance.remoteLoad();

	// collapse both tree's:
	 currentForum.model.collapse();

	 // expand the rootNode
	 currentForum.model.rootNode.toggle(currentForum.model.rootNode, true);

}

dotLookup = {
	49182:['red',2,8],					49187:['red',28,75],				49550:['red',42,134],
	49189:['red',32,266],				49190:['red',4,285],				49567:['red',12,310,'red',5,363],
	49194:['red',18,375,'red',26,400],	49551:['red',37,267,'red',32,290],	49557:['green',32,23],
	49202:['green',22,20],				49203:['green',28,51],				49558:['green',22,60],
	49205:['green',80,207],				49410:['green',41,367],				49549:['green',39,391],
	49208:['green',51,397],				49209:['green',48,388],				49210:['green',42,392],
	49211:['green',1,423],				49559:['green',44,425],				49213:['green',67,479]
};

function makeArchivePage(type, title, video, TM_text, TM_ID, Diag1_text, Diag1_ID, Diag2_text, Diag2_ID, Diag3_text, Diag3_ID, comment_text){
	var archivePage = '';

	archivePage += "<div id='whiteSpace' class='blauw witText menuItem'>" + title + "</div>";
	archivePage += "<EMBED src='http://videos.bwintech.nl/videos/ctfarchive/" + video + "' id='stream' align=middle type=application/x-mplayer2 ShowControls='false'> </EMBED>";
	if( type != 'Diag4' && TM_ID > 0 ) {
		archivePage += "<img class='tripleSlice' src=./?id=" + TM_ID + ">";
		archivePage += "<div class='tripleSliceFootnote'>" + TM_text + "</div>";
	}
	if ( type != 'Diag0' )
	{
		archivePage += "<img class='Diag Left' src='./?id=" + Diag1_ID + "'>";
		archivePage += "<div class='DiagFootnote Left'>" + Diag1_text + "</div>";
	}
	if ( type == 'Diag2')
	{
		archivePage += "<img class='Diag Right' src='./?id=" + Diag2_ID + "'>";
		archivePage += "<div class='DiagFootnote Right'>" + Diag2_text + "</div>";
		archivePage += "<p class='comment top'>" + comment_text + "</p>";
	} else if ( type == 'Diag4'){
		archivePage += "<img class='Diag Right' src='./?id=" + Diag2_ID + "'>";
		archivePage += "<div class='DiagFootnote Right'>" + Diag2_text + "</div>";
		archivePage += "<p class='comment top'>" + comment_text + "</p>";		
		archivePage += "<img class='Diag someRight' src='./?id=" + TM_ID + "'>";
		archivePage += "<div class='DiagFootnote someRight'>" + TM_text + "</div>";
		archivePage += "<img class='Diag farRight' src='./?id=" + Diag3_ID + "'>";
		archivePage += "<div class='DiagFootnote farRight'>" + Diag3_text + "</div>";
		archivePage += "<p class='comment top'>" + comment_text + "</p>";	
	} else {
		archivePage += "<p class='comment mid'>" + comment_text + "</p>";
	}
	
	$("content").innerHTML = archivePage;
}

/******************************************************************************
	Events inits
******************************************************************************/
Event.init(document, "readystatechange",
	function(){
		if(document.readyState != "complete"){ return; }

		// pre even declairing
		Event.destroy(document, "readystatechange");
		windowResize(); // place the wrapper div at the nice center location...

		BWin.addSite("Fluoroscopy");
		BWin.setCurrentSite("Fluoroscopy");

		BWin.CurrentSite.Pages.insert(0, {first: 49237, second: new RelNode(49237, new $Page("index.html"))});

		BWin.CurrentSite.Pages.insert(0, {first: 1, second: new RelNode(1, new $Page("pages/"))});
		BWin.CurrentSite.Pages.insert(1, {first: 49245, second: new RelNode(49245, new $Page("pages/live_streaming.html"))});
		BWin.CurrentSite.Pages.insert(1, {first: 49335, second: new RelNode(49335, new $Page("pages/registration.html"))});
		BWin.CurrentSite.Pages.insert(1, {first: 49503, second: new RelNode(49503, new $Page("pages/preview.html"))});
		BWin.CurrentSite.Pages.insert(1, {first: 49346, second: new RelNode(49346, new $Page("pages/forum.html"))});
		BWin.CurrentSite.Pages.insert(1, {first: 49411, second: new RelNode(49411, new $Page("pages/archive.html"))});
		BWin.CurrentSite.Pages.insert(1, {first: 49409, second: new RelNode(49409, new $Page("pages/agenda.html"))});
		BWin.CurrentSite.Pages.insert(1, {first: 49412, second: new RelNode(49412, new $Page("pages/disclaimer.html"))});
		BWin.CurrentSite.Pages.insert(1, {first: 49410, second: new RelNode(49410, new $Page("menus/archive/LumbarEpidural/Menu.html"))});
		BWin.CurrentSite.Pages.insert(1, {first: 49549, second: new RelNode(49549, new $Page("menus/archive/LumbarPeriradicular/Menu.html"))});
		BWin.CurrentSite.Pages.insert(1, {first: 49410, second: new RelNode(49410, new $Page("menus/archive/Vertebroplasty/Menu.html"))});
		BWin.CurrentSite.Pages.insert(1, {first: 49550, second: new RelNode(49550, new $Page("menus/archive/ThoracicNeurolysis/Menu.html"))});
		BWin.CurrentSite.Pages.insert(1, {first: 49551, second: new RelNode(49551, new $Page("menus/archive/Vertebroplasty/Menu.html"))});
		BWin.CurrentSite.Pages.insert(1, {first: 49557, second: new RelNode(49557, new $Page("menus/archive/GreaterOccipitalNerve/Menu.html"))});
		BWin.CurrentSite.Pages.insert(1, {first: 49558, second: new RelNode(49558, new $Page("menus/archive/CervicalPeriradicular/Menu.html"))});
		BWin.CurrentSite.Pages.insert(1, {first: 49559, second: new RelNode(49559, new $Page("menus/archive/SacroIliacJoint/Menu.html"))});
		BWin.CurrentSite.Pages.insert(1, {first: 49567, second: new RelNode(49567, new $Page("menus/archive/LumbarNeurolysis/Menu.html"))});

		// We will have to create a cool menu aswell...
		BWin.CurrentSite.Menus.addMenu("contextMenu", new $menuItem("contextMenu"));
		BWin.CurrentSite.Menus.getMenu("contextMenu").addItem({html: "Login", onClick: function(){ window.open("./?id=48913", "BWin_login", "height = 183, width = 235 "); }});
		BWin.CurrentSite.Menus.getMenu("contextMenu").addItem({html: "Information", onClick: function(){ alert("Clicked Info"); }});
		BWin.CurrentSite.Menus.getMenu("contextMenu").addItem({html: "BWinTech", onClick: function(){ alert("Clicked BWinTech"); }});

		for(var someInt = 0; someInt < 6; someInt++)
		{
			Event.init($("FluoroscopyMenu_" + someInt), "mouseenter", menu_onMouseenter, true);
			Event.init($("FluoroscopyMenu_" + someInt), "mouseleave", menu_onMouseleave, true);
			//Event.init($("FluoroscopyMenu_" + someInt), "click", menu_onMouseclick, true);
		}

		BWin.disclaimer = false;

		Event.init($("FluoroscopyMenu_0"), "click", function(){ if( BWin.disclaimer != true ) { return; } if($("chatSendButton") && $("chatTextBox")){ destroyChat(); } menu_onMouseclick(); BWin.write(49335, $("content"), initLoginRegPage); $("LeftMenuContainer").innerHTML = '';}, true);
		Event.init($("FluoroscopyMenu_1"), "click", function(){ if( BWin.disclaimer != true ) { return; } if($("chatSendButton") && $("chatTextBox")){ destroyChat(); } menu_onMouseclick(); BWin.write(49503, $("content")); $("LeftMenuContainer").innerHTML = ''; if($("chatSendButton") && $("chatTextBox")){ destroyChat(); }}, true);
		Event.init($("FluoroscopyMenu_2"), "click", function(){ if( BWin.disclaimer != true ) { return; } if($("chatSendButton") && $("chatTextBox")){ destroyChat(); } menu_onMouseclick(); BWin.write(49409, $("content")); $("LeftMenuContainer").innerHTML = ''; if($("chatSendButton") && $("chatTextBox")){ destroyChat(); }}, true);
		Event.init($("FluoroscopyMenu_3"), "click", function(){ if( BWin.disclaimer != true ) { return; } if(BWin.user.userName == null){ $("FluoroscopyMenu_0").click(); Event.stopBubble(); return; } menu_onMouseclick(); BWin.write(49245, $("content")); $("LeftMenuContainer").innerHTML = ''; if($("chatSendButton") && $("chatTextBox")){ initChat(); }}, true);

		Event.init($("FluoroscopyMenu_4"), "click", function(){ if( BWin.disclaimer != true ) { return; } if($("chatSendButton") && $("chatTextBox")){ destroyChat(); } if(BWin.user.userName == null){ $("FluoroscopyMenu_0").click(); Event.stopBubble(); return; } menu_onMouseclick(); BWin.write(49346, $("content")/*, initForum*/); $("LeftMenuContainer").innerHTML = ''; }, true);

		Event.init($("FluoroscopyMenu_5"), "click", function(){ if( BWin.disclaimer != true ) { return; } if($("chatSendButton") && $("chatTextBox")){ destroyChat(); } if(BWin.user.userName == null){ $("FluoroscopyMenu_0").click(); Event.stopBubble(); return; } menu_onMouseclick(); BWin.write(49411, $("content")); $("LeftMenuContainer").innerHTML = ''; ArchiveItems.newArchiveItems(); }, true);

		BWin.write(49412, $("content"));

		Event.init($("accept_eng"), "click", function(){ BWin.disclaimer = true; BWin.write(49335, $("content"), initLoginRegPage); }, true);
		Event.init($("accept_fr"), "click", function(){ BWin.disclaimer = true; BWin.write(49335, $("content"), initLoginRegPage); }, true);

		// Add all the neccesary events.
		Event.init(window, "resize", windowResize, true);
//		ContextMenu.newContextMenu(BWin.CurrentSite.Menus.getMenu("contextMenu"), document.body);
//		FluoroscopyLeftMenu.newFluoroscopyLeftMenu(BWin.CurrentSite.Menus.getMenu("leftTechMenu"), $("LeftMenuContainer"));
	}, true);
