//Transform an Array to a dictionary;
toDictionary = function (keyField, array) 
{
	var tranform = new Function("arr", "var dic = new Array(); for (var i = 0; i < arr.length; i++) { var el = arr[i]; dic[el." + keyField + "] = el;} return dic;");
	var dic = tranform(array);
	return dic;
}

function GE(id)
{
	return typeof (id) == "string" ? document.getElementById(id) : id;
}

function CE(name)
{
	return document.createElement("IMG");
}

var page =
{
	frame: null,
	href: function (url) {
		return url.replace("~/", "/");
	},

	expand: function () {
	},

	hideContent: function () {
		if (page.state == "slideShow") {
			return true;
		}
		this.onHideContent();
		page.state = "slideShow";
	},

	onResize: function () {
		if (this.isMobile) {
			document.body.parentNode.className = "mobile";
		}
		if (this.isMobile || document.body.parentNode.offsetWidth < 560) {
			document.body.className = "mobile";
		}
		else {
			document.body.className = "";
		}
		try {
			if (onResize) {
				onResize();
			}
		} catch (e) {
		}
	},

	onHideContent: function () {
		var frame = GE("frame");
		if (frame) {
			h = frame.offsetHeight;
			w = frame.offsetWidth - 2;
			t = frame.offsetTop;
			l = frame.offsetLeft;
			wh = document.documentElement.clientHeight;
			frame.style.width = w + "px";
			frame.style.top = t + "px";
			frame.style.left = l + "px";
			frame.style.position = "absolute";
			window.scrollTo(0, 0);
			frame.moving = true;
			$(frame).animate({ top: -h }, null, null, function () {
				$(frame).addClass("showMode");
				document.body.style.overflow = "hidden";
				frame.moving = false;
			});

			frame.onclick = function () {
				if (frame.moving) {
					return;
				}
				this.onclick = null;
				var s = frame.style;
				$(frame).removeClass("showMode");
				$(this).animate({ top: t }, null, null, function () {
					if (this.onShow) {
						this.onShow();
					}
					else {
						s.width = "";
						s.top = "";
						s.left = "";
						s.position = "";
					}
					document.body.style.overflow = "";
				});
				page.state = "";
			};
			return false;
		}
		return true;
	}
}


var userAgent = navigator.userAgent.toLowerCase();
var browser = {
	version: (userAgent.match(/.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/) || [0, '0'])[1],
	safari: /webkit/.test(userAgent),
	opera: /opera/.test(userAgent),
	msie: /msie/.test(userAgent) && !/opera/.test(userAgent),
	mozilla: /mozilla/.test(userAgent) && !/(compatible|webkit)/.test(userAgent),
	InitIDCode: function (id) {
		return 'var ' + id + ' = document.getElementById("' + id + '");';
	},
	InitAllIDCode: function (vars) {
		var code = "";
		for (var i = 0; i < vars.length; i++) {
			code += this.InitIDCode(vars[i]);
		}
		return code;
	},
	InitAllIDCodeIf: function (vars) {
		if (this.mozilla)
			return this.InitAllIDCode(vars);
		return "";
	}
};


function Delay(callback, mseconds) {
	var timeout = null;
	var last = null;
	this.calls = 0;
	mseconds = mseconds / 2;
	function doCall() 
	{
		var now = new Date();
		if ((now - last) >= mseconds) {
			callback();
		}
		else
		{
			start();
		}
	}

	function start() 
	{
		clearTimeout(timeout);
		timeout = setTimeout(doCall, mseconds);
		last = new Date();
	}

	this.postpone = function () {
		if (last == null)
		{
			start();
		}
		var now = new Date();
		if ((now - last) > (mseconds / 1.2))
		{
			start();
		}
		last = now;
	}
}


if (window.attachEvent) {
	window.attachEvent('onresize', page.onResize)
}
else {
	window.addEventListener('resize', page.onResize, false)
}
