
//Das Objekt, das gerade bewegt wird.
var dragobjekt = null;

// Position, an der das Objekt angeklickt wurde.
var dragx = 0;
var dragy = 0;

// Mausposition
var posx = 0;
var posy = 0;


//function draginit()
 {
 // Initialisierung der &Uuml;berwachung der Events

  document.onmousemove = drag;
  document.onmouseup = dragstop;
}


function dragstart(element) {
   //Wird aufgerufen, wenn ein Objekt bewegt werden soll.

  dragobjekt = element;
  dragx = posx - dragobjekt.offsetLeft;
  dragy = posy - dragobjekt.offsetTop;
}


function dragstop() {
  //Wird aufgerufen, wenn ein Objekt nicht mehr bewegt werden soll.

  dragobjekt=null;
}



function drag(e) {
  //Wird aufgerufen, wenn die Maus bewegt wird und bewegt bei Bedarf das Objekt.

  posx = document.all ? window.event.clientX : e.pageX;
  posy = document.all ? window.event.clientY : e.pageY;
  if(dragobjekt != null) {
    dragobjekt.style.left = (posx - dragx) + "px";
    dragobjekt.style.top = (posy - dragy) + "px";
  }
}




//____________________________________________________________________



 // The constructor should be called with
// the parent object (optional, defaults to window).

function Timer(){
    this.obj = (arguments.length)?arguments[0]:window;
    return this;
}

// The set functions should be called with:
// - The name of the object method (as a string) (required)
// - The millisecond delay (required)
// - Any number of extra arguments, which will all be
//   passed to the method when it is evaluated.

Timer.prototype.setInterval = function(func, msec){
    var i = Timer.getNew();
    var t = Timer.buildCall(this.obj, i, arguments);
    Timer.set[i].timer = window.setInterval(t,msec);
    return i;
}
Timer.prototype.setTimeout = function(func, msec){
    var i = Timer.getNew();
    Timer.buildCall(this.obj, i, arguments);
    Timer.set[i].timer = window.setTimeout("Timer.callOnce("+i+");",msec);
    return i;
}

// The clear functions should be called with
// the return value from the equivalent set function.

Timer.prototype.clearInterval = function(i){
    if(!Timer.set[i]) return;
    window.clearInterval(Timer.set[i].timer);
    Timer.set[i] = null;
}
Timer.prototype.clearTimeout = function(i){
    if(!Timer.set[i]) return;
    window.clearTimeout(Timer.set[i].timer);
    Timer.set[i] = null;
}

// Private data

Timer.set = new Array();
Timer.buildCall = function(obj, i, args){
    var t = "";
    Timer.set[i] = new Array();
    if(obj != window){
        Timer.set[i].obj = obj;
        t = "Timer.set["+i+"].obj.";
    }
    t += args[0]+"(";
    if(args.length > 2){
        Timer.set[i][0] = args[2];
        t += "Timer.set["+i+"][0]";
        for(var j=1; (j+2)<args.length; j++){
            Timer.set[i][j] = args[j+2];
            t += ", Timer.set["+i+"]["+j+"]";
    }}
    t += ");";
    Timer.set[i].call = t;
    return t;
}
Timer.callOnce = function(i){
    if(!Timer.set[i]) return;
    eval(Timer.set[i].call);
    Timer.set[i] = null;
}
Timer.getNew = function(){
    var i = 0;
    while(Timer.set[i]) i++;
    return i;
}




//______________________________________________________________


function  SiteElement(ID,posx,posy){
	this.count = 0;
        this.Active = null;
	this.id = ID;
	this.posX = posx;
	this.posY = posy;
        this.move = new Timer(this);
}

var naviZustand = null;

function schalt(obj){
	if( obj.Active == null && objDrei.Active == null ){		
	if(naviZustand != null){
		//naviZustand.move.clearInterval(naviZustand.Active);
		naviZustand.bewegen();
		if (naviZustand == obj){			
			objDrei.bewegen();
			naviZustand = null;
		}else{
			obj.bewegen();
			naviZustand = obj;
		}		
	}else{
		obj.bewegen();
		objDrei.bewegen();
		naviZustand = obj;
	}
	}
}

