if( !(window["Elieram"] instanceof Function) ) {

function $( id ) {
	return document.getElementById(id);
}
function $cel( el_name ) {
	return document.createElement(el_name);
}
function $ctxt( txt ) {
	return document.createTextNode(txt);
}

Elieram = function() {
}

Elieram.Hex2Dec = {"0": 0, "1": 1, "2": 2, "3": 3, "4": 4, "5": 5, "6": 6, "7": 7, "8": 8, "9": 9, "a": 10, "b": 11, "c": 12, "d": 13, "e": 14, "f": 15 };
Elieram.hexCharToDec = function( hex ) {
	var hex2dec = Elieram.Hex2Dec;
	var i;
	var dec = 0;
	return (hex2dec[hex.charAt(0)] << 4) + hex2dec[hex.charAt(1)];
}

Elieram.Browser = function() {
}
Elieram.Browser.Name = null;
Elieram.Browser.IE = false;
Elieram.Browser.OPERA = false;
Elieram.Browser.SAFARI = false;
Elieram.Browser.MOZILLA = false;
Elieram.Browser.KONQUEROR = false;
Elieram.Browser.FIREFOX = false;
Elieram.Browser.CAMINO = false;
Elieram.Browser.NAVIGATOR = false;
Elieram.Browser.MAC = false;
Elieram.Browser.LINUX = false;
Elieram.Browser.WINDOWS = false;
Elieram.Browser.MajorVersion = 0;
Elieram.Browser.MinorVersion = 0;
Elieram.Browser.Revision = 0;
// see: http://developer.apple.com/internet/safari/uamatrix.html
Elieram.Browser.SAFARI_VERSION_TABLE = {
	85: {
		"default": [1,0,0],
		5: [1,0,0],
		7: [1,0,2],
		8: [1,0,3]
	},
	100: {
		"default": [1,1,0],
		1: [1,1,1]
	},
	125: {
		"default": [1,2,0],
		7: [1,2,2],
		8: [1,2,2],
		9: [1,2,3],
		11: [1,2,4],
		12: [1,2,4]
	},
	312: {
		"default": [1,3,0],
		3: [1,3,1],
		5: [1,3,2],
		6: [1,3,2]
	},
	412: {
		"default": [2,0,0],
		2: [2,0,0],
		5: [2,0,1]
	},
	416: {
		"default": [2,0,2]
	},
	417: {
		"default": [2,0,3]
	},
	417: {
		"default": [2,0,3]
	},
	419: {
		"default": [2,0,4]
	},
	523: {
		"default": [3,0,4]
	},
	// unknown version are treated like new browsers
	"default": [4,0,0]
}
Elieram.Browser.detect = function() {
	try {
		// detect OS
		Elieram.Browser.MAC = navigator.userAgent.indexOf("Macintosh")>=0;
		Elieram.Browser.WINDOWS = navigator.userAgent.indexOf("Windows")>=0;
		Elieram.Browser.LINUX = navigator.userAgent.indexOf("Linux")>=0;
			
		if( navigator.userAgent.match(new RegExp("Camino")) ) {
			Elieram.Browser.CAMINO = true;
			Elieram.Browser.Name = "Camino";

			// detect browser version
			var rexp = new RegExp("Camino[ /]*([\d])\.([\d]{1,2})");
			var res = rexp.exec( navigator.userAgent );
			Elieram.Browser.MajorVersion = parseInt(res[1]);
			Elieram.Browser.MinorVersion = parseInt(res[2]);
			Elieram.Browser.Revision = 0;
		} else
		if( navigator.userAgent.match(new RegExp("Navigator")) ) {
			Elieram.Browser.NAVIGATOR = true;
			Elieram.Browser.Name = "Netscape Navigator";

			// detect browser version
			var rexp = new RegExp("Navigator[ /]*([\d])\.([\d]{1,2})");
			var res = rexp.exec( navigator.userAgent );
			Elieram.Browser.MajorVersion = parseInt(res[1]);
			Elieram.Browser.MinorVersion = parseInt(res[2]);
			Elieram.Browser.Revision = 0;
		} else		
		// detect browser
		if( navigator.userAgent.match(new RegExp("Opera")) ) {
			
			Elieram.Browser.OPERA = true;
			Elieram.Browser.Name = "Opera";
			
			// detect browser version
			var rexp = new RegExp("Opera[ /]+([0-9])\\.([0-9]{1,2})");
			var res = rexp.exec( navigator.userAgent );
			Elieram.Browser.MajorVersion = parseInt(res[1]);
			Elieram.Browser.MinorVersion = parseInt(res[2]);
			Elieram.Browser.Revision = 0;
		} else
		if( navigator.userAgent.match(new RegExp("MSIE")) ) {
			Elieram.Browser.IE = true;
			Elieram.Browser.Name = "Microsoft Internet Explorer";

			// detect browser version
			var rexp = new RegExp("MSIE ([0-9])\\.([0-9])([0-9]{0,1})");
			var res = rexp.exec( navigator.userAgent );
			Elieram.Browser.MajorVersion = parseInt( res[1] );
			Elieram.Browser.MinorVersion = parseInt( res[2] );
			try {
				Elieram.Browser.Revision = parseInt( res[3] );
			} catch( e ) {}
			if( isNaN(Elieram.Browser.Revision) ) Elieram.Browser.Revision = 0;

			// detect SP2 for IE 6.0
			if( Elieram.Browser.MajorVersion==6 && Elieram.Browser.MinorVersion==0 ) {
				try {
					var ie_rexp = new RegExp("(SV1)");
					var ie_res = rexp.exec( navigator.userAgent );
					if( (ie_res instanceof Array) &&
						(ie_res.length>=2) && 
						(ie_res[1]=="SV1") )
					{
						Elieram.Browser.Revision = 1;
					}
				} catch(e) {}
			}
		} else
		if( navigator.userAgent.match(new RegExp("Safari")) ) {
			Elieram.Browser.SAFARI = true;
			Elieram.Browser.Name = "Safari";
			// detect browser version
			// see: http://developer.apple.com/internet/safari/uamatrix.html
			try {
				// extract the safari build number
				var rexp = new RegExp("Safari\\/([0-9]+)\\.([0-9]+)");
				var res = rexp.exec( navigator.userAgent );
				var build_major = parseInt( res[1] );
				var build_minor = parseInt( res[2] );
				var version = null;
				
				// if we know about that build
				if( Elieram.Browser.SAFARI_VERSION_TABLE[build_major] ) {
					var builds = Elieram.Browser.SAFARI_VERSION_TABLE[build_major];
					if( builds[build_minor] )
						version = builds[build_minor];
					else
						version = builds["default"];
				} else {
					version = Elieram.Browser.SAFARI_VERSION_TABLE["default"];
				}

				// default values
				Elieram.Browser.MajorVersion = version[0];
				Elieram.Browser.MinorVersion = version[1];
				Elieram.Browser.Revision = version[2];
			} catch(e) {}
		} else
		if( navigator.userAgent.match(new RegExp("Firefox")) ) {
			Elieram.Browser.FIREFOX = true;
			Elieram.Browser.Name = "Firefox";

			// detect browser version
			var rexp = new RegExp("Firefox\\/([0-9])\\.([0-9])\\.?([0-9]{0,1})");
			var res = rexp.exec( navigator.userAgent );
			Elieram.Browser.MajorVersion = parseInt( res[1] );
			Elieram.Browser.MinorVersion = parseInt( res[2] );
			try {
				Elieram.Browser.Revision = parseInt( res[3] );
			} catch( e ) {}
			if( !Elieram.isNumeric(Elieram.Browser.Revision) )
				Elieram.Browser.Revision = 0;
		} else
		if( navigator.userAgent.match(new RegExp("Konqueror\\/")) ) {
			Elieram.Browser.KONQUEROR = true;
			Elieram.Browser.Name = "Konqueror";

			// detect browser version
			var rexp = new RegExp("Konqueror\\/([0-9])\\.([0-9])\\.{0,1}([0-9]{0,1})");
			var res = rexp.exec( navigator.userAgent );
			Elieram.Browser.MajorVersion = parseInt( res[1] );
			Elieram.Browser.MinorVersion = parseInt( res[2] );
			try {
				Elieram.Browser.Revision = parseInt( res[3] );
			} catch( e ) {}
			if( !Elieram.isNumeric(Elieram.Browser.Revision) )
				Elieram.Browser.Revision = 0;
		} else
		if( navigator.userAgent.match(new RegExp("Mozilla\\/")) ) {
			Elieram.Browser.MOZILLA = true;
			Elieram.Browser.Name = "Mozilla";

			// detect browser version
			var rexp = new RegExp("rv:([0-9])\\.([0-9]{1,2})\\.?([0-9]{0,})");
			var res = rexp.exec( navigator.userAgent );
			Elieram.Browser.MajorVersion = parseInt(res[1]);
			Elieram.Browser.MinorVersion = parseInt(res[2]);
			try {
				Elieram.Browser.Revision = parseInt(res[3]);
			} catch( e ) {}
			if( !Elieram.isNumeric(Elieram.Browser.Revision) )
				Elieram.Browser.Revision = 0;
		} else {
			Elieram.Browser.Name = "Unknown";
		}
	} catch(e) {
		// well browser detection should hinder us completely
		Elieram.Browser.Name = "Unknown";
	}
}

Elieram.Mail = function() {
}

Elieram.Mail.decryptMailAddress = function( mail_address ) {
	var decryped = [];
	var i,j,c;
	var key = "voh8t9h549ghvghpqxd4ghqp5hp4cgvh35h4g204xh5g1235mg4";
	for( i=0; i < mail_address.length; i+=2 ) {
		c = Elieram.hexCharToDec( mail_address.charAt(i)+mail_address.charAt(i+1) );
		for( j=key.length-1; j >= 0; j-- ) {
			c = c ^ key.charCodeAt(j); 
		}
		decryped[decryped.length] = String.fromCharCode(c);
	}
	return decryped.join("");
}

Elieram.Mail.decryptMailLinks = function() {
	var i,node;
	var links = document.getElementsByTagName("a");
	for( i=0; i < links.length; i++ ) {
		node = links[i];
		if( node.getAttribute("encrypted_email") ) {
			node.setAttribute("href", "mailto:"+Elieram.Mail.decryptMailAddress(node.getAttribute("encrypted_email")) );
		}
	}
}

Elieram.Gallery = function() {
}
Elieram.Gallery.BackgroundDiv = null;
Elieram.Gallery.CurrentFullImage = null;
Elieram.Gallery.onClose = function() {
	var img = Elieram.Gallery.CurrentFullImage;
	var background = Elieram.Gallery.BackgroundDiv;
	if( img != null ) {
		img.parentNode.removeChild(img);
		img = null;
	}
	if( background != null ) {
		background.parentNode.removeChild(background);
		background = null;
	}
}
Elieram.Gallery.showFullImage = function( filename, width, height ) {
	var body = $("body");

	var outer_div = $cel("div");
	outer_div.setAttribute("id", "gallery_large_image");
	outer_div.style.position = "absolute";
	outer_div.style.left = "0px";
	outer_div.style.top = "0px";
	outer_div.style.right = "0px";
	outer_div.style.bottom = "0px";
	outer_div.style.backgroundColor = "#ffffff";
	outer_div.style.opacity = 0.8;
	outer_div.style.filter = 'alpha(opacity='+80+')';
	outer_div.style.zIndex = 0;
	outer_div.onclick = Elieram.Gallery.onClose;

	var div = $cel("div");
	var left = (document.width - width - 2) / 2;
	var top = (document.height - height - 24) / 2;
	if( left < 0 ) {
		left = 0;
		width = document.width;
	}
	if( top < 0 ) {
		top = 0;
		height = document.height - 24;
	}
	div.style.zIndex = 1;
	div.style.position = "absolute";
	div.style.left = left+"px";
	div.style.top = top+"px";
	div.style.width = (width)+"px";
	div.style.height = (height+22)+"px";
	div.style.backgroundColor = "#ffffff";
	div.style.border = "1px solid black";
	div.style.overflow = "hidden";
	div.style.opacity = 1.0;
	div.style.filter = 'alpha(opacity='+100+')';
	
	var window_title = $cel("div");
	window_title.setAttribute("id", "gallery_large_image");
	window_title.style.position = "absolute";
	window_title.style.left = "0px";
	window_title.style.top = "0px";
	window_title.style.width = width+"px";
	window_title.style.height = "22px";
	window_title.style.fontFamily = "Tahoma, Arial, Helvetica, sans-serif";
	window_title.style.fontSize = "12px";
	window_title.style.backgroundColor = "#79a172";
	window_title.style.color = "#ffffff";
	window_title.style.padding = "3px 0px 0px 3px";
	window_title.appendChild( $ctxt(filename) );
	div.appendChild( window_title );

	var image = $cel("img");
	image.src = filename;
	image.setAttribute("border", 0);
	image.onclick = Elieram.Gallery.onClose;
	image.style.cursor = (Elieram.Browser.IE?"hand":"pointer");
	image.style.position = "absolute";
	image.style.top = "22px";
	image.style.left = "0px";
	image.style.width = width+"px";
	image.style.height = height+"px";
	div.appendChild( image );

	var close_button = $cel("img");
	close_button.src = GLOBAL_SITE+"/core/images/closebutton.png";
	close_button.setAttribute("border", 0);
	close_button.onclick = Elieram.Gallery.onClose;
	close_button.style.cursor = (Elieram.Browser.IE?"hand":"pointer");
	close_button.style.position = "absolute";
	close_button.style.top = "5px";
	close_button.style.right = "5px";
	div.appendChild( close_button );

	body.appendChild( outer_div );
	body.appendChild( div );
	Elieram.Gallery.BackgroundDiv = outer_div;
	Elieram.Gallery.CurrentFullImage = div;
}

Elieram.onload = function() {
	Elieram.Browser.detect();
	Elieram.Mail.decryptMailLinks();
}


}