
//erzeugt einen blink mit dem fisch
//fischname
function doBlink(fishname)
{
	var elem = "_fisch" + fishname;
	if (!getID(elem)) return;
	if (getID(globalBlinkLast)) {cssSetOpacity( getID(globalBlinkLast),100);} //letzten wieder sichtbar machen
	_blink(elem,true,100,5);
}	



//blinkt  (priv)
//element, runterDimmen, aktuelleTransp, anzahl der dimmungen
function _blink(el,isDown,alphachannel,few) 
{
	window.clearTimeout(globalBlink);//letztes geblinkte zurücksetzen ...

	globalBlinkLast = el; //setze neues Element fürs spätere Rücksetzen
	isDown = (isDown) ? isDown : false; //ist am runter-dimmen
	if (isDown)	alphachannel -= 10;else alphachannel += 10; //alphachannel erhöhen/erniedrigen
	if (alphachannel<0) {
		alphachannel = 0; //wieder hoch-dimmen mit selben eigenschafte
		globalBlink = window.setTimeout("_blink('" + el +"',false,"+alphachannel+","+few+")",100);
	}
	else if (alphachannel>100) {
		alphachannel = 100;
		few = few - 1; //eine dimmung abgeschlossen; runterzählen
		if (few<=0) return; //fertig!!!
		globalBlink = window.setTimeout("_blink('" + el +"',true,"+alphachannel+","+few+")",100);// wieder runterdimmen---
	}
	else {
		cssSetOpacity( getID(el),alphachannel); //neuen style setzen
		globalBlink = window.setTimeout("_blink('" + el +"',"+isDown+","+alphachannel+","+few+")",100);
	}
}
		   
		   
//erzeugt eine Tabelle mit den Fisch-Informationen
//info-Array des bestimmten Tieres ... (feature-list)
function infoStringCreation(infos)
{
	var InfosStr = '<table style="width:280px">';
	
	InfosStr += MakeTableCell('Name:',infos['name']);	
	InfosStr += MakeTableCell('Gattung:',infos['gattung']);	
	InfosStr += MakeTableCell('Kaufdatum:',infos['kaufdatum']);	
	InfosStr += MakeTableCell('Lieblingsspeise:',infos['essen']);	
	InfosStr += MakeTableCell('Hobby:',infos['hobby']);	
	InfosStr += MakeTableCell('Merkmal:',infos['merkmal']);	
	
	if (!istUndefined(infos['info'])) {
		InfosStr += MakeTableCell('Infos:','&nbsp;');	
		InfosStr += MakeDoubleTableCell(infos['info']);
		}
	return InfosStr += '</table>';
}

//erzeugt eine zwei spaltige Tabelle mit den Werten ...
function MakeTableCell(node,value)
{
   return '<tr><td align="left" valign="top">'+node+'</td><td><b>' + value + '</b></td>';
}
function MakeTableCellInvers(node,value)
{
   return '<tr><td align="left" valign="top"><b>'+node+'</b></td><td>' + value + '</td>';
}
function MakeDoubleTableCell(value)
{
   return '<tr><td align="left" valign="top" colspan="2">'+value+'</td>';
}

