


var layoutObj = {}
	
	//PART I Functions for wall extensions

	//Defines which table to use
	layoutObj.table_body = function ()
								{ return document.getElementById("tb_body"); }

	//Array for storing wall sections
	layoutObj.wall_sections = new Array();
	
	//FUNCTIONS SHARED BETWEEN wall_section and ajax_div
	//Generate the necessary url
	layoutObj.get_page_info_url = function (page_info_url, start_id, end_id)
								{
									var xml_url = location.href.substring(0, location.href.lastIndexOf("?"));
									xml_url = xml_url.substring(0, xml_url.lastIndexOf("/")+1);
									xml_url += "htmAJAX_PageInfoRead.php";
									xml_url += "?pageinfo_src=";
									xml_url += page_info_url;
									
									if (start_id != null && end_id != null)
									{
										xml_url += "&start_id=";
										xml_url += start_id;
										xml_url += "&end_id=";
										xml_url += end_id;
									}
									
									return xml_url;
								}
								
	layoutObj.setFocus = function (smooth)
								{
									if (smooth)
									{
										smoothscrollObj.scrollTo("X", browserObj.elementclientLeft(this.div()));
									} else {
										//alert(browserObj.scrollXpos() + " " + browserObj.elementclientLeft(this.div()));
										browserObj.scrollToX(browserObj.elementclientLeft(this.div()));
									}
									
								}
	
	layoutObj.replace_innerHTML = function (div, innerHTML, firefox2scrollfix)
								{
									firefox2scrollfix = (typeof firefox2scrollfix == "undefined") ? false : firefox2scrollfix;
									
									if (browserObj.is_IE() && browserObj.is_legacy_browser())
									{
										for (var i = 0; i<div.childNodes.length; i++)
										{
											div.removeChild(div.childNodes[i]);
										}
										
										var new_div = document.createElement("div");
										new_div.innerHTML = innerHTML;
										div.appendChild(new_div);
									} else {
										div.innerHTML = innerHTML;
									}
									
									//introduce firefox2scrollfix to make sure that no scrolling is done when using ajax_div not wall_section
									//if (browserObj.match_browser("Firefox/2") && firefox2scrollfix)
									//{
									//	browserObj.scrollToX(browserObj.elementclientLeft(div));
									//}
								}
			
		layoutObj.global = new Array();
		layoutObj.parseResponseHeader = function (responseText)
								{
									var responsePrefix = "";
									
									var return_array = new Array();
									return_array["responseText"] = responseText;
									return_array["parameters"] = new Array();
									return_array["script"] = "";
									return_array["title"] = "(untitled)";
																	
									//Cut all the <!-- something1 { something2 } --> out
										//This produces an array with:
										//index 0: The whole chunk of comment line
										//index 1: something1
										//index 2: something2
										
									while (responsePrefix = responseText.match(/^\s*<!--\s*([a-z0-9]+)\s*\{\s*([^\{\}]*)\s*\}\s*-->/))
									{
										
										responseText = responseText.slice(responsePrefix[0].length);
										
										return_array["responseText"] = responseText;
										
										switch (responsePrefix[1].toLowerCase())
										{
											case "global":
											case "parameters":
												for (parameter_id in parameters=responsePrefix[2].match(/[^&]+/g))
													if (typeof parameters[parameter_id] == "string")
													if ((equal_location = parameters[parameter_id].indexOf("=")) != -1)
													{
														
														//Check if return_array had been defined
														if (typeof return_array[responsePrefix[1].toLowerCase()] != "object")
														{
															return_array[responsePrefix[1].toLowerCase()] = new Array();
														}
														//Extract name of parameter and value of parameter by String.slice
														var_name = parameters[parameter_id].slice(0, equal_location);
														var_value = parameters[parameter_id].slice(equal_location+1);
														
														//if its all numericals
														if (var_value.match(/^\d+$/))
														{
															var_value = parseInt(var_value);
														}
														
														return_array[responsePrefix[1].toLowerCase()][var_name] = var_value;
													}
												break;
											case "script":
												return_array["script"] = responsePrefix[2];
												break;
											case "title":
												return_array["title"] = responsePrefix[2];
												break;
											case "locationhref":
												if (responsePrefix[2].match(/^http[s]?:\/\/[^\s]+/))
													location.href = responsePrefix[2];
												break;
										}
									}
									
									return return_array;
								}
	
	layoutObj.set_page_value_limits = function (start_id, end_id)
								{
									this.start_id = start_id;
									this.end_id = end_id;
								}
								
	layoutObj.clear_page_value_limits = function ()		
								{
									this.set_page_value_limits(null, null);
								}
	
	/*
	//ORIGINALLY USED FOR CLASS EXTENSION.
	//NOT USED DUE TO objThis MESSING UP AFTER x.prototype = new y();
	//Object layoutObj.ajax_element (string id, string div_id, string page_info_url)
	//The basic ajax object. Require extension of success_func and failure_func to function.
	//See layoutObj.wall_section and layoutObj.ajax_div for more information.
	layoutObj.ajax_element = function (id, div_id, page_info_url)
								{
									this.id = id;
									this.div_id = div_id;
									this.page_info_url = page_info_url;
									this.div = function () { return document.getElementById(div_id); };
									
									this.xml_connect = {};
									
									this.parameters = {};
									
									var objThis = this;
									
									this.connect = function ()
																{
																	var xml_url = layoutObj.get_page_info_url(this.page_info_url);
																	
																	this.xml_connect = new ajax_XML_Connect(xml_url, function () {objThis.success_func.call(objThis)}, function () {objThis.failure_func.call(objThis)});
																}
									
								}
	*/
	
	//Object layoutObj.wall_section (string id, string div_id, string page_info_url)
	//extends layoutObj.ajax_element
	//
	//An object containing all information about a wall section.
	//Differentiate from a ajax_div by the success_func/failure_func
	
	//Class extension. Does not work due to objThis pointing to the wrong object.
	//layoutObj.wall_section = function () {};
	//layoutObj.wall_section.prototype = new layoutObj.ajax_element();

	layoutObj.wall_section = function (id, div_id, page_info_url)
								{
									this.id = id;
									
									this.td = function () { return document.getElementById((typeof id=="number") ? "td_body_ajax_"+id : id); }
									
									this.page_info_url = page_info_url;
									
									this.title = "loading";
									
									this.div_id = div_id;
									this.div = function () { return document.getElementById(div_id); };
									
									this.start_id = null;
									this.end_id = null;
									this.set_page_value_limits = layoutObj.set_page_value_limits;
									this.clear_page_value_limits = layoutObj.clear_page_value_limits;
									
									this.xml_connect = {};
									
									this.parameters = new Array(this.id);
									
									var objThis = this;
									
									this.connect = function ()
																{
																	var xml_url = layoutObj.get_page_info_url(this.page_info_url, this.start_id, this.end_id);
																	
																	this.xml_connect = new ajax_XML_Connect(xml_url, function () {objThis.success_func.call(objThis)}, function () {objThis.failure_func.call(objThis)});
																}
									
									this.sync = function ()
																{
																	this.connect();
																}
									
									this.success_func = function ()
																{
																	if (browserObj.is_IE() && browserObj.is_legacy_browser())
																	{
																		var responseText = xmlconnect_layoutObj_ie_responseText;
																	} else {
																		var responseText = this.xml_connect.responseText;
																	}
																	//alert(responseText);
																	
																	var responseHeader = layoutObj.parseResponseHeader(responseText);
																	
																	this.parameters = responseHeader["parameters"];
																	this.title = responseHeader["title"];
																	this.responseText = responseHeader["responseText"];
																	
																	this.setFocus = layoutObj.setFocus;
																	
																	if (!this.responseText.match(/^\s*$/))
																	{
																		opcGradient(this.div(), 100, 0, -5, 25);
																		
																		window.setTimeout("layoutObj.replace_innerHTML(document.getElementById('"+this.div_id+"'), layoutObj.wall_sections["+this.id+"].responseText, true); "+responseHeader["script"]+"; layoutObj.imgfrm_add_frame_from_parameters("+this.id+"); layoutObj.wall_sections["+this.id+"].setFocus(false);", 500);
																		window.setTimeout("opcGradient(document.getElementById('"+ this.div().id +"'), 0, 100, 5, 25)", 510);
																	} else {
																		//Pure variable definition AJAX. Do nothing.
																		//alert("Variables Defined.");
																		if (!responseHeader["script"].match(/^\s*$/))
																		{
																			eval(responseHeader["script"]);
																		}
																	}
																};
									
									this.failure_func = function ()
																{
																	alert("Unfortunately there is a connection error at the moment.");
																};
								}
								
								
	//Object layoutObj.ajax_div (string id, string div_id, string page_info_url)
	//extends layoutObj.ajax_element
	//
	//An object containing all information about a wall section.
	//Differentiate from a ajax_div by the success_func/failure_func	
	layoutObj.ajax_div_next_code = "";
	layoutObj.ajax_div = function (id, div_id, page_info_url)
								{
									this.id = id;
									this.div_id = div_id;
									this.page_info_url = page_info_url;
									this.div = function () { return document.getElementById(div_id); };
									
									this.start_id = null;
									this.end_id = null;
									this.set_page_value_limits = layoutObj.set_page_value_limits;
									this.clear_page_value_limits = layoutObj.clear_page_value_limits;
									
									this.xml_connect = {};
									
									this.parameters = new Array(this.id);
									
									var objThis = this;
									
									this.connect = function ()
																{
																	var xml_url = layoutObj.get_page_info_url(this.page_info_url, this.start_id, this.end_id);
																	//alert(xml_url);
																	
																	this.xml_connect = new ajax_XML_Connect(xml_url, function () {objThis.success_func.call(objThis)}, function () {objThis.failure_func.call(objThis)});
																}
									
									this.success_func = function ()
																{
																	if (browserObj.is_IE() && browserObj.is_legacy_browser())
																	{
																		var responseText = xmlconnect_layoutObj_ie_responseText;
																	} else {
																		var responseText = this.xml_connect.responseText;
																	}
																	
																	var responseHeader = layoutObj.parseResponseHeader(responseText);
																	
																	this.parameters = responseHeader["parameters"];
																	
																	for (variable in responseHeader["global"])
																	{
																		layoutObj.global[variable] = responseHeader["global"][variable];
																	}
																	
																	this.responseText = responseHeader["responseText"];
																	//alert(this.responseText);
																	
																	if (!this.responseText.match(/^\s*$/))
																	{
																		layoutObj.ajax_div_next_code = responseText;
																		opcGradient(this.div(), 100, 0, -5, 25);
																		window.setTimeout("layoutObj.replace_innerHTML(document.getElementById('"+this.div_id+"'), layoutObj.ajax_div_next_code, false); "+responseHeader["script"], 500);
																		window.setTimeout("opcGradient(document.getElementById('"+ this.div().id +"'), 0, 100, 5, 25)", 510);
																	} else {
																		//Pure variable definition AJAX. Do nothing.
																		//alert("Variables Defined.");
																		if (!responseHeader["script"].match(/^\s*$/))
																		{
																			eval(responseHeader["script"]);
																		}
																	}
																}
																
									this.failure_func = function ()
																{
																	alert("Unfortunately there is a connection error at the moment.");
																};
	
									this.sync = function ()
																{
																	this.connect();
																}
								}
									
	//Returns an array of elements that is to be shown while the page loads
	layoutObj.get_loading_element = function ()
								{
									var contents = {};
		
									var tb_alignment = document.createElement("table");
									var tr_alignment = document.createElement("tr");
									var td_alignment = document.createElement("td");
									tb_alignment.className = "full_height";
									tb_alignment.width = browserObj.width;
									
									td_alignment.className = "v-bottom h-right";
									
									var img_ajax_loading = document.createElement("img");
									img_ajax_loading.src = "./img-web/obj-animation/loading-text.png";
									
									td_alignment.appendChild(img_ajax_loading);
									tr_alignment.appendChild(td_alignment);
									tb_alignment.appendChild(tr_alignment);
									
									contents[0] = tb_alignment;
									
									return contents;
								}
	
	//Creating wall sections	
	layoutObj.create_wall_section = function (page_info_url)
									{
										var section_number = this.wall_sections.length;
										var id = "td_body_ajax_"+section_number;
										var div_id = "div_body_ajax_"+section_number;
										
										//For the "id" property section_number is passed instead so that you can extract the wall section index out of the object itself
										layoutObj.wall_sections[section_number] = new layoutObj.wall_section(section_number, div_id, page_info_url);
										var new_extension = tableObj.insertColumn(layoutObj.table_body(), layoutObj.table_body().rows[0].cells.length-2);
									
										new_extension = new_extension[0];
										
										new_extension.id = id;
										
										var div_ajax = document.createElement("div");
										div_ajax.id = div_id;
										
										var loading_element = this.get_loading_element();
										
										for (i in loading_element)
										{
											div_ajax.appendChild(loading_element[i]);
										}
										new_extension.appendChild(div_ajax);
										
										smoothscrollObj.scrollFor("X", browserObj.elementclientLeft(new_extension) - browserObj.scrollXpos() - browserObj.width + new_extension.clientWidth);
										//window.setTimeout("opcGradient(document.getElementById('"+ div_id +"'), 100, 0, -5, 25)", 1500);
										window.setTimeout("layoutObj.wall_sections["+section_number+"].sync();", 2000);
										
										return section_number;
									}
									
	layoutObj.shift_wall = function (page_info_url)
									{
										opcGradient(document.getElementById('td_body_menu'), 100, 0, -5, 25);
										
										window.setTimeout("layoutObj.create_wall_section('"+page_info_url+"');", 500);
										window.setTimeout("opcChange(document.getElementById('td_body_menu'), 100, true);", 510);
									}
								
	//PART II Functions for scrolling effects
	layoutObj.keydown_use_tab = true;
	layoutObj.keydown_use_arrows = true;
	layoutObj.keydown_use_home = true;
	layoutObj.keydown_use_end = true;
	layoutObj.keydown_home = function (e)
								{
									var keyCode = (window.event) ? window.event.keyCode : e.keyCode;
									switch (keyCode)
									{
									case 36:
									case 63273:
										if (layoutObj.keydown_use_home)
										{
											smoothscrollObj.scrollFor("X", -1 * browserObj.scrollXpos());
											(window.event) ? window.event.keyCode=0 : e.keyCode=0;
										}
										break;
									case 35:
									case 63275:
										if (layoutObj.keydown_use_end)
										{
											smoothscrollObj.scrollFor("X", browserObj.elementclientLeft(document.getElementById("td_body_menu")) + document.getElementById("td_body_menu").clientWidth - browserObj.width - browserObj.scrollXpos());
											(window.event) ? window.event.keyCode=0 : e.keyCode=0;
										}
										break;
									case 33:
										if (layoutObj.keydown_use_tab)
										{
											smoothscrollObj.scrollFor("X", -1* browserObj.width);
											(window.event) ? window.event.keyCode=0 : e.keyCode=0;
											return false;
										}
										break;
									case 9:
									case 34:
										if (layoutObj.keydown_use_tab)
										{
											smoothscrollObj.scrollFor("X", browserObj.width);
											(window.event) ? window.event.keyCode=0 : e.keyCode=0;
											return false;
										}
										break;
									case 39:
										if (layoutObj.keydown_use_arrows)
										{
											smoothscrollObj.scrollFor("X", 800);
											(window.event) ? window.event.keyCode=0 : e.keyCode=0;
											return false;
										}
										break;
									case 37:
										if (layoutObj.keydown_use_arrows)
										{
											smoothscrollObj.scrollFor("X", -800);
											(window.event) ? window.event.keyCode=0 : e.keyCode=0;
											return false;
											
										}
										break;
									default:
									}
								}
																
	if (browserObj.is_IE() && browserObj.is_legacy_browser())
	{
		document.body.onkeydown = layoutObj.keydown_home;
	} else {
		browserObj.AddEventListener ("keydown", layoutObj.keydown_home);
	}
	
	//PART III Misc Functions
	layoutObj.set_ScrollAreaX = function ()
									{
										if (browserObj.width > 0)
										{
											autoscrollObj.ScrollAreaX=Math.floor(browserObj.width * 0.1);
										} else {
											window.setTimeout("browserObj.update.call(browserObj); layoutObj.set_ScrollAreaX();", 500);
										}
									}
	
	
	layoutObj.imgfrms = new Array();
	
	//Dummy imgfrm object. Do nothing when called to add frame.
	layoutObj.imgfrms[0] = new Object();
		layoutObj.imgfrms[0].add_frame = function () {};
		layoutObj.imgfrms[0].print_frame = function () {};
	
	layoutObj.imgfrms[1] = imgfrm_frame01;
	layoutObj.imgfrms[2] = imgfrm_frame02;
	
	layoutObj.imgfrm_add_frame_multi = function (frame_no, elements, wall_section_id, frame_width)
											{
												layoutObj.imgfrms[frame_no].add_frame_multi (elements, "gallery_collection_album_"+wall_section_id+"_", "./img-web/frame-generic/", frame_width);
											}
											
	layoutObj.imgfrm_add_frame_from_parameters = function (wall_section_id)
											{
												for (var i in layoutObj.imgfrms)
												{
													if (typeof layoutObj.wall_sections[wall_section_id].parameters["imgfrm_add_frame_"+i] != "undefined")
													{
														layoutObj.imgfrm_add_frame_multi (i, layoutObj.wall_sections[wall_section_id].parameters["imgfrm_add_frame_"+i], wall_section_id, 20);
													}
												}
											}
	
	layoutObj.make_screen_wide = function (obj_id, minus)
									{
										if (typeof minus == "undefined") { minus = 0; }
										switch (typeof obj_id)
										{
											case "string":
												obj_id = document.getElementById(obj_id);
												//alert(obj_id.id);
											case "object":
												obj_id.style.width = (browserObj.width - minus) + "px";
												break;
										}
										return obj_id.clientWidth;
									}
	
	layoutObj.adjust_window_size = function ()
									{
										//Resize window if needed
										if (browserObj.windowWidth())
										{
											if (browserObj.windowWidth() > 0 && browserObj.windowHeight() > 0)
											if (!browserObj.windowMaximized())
											{
												var new_width = browserObj.windowWidth();
												var new_height = browserObj.windowHeight();
												var do_resize = false;
																						
												if (browserObj.width <= 1200)
												{
													do_resize = true;
													
													new_width = (screen.availWidth < 1280) ? screen.availWidth : 1280;
												}
												
												if (browserObj.height <= 725)
												{
													do_resize = true;
													
													new_height = (screen.availHeight < 900) ? screen.availHeight : 900;
												}
												
												if (do_resize)
												{
													if (browserObj.is_mac())
													{
														window.moveTo(1,1);
													} else {
														window.moveTo(0,0);
													}
													window.resizeTo(new_width, new_height);
												}
											} else {
												//Do nothing if the window is already maximized
												//Don't disturb...
											}
										} else {
											
											
										}
									}
									
	layoutObj.make_relative_to = function (obj_move, obj_anchor, relative_x, relative_y)
									{
										obj_move.style.left = (browserObj.elementclientLeft(obj_anchor) + relative_x) + "px";
										obj_move.style.top = (browserObj.elementclientTop(obj_anchor) + relative_y) + "px";
									}
									
	layoutObj.show_err_message = function (title, message, duration)
									{
										var span_title = document.getElementById("span_err_title");
										var span_message = document.getElementById("span_err_message");
										var div_message = document.getElementById("div_err_message");
										
										span_title.innerHTML = title;
										span_message.innerHTML = message;
										
										div_message.style.left = Math.floor(browserObj.scrollXpos() + (browserObj.width - div_message.clientWidth)/2) + "px";
										div_message.style.top = Math.floor(browserObj.scrollYpos() + (browserObj.height - div_message.clientHeight)/2) + "px";
										
										opcGradient(div_message, 0, 100, 5, 25);
										
										//Default duration
										if (typeof duration == "undefined")
										{
											duration = 3500;
										}
										if (duration > 0)
										{
											 window.setTimeout("opcGradient(document.getElementById('"+div_message.id+"'), 100, 0, -5, 25)", duration);
										}
									}
