/* version 1.1.6.0 */

/* estrada */

window.estrada = {
	"namespace": "var frame = window.estrada.frame; var area = window.estrada.area; var cols = window.estrada.cols; var grab = window.estrada.grab; var attachEvent = window.tilt.attachEvent;var detachEvent = window.tilt.detachEvent;",
	setUniqueId: function(node) {
		if (node) {
			var id = node.id;
			if (!id) {
				if (document.uniqueID) {
					id = document.uniqueID;
				} else {
					if (!arguments.callee.count) arguments.callee.count = 0;
					id = "uid-" + arguments.callee.count++;
				}
				node.id = id;
			}
			return id;
		}
	},
	"$behaviors": {
	},
	behavior: function(name) {
		return this.$behaviors[name] || (this.$behaviors[name] = {
			is: function(decl) {
				this.$decl = decl;
			}
		});
	},
	scope: {
		retrieve: function(arg) {
			return this.$store[arg.callee.scopeId];
		},
		create: function(key, id, eventName) {
			var scopeId = key ? key : "";
			if (id) {
				scopeId += "\\" + id;
			}
			if (eventName) {
				scopeId += "\\" + eventName;
			}
			
			return this.$store[scopeId] || (this.$store[scopeId] = {
				"#": id,
				"$key": key,
				"$id": "\\" + id,
				id: scopeId,
				getBehaviorScope: function() {
					return estrada.scope.$store[this.$key];
				},
				getElementScope: function() {
					return estrada.scope.$store[this.$id];
				},
				getBindingScope: function() {
					return estrada.scope.$store[this.id];
				},
				getElement: function() {
					return document.getElementById(this["#"]);
				}
			})
		},
		"$store": {},
		"$keyStore": {},
		"$idStore": {}
	},
	"$buildNode": function(node, id, html) {
		var div = node.appendChild(document.createElement("div"));
		if (id) {
			div.id = id;
		}
		if (html) {
			div.innerHTML = html;
		}
		return div;	
	},
	"$createNodeId": function(id) {
		return "l-" + id;
	},
	"$addNodeId": function(id, ids) {
		var oldId = ids[id];
		if (oldId) {
			var newId;
			if (typeof(oldId) == "string") {
				newId = this.$createNodeId(id) + "-1";
				ids[id] = [ oldId, newId ];
			}
			else {
				newId = this.$createNodeId(id) + "-" + (old.length - 1);
				oldId.push(newId);
			}
			return newId;
		}
		return ids[id] = this.$createNodeId(id);
	},
	grab: function(node, buckets) {
		var result = {};
		foreach(node, function(node) {
			push(getClassName());
			
			function push(bucket) {
				if (bucket) {
					var items = result[bucket];
					if (!items) {
						items = [];
						result[bucket] = items;
					}
					items.push(node);
				}
			}
			
			function getClassName() {
				for(var className in buckets) {
					if (foreach(node.className.split(" "), function(nodeClassName) {
						return nodeClassName == className;
					})) {
						return buckets[className];
					}
				}
			}

		});
		return result;
	},
	frame: function(id) {
		var items = [];
		var flags = [];
		for(var i = 1; i < arguments.length; i++) {
			var item = arguments[i];
			if (item.link) {
				item.link(flags);
			}
			items.push(item);
		}
				
		return {
			id: id,
			build: function(node) {
				var ids = {};
				var posts = {};
				var html = this.$write(ids, posts);
				estrada.$buildNode(node, estrada.$createNodeId(id), html);
				return {
					bind: function(behavior) {
						return {
							to: function(area) {
								var b = estrada.behavior(behavior);
								if (b) {
									var decl = b.$decl;
									var node = area.nodeType && area.nodeName ? area : function() {
										var id = ids[area];
										if (id) {
											return document.getElementById(id);
										}
									}();
									if (node && decl) {
										estrada.scope.create(behavior);
										estrada.scope.create(behavior, this.nodeId);
										decl.nodeId = estrada.setUniqueId(node);
										decl.attachEvent = function(element, name, handler) {
											var scope = estrada.scope.create(behavior, this.nodeId, name);
											handler.scopeId = scope.id;
											tilt.attachEvent(element, name, handler);
										}
										decl.bind(node);
									}
								}
							}
						}
					},
					push: function(params) {
						for(var p in params) {
							var dest = ids[p];
							if (dest) {
								var hasData;
								if (typeof(dest) == "string") {
									forDest(dest, function(node) {
										hasData = appendRec(params[p], node);
									});
								}
								else { // array
									var firstDest = dest[0];
									firstDest = forDest(firstDest, function(node) {
										hasData = appendRec(params[p], node);
									});
									if (firstDest) {
										var html = firstDest.innerHTML;
										for(var i = 1; i < dest.length; i++) {
											forDest(dest[i], function(node) {
												node.innerHTML = html;
											});
										}
									}
								}
								if (hasData) {
									foreach(posts[p], function(post) {
										post.raise();
									})
								}
							}
						}
						
						function forDest(id, handler) {
							var dest = document.getElementById(id);
							if (dest) {
								handler(dest);
								return dest;
							}
						}
						
						function appendRec(ref, dest) {
							if (ref) {
								if (typeof(ref) == "string") {
									return append(document.getElementById(ref), dest);
								}
								if (typeof(ref) == "function") {
									return append(ref(), dest);
								}
								if (ref.nodeType) {
									return append(ref, dest);
								}
								if (ref.length) {
									var hasData;
									foreach(ref, function(item) {
										var r = appendRec(item, dest);
										if (r && !hasData) {
											hasData = true;
										}
									})
									return hasData;
								}
							}
						}
						
						function append(target, dest) {
							if (target && target.nodeType) {
								dest.appendChild(target);
								return true;
							}
						}	
					}
				}
			},
			"$write": function(ids, posts) {
				var html = "";
				foreach(items, function(item) {
					if (item.write) {
						html += item.write(ids, posts);
					}
				});
				return html;
			},
			write: function(ids, posts) {
				return "<div id=\"" + estrada.$addNodeId(id, ids) + "\">" + this.$write(ids, posts) + "</div>";
			},
			link: function(parentFlags) {
				foreach(flags, function(flag) {
					parentFlags.push(flag);
				});
			}
		}
	},
	area: function(id) {
		return {
			id: id,
			write: function(ids, posts) {
				return "<div id=\"" + estrada.$addNodeId(id, ids) + "\"></div>";
			},
			build: function(node) {
				$buildNode(node, id);
				return {
				}
			},
			link: function(flags) {
				flags.push(id);
			}
		}
	},
	cols: function(one, two) {
		var oneFlags = [];
		if (one.link) {
			one.link(oneFlags);
		}
		var twoFlags = [];
		if (two.link) {
			two.link(twoFlags);
		}
		return {
			write: function(ids, posts) {
				var oneId = one.id;
				var twoId = two.id;
				var composite = oneId + "-" + twoId;
				var boxId = "l-" + composite;
				var noneFlag = boxId + "--";
				var bothFlag = boxId;
				foreach(oneFlags, function(flag) {
					var post = posts[flag];
					if (!post) {
						post = [];
						posts[flag] = post;
					}
					post.push({
						raise: function() {
							setFlag(oneId);
						}
					})
				})
				foreach(twoFlags, function(flag) {
					var post = posts[flag];
					if (!post) {
						post = [];
						posts[flag] = post;
					}
					post.push({
						raise: function() {
							setFlag(twoId);
						}
					})
				})
				return "<div id=\"" + boxId + "\" class=\"" + noneFlag + "\">" + one.write(ids, posts) + two.write(ids, posts) + "<div id=\"l-bottom-" + composite + "\"></div></div>";
				function setFlag(id) {
					var box = document.getElementById(boxId);
					if (box) {
						var flag = box.className;
						var idFlag = "l-" + id;
						if (flag != bothFlag && flag != idFlag) {
							if (flag ==  noneFlag) {
								box.className = idFlag;
							} 
							else {
								box.className = bothFlag;
							}
						}
					}
				}
			},
			link: function(flags) {
				foreach(oneFlags, function(flag) {
					flags.push(flag);
				});
				foreach(twoFlags, function(flag) {
					flags.push(flag);
				});
			}
		}
	}
}