//erzeugt den Slider
//weite,hoehe,scrittweite,abstandvon aquarium, geschlossen?
function createTipSlider(w,h,step,abstand_becken,closedSlider)
{
	this.SetTitle = function(url,w,h,alternativTitel)
	{
		alternativTitel = (alternativTitel) ? alternativTitel : 'Überschrift';
		url = (url) ? url : "titel_fischbestand.png";
		w = (w) ? w : 171;
		h = (h) ? h : 30;
		this.infotitle.src = url;//"corner_close.png";
		this.infotitle.alt = "Titel: "+alternativTitel;	
		this.infotitle.title = "";
		this.infotitle.align = "right";
		cssSetStyle( this.infotitle,'align','right');
		cssSetStyle( this.infotitle,'width',w+'px');
		cssSetStyle( this.infotitle,'height',h+'px');
		cssSetStyle( this.infotitle,'display','block');
	}	
	
	//TEXT SETZEN IM TOOLTIPP
	this.SetText = function(txt)
	{
			this.inhalt.innerHTML = txt;
	}
	//ZUSTAND HART SETZEN
	//sollGeschlossen?
	this.setClosed = function(close)
		{
			if (close) {
				this.ml = this.Max;
				this.w = 0;
			} else {
				this.w = this.Max;
				this.ml = 0;
			}			
			cssSetStyle( this.contentobject,'margin','0px 0px 0px -' + this.ml +'px');
			cssSetStyle( this.object ,'width',this.w+'px');
		}
	//SLIDEIN
	//ms zeit
	this.slideIn = function(s)
		{
			if (getID('_scrollablebox')) //wenn eine overflow:auto in der SliderBox ... -> hidden ....
				{
				cssSetStyle( getID('_scrollablebox') ,'overflow','hidden');
				}
				
		    s = (s) ? s : 65; //zeit
			this.ml = this.ml + this.step;
			this.w = this.w - this.step;
			cssSetStyle( this.contentobject,'margin','0px 0px 0px -' + this.ml +'px');
			if (this.w >= 0) cssSetStyle( this.object ,'width',this.w+'px');
			this.isClosed = true; //Slider ist (am) schließen / geschlossen
			if (this.w <= 0) {
			    //wenn SlideReOpen -> dann Endfunktion aufrufen ... (wenn ganz versteckt ...)
				if (istFunction(this.closesInterrupt))  {this.doEvents();};
			} else {
				this.timerID = window.setTimeout("this.slideIn("+s+")",s); //erneut Rein-Slidern ....
			}	
		}
	//SLIDEOUT
	//ms zeit	
	this.slideOut = function (s)
		{
			s = (s) ? s : 65; //zeit
			this.ml = this.ml - this.step;
			this.w = this.w + this.step;
			cssSetStyle( this.contentobject,'margin','0px 0px 0px -'  + this.ml +'px');
			cssSetStyle( this.object,'width',this.w+'px');
			this.isClosed = false; //Slider ist (am) öffnen / geöffnet
			if (this.w >= this.Max) {
				if (getID('_scrollablebox')) //wenn eine overflow:auto in der SliderBox ... -> hidden ....
				{
					cssSetStyle( getID('_scrollablebox') ,'overflow','auto');
				}
			} else {
				this.timerID = window.setTimeout("this.slideOut("+s+")",s); //slider weiter öffnen ...
			}	
		}	
		
	//SCHlIESSEN, AKTUALISIERN UND WIEDER ÖFFNEN
	//schließzeit, wartezeit, öffnenzeit, funktion, die aktualisiert
	this.slideReOpen = function (closespeed,waitspeed,openspeed,fnk)
		{
			UnTip();
			this.closesInterrupt = fnk;
			this.closesInterruptWaitspeed = waitspeed;
			this.closesInterruptOpenspeed = openspeed;
			this.slideIn(closespeed);
		}
    //Funktion wird bei REOPEN aufgerufen, wenn das Div-repainted wird ... bevor es neu geöffnet wird!		
	this.doEvents = function()
		{
			this.closesInterrupt(); //wartefunktion aufrufen
			this.closesInterrupt = null; //funktion löschen
			//nun slider wieder ausfahren
			window.setTimeout("this.slideOut('"+ this.closesInterruptOpenspeed + "')",this.closesInterruptWaitspeed);
		}	

	//slider auch im sliden stoppen und für neuen befehl verfügbar machen	
	this.stopSlider = function()
		{
			window.clearTimeout(this.timerID);
		}	

		
 	var bodyTag = getID('wrapper');
	if (!bodyTag) return;
	this.isClosed = (closedSlider) ? closedSlider : false;

	this.step = (step) ? step : 10; //schrittgröße animation
	this.w = (w) ? w : 300; //weite des sliders
	this.h = (h) ? h : 500; //hoehe des sliders
	this.abstandbecken = (abstand_becken) ? abstand_becken : 0; //abstand vom aquarium
	this.m = 0; //aktueller margin
	this.Max = this.w; //maximale weite des sliders [offset-speicherung]
	this.ml = 0; //margin-left 
	
	//Hilfswrapper
	this.object = document.createElement("div");
	this.object.id = "_slide_helper";
	cssSetStyle( this.object,'position','absolute');
	cssSetStyle( this.object,'width',this.w + 'px');
	
	this.h = (document.all) ? this.h-2*global_rahmen_weite : this.h;
	cssSetStyle( this.object,'height',this.h+'px');
	cssSetStyle( this.object,'margin',this.m+'px');
	cssSetStyle( this.object,'overflow','hidden');
	
	this.t = elementGetCoordinates(getID('water')).top;
	this.t = (document.all) ? this.t + global_rahmen_weite : this.t;
	cssSetStyle( this.object,'top',this.t+'px');
	
	this.left = elementGetCoordinates(getID('water')).right;
	this.left = (document.all) ? this.left - global_rahmen_weite : this.left;
	this.left += this.abstandbecken;
	cssSetStyle( this.object,'left',this.left+'px');

	//Slider-Frame	
	this.contentobject = document.createElement("div");
	this.contentobject.id = "_info_frame";
	this.contentobject.className = "rund";
	cssSetStyle( this.contentobject,'position','absolute');
	cssSetStyle( this.contentobject,'width',this.w + 'px');
	cssSetStyle( this.contentobject,'left','0px');
	cssSetStyle( this.contentobject,'height',this.h+'px');
	cssSetStyle( this.contentobject,'margin','0px 0px 0px 0px');
	cssSetStyle( this.contentobject,'background','white');
	cssSetStyle( this.contentobject,'background','url(water_right.png)');
	
	this.contentHight = this.h - 2*30; //zwei mal eckenhöhe, für den richtigen inhalt des textes ...
	this.setClosed(this.isClosed); //setze zustand ..
	
	//close-button
	var topseq = document.createElement("div");
	topseq.className = "roundtop";
	cssSetStyle( topseq,'height','30px');
	cssSetStyle( topseq,'width','100%');
	this.infotitle = document.createElement("img");
	this.infotitle.className = "title_tag";	
	this.infotitle.id = "_btnCloseInfoTitle";	
	this.infotitle.src = "titel_fischbestand.png";//"corner_close.png";
	this.infotitle.alt = "Titel: Fischbestand";	
	this.infotitle.title = "";
	this.infotitle.align = "right";
	cssSetStyle( this.infotitle,'align','right');
	cssSetStyle( this.infotitle,'width','171px');
	cssSetStyle( this.infotitle,'height','30px');
	cssSetStyle( this.infotitle,'display','none');
	this.closer = document.createElement("img");
	this.closer.className = "corner";	
	this.closer.id = "_btnCloseInfo";	
	this.closer.src = "corner_close.png";//"corner_closeinfo.png";
	this.closer.alt = "Schließen";	
	this.closer.title = "Schließen";
	this.closer.align = "right";
	cssSetStyle( this.closer,'align','right');
	cssSetStyle( this.closer,'width','41px');
	cssSetStyle( this.closer,'height','30px');
	cssSetStyle( this.closer,'display','none');
	topseq.appendChild(this.closer);
	topseq.appendChild(this.infotitle);
	
	
	//inhalt
	this.inhalt = document.createElement("div");
	this.inhalt.className = "tipscnt";	
	this.inhalt.id ="_tip_bar_content";
	this.inhalt.innerHTML = "auch programmierer haben langweile und schreiben hier mist rein!";
	cssSetStyle( this.inhalt,'height',this.contentHight+'px');
	cssSetStyle( this.inhalt,'margin','0px 0px 0px 10px');
	
	//pseudo-corner unten
	var bottomseq = document.createElement("div");
	bottomseq.className = "roundbottom";
	this.corner = document.createElement("img");
	this.corner.className = "corner";	
	this.corner.src = "corner_br.png";
	this.corner.alt = "";	
	cssSetStyle( this.corner,'width','30px');
	cssSetStyle( this.corner,'height','30px');
	cssSetStyle( this.corner,'display','none');
	cssSetStyle( this.corner,'visibility','hidden');
	bottomseq.appendChild(this.corner);
	

//corner und content dem slider adden	
	this.contentobject.appendChild(topseq);
	this.contentobject.appendChild(this.inhalt);
	this.contentobject.appendChild(bottomseq);
//slider zum warpper adden	
	this.object.appendChild(this.contentobject);
//alles ins DOM anfügen	
	bodyTag.appendChild(this.object);

//Close-Button	
	listenerAdd(this.closer,'click',function(){sliderDIV.slideIn();});//this.slideIn //SchliesseTipBar();
	listenerAdd(this.closer,'mouseover',function(){Tip('Schließen');});//this.slideIn //SchliesseTipBar();
	listenerAdd(this.closer,'mouseout',function(){UnTip();});//this.slideIn //SchliesseTipBar();
	
	
	return this;
}



