
var Werbung = {

  /* constructor */
  init : function() {
		this.top = document.getElementById('topwerbungimg');
		this.bottom = document.getElementById('bottomwerbungimg');
        this.top.style.left = "190px";
        this.bottom.style.left = "-190px";
		this.setArrays(); 
		this.topindx = this.randInt(0,this.toparr.length);
		this.bottomindx = this.randInt(0,this.bottomarr.length);
		this.nextAdd();
   },
   
	/* add new div */	
   setArrays : function(){
		this.toparr = new Array();
		this.bottomarr = new Array();
		this.toplinkarr = new Array();
		this.bottomlinkarr = new Array();
		
		this.toparr[this.toparr.length] = "Logo_RRT.png";
		this.toplinkarr[this.toplinkarr.length] = "http://www.rrt.ch";
		this.toparr[this.toparr.length] = "Logo_DG.png";
		this.toplinkarr[this.toplinkarr.length] = "http://www.doetschgrether.ch";
		this.toparr[this.toparr.length] = "Logo_Mepha.png";
		this.toplinkarr[this.toplinkarr.length] = "http://www.mepha.ch";
		this.toparr[this.toparr.length] = "Logo_TRB_Chemedica.png";
		this.toplinkarr[this.toplinkarr.length] = "http://www.trbchemedica.de";
		this.toparr[this.toparr.length] = "Logo_Essex.png";
		this.toplinkarr[this.toplinkarr.length] = "https://www.essex.ch";
		this.toparr[this.toparr.length] = "Logo_Bristol.png";
		this.toplinkarr[this.toplinkarr.length] = "http://www.bms.ch";
		this.toparr[this.toparr.length] = "Logo_Novartis.png";
		this.toplinkarr[this.toplinkarr.length] = "http://www.novartis.ch";
		
		this.bottomarr[this.bottomarr.length] = "Logo_Menarin.png";
		this.bottomlinkarr[this.bottomlinkarr.length] = "http://www.menarini.ch";
		this.bottomarr[this.bottomarr.length] = "Logo_Nycomed.png";
		this.bottomlinkarr[this.bottomlinkarr.length] = "http://www.nycomed.ch";
		this.bottomarr[this.bottomarr.length] = "Logo_Abott_Immunology.png";
		this.bottomlinkarr[this.bottomlinkarr.length] = "https://www.abbott.ch";
		this.bottomarr[this.bottomarr.length] = "Logo_IBSA.png";
		this.bottomlinkarr[this.bottomlinkarr.length] = "http://www.ibsa.ch";
		this.bottomarr[this.bottomarr.length] = "Logo_Peramed1.png";
		this.bottomlinkarr[this.bottomlinkarr.length] = "http://www.paramed.ch";
   },
   
	/* add new div */	
   nextAdd : function(){
        window.clearTimeout(this.timeout);
        this.fadeout();
   },
   
	/* add new div */	
   changeAdd : function() {
        window.clearTimeout(this.timeout);
		this.topindx++;
		this.bottomindx++;
		if(this.topindx >= this.toparr.length)
		    this.topindx = 0;
		if(this.bottomindx >= this.bottomarr.length)
		    this.bottomindx = 0;
        this.top.style.left = "-190px";
        this.bottom.style.left = "190px";
		this.top.src = "grafik/werbung/" + this.toparr[this.topindx];
		this.bottom.src = "grafik/werbung/" + this.bottomarr[this.bottomindx];
		this.fadein();
   },
   
   fadeout : function(){ 
        window.clearTimeout(this.timeout);
        if(parseInt(this.top.style.left) < 190)
            this.top.style.left = (parseInt(this.top.style.left)+2)+"px";
            
        if(parseInt(this.bottom.style.left) > -190)
            this.bottom.style.left = (parseInt(this.bottom.style.left)-2)+"px";
        if(parseInt(this.top.style.left) >= 190 && parseInt(this.bottom.style.left) <= -190){
            this.changeAdd();
        } else this.timeout = window.setTimeout("Werbung.fadeout()",3);
    },
   
   fadein : function(){ 
        window.clearTimeout(this.timeout);
        if(parseInt(this.top.style.left) < 0)
            this.top.style.left = (parseInt(this.top.style.left)+2)+"px";
            
        if(parseInt(this.bottom.style.left) > 0)
            this.bottom.style.left = (parseInt(this.bottom.style.left)-2)+"px";
            
        if(parseInt(this.top.style.left) >= 0 && parseInt(this.bottom.style.left) <= 0)
            this.timeout = window.setTimeout("Werbung.nextAdd()",3000);
        else this.timeout = window.setTimeout("Werbung.fadein()",3);
    },
   
   
   randInt : function(min,max){ 
        var div = (max - min) + 1
        var randNum = Math.random()
        for (var i = 0; i <= div - 1; i++)
        {
                if (randNum >= i / div && randNum < (i+1) / div)
                        {return i + min}
        }
    },
    
    openLink : function(val){ 
        var link = this.toplinkarr[this.topindx];
        if(val == 0)
            link = this.bottomlinkarr[this.bottomindx];
        if(link.indexOf('http') == 0)
			window.open(link,"","","");
		else top.location.href = link;
    }

}