/* common iterator functions */

	function first(col) {
		if (col) {
			if (col.length) {
				return col.length > 0 && col[0];
			}
			else {
				var child = col.firstChild;
				while(child) {
					if (child.nodeType == 1) {
						return child;
					}
					child = child.nextSibling;
				}
			}
		}
		return null;
	}
	
	function map(col, func) {
		var result = [];
		if (col) {
			if (!func) {
				func = function(item) {
					return item;
				}
			}
			var length = col.length;
			if (length) {
				for(var i = 0; i < length; i++) {
					result.push(func(col[i], i, col));
				}
			}
			else {
				var child = col.firstChild;
				var i = 0;
				while(child) {
					if (child.nodeType == 1) {
						result.push(func(child, i, col));
					}
					child = child.nextSibling;
					i++;
				}
			}
		}
		return result;
	}
	
	function filter(col, func) {
		var result = [];
		if (col) {
			var length = col.length;
			if (length) {
				if (!func) {
					func = function() {
						return true;
					}
				}
				for(var i = 0; i < length; i++) {
					var item = col[i];
					if (func(item, i, col)) {
						result.push(item);
					}
				}
			}
		}
		return result;
	}
	
	function foreach(col, func) {
		if (col) {
			var length = col.length;
			if (length) {
				for(var i = 0; i < length; i++) {
					if (func(col[i], i, col)) {
						return true;
					}
				}
			}
			else {
				var child = col.firstChild;
				var i = 0;
				while(child) {
					if (child.nodeType == 1 && func(child, i, col)) {
						return true;
					}
					child = child.nextSibling;
					i++;
				}
			}
		}
	}
	
	function rationalize(col) {
		if (col) {
			if (col.nodeType)
			{
				return col;
			}
			var hasValues;
			if (col.length > 0) {
				foreach(col, function(item) {
					if (item) {
						hasValues = true;
						return true;
					}
				});
				if (hasValues) {
					return col;
				}
			}
		}
	}


