
// This is a variation of the addEvent script written by Dean Edwards (dean.edwards.name).
if (!events)
{
	var events =
	{
		nEventID: 1,

		add: function(ndElement, sType, fnHandler)
		{
			if (!fnHandler.$$nEventID) fnHandler.$$nEventID = this.nEventID++;
			if (ndElement.objEvents === undefined) ndElement.objEvents = {};

			var aHandlers = ndElement.objEvents[sType];
			if (!aHandlers)
			{
				aHandlers = ndElement.objEvents[sType] = {};
				if (ndElement['on' + sType]) aHandlers[0] = ndElement['on' + sType];
			}

			aHandlers[fnHandler.$$nEventID] = fnHandler;
			ndElement['on' + sType] = this.handle;

			return true;
		},

		handle: function(e)
		{
			e = e || events.fix(event);

			var bReturn = true, aHandlers = this.objEvents[e.type];
			for (var nIndex in aHandlers)
			{
				this.$$handle = aHandlers[nIndex];
				if (this.$$handle(e) === false) bReturn = false;
			}

			return bReturn;
		},

		fix: function(e)
		{
			e.preventDefault = this.fix.preventDefault;
			e.stopPropagation = this.fix.stopPropagation;

			return e;
		}
	};

	events.fix.preventDefault = function()
	{
		this.returnValue = false;

		return true;
	}

	events.fix.stopPropagation = function()
	{
		this.cancelBubble = true;

		return true;
	}
}










//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//

window.size = function() {
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth-20;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}

	
	return {width:pageWidth,height:pageHeight};
}

/* 
	JavaScript - Cross Browser Window Size And Centering
	http://www.geekdaily.net/2007/07/04/javascript-cross-browser-window-size-and-centering/
*/


window.center = function() {
	var hWnd = (arguments[0] != null) ? arguments[0] : {width:0,height:0};

	var _x = 0;
	var _y = 0;
	var offsetX = 0;
	var offsetY = 0;

	//IE
	if(!window.pageYOffset)
	{
		//strict mode
		if(!(document.documentElement.scrollTop == 0))
		{
			offsetY = document.documentElement.scrollTop;
			offsetX = document.documentElement.scrollLeft;
		}
		//quirks mode
		else
		{
			offsetY = document.body.scrollTop;
			offsetX = document.body.scrollLeft;
		}
	}
	//w3c
	else
	{
		offsetX = window.pageXOffset;
		offsetY = window.pageYOffset;
	}

	_x = ((this.size().width-hWnd.width)/2)+offsetX;
	_y = ((this.size().height-hWnd.height)/2)+offsetY;

	return{x:_x,y:_y};
}

// lightbox initialisieren
window.createLightBox = function(el) {
	
	myEl = document.getElementById(el);

	if(myEl) {

		// IE - select fields ueberlagern
		/*@cc_on
			lightboxIframe = document.createElement('iframe');
			lightboxIframe.src = 'about:blank';
			lightboxIframe.style.position = 'absolute';
			lightboxIframe.style.left = '0';
			lightboxIframe.style.top = '0';
			lightboxIframe.style.zIndex = '1';
			lightboxIframe.style.width = this.size().width + "px";
			lightboxIframe.style.height = this.size().width + "px";
			lightboxIframe.style.filter= 'progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)';
			document.body.appendChild(lightboxIframe);
		@*/	

		div = document.createElement("div");
		div.style.background = "#000000";
		div.style.zIndex = 300;
		div.style.opacity = 0.6;
		div.style.filter = "alpha(opacity=60)";
		div.style.position = "absolute";
		div.style.top = 0;
		div.style.left = 0;

		div.style.width = this.size().width + "px";
		div.style.height = this.size().height + "px";
		document.body.appendChild(div);
		window.lightbox = div;	
		window.openLightbox = el;	
		myEl.style.position = "absolute";
		myEl.style.display = 'block';	
		myEl.style.zIndex = 400;
		myEl.style.top = Math.round(this.center().y-(myEl.offsetHeight/2)) +"px";
		myEl.style.left = Math.round(this.center().x-(myEl.offsetWidth/2)) +"px";
	} else {
		void(0);	
	}
	
}
window.destroyLightBox = function() {
	document.body.removeChild(div);
	// IE - select fields ueberlagern
	/*@cc_on
	document.body.removeChild(lightboxIframe);
	@*/	
	myEl.style.display = 'none';
}


// X und Y Koordinaten von Elementen herausfinden
function findPosX(obj) {
  	var curleft = 0;
  	if (obj.offsetParent) {
    	while (obj.offsetParent) {
      		curleft += obj.offsetLeft;
      		if (obj.scrollLeft) {
       			 curleft -= obj.scrollLeft;
      		}
      			obj = obj.offsetParent;
    		}
  	} else if (obj.x) {
    		curleft += obj.x;
  	}
  	return curleft;
}

function findPosY(obj) {
	var curtop = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curtop += obj.offsetTop;
			if (obj.scrollTop) {
				curtop -= obj.scrollTop;
			};
			obj = obj.offsetParent;
		}
	} else if (obj.y) {
		curtop += obj.y;
	}
  	return curtop;
}