SiteElement.prototype.bewegen = function(){	
	this.Active = this.move.setInterval("fallen",1);
}
SiteElement.prototype.fallen = function(){
	this.count+=2;
         document.getElementById(this.id).style.top =(this.posX+300)*( Math.sin((this.count)*Math.PI/200)  )-300+'px';
         if(Math.abs(Math.sin((this.count)*Math.PI/200)) == 1){
                  this.move.clearInterval(this.Active);
                  this.Active = null;		  
         }
}
SiteElement.prototype.schieben = function(){
        	if(this.Active == null)
	this.Active = this.move.setInterval("fahren",1);
}
SiteElement.prototype.fahren = function(){
/*	this.count+=2;
	 document.getElementById(this.id).style.top =(this.posX+300)*( Math.sin((this.count)*Math.PI/200)  )-300+'px';
         document.getElementById(this.id).style.left =(this.posY+100)*( Math.sin((this.count)*Math.PI/200)  )-100+'px';
         if(Math.abs(Math.sin((this.count)*Math.PI/200))==1){
                  this.move.clearInterval(this.Active);
                  this.Active = null;
         }
*/
}


//______________________________________________________________


var n_x_untermenu = 18;

function keks(wo,nam){

	var ablauf = new Date();
	var wielang = ablauf.getTime() + (2 * 60 * 60 * 1000)+(20 * 1000);
	ablauf.setTime(wielang);
	document.cookie = nam+"="+wo+";Max-age=600;";

}


function farbwechsel(rgb){
	farb = new Array('rot','grun','blau');
	for( i = 0 ; i < 3 ; i++ ){
		document.getElementById(farb[i]).style.borderTop = "white";
		document.getElementById(farb[i]).style.borderLeft = "white";
		document.getElementById(farb[i]).style.borderBottom = "solid 1px black";
		document.getElementById(farb[i]).style.borderRight = "solid 1px black";

	}
	document.getElementById(rgb).style.borderTop = "solid 1px black";
	document.getElementById(rgb).style.borderLeft = "solid 1px black";
	document.getElementById(rgb).style.borderBottom = "white";
	document.getElementById(rgb).style.borderRight = "white";

	//keks(rgb, 'FARBE' );

	if(rgb == 'rot'){
		document.titel.src = rtitel.src;
		document.menu.src = rmenu.src;
		document.inhalt.src = rinhalt.src;
		document.inhaltpic.src = rinhaltpic.src;
		for( i = 0 ; i < n_x_untermenu ; i++ ){
			document.untermenu[i].src = runtermenu.src;
		}
	}
	if(rgb == 'grun'){
		document.titel.src = gtitel.src;
		document.menu.src = gmenu.src;
		document.inhalt.src = ginhalt.src;
		document.inhaltpic.src = ginhaltpic.src;
		for( i = 0 ; i < n_x_untermenu ; i++ ){
			document.untermenu[i].src = guntermenu.src;
		}
	}
	if(rgb == 'blau'){
		document.titel.src = titel.src;
		document.menu.src = menu.src;
		document.inhalt.src = inhalt.src;
		document.inhaltpic.src = inhaltpic.src;
		for( i = 0 ; i < n_x_untermenu ; i++ ){
			document.untermenu[i].src = untermenu.src;
		}
	}
	return true;
}


var cookieWert='leer';
function getkeks(Keksname){//alert(document.cookie);
	alleCookies=document.cookie;
	cookieArr=alleCookies.split("; ");
	for(var i=0;i<cookieArr.length;i++){//alert("-"+unescape(cookieArr[i].split("=")[0])+"=="+Keksname+"-");
		if(cookieArr[i].split("=")[0] == Keksname){
			cookieWert=cookieArr[i].split("=");
			cookieWert=cookieWert[1];
			return true;
		}
	}
	return false;
}


function start( wann ){
	//if(getkeks('PERFORM') && cookieWert == 'low' && location.href != 'http://3zwo1.com/2tag.html'){alert(location.href);
	//	location.href='2tag.html';
	//}
	if(getkeks('FARBE')){
		farbwechsel(cookieWert);
	}	
	
	if (getkeks('ORT')){
		document.getElementById('elf').style.left = parseInt(cookieWert)+'px';
		document.getElementById('elf').style.top = (parseFloat(cookieWert)-Math.floor(parseFloat(cookieWert)))*1000+'px';
	}else if( wann == 'alt' ){
		document.getElementById('elf').style.left = '144px';
		document.getElementById('elf').style.top =  '395px';
	}
	if( wann == 'neu' ){
		objEins.bewegen();
		window.setTimeout('objZwei.bewegen()',900);
		window.setTimeout('objDrei.bewegen()',1400);
		window.setTimeout('objFunf.bewegen()',1800);
		if (!getkeks('ORT'))window.setTimeout('objElf.schieben()',1000);
	}else{
		document.getElementById('eins').style.top = '0px';
		document.getElementById('zwei').style.top = '95px';
		objDrei.bewegen();
		objFunf.bewegen();
		if(getkeks('FARBE')){
			farbwechsel(cookieWert);
		}
	}

}