window.tilt = new function()
{
	var safari = document.childNodes && !document.all && !navigator.taintEnabled;
	var head = document.getElementsByTagName ? document.getElementsByTagName("head")[0] : null;
	var layoutHandlers = [];
	var beforeLayoutHandlers = [];
	var layoutErrorHandlers = [];
	
	var scriptBase = function() {
		var scripts = head.getElementsByTagName("script");
		for(var i = 0; i < scripts.length; i++)
		{
			var src = scripts[i].src;
			if (src && src.indexOf("tilt.js") >= 0)
			{
				return src.replace(/tilt\.js/, "");
			}
		}
		return "";
	}();

	setHeadClassName("l-before-layout");
	
	this.attachEvent = function()
	{
		if (window.attachEvent)
		{
			return function(element, name, handler)
			{
				if (!attachLayoutHandlers(element, name, handler))
				{
					element.attachEvent("on" + name, function()
					{
						if (!handler(element, event))
						{
							event.returnValue = false;
							event.cancelBubble = true;
						}
					});
				}
			}
		}
		if (window.addEventListener)
		{
			return function(element, name, handler)
			{
				if (!attachLayoutHandlers(element, name, handler))
				{
				    if (safari && name == "click" && element.nodeName == "A") {
				        element.onclick = function(e) {
				            return handler(element, e);
				        };
				    } else {
				    element.addEventListener(name, function(e)
				    {
					    if (!handler(element, e))
					    {
						    e.stopPropagation();
						    e.preventDefault();
					    }
				    }, false);
				    }
				}
			}
		}
		if (document.getElementById) // IE Mac
		{
			return function(element, name, handler)
			{
				if (!attachLayoutHandlers(element, name, handler))
				{
					var handlerName = "on" + name;
					var oldHandler = element[handlerName];
					if (oldHandler)
					{
						element[handlerName] = function()
						{
							return oldHandler(element) && handler(element);
						}
					}
					else
					{
						element[handlerName] = function()
						{
							return handler(element);
						}
					}
				}
			}
		}
		return function(){};
		
		function attachLayoutHandlers(element, name, handler)
		{
			if (element === document) {
				if (name == "contentreceived" || name == "layout" || name == "DOMContentLoaded") {
					layoutHandlers[layoutHandlers.length] = handler;
					return true;
				} 
				if (name == "beforelayout") {
					beforeLayoutHandlers[beforeLayoutHandlers.length] = handler;
					return true;
				}
				if (name == "layouterror") {
					layoutErrorHandlers[layoutErrorHandlers.length] = handler;
				}
			}
		}
	}();
	
	if (document.addEventListener && !safari) {
		document.addEventListener("DOMContentLoaded", fireFire, false);
	} else {
		// Dean Edwards (http://dean.edwards.name/)
		/*@cc_on @*/
		/*@if (@_win32)
			document.write("<script id=__ie_onload defer src=//:><\/script>");
			var script = document.getElementById("__ie_onload");
			script.onreadystatechange = function() {
				if (this.readyState == "complete") {
					fireFire();
				}
			}
		/*@end @*/
		//this.attachEvent(window, "load", fireFire);
	}

	wait(30000, 100);

	this.detachEvent = function()
	{
		if (window.detachEvent)
		{
			return function(element, name, handler)
			{
				if (!detachOnContentReceived(element, name, handler))
				{
					element.detachEvent("on" + name, handler);
				}
			}
		}
		if (window.removeEventlistener) {
			return function(element, name, handler) {
				if (!detachOnContentReceived(element, name, handler)) {
					element.removeEventListener(name, handler, false);
				}
			}
		}
		return function(){};
		
		function detachOnContentReceived(element, name, handler)
		{
			if (name == "contentreceived" && element === document)
			{
				for(var i = 0; i < this.layoutHandlers.length; i++)
				{
					if (this.layoutHandlers[i] === handler)
					{
						this.layoutHandlers.splice(i, 1);
					}
				}
			}
		}
	}();
	
	this.createTable = function(content, className)
	{
		var table = document.createElement("TABLE");
		table.className = "Layout " + (className != null ? className : "");
		table.cellSpacing = 0;
		var tbody = table.appendChild(document.createElement("TBODY"));

		var colCount = 0;
		var needsColspans;
		for(contentMember in content)
		{
			var rowInfo = content[contentMember];
			if (rowInfo)
			{
				var row = tbody.appendChild(document.createElement("TR"));
				row.className = contentMember;
				var runningColCount = 0;
				if (isContent(rowInfo))
				{
					var cell = row.appendChild(document.createElement("TD"));
					appendContent(cell, rowInfo);
					runningColCount++;
				}
				else
				{
					for(rowInfoMember in rowInfo)
					{
						var cellInfo = rowInfo[rowInfoMember];
						if (!isEmpty(cellInfo))
						{
							var cell = row.appendChild(document.createElement("TD"));
							cell.className = rowInfoMember;
							appendContent(cell, cellInfo);
							runningColCount++;
						}
					}
				}
				if (runningColCount != colCount)
				{
					if (colCount > 0)
					{
						needsColspans = true;
					}
					if (runningColCount > colCount)
					{
						colCount = runningColCount;
					}
				}
			}
		}
		if (needsColspans)
		{
			var rows = tbody.rows;
			var emptyRows = [];
			for(var rowIndex = 0; rowIndex < rows.length; rowIndex++)
			{
				var row = rows[rowIndex];
				var cells = row.cells.length == 0 && row.children ? row.children : row.cells;
				if (cells.length == 0)
				{
					emptyRows[emptyRows.length] = row;
				}
				else
				{
					var colSpan = colCount - cells.length + 1;
					if (colSpan > 1)
					{
						cells[cells.length - 1].colSpan = colSpan;
					}
				}
			}
			for(var emptyRowIndex = 0; emptyRowIndex < emptyRows.length; emptyRowIndex++)
			{
				var row = emptyRows[emptyRowIndex];
				row.parentNode.removeChild(row);
			}
		}
		return table;
	}
	
	this.createDiv = function(content, className)
	{
		if (content) {
			var div = document.createElement("div");
			div.className = className;
			appendContent(div, content);
			return div;
		}
	}

	function fireFire()
	{
		if (!tilt.__fired) {
			tilt.__fired = true;
			var hasErrors;
			var errors = [];
			for(var i = 0; i < beforeLayoutHandlers.length; i++) {
				try {
					beforeLayoutHandlers[i]();
				}
				catch(e) {
					hasErrors = true;
					errors.push(e);
				}
			}
			setHeadClassName("l-layout");
			for(var i = 0; i < layoutHandlers.length; i++)
			{
				try
				{
					layoutHandlers[i]();
				}
				catch(e)
				{
					hasErrors = true;
					e.layout = true;
					errors.push(e);
				}
			}
			if (hasErrors && layoutErrorHandlers.length > 0) {
				for(var i = 0; i < layoutErrorHandlers.length; i++) {
					try {
						layoutErrorHandlers[i](errors);
					}
					catch(e) {
					}
				}
			}
			setHeadClassName("l-layout-complete");
		}
	}
	

	function wait(timeout, delta) {
		if (window.webroot != "yes") {
			var interval = window.setInterval(function() {
				if (tilt.__fired) {
					window.clearInterval(interval);
					// John Resig via Dean Edwards (http://dean.edwards.name/)
				} else if ((safari && /loaded|complete/.test(document.readyState))||timeout < 0) {
					window.setTimeout(fireFire, 0);
				}
				timeout -= delta;
				
			}, delta);
		}
	}
	
	function setHeadClassName(className) {
		document.getElementsByTagName("html")[0].className = className;
	}
	
	function isEmpty(obj)
	{
		if (obj)
		{
			if (isInstanceOf(obj, Array))
			{
				for(var i = 0; i < obj.length; i++)
				{
					if (obj[i])
					{
						return false;
					}
				}
				return true;
			}
			return false;
		}
		return true;
	}
		
	function isInstanceOf(obj, type)
	{
		return obj.constructor === type;
	}
	
	function isContent(data)
	{
		return isInstanceOf(data,Array) || typeof(data) == "string" || data.nodeName;
	}
	
	function appendContent(node, content)
	{
		if (content)
		{
			var contentType = typeof(content);
			if (contentType == "string")
			{
				node.appendChild(document.createTextNode(content));	
			}
			else if (isInstanceOf(content, Array))
			{
				for(var i = 0; i < content.length; i++)
				{
					appendContent(node, content[i]);
				}
			}
			else if (content.nodeName)
			{
				node.appendChild(content);
			}
		}
	}

	this.createClassNameBag = function(node)
	{
		return new function(node)
		{
			var child = node.firstChild;
			while(child)
			{
				if (child.nodeType == 1 && child.className && child.className.length > 0)
				{
					var classNames = child.className.split(" ");
					for(var i = 0; i < classNames.length; i++)
					{
						var className = classNames[i];
						if (this[className])
						{
							var singleValue = this[className];
							var array = [singleValue,child];
							this[className] = array;
						}
						else
						{
							this[className] = child;				
						}
					}
				}
				child = child.nextSibling;
			}
		}(node);
	};
	
	this.addScript =  safari ? function(script) {
		if (script && head) {
			var e = document.createElement("script");
			e.type = "text/javascript";
			e.src = scriptBase + script;
			head.appendChild(e);
		}
	}: function(script) {
		if (script && head) {
			var e = head.appendChild(document.createElement("script"));
			e.type = "text/javascript";
			e.src = scriptBase + script;
		}
	}
}

for(var name in tilt) {
	estrada[name] = tilt[name];
}