// tools.js holger pfaff - 30-jul-2007
// based on crosswipe/fade http://www.brothercake.com/
// based on SDMenu http://www.dynamicdrive.com/dynamicindex1/slashdot.htm
var ix = { 'clk' : null, 'cnt' : 1 }
function fade() { // arg1=newimg
 if(ix.clk == null) {
  ix.obj = document.getElementById('image');
  if(ix.neu == undefined) {
	 ix.neu = document.getElementsByTagName('body')[0].appendChild(document.createElement('img'));
	 ix.typ = ix.gom(ix.obj);
	 ix.tim = 500; // msec
	 ix.res = 5 // resolution
	 ix.neu.className = 'idupe';
	 ix.neu.style.left = ix.grp(ix.obj, 'x') + 'px';
	 ix.neu.style.top = ix.grp(ix.obj, 'y') + 'px';
	 ix.so(ix.obj, 1);
	 ix.so(ix.neu, 0);
  }
  ix.neu.src = arguments[0];
  ix.cnt = 1;
  ix.clk = setInterval('ix.fade()', ix.tim / ix.res);
 }
}
ix.fade = function() {
 ix.cnt -= (1 / ix.res);
 if(ix.cnt < (1 / ix.res)) {
  clearInterval(ix.clk);
  ix.clk = null;
  ix.cnt = 1;
  ix.so(ix.neu, 1);
  ix.so(ix.obj, 0);
  ix.obj.src = ix.neu.src;
 }
 ix.so(ix.neu,1-ix.cnt);
 ix.so(ix.obj,ix.cnt);
}
ix.grp = function() { // get Real Position
 this.pos = (arguments[1] == 'x') ? arguments[0].offsetLeft : arguments[0].offsetTop;
 this.tmp = arguments[0].offsetParent;
 while(this.tmp != null) {
  this.pos += (arguments[1] == 'x') ? this.tmp.offsetLeft : this.tmp.offsetTop;
  this.tmp = this.tmp.offsetParent;
 }
 return this.pos ;
};
ix.gom = function() { // get opacity method
 if(typeof arguments[0].filters == 'object') {
  return (arguments[0].filters.length > 0 && typeof arguments[0].filters.alpha == 'object' && typeof arguments[0].filters.alpha.opacity == 'number') ? 'ie' : 'none';
 } else if(typeof arguments[0].style.MozOpacity != 'undefined') {
  return 'moz';
 } else if(typeof arguments[0].style.opacity != 'undefined') {
  return 'w3c';
 } else if(typeof arguments[0].style.KhtmlOpacity != 'undefined') {
  return 'khtml';
 } else {
  return 'none';
 }
}
ix.so = function() { // set opacity
  switch(ix.typ) {
   case 'ie' :
    arguments[0].filters.alpha.opacity = arguments[1] * 100; break;
   case 'khtml' :
    arguments[0].style.KhtmlOpacity = arguments[1]; break;
   case 'moz' :
    arguments[0].style.MozOpacity = (arguments[1] == 1) ? 0.9999999 : arguments[1]; break;
   default :
    arguments[0].style.opacity = (arguments[1] == 1) ? 0.9999999 : arguments[1]; break;
	}
}
function SDMenu(id) {
 if (!document.getElementById || !document.getElementsByTagName) return false;
 this.menu = document.getElementById(id);
 this.submenus = this.menu.getElementsByTagName("div");
 this.speed = 3;
}
SDMenu.prototype.init = function() {
 var mainInstance = this;
 for (var i = 0; i < this.submenus.length; i++) {
  this.submenus[i].getElementsByTagName("span")[0].onclick = function() { mainInstance.toggleMenu(this.parentNode);};
  this.submenus[i].onmouseover = function() { this.className=this.className+" active";};
  this.submenus[i].onmouseout = function() { this.className=this.className.replace (/ *active/,"");};
 }
};
SDMenu.prototype.toggleMenu = function(submenu) {
 if (submenu.className.substr(0,2) == "co")
  this.expandMenu(submenu);
 else if(submenu.className.substr(0,2) == "st")
  this.gotoUrl(submenu);
 else
  this.collapseMenu(submenu);
};
SDMenu.prototype.gotoUrl = function(submenu) {
 var links = submenu.getElementsByTagName("a");
 window.open(links[0], "inhaltframe");
}
SDMenu.prototype.expandMenu = function(submenu) {
 var fullHeight = submenu.getElementsByTagName("span")[0].offsetHeight;
 var links = submenu.getElementsByTagName("a");
 for (var i = 0; i < links.length; i++) {
  fullHeight += links[i].offsetHeight;
  links[i].disabled = false;
 }
 var moveBy = Math.round(this.speed * links.length);
 var mainInstance = this;
 var intId = setInterval(function() {
  var curHeight = submenu.offsetHeight ;
  var newHeight = curHeight + moveBy;
  if (newHeight < fullHeight)
   submenu.style.height = newHeight + "px";
  else {
   clearInterval(intId);
   submenu.style.height = "";
   submenu.className = submenu.className.replace(/collapsed/,"");
  }
 }, 30);
};
SDMenu.prototype.collapseMenu = function(submenu) {
 var minHeight = submenu.getElementsByTagName("span")[0].offsetHeight;
 var moveBy = Math.round(this.speed * submenu.getElementsByTagName("a").length);
 var mainInstance = this;
 var links = submenu.getElementsByTagName("a");
 for (var i = 0; i < links.length; i++) {
  links[i].disabled = true;
 }
 var intId = setInterval(function() {
  var curHeight = submenu.offsetHeight;
  var newHeight = curHeight - moveBy;
  if (newHeight > minHeight)
   submenu.style.height = newHeight + "px";
  else {
   clearInterval(intId);
   submenu.style.height = "";
   submenu.className = "collapsed "+submenu.className;
  }
 }, 30);
};

