/*@cc_on IE6 = /MSIE [4-6]/.test(navigator.appVersion); @*/

/**
 * addEvent & removeEvent -- cross-browser event handling
 * Copyright (C) 2006  Dao Gottwald
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * Contact information:
 *   Dao Gottwald  <dao at design-noir.de>
 *   Herltestraße 12
 *   D-01307, Germany
 *
 * @version  1.1.4
 */

/*@cc_on if (window.addEventListener) { @*/
	function addEvent (o, type, fn) {
		o.addEventListener (type, fn, false);
	}
	function removeEvent (o, type, fn) {
		o.removeEventListener (type, fn, false);
	}
/*@cc_on } else if (window.attachEvent) {
	function addEvent (o, type, fn) {
		if (!o._events) o._events = {};
		if (!o._events[type]) {
			o._events[type] = [fn];
			if (!o._events._callback)
				o._events._callback = function (e) { Event._callListeners (e, o) };
			o.attachEvent ('on' + type, o._events._callback);
		} else if (Event._fnIndex (o, type, fn) == -1)
			o._events[type].push (fn);
		else return;
		Event._mem.push ([o, type, fn]);
	}
	function removeEvent (o, type, fn) {
		var i = Event._fnIndex (o, type, fn);
		if (i < 0) return;
		if (o._events[type].calling) {
			delete o._events[type][i];
			if (o._events[type].removeListeners)
				o._events[type].removeListeners.push(i);
			else
				o._events[type].removeListeners = [i];
		} else
			if (o._events[type].length == 1)
				Event._detach (o, type);
			else
				o._events[type].splice (i, 1);
	}
	var Event = {
		AT_TARGET : 2,
		BUBBLING_PHASE : 3,
		stopPropagation : function() { this.cancelBubble = true },
		preventDefault : function() { this.returnValue = false },
		_mem : [],
		_callListeners : function (e, o) {
			e.stopPropagation = Event.stopPropagation;
			e.preventDefault = Event.preventDefault;
			e.currentTarget = o;
			e.target = e.srcElement;
			e.eventPhase = e.currentTarget == e.target ? Event.AT_TARGET : Event.BUBBLING_PHASE
			switch (e.type) {
				case 'click': case 'mousedown': case 'mouseup':
					if (e.button == 1) e.button = 0; // left
					else if (e.button == 4) e.button = 1; // middle
					break;
				case 'mouseover':
					e.relatedTarget = e.fromElement;
					break;
				case 'mouseout':
					e.relatedTarget = e.toElement;
			}
			o._events[e.type].calling = true;
			for (var i=0; i < o._events[e.type].length; i++)
				if (o._events[e.type][i])
					o._events[e.type][i].call(o,e);
			o._events[e.type].calling = null;
			if (!o._events[e.type].removeListeners)
				return;
			if (o._events[e.type].length == o._events[e.type].removeListeners.length) {
				Event._detach (o, e.type);
				return;
			}
			var offset = 0;
			for (var i=0; i < o._events[e.type].removeListeners.length; i++)
				o._events[e.type].splice (o._events[e.type].removeListeners[i] - offset++, 1);
			if (o._events[e.type].length == 0)
				Event._detach (o, e.type);
			else
				o._events[e.type].removeListeners = null;
		},
		_detach : function (o, type) {
			o.detachEvent ('on' + type, o._events._callback);
			delete o._events[type];
		},
		_fnIndex : function (o, type, fn) {
			if (o._events[type])
				for (var i=0; i < o._events[type].length; i++)
					if (o._events[type][i] == fn)
						return i;
			return -1;
		},
		_cleanup : function() {
			for (var i=0; i < Event._mem.length; i++)
				if (Event._mem[i][1] != 'unload' || Event._mem[i][2] == Event._cleanup)
					removeEvent (Event._mem[i][0], Event._mem[i][1], Event._mem[i][2]);
		}
	};
	addEvent (window, 'unload', Event._cleanup);
} @*/

function whenDOMReady (fn) {
	var callback = function() {
		removeEvent (window, 'load', callback);
		if (document.removeEventListener)
			document.removeEventListener('DOMContentLoaded', callback, false);
		fn();
	};
	if (document.addEventListener)
		document.addEventListener('DOMContentLoaded', callback, false);
	addEvent (window, 'load', callback);
}

/**
 * function request
 * Copyright (C) 2006  Dao Gottwald
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * Contact information:
 *   Dao Gottwald  <dao at design-noir.de>
 *   Herltestraße 12
 *   D-01307, Germany
 *
 * @version  1.2
 */

