// cmsbox (cola light)
// // // // // // // // // // // // // // // // // // // // // // // // // //
var Cmsbox = {
	
	// information
	version: 2.0,
	copyright: '(c) Copyright 2007 cmsbox GmbH. All Rights Reserved.',
	
	// initialization
	setup: function () { },
	
	// public
	crop: function (element) {
		element = $(element);
		var image = element.down("img");
		var relative = Position.cumulativeOffset(element);
		if (image) {
			element.observe('mousemove', function (event) {
				var x = (Event.pointerX(event) - relative[0]) / element.offsetWidth;
				var y = (Event.pointerY(event) - relative[1]) / element.offsetHeight;
				image.style.left = -1 * (image.offsetWidth - element.offsetWidth) * x + "px";
				image.style.top = -1 * (image.offsetHeight - element.offsetHeight) * y + "px";
			}.bindAsEventListener(this));
		}
	},
	lightbox: function (lightbox, overlay) {
		lightbox = $(lightbox); overlay = $(overlay);
		var page = Position.pageBounds(), window = Position.windowBounds();
		overlay.style.height = (page[1] > window[1] ? page[1] : window[1]) + 'px';
		lightbox.style.marginTop = Position.windowOffset()[1] + 'px'; // stay where you are
		$$("#desk input", "#desk select", "#desk textarea").each(function(each){ 
			if (Prototype.Browser.IE)
				each.style.visibility="hidden";
			each.disabled="true";
		});
		lightbox.style.display = overlay.style.display = 'block';
	},
	lightboxCloseHandler: function (url, overlay) {
		document.onkeyup = function (event) {
			if (event.keyCode == Event.KEY_ESC) window.location=url;
		}.bindAsEventListener(this);
		$(overlay).onclick = function () {
			window.location = url;
		};
	},
	decode: function (input) {
		var i = 0;
		var output = "";
		var chr1, chr2, chr3;
		var enc1, enc2, enc3, enc4;
		var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
		input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
		do {
			enc1 = keyStr.indexOf(input.charAt(i++));
			enc2 = keyStr.indexOf(input.charAt(i++));
			enc3 = keyStr.indexOf(input.charAt(i++));
			enc4 = keyStr.indexOf(input.charAt(i++));
			chr1 = (enc1 << 2) | (enc2 >> 4);
			chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
			chr3 = ((enc3 & 3) << 6) | enc4;
			output += String.fromCharCode(chr1);
			if (enc3 != 64) output += String.fromCharCode(chr2);
			if (enc4 != 64) output += String.fromCharCode(chr3);
		} while (i < input.length);
		return output;
	}
};

// position extensions (woooh)
// // // // // // // // // // // // // // // // // // // // // // // // // //
Position.windowBounds = function () { // dimenasion of the window-viewport
	var x = window.innerWidth || 
		self.innerWidth ||
		document.documentElement.clientWidth ||
		document.body.clientWidth ||
		0;
	var y = window.innerHeight ||
		self.innerHeigth ||
		document.documentElement.clientHeight ||
		document.body.clientHeight ||
		0;
	return [x, y]; 
};
Position.windowOffset = function () {
	var x = window.pageXOffset ||
		document.documentElement.scrollLeft ||
		document.body.scrollLeft || 
		0;
	var y = window.pageYOffset ||
		document.documentElement.scrollTop ||
		document.body.scrollTop ||
		0;
	return [x, y];
};
Position.pageBounds = function () { // dimensions of the entire page
	var x = document.body.scrollWidth || 0;
	var y = (window.innerHeight && window.scrollMaxY ?
		window.innerHeight + window.scrollMaxY : 
		document.body.scrollHeight) || 0;
	return [x, y]; 
};