//zeigt einen Text in der SliderBox-An
//Feaurelist des Tieres (object)
function ShowRightFischInfo(feature_object)
{
  //schließzeit, wartezeit, öffnenzeit, funktion, die aktualisiert
  sliderDIV.slideReOpen(10,100,15,function(){sliderDIV.SetText(infoStringCreation(feature_object));sliderDIV.SetTitle("titel_informationen.png",175,30,"Informationen")});
}

 //Objektbild im Aquarium positionieren
 //weite,höhe,top,left,bildurl,transparenz;
 function Zubehoer(w,h,t,l,url,alpha)
 {
    var level = (alpha) ? alpha : 100;
 	var bodyTag = getID('_aquarium');
	if (!bodyTag) return;
	var water_right = elementGetCoordinates(getID('water')).right;
	var water_left = elementGetCoordinates(getID('water')).left;
	var water_top = elementGetCoordinates(getID('water')).top;
	var water_down = elementGetCoordinates(getID('water')).bottom;
	l = water_left + l;
    t = water_top + t;
	this.object = document.createElement("div");
	this.object.id = "_zubehoer";
	this.object.className = "holz";
	cssSetStyle( this.object,'position','absolute');
	cssSetStyle( this.object,'left',l+'px');
	cssSetStyle( this.object,'top',t+'px');
	cssSetStyle( this.object,'height',h+'px');
	cssSetStyle( this.object,'width',w + 'px');
	cssSetStyle( this.object,'z-index','1');
	cssSetStyle( this.object,'background','url('+url+')');
	cssSetOpacity(this.object,level);
	bodyTag.appendChild( this.object);
 }

