function $(id) {
	return document.getElementById(id);
}

var bgFade = function (el, color, depth) {
	if (!el) return false;
  var r, g, b;
  if (!color) color = "#FFFFFF";
  if (color.indexOf("#") != 0) color = "#"+color;
  if (!depth) depth = 100; if (depth > 255) depth = 255;
  el.r = r = parseInt(color.substr(1,2), 16); r -= depth;
  el.g = g = parseInt(color.substr(3,2), 16); g -= depth;
  el.b = b = parseInt(color.substr(5,2), 16); b -= depth;
  if (this.bgTimer) clearTimeout(this.bgTimer); // window.var -> global var oder ...
  function fade() {
    el.style.background = 'rgb('+ (r+=4) +','+ (g+=4) +','+ (b+=4) +')';
    if (b < el.b) this.bgTimer = setTimeout(fade, 20);
  };
  fade();
}

function openSel(e) {
	if (!e) var e = window.event;
	e.cancelBubble = true;
	if (e.stopPropagation) e.stopPropagation();
	if (!t2.isPlaying && !t1.isPlaying && inOut == 0) {
		t1.onMotionFinished = function(){
			inOut = 1;
			theObj.style.overflow = 'auto';
		}
		t3.start(); t1.start();
	}
}
function openSelFirst() {
	if (!t2.isPlaying && !t1.isPlaying && inOut == 0) {
		t1.onMotionFinished = function(){
			inOut = 1;
			theObj.style.overflow = 'auto';
		}
		t3.start(); t1.start();
	}
}
function closeSel(e) {
	if (!e) var e = window.event;
	e.cancelBubble = true;
	if (e.stopPropagation) e.stopPropagation();
	if (!t1.isPlaying && !t2.isPlaying && inOut == 1) {
		t2.onMotionFinished = function(){
			inOut = 0;
		};
		t2.onMotionStarted = function(){theObj.style.overflow = 'hidden'};
		t4.start(); t2.start();
	}
}
function closeSelLast(obj) {
	if (!t1.isPlaying && !t2.isPlaying && inOut == 1) {
		t2.onMotionFinished = function(){
			inOut = 0;
			document.location.href=obj.href;
		};
		t2.onMotionStarted = function(){theObj.style.overflow = 'hidden'};
		t4.start(); t2.start();
		
	}
}

window.onload = function() {
	if (document.getElementById('workmenu')) {
	
		var _init = function() {
			var t = this, ua = navigator.userAgent, i, nl, n, base;
	
			// Browser checks
			t.isOpera = window.opera && opera.buildNumber;
			t.isWebKit = /WebKit/.test(ua);
			t.isOldWebKit = t.isWebKit && !window.getSelection().getRangeAt;
			t.isIE = !t.isWebKit && !t.isOpera && (/MSIE/gi).test(ua) && (/Explorer/gi).test(navigator.appName);
			t.isIE6 = t.isIE && /MSIE [56]/.test(ua);
			t.isGecko = !t.isWebKit && /Gecko/.test(ua);
			t.isMac = ua.indexOf('Mac') != -1;
			return this;
		}
		
		var browser = _init();
		
		inOut = 0;
		theObj = $('workmenu');
		duration = 0.7;
		minheight = 525;
		// maxheight = 525;
		minwidth = 0;
		maxwidth = 365; //562; //537;
		
		if (!browser.isIE) {
			theObj.style.overflow = 'scroll'; // für FireFox
			theObj.style.height = 18; // für FireFox
		}
		
		maxheight = theObj.scrollHeight;
		
		if (!browser.isIE) {
			maxheight += 1;
			theObj.style.overflow = 'hidden'; // für FireFox
		}
		
		if (maxheight > 525) maxheight = 525;
		
		t1 = new Tween(theObj.style,'height',Tween.strongEaseInOut,minheight,maxheight,duration,'px');
		t2 = new Tween(theObj.style,'height',Tween.strongEaseInOut,maxheight,minheight,duration,'px');
		t3 = new Tween(theObj.style,'width',Tween.strongEaseInOut,minwidth,maxwidth,duration,'px');
		t4 = new Tween(theObj.style,'width',Tween.strongEaseInOut,maxwidth,minwidth,duration,'px');
	}
	
	if (location.search){ 
		var vals=location.search.substr(1).split("&");
		var request= new Array(); 
		
		for (var i in vals) { 
			vals[i] = vals[i].replace(/\+/g, " ").split("="); 
			request[unescape(vals[i][0])] =unescape(vals[i][1]);
		}
	} else request= new Array();
	
	if (!request["proj"]) {
		if (document.getElementById('workmenu')) openSelFirst();
		inOut = 0;
	} else {
		naaaa = $('navbar');
		theObj.onmouseover = openSel;
		theObj.onmousemove = openSel;
		naaaa.onmouseover = openSel;
		naaaa.onmousemove = openSel;
		window.document.onmouseover  = closeSel;
		window.document.onmousemove  = closeSel;
	}
}





