/**
  @author: Georg Sievers 
**/

function DynamicLayer()
{
    this.fadeDuration = 1;
    this.framesPerSecond = 18;
    this.maxHeight = 700;

    this.fadeIn  = function() {
        var frames = this.fadeDuration * this. framesPerSecond;
        this.innerHTML = "";
        var time = 1/this.framesPerSecond;
        
        var heightSteps = this.maxHeight / frames;
        this.setVisibility(true);
        for (var i = 0; i < frames; ++i) {
    	    timer.register(this, "setHeight", [i*heightSteps, "ab"], i*time * 1000);
	}
        var ob = _$get('note_left_main');
        ob.setVisibility =  this.setVisibility;
        timer.register(ob, "setVisibility", false, i*time*1000);         
    }

    this.fadeOut  = function() {
        var frames = this.fadeDuration * this. framesPerSecond;
        var time = 1/this.framesPerSecond;
       
        this.innerHTML = "";
        var heightSteps = this.maxHeight / frames;
        for (var i = 0; i < frames; ++i){
    	    timer.register(this, "setHeight", (frames-i)*heightSteps, i*time * 1000);
	}
        _$get('note_left_main').setVisibility(true);
        timer.register(this, "setVisibility", false, this.fadeDuration * 1000);
    }
    
    this.setVisibility = function (visible)
    {
        this.style.display = (visible) ? 'block' :'none';
    }
    
    
    this.setHeight = function(h) {
        this.style.height = h + "px";
    }
   
}


function currentPath() {
    var loc = new String(window.location);
    var pathParts = loc.split('/');
    return loc.replace(pathParts[pathParts.length-1],'') ;   
}

function ptAJAX() {
    this.url = currentPath()+"folge.php?id=";

    this.getRequestObject = function() {

	var req = null;
        // Mozilla & co.
        if (typeof XMLHttpRequest != "undefined")
            req = new XMLHttpRequest();
		
        // IE 
        if (!req && typeof ActiveXObject != "undefined") {
	    try {
	        req = new ActiveXObject("Msxml2.XMLHTTP");
	    } catch (e) {
	        try {
		    req=new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e2) {
		    try {
		        req=new ActiveXObject("Msxml2.XMLHTTP.4.0");
		    } catch (e3) {
		        req=null;
		    }
		}
	    }
	}
        // ?
	if(!req && window.createRequest)
	    req = window.createRequest();
		
        return req;
    }
    
    this.call = function(id){
        this.fadeIn();    
        
        var self = this;
        var r = this.getRequestObject();

        r.open("GET", this.url+id, true);
        r.onreadystatechange = function() {
            if (r.readyState != 4 || r.status != 200) 
                return;
        
            timer.register(self, "setInnerHTML", false, 1000);
            self.r = r;            
        }
        r.send("");        
    } 

    this.setInnerHTML = function(input) {
         this.innerHTML = this.r.responseText;
    }
}


function mix_in_ob(ob, mixe){
    for (i in mixe){    
        ob[i] = mixe[i];
    }
}



function ol_initiate(){

    var ob = document.getElementById("pt_overlay");
//DynamicLayer.prototype = ob;
    mix_in_ob(ob, new DynamicLayer());
    mix_in_ob(ob, new ptAJAX());

//window.setTimeout("a.fadeOut()", 4000);
//document.getElementById("pagehead").fadeIn();
}




function Timer() 
{
    var last_id = 0;
    this.prepareArgStr = function (arg) {

        switch(typeof(arg)) {                
          case "string":
              return "\""+arg+"\"";
          break;

          case "number":
             return arg;
          break;
          case "boolean":
             return (arg) ? 'true' : 'false';      
          default:
            alert("pp:"+arg+ " "+typeof(arg));
       }  
    }

    this.register = function(ob, method, args, time, more) {
        
        if (ob.id == undefined) {
            ob.id = '_timer_'+(++this.last_id);
        }
        var argstr = ""

        if (typeof(args) == "array" || typeof(args) == 'object'){                
            for (i in args) {            
                if (i>0) argstr += ",";
                argstr += this.prepareArgStr(args[i]);
            }
        } else {
            argstr += this.prepareArgStr(args);
        }
     	window.setTimeout("_$get('"+ob.id+"')."+method+"("+argstr+")",time);
    }
}

var timer = new Timer();