//Erzeugt einen Rahmen um das Aquariumwasser ....
//dicke
function Rahmen(size)
 {
    size = (size) ? size : '10';
 	var bodyTag = getID('_aquarium');
	if (!bodyTag) return;
	var sizes = size;
	if (document.all) sizes=0;
	var l = elementGetCoordinates(getID('water')).left-sizes;
	var t = elementGetCoordinates(getID('water')).top-sizes;
	var h = elementGetSize(getID('water')).y;
	var w = elementGetSize(getID('water')).x;
	this.object = document.createElement("div");
	this.object.id = "_rahmen";
	this.object.className = "border";
	cssSetStyle( this.object,'position','absolute');
	cssSetStyle( this.object,'left',l+'px');
	cssSetStyle( this.object,'top',t+'px');
	cssSetStyle( this.object,'height',h+'px');
	cssSetStyle( this.object,'width',w + 'px');
	cssSetStyle( this.object,'z-index','1000'); //???
	cssSetStyle( this.object,'border','10px solid black');
	bodyTag.appendChild( this.object);
 } 

 //Erstellt ein neues Aquariumtier
 //weite,hoehe,bildurl,name,gattung
 function Tier(w,h,picture,name,gattung,max_schwimmhoehe)
{
			//wechselt das Bild der Richtungen ...
		   var klicked = false;
		   var changeRichtungsBild = function(obj,toRight) {
			    if (!toRight) cssSetStyle(obj,'background','url(left_' + picture + ')'); 
				if (toRight) cssSetStyle(obj,'background','url(right_' + picture + ')'); 
			}
		   //zeigt tooltip ....	
		  var showInfoTag = function(show)
		   {
			show = (show) ? show : false;
			Tip(infoString);
			if ((!show)) {UnTip();}
		   }
		  var showInfoTag2 = function()
		   {
		    klicked = false;
			//alert();
			if (!((name == TierBestand[UID]['name']))) alert('Interne RaceCondition');
			ShowRightFischInfo(TierBestand[UID]);
		   }
		  
		  this.highlight = function(b)
		   {
			 b = (b) ? b : false;  
		     doBlink("_"+ this.name);
		   //blink	_fisch_ true 100
		   }
		 	   
		  
		  this.setFeature = function(node,value)
		  {
			Eigenschaften[node] = value;
			tierinfos['picture'] = this.picture;
			TierBestand[this.UID][node] = value;
 
		  }
		   
		  		   
		  //bewegen der Fische
		  this.move = function()
			{
				if (this.RichtungX==1) { //nach rechts
				  this.left += this.moveStep;
				  cssSetStyle(this.object,'left',this.left + 'px');
				  if ((this.left + this.width +10) > (this.water_right)) 
				    {
						this.RichtungX = 1 - this.RichtungX;
						changeRichtungsBild(this.object,this.RichtungX); //(-> dann nach Links)
					}	
				}
				if (this.RichtungX==0) { //nach links
				  this.left -= this.moveStep;
				  cssSetStyle(this.object,'left',this.left + 'px');
				  if ((this.left-10) < (this.water_left)) 
				   {
						this.RichtungX = 1 - this.RichtungX;
						changeRichtungsBild(this.object,this.RichtungX); //(-> dann nach Rechts)
					}
				} 		
			
				if (this.RichtungY==0) { //nach unten
				  this.top += this.moveStep;
				  cssSetStyle(this.object,'top',this.top + 'px');
				  if ((numberZufallsZahl(0,10)>7)) this.RichtungY = 1 - this.RichtungY;
				  if (((this.top+this.height+10 ) > (this.water_down))) {
				    this.RichtungY = 1;
					this.top = this.water_down - this.height - 10;
					//cssSetStyle(this.object,'top',this.top + 'px');
				  }
				} 
				
				if (this.RichtungY==1) { //nach oben
				  this.top -= this.moveStep;
				  cssSetStyle(this.object,'top',this.top + 'px');
				  if ((numberZufallsZahl(0,10)>7)) this.RichtungY = 1 - this.RichtungY;
				  if (((this.top - 10) < (this.water_top))) {
				    this.RichtungY = 0;
					this.top = this.water_top+10;
					//cssSetStyle(this.object,'top',this.top + 'px');
				  }	
				}
				
			}
			
	
 //this.features = new Array();
 var Eigenschaften = new Object();
 this.name = (name) ? name : 'unbekannt';
 var namenString = this.name;
 this.gattung = (gattung) ? gattung : 'Fisch';
 this.picture =  (picture) ? picture :  'fish.png';	
 var tierinfos = new Object();
 tierinfos['name'] = this.name;
 tierinfos['gattung'] = this.gattung;
 tierinfos['picture'] = this.picture;
 
 this.UID = TierBestand.push(tierinfos)-1;
 var UID =  this.UID;
 this.setFeature('UID',UID);
 
 //var UID = TierBestand.length-1;
 var picture = this.picture;
 var infoString = this.name + " ("+this.gattung+")";
 this.alphachannel = 100;
 this.RichtungX = (numberZufallsZahl(0,1)==1) ?  1 : 0;
 this.RichtungY = 0;
 this.left = 0;
 this.top = 0;
 this.width = w;
 this.height = h;
 this.water_right = elementGetCoordinates(getID('water')).right;
 this.water_left = elementGetCoordinates(getID('water')).left;
 this.water_top = (max_schwimmhoehe) ? max_schwimmhoehe : elementGetCoordinates(getID('water')).top;
 this.water_down = elementGetCoordinates(getID('water')).bottom;
 this.left = numberZufallsZahl(this.water_left,this.water_right-this.width);
 this.top = numberZufallsZahl(this.water_top,this.water_down-this.height);

 this.moveStep = 10;
 this.object = null;

 var bodyTag = getID('_aquarium');
 if (!bodyTag) return;
  this.object = document.createElement("div");
  this.object.id = "_fisch_" + this.name;
  this.object.className = "fisch";
   cssSetStyle( this.object,'position','absolute');
   cssSetStyle( this.object,'left',this.left+'px');
   cssSetStyle( this.object,'top',this.top+'px');
   cssSetStyle( this.object,'height',this.height+'px');
   cssSetStyle( this.object,'width',this.width + 'px');
   cssSetStyle( this.object,'background','red');
   cssSetStyle( this.object,'background','url(fish.png)');
   changeRichtungsBild(this.object,this.RichtungX);
   bodyTag.appendChild( this.object);

   listenerAdd(this.object,'mouseover',function(){showInfoTag(true)});//zeige Hover-Tip
   listenerAdd(this.object,'click',function(){showInfoTag2()}); //zeige Infos in rechtem Slider
   listenerAdd(this.object,'mouseout',function(){showInfoTag(false)});//verschwinde Hover-Tip
return this;
};

