var _CTRL = {

    // Endposition für slideout
    maxout: -30,

    // Startposition für slide-in
    minin: 30,

    // Position für Anzeige des aktuellen untermenüs
    statePos: 0,

    // Anzahl der Pixel um die je Animations-Schritt geslided wird
    step: 1,

    // Millisekunden bis nächster Animations-Schritt
    timeout:25,

    flowin: null,

    flowout: null,

    state: null,

    next: null,

    active: null,

    interval: null,

    timer: null,

    init: function (){
	// Reinitialize for IE <7
	_CTRL.maxout = _CTRL.maxout | -30;
	_CTRL.minin = _CTRL.minin | 30;
	_CTRL.statePos = _CTRL.statePos | 0;
	_CTRL.step = _CTRL.step | 1;
	_CTRL.timeout = _CTRL.timeout | 25;
	
	if(activeLink = _UTIL.getElementById("jpropactive").value){
	_CTRL.active = _UTIL.getElementById(activeLink);
	_CTRL.state = _CTRL.active;
	_CTRL.state.style.display = "block";
	_CTRL.state.style.top = _CTRL.statePos + "px";
	}
    },

    activate: function (name){
	if(_CTRL.active != null){
		var nominate = _UTIL.getElementById(name);
		if(nominate == _CTRL.flowin){
		    _CTRL.next = null;
		    if(_CTRL.interval == null){
			_CTRL.interval = window.setInterval("_CTRL.animate()",_CTRL.timeout);
		    }
		}else if(nominate == _CTRL.state){
		    _CTRL.next = null;
		    if(_CTRL.interval != null){
			window.clearInterval(_CTRL.interval);
			_CTRL.interval = null;
		    }
		}else{
		    if(nominate != _CTRL.next) _CTRL.next = nominate;
		    if(_CTRL.interval == null){
			_CTRL.interval = window.setInterval("_CTRL.animate()",_CTRL.timeout);
		    }
		}
	}
    },
    
    deactivate: function(){
	if(_CTRL.active){
		if((_CTRL.state != _CTRL.active) && (_CTRL.flowin != _CTRL.active)){
		    _CTRL.next = _CTRL.active;
		    if(_CTRL.interval == null){
			_CTRL.interval = window.setInterval("_CTRL.animate()",_CTRL.timeout);
		    }
		}
	}
    },

    startStop: function(){
	if(_CTRL.active)
		_CTRL.timer = window.setTimeout("_CTRL.deactivate()",500);
    },

    stopStop: function(){
	if(_CTRL.timer != null){
	    window.clearTimeout(_CTRL.timer);
	    _CTRL.timer = null;
	}
    },

    animate: function(){
	if(((_CTRL.next == null) || (_CTRL.next == _CTRL.state)) && (_CTRL.state != null) && (_CTRL.interval != null)){
	    window.clearInterval(_CTRL.interval);
	    _CTRL.interval = null;
	}else{
	    if((_CTRL.state != null) && (_CTRL.next != null)){
		_CTRL.flowin = _CTRL.next;
		_CTRL.next = null;
		_CTRL.flowin.style.top = _CTRL.minin + "px";
		_CTRL.flowin.style.display = "block";
		_CTRL.flowout = _CTRL.state;
		_CTRL.state = null;
	    }
	    if(_CTRL.flowout != null){
		var offsetTop = parseInt(_CTRL.flowout.style.top);

		if((offsetTop >= (_CTRL.statePos-3))||(offsetTop <= (_CTRL.statePos+_CTRL.maxout+3))) _CTRL.step=1;
		else if ((offsetTop >= (_CTRL.statePos-7))||(offsetTop <= (_CTRL.statePos+_CTRL.maxout+7))) _CTRL.step=2;
		else if ((offsetTop <= (_CTRL.statePos-10))||(offsetTop >= (_CTRL.statePos+_CTRL.maxout+10))) _CTRL.step=3;
		else _CTRL.step = 4;

		_UTIL.log(_CTRL.step);

		if(offsetTop > _CTRL.maxout)
		    _CTRL.flowout.style.top = offsetTop - _CTRL.step + "px";
		else{
		    _CTRL.flowout.style.display = "none";
		    _CTRL.flowout = null;
		}
	    }
	    if(_CTRL.flowin != null){
		var offsetTop = parseInt(_CTRL.flowin.style.top);

		if(offsetTop > _CTRL.statePos)
		    _CTRL.flowin.style.top = offsetTop - _CTRL.step + "px";
		else{
		    _CTRL.state = _CTRL.flowin;
		    _CTRL.flowin = null;
		}
	    }
	} 
    }
}

var dom = document.getElementById ? true : false;
var ie = document.all ? true : false;
var ns = document.layers ? true : false;

var _UTIL = {
    
    getElementById: function (Identifier){
	var Element;
	if (dom) {
	Element = document.getElementById(Identifier);
	    if (!Element) {
		Element = false;
	    }
	    return Element;
	}
	if (ie) {
	    Element = document.all(Identifier);
	    if (!Element) {
		Element = false;
	    }
	    return Element;
	}
	if (ns) {
	    Element = document[Identifier];
	    if (!Element) {
		Element = document.anchors[Identifier];
	    }
	    if (!Element) {
		Element = false;
	    }
	    return Element;
	}
	return false;	
    },



    log: function (txt){
	var mylog = document.getElementById("mylog");
	if(mylog){
	    mylog.appendChild(document.createTextNode(txt));
	    mylog.appendChild(document.createElement("br"));
	}
    }
}