/*@cc_on @if (@_win32 && @_jscript_version >= 5) if (!window.XMLHttpRequest)
function XMLHttpRequest() { return new ActiveXObject('Microsoft.XMLHTTP') }
@end @*/

function request (url, method, data, callback) {
	var http = new XMLHttpRequest;
	if (!http)
		return false;
	if (data !== null && typeof data == 'object') {
		var _data = [];
		for (var i in data)
			_data.push (i + '=' + escape (data[i]));
		data = _data.join ('&');
		delete _data;
	}
	method = method.toUpperCase();
	if (method == 'POST') {
		http.open (method, url, true);
		http.setRequestHeader ('Method', 'POST '+url+' HTTP/1.1');
		http.setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');
	} else {
		if (data)
			url += '?' + data;
		data = '';
		http.open (method, url, true);
	}
	if (callback)
		http.onreadystatechange = function() {
			if (http.readyState == 4) {
				http.onreadystatechange = function(){};
				callback (http);
			}
		};
	http.send (data);
	return true;
}

/* Sprache */
whenDOMReady (function() {
	if (document.documentElement.id == 'sub') {
		var	lang = ['de','sr'],
			switchLang = function(e) {
				request ('.setlang.php', 'GET', 'lang='+ e.currentTarget.id.replace(/^lang-/, ''));
				removeEvent (e.currentTarget, 'click', switchLang);
				trans (last, e.currentTarget);
				last = e.currentTarget;
				e.stopPropagation();
				e.preventDefault();
			},
			trans = function(a,b) {
				if (a && b) {
					trans.target1 = a;
					trans.target2 = b;
					trans.step = 1;
					trans.overlay.style.display = 'block';
					trans.timer = setInterval(trans,20);
				} else if (trans.step >= trans.steps) {
					clearInterval(trans.timer);
					trans.overlay.style.display = 'none';
					addEvent (trans.target1, 'click', switchLang);
					return;
				}
				trans.overlay.style.width = Math.round (100 * Math.sin(Math.PI * trans.step/trans.steps * Math.pow(Math.sin(Math.PI * trans.step/trans.steps), 3))) + '%';
				if (trans.step++ == trans.steps/2 + 1) {
					trans.target1.className = 'lang-disabled';
					trans.target2.className = 'lang-enabled';
				}
			};
		trans.steps = 20;
		trans.overlay = document.createElement('div');
		trans.overlay.style.display = 'none';
		trans.overlay.style.zIndex = 100;
		trans.overlay.style.position = /*@cc_on IE6 ? 'absolute' : @*/ 'fixed';
		trans.overlay.style.top = trans.overlay.style.left = 0;
		trans.overlay.style.width = trans.overlay.style.height = '100%';
		trans.overlay.style.background = '#fffdf3';
		document.body.appendChild(trans.overlay);
		for (var i=0; i < lang.length; i++) {
			var container = document.getElementById('lang-' + lang[i]);
			if (container.className == 'lang-disabled')
				addEvent (container, 'click', switchLang);
			else
				var last = container;
		}
		
	}
});

/* E-Mail-Adressen */
whenDOMReady (function() {
	var link, all = document.getElementsByTagName('a');
	for (var i=0, ele; ele = all[i]; i++)
		if (!ele.href)
			if (/\)$/.test(ele.innerHTML)) {
				if (link = ele.innerHTML.match(/^(.*) \((.*?) at (.*?)\)$/)) {
					ele.innerHTML = link[1];
					ele.href = 'mailto:' + link[2] + '@' + link[3];
				}
			} else if (link = ele.innerHTML.match(/^(.*) at (.*)$/))
				ele.href = 'mailto:' + (ele.innerHTML = link[1] + '@' + link[2]);
});

/*@cc_on

if (IE6)
addEvent (window, 'load', function() {
	var img, imgs = [document.getElementById('logo')];
	for(var i=0; i < imgs.length; i++)
		if (img = imgs[i]) {
			var	imgID = (img.id) ? "id='" + img.id + "' " : "",
				imgClass = (img.className) ? "class='" + img.className + "' " : "",
				imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' ",
				imgStyle = "display:inline-block;" + img.style.cssText;
			if (img.parentElement.href) imgStyle = "cursor:pointer;" + imgStyle;
			img.outerHTML = "<span " + imgID + imgClass + imgTitle
				+ " style=\"" + "width:" + img.clientWidth + "px; height:" + img.clientHeight + "px;" + imgStyle + ";"
				+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
				+ "(src='" + img.src + "', sizingMethod='image');\"></span>";
		}
});

@*/