//erzeugt ein neues Aquarium mit den Abmaßen left,top,weite,höhe,bgurl,transparenz
function Aquarium(l,t,w,h,water,alpha)
{
	this.getHoehe = function()
	{
		return elementGetSize(this.object).y;
	}
	
	this.getWeite = function()
	{
		return elementGetSize(this.object).x;
	}
	
	water = (water) ? water : 'water.jpg';
	var level = (alpha) ? alpha : 20;
  	var bodyTag = getID('left');
	if (!bodyTag) return;
	this.objectWrapp = document.createElement("div");
	this.objectWrapp.id = "_aquarium";
	this.objectWrapp.className = "aquarium";
	cssSetStyle( this.objectWrapp,'background-color','green');
	this.object = document.createElement("div");
	this.object.id = "water";
	this.object.className = "aquarium";
	cssSetStyle( this.object,'position','absolute');
	cssSetStyle( this.object,'left',l+'px');
	cssSetStyle( this.object,'top',t+'px');
	cssSetStyle( this.object,'height',h+'px');
	cssSetStyle( this.object,'width',w + 'px');
	cssSetStyle( this.object,'background','url('+water+')');
	cssSetStyle( this.object,'backgroundRepeat',"repeat-x"); 
	cssSetOpacity(this.object,level);
	this.objectWrapp.appendChild(this.object);
	bodyTag.appendChild( this.objectWrapp );
}

