/* Copyright 2008  Adrian Wimmer,Birgit Pfeil. adrian-wimmer(a) gmx.net  version 27.10.2008*/

	var CssStyleTIME =50; 	
	var OpacityMin= 0.0;	var OpacityMax= 1.0;	var OpacityInc= 0.1; 	
	var HeightMin= 30;		var HeightMax= 250;		var HeightInc = 3;	
	var WidthMin= 250;		var WidthMax= 650;		var WidthInc = 15;		
	var BoxT1= 0;		var BoxL1= 0;		var BoxH1= 50;		var BoxW1= 50;
	var BoxT2= 0;		var BoxL2= 0;		var BoxH2= 150;		var BoxW2= 150;
	var BoxSteps= 15;
	var BgcolorMin=0xaaaaaa;var BgColorMax=0x333333;var BgColorSteps= 15;	

	var ChgCssElements= new Array();
	setInterval("chgCssInterval()",CssStyleTIME);
/*	function installMenu(){
		setInterval("chgCssInterval()",CssStyleTIME);
		// menuneu =new CssStyleMenu();	// Installationsbeispiel
	}
*/	
/*  CSS Funktionen : Aufruf Element,neuer Wert- */
	function changeOpacity(element,value){	
		IELayout(element);
		element.style.opacity=value;
		element.style.filter="Alpha(opacity="+value*100+")";
		element.style.MozOpacity=value;
		return;
	}
	function IELayout(element){	
		if(element.currentStyle && !element.currentStyle.hasLayout) {
			if (window.XMLHttpRequest) element.style.zoom=1; else element.style.height=0;
		}
		return;
	}
	function changeDisplay(element,value){
		if(value) element.style.display="block"; else element.style.display="none";return;
	}
	function changeBgColor(element,r,b,g){element.style.backgroundColor="rgb("+r+","+g+","+b+")";return;}
	function changeTop(element,value){element.style.top=value +"px";return;}
	function changeLeft(element,value){element.style.left=value +"px";return;}	
	function changeHeight(element,value){element.style.height=value +"px";return;}
	function changeWidth(element,value){element.style.width=value +"px";return;}
	function changeBox(element,top,left,height,width){ 
		element.style.top=top +"px"; element.style.left=left +"px";
		element.style.height=height +"px";element.style.width=width +"px";
		return;
	}
// Neue Funktionalität: CssFunktion, die den Style ändert.
/*	function changeX  (element, value, data){ element.style.height= value;	return;}               */	
	function createChgCssElement(element,type,args,menu){
		var create=true;
		for(k=0; k<ChgCssElements.length;k++){
			if (ChgCssElements[k].element== element)
			if(ChgCssElements[k].type.substring(0,ChgCssElements[k].type.indexOf("-"))== type.substring(0,type.indexOf("-"))) {
				ChgCssElements[k].set(type);
				create= false;
				l=k;
			}
		}
		if (create){ l=ChgCssElements.length; ChgCssElements[l]= new ChgCssElement(element,type,args,menu);}	
		return l;
	}	
	function chgCssInterval(){for(var k=0;k<ChgCssElements.length;k++)ChgCssElements[k].doIt();	}
	/* Data-Klassen*/
	function MinMaxData(min, max, inc){
		this.min= min;		this.max= max;		this.inc= inc;
		return;
	}
	function ColorData(rgbM, rgbM1, rgbSteps){   // Aufruf mit rgbMin/max = 0xRRGGBB
		this.rStart= rgbM>> 16; this.rEnd= rgbM1>> 16;
		this.rMin= Math.min(this.rStart,this.rEnd); this.rMax= Math.max(this.rStart,this.rEnd); 
		this.rInc=  Math.ceil((this.rEnd-this.rStart)/rgbSteps);
		this.gStart= (rgbM>> 8)& 0xff;	this.gEnd= (rgbM1>> 8)& 0xff;
		this.gMin= Math.min(this.gStart,this.gEnd);	this.gMax= Math.max(this.gStart,this.gEnd); 
		this.gInc=  Math.ceil((this.gEnd-this.gStart)/rgbSteps);
		this.bStart=(rgbM) & 0xff;  this.bEnd= (rgbM1) & 0xff;
		this.bMin= Math.min(this.bStart,this.bEnd); this.bMax= Math.max(this.bStart,this.bEnd); 
		this.bInc=  Math.ceil((this.bEnd-this.bStart)/rgbSteps);
		this.rValue= this.rStart; this.gValue= this.gStart;	this.bValue= this.bStart;
		this.rReady=false; this.gReady=false; this.bReady=false;
		this.ergReady=false;
		this.rCheck= function _rCheck(){
			if(this.rValue<this.rMin) return true;
			if(this.rValue>this.rMax) return true; 
			return false;
		}
		this.gCheck= function _gCheck(){
			if(this.gValue<this.gMin) return true;
			if(this.gValue>this.gMax) return true;
			return false;
		}
		this.bCheck= function _bCheck(){
			if(this.bValue<this.bMin) return true;
			if(this.bValue>this.bMax) return true;
			return false;
		}
		return;
	}
function BoxData(bt1,bl1,bh1,bw1,bt2,bl2,bh2,bw2,bs){ 
		this.bt1= bt1; this.bl1 =bl1; this.bh1=bh1; this.bw1=bw1;
		this.bt2= bt2; this.bl2 =bl2; this.bh2=bh2; this.bw2=bw2;
		this.bti= Math.ceil((bt2-bt1)/bs);
		this.bli= Math.ceil((bl2-bl1)/bs);
		this.bhi= Math.ceil((bh2-bh1)/bs);
		this.bwi= Math.ceil((bw2-bw1)/bs);
		this.t= bt1; this.l=bl1; this.h= bh1; this.w= bw1;
		this.tReady=false; this.lReady=false; this.hReady=false; this.wReady=false;
		this.tCheck= function _tCheck(){
			if(this.t<Math.min(this.bt1, this.bt2)) return true;
			if(this.t>Math.max(this.bt1, this.bt2)) return true;
			return false;
		}
		this.lCheck= function _lCheck(){
			if(this.l<Math.min(this.bl1, this.bl2)) return true;
			if(this.l>Math.max(this.bl1, this.bl2)) return true;
			return false;
		}
		this.hCheck= function _hCheck(){
			if(this.h<Math.min(this.bh1, this.bh2)) return true;
			if(this.h>Math.max(this.bh1, this.bh2)) return true;
			return false;
		}
		this.wCheck= function _wCheck(){
			if(this.w<Math.min(this.bw1, this.bw2)) return true;
			if(this.w>Math.max(this.bw1, this.bw2)) return true;
			return false;
		}
		return;
	}

/* MenüKlasse --------------------------------------------------------------------------------------------------------------------------*/
	function CssStyleMenu(){
		this.cssElement = null;
		this.chgCssElementIndex = -1;	
		this.active= true;
		this.wait= false;
		this.all_at_once= false;
		this.AAOElements= new Array();
		this.wait_until_ready= false; //
		this.chgCssElementInversType;
		this.cssIn= function _chgCssIn(element,type){
			if(! this.active) return;
			if (this.wait) if(this.cssElement== element) return;
			this.wait= false;
			if(this.chgCssElementIndex!=-1){
				if(ChgCssElements[this.chgCssElementIndex].element==element) return;
				if(this.wait_until_ready && !ChgCssElements[this.chgCssElementIndex].ready) return;//
				if(this.all_at_once){
					for(var k=0; k< this.AAOElements.length; k++){
						if(this.AAOElements[k]==element){
							return;
						}
					}	
					this.AAOElements[this.AAOElements.length]=element;
				}				
				ChgCssElements[this.chgCssElementIndex].chgType(this.chgCssElementInversType); 
			}

			this.cssElement= element;
			this.chgCssElementIndex= createChgCssElement(element,type,this.cssIn.arguments,this);
			this.chgCssElementInversType= (type.indexOf("-in")!=-1)?type.replace(/-in/,"-out"):type.replace(/-out/, "-in");
		}
		this.cssInById= function _chgCssInById(Id,type){
			if(! this.active) return;
			var element= document.getElementById(Id);
			if (this.wait) if(this.cssElement== element) return;
			this.wait= false;
			if(this.chgCssElementIndex!=-1){
				if(ChgCssElements[this.chgCssElementIndex].element==element) return;
				if(this.wait_until_ready && !ChgCssElements[this.chgCssElementIndex].ready) return;//
				if(this.all_at_once){
					for(var k=0; k< this.AAOElements.length; k++){
						if(this.AAOElements[k]==element){
							return;
						}
					}	
					this.AAOElements[this.AAOElements.length]=element;
				}
				ChgCssElements[this.chgCssElementIndex].chgType(this.chgCssElementInversType); 
			}

			this.cssElement= element;
			this.chgCssElementIndex= createChgCssElement(element,type,this.cssInById.arguments,this);
			this.chgCssElementInversType= (type.indexOf("-in")!=-1)?type.replace(/-in/,"-out"):type.replace(/-out/, "-in");
		}
		this.cssOut= function _chgCssAllOut(){
			if(! this.active) return;
			if(this.wait) return;
			if(this.all_at_once){
				this.fade();
			}
			if(this.chgCssElementIndex!=-1){
				ChgCssElements[this.chgCssElementIndex].chgType(this.chgCssElementInversType); 
		        this.chgCssElementIndex = -1;
			}
		}
		this.stop= function stop(){
			this.active= false;
			//this.cssOut(); 
			return;
		}
		this.go= function go(){
			this.active= true;
			return;
		}
		this.pause= function wait(){ /* verhindert das durch Click auf ein NichtMenuElement mit xxx.CssOut() das Menu ausgeblendet wird. */
			this.wait= true;
			//this.cssOut(); 
			return;
		}
		this.cont = function cont(){
			this.wait= false;
			return;
		}
		this.waitUntilReady= function wur(){ /* verhindert das öfnen eines neuen Menüs, bevor das vorherige geöffnet ist. */
			this.wait_until_ready= true;
			return;
		}		
		this.doNotWait= function dnw(){ /* standard. */
			this.wait_until_ready= false;
			return;
		}	
		this.fadeNone= function fa(){ /* standard. */
			this.all_at_once = true;
			return;
		}
		this.fade= function fn(){ /* standard. */
			this.AAOElements.length=0;
			this.all_at_once = false;
			return;
		}		
	}
	
/* Element Klasse */
	function ChgCssElement(elem,type,args,menu){
		this.element=elem; this.type= type; this.ready=false; this.value; this.data= null; this.menu= menu;
		if(args.length>3){
			switch(type){
				case "opacity-in":
				case "opacity-out":
					this.data= new MinMaxData(args[2],args[3],args[4]);
					break;
				case "height-in":
				case "height-out":
					this.data= new MinMaxData(args[2],args[3],args[4]);
					break;
				case "width-in":
				case "width-out":
					this.data= new MinMaxData(args[2],args[3],args[4]);
					break;
				case "bgColor-in":
				case "bgColor-out":
					this.data= new ColorData(args[2],args[3],args[4]);
					break;
				case "box-in":
				case "box-out":
					this.data= new BoxData(args[2],args[3],args[4],args[5],args[6],args[7],args[8],args[9],args[10]);
					break;
					
// Neue Funktionalität: Neue DataKlasse erzeugen, wenn die Parameter der Klasse beim Aufruf mit cssIn(element,type, arg[2],arg[3] ...) definiert wurden		
	/*			case "-in", "-out":
					break;
	*/
				default:
			}
		}
		if(this.data== null){
			switch(type){
				case "opacity-in":
				case "opacity-out":
					this.data= new MinMaxData(OpacityMin,OpacityMax,OpacityInc);
					break;
				case "height-auto-in":
				case "height-auto-out":
				case "height-in":
				case "height-out":
					this.data= new MinMaxData(HeightMin,HeightMax,HeightInc);
					break;
				case "width-in":
				case "width-out":
					this.data= new MinMaxData(WidthMin,WidthMax,WidthInc);
					break;
				case "bgColor-in":
				case "bgColor-out":
					this.data= new ColorData(BgcolorMin,BgColorMax,BgColorSteps);
					break;
				case "box-in":
				case "box-out":
					this.data= new BoxData(BoxT1,BoxL1,BoxH1,BoxW1,BoxT2,BoxL2,BoxH2,BoxW2,BoxSteps);
					break;

// Neue Funktionalität: Neue DataKlasse erzeugen, wenn die Parameter der Klasse beim Aufruf mit cssIn(element,type) nicht definiert wurden
// Es werden globale Variablen eingesetzt.		
		/*		case "-in", "-out":
					break;
				*/
				default:
			}
		}
		this.set = function _set(type){
			this.type= type; this.ready= false;
			switch(type){
				case "opacity-in": 
				case "height-in":
				case "height-auto-in":
				case "width-in":
					this.value=this.data.min;
					break;
				case "height-auto-out":	
				case "opacity-out":
				case "height-out":
				case "width-out":
					this.value=this.data.max;
					break;
				case "bgColor-in":
					this.data.rValue=this.data.rStart; this.data.gValue=this.data.gStart; this.data.bValue=this.data.bStart;
					this.data.rReady=false; this.data.gReady=false; this.data.bReady=false;
					break;
				case "bgColor-out":
					this.data.rValue=this.data.rEnd; this.data.gValue=this.data.gEnd; this.data.bValue=this.data.bEnd;					
					this.data.rReady=false; this.data.gReady=false; this.data.bReady=false;
					break;
					
				case "box-in":
					this.data.t=this.data.bt1; this.data.l=this.data.bl1;
					this.data.h=this.data.bh1; this.data.w=this.data.bw1;
					this.data.tReady=false; this.data.lReady=false; 
					this.data.hReady=false; this.data.hReady=false; 
					break;
				case "box-out":
					this.data.t=this.data.bt2; this.data.l=this.data.bl2;
					this.data.h=this.data.bh2; this.data.w=this.data.bw2;
					this.data.tReady=false; this.data.lReady=false; 
					this.data.hReady=false; this.data.hReady=false; 
					break;
// Neue Funktionalität:  Mit set wird der Typ von xxx-in nach xxx-out geändertund aktiviert. Anfangswerte werden hier gesetzt.  	

					/*
				case "-in":
					break;
				case "-out":
					break;
				*/
				default:
			}
			return;
		}
		this.chgType = function _chg(type){
			this.type= type;
			this.ready= false;
			switch(type){
				case "bgColor-in":
				case "bgColor-out":
					this.data.rReady=false; this.data.gReady=false; this.data.bReady=false;
					break;
				case "box-in":
				case "box-out":
					this.data.tReady=false;	this.data.lReady=false; 
					this.data.hReady=false; this.data.wReady=false;
					break;

// Neue Funktionalität:  interne Ready vars auf False setzen	
					/*
				case "-in":
					break;
				case "-out":
					break;
				*/

				default:
			}
			return;
		}
		this.set(this.type);
		this.doIt= function _doIt(){
			if(this.ready) return;
			switch(this.type){
				case "opacity-in":
					if (this.value<=0)changeDisplay(this.element, true);
					this.value+= this.data.inc;	
					if (this.value>this.data.max){this.value= this.data.max; this.ready=true;}
					changeOpacity(this.element, this.value);
					
					break;
				case "opacity-out":
					if(this.value==this.data.max && this.menu.all_at_once) break;
					this.value-= this.data.inc;
					if (this.value<=0)changeDisplay(this.element, false);
					if (this.value<this.data.min){this.value= this.data.min; this.ready=true;}
					changeOpacity(this.element, this.value);
					break;
				case "height-auto-in":
					this.value+= this.data.inc;
					if (this.value>this.data.max){this.value= this.data.max; this.ready=true;
					(this.element).style.height="auto";}else
					changeHeight(this.element, this.value);
					break;
				case "height-in":
					this.value+= this.data.inc;
					if (this.value>this.data.max){
						this.value= this.data.max;
						this.ready=true;
					}
					changeHeight(this.element, this.value);
					break;
				case "height-auto-out":
				case "height-out":
					if(this.value==this.data.max && this.menu.all_at_once) break;
					this.value-= this.data.inc;
					if (this.value<this.data.min){this.value= this.data.min; this.ready=true;}
					changeHeight(this.element, this.value);
					break;

					case "width-in":
					this.value+= this.data.inc;
					if (this.value>this.data.max){this.value= this.data.max; this.ready=true;}
					changeWidth(this.element, this.value);
					break;
				case "width-out":
					if(this.value==this.data.max && this.menu.all_at_once) break;
					this.value-= this.data.inc;
					if (this.value<this.data.min){this.value= this.data.min; this.ready=true;					}
					changeWidth(this.element, this.value);
					break;
				case "bgColor-in":
					this.data.rValue+= this.data.rInc;
					if (this.data.rCheck()){this.data.rValue= this.data.rEnd; this.data.rReady=true;}
					this.data.gValue+= this.data.gInc;
					if (this.data.gCheck()){this.data.gValue= this.data.gEnd; this.data.gReady=true;}
					this.data.bValue+= this.data.bInc;
					if (this.data.bCheck()){this.data.bValue= this.data.bEnd; this.data.bReady=true;}
					changeBgColor(this.element,this.data.rValue,this.data.gValue,this.data.bValue);
					if(this.data.rReady & this.data.gReady & this.data.bReady) this.ready=true;
					break;
				case "bgColor-out":
					this.data.rValue-= this.data.rInc;
					if (this.data.rCheck()){this.data.rValue= this.data.rStart; this.data.rReady=true;}
					this.data.gValue-= this.data.gInc;
					if (this.data.gCheck()){this.data.gValue= this.data.gStart; this.data.gReady=true;}
					this.data.bValue-= this.data.bInc;
					if (this.data.bCheck()){this.data.bValue= this.data.bStart; this.data.bReady=true;}
					changeBgColor(this.element,this.data.rValue,this.data.gValue,this.data.bValue);
					if(this.data.rReady & this.data.gReady & this.data.bReady) this.ready=true;
					break;
				case "box-in":
					this.data.t+= this.data.bti;
					if (this.data.tCheck()){this.data.t= this.data.bt2; this.data.tReady=true;}
					this.data.l+= this.data.bli;
					if (this.data.lCheck()){this.data.l= this.data.bl2; this.data.lReady=true;}
					this.data.h+= this.data.bhi;
					if (this.data.hCheck()){this.data.h= this.data.bh2; this.data.hReady=true;}
					this.data.w+= this.data.bwi;
					if (this.data.wCheck()){this.data.w= this.data.bw2; this.data.wReady=true;}
					changeBox(this.element,this.data.t,this.data.l,this.data.h,this.data.w);
					if(this.data.tReady & this.data.lReady & this.data.hReady& this.data.wReady) this.ready=true;
					break;
				case "box-out":
					this.data.t-= this.data.bti;
					if (this.data.tCheck()){this.data.t= this.data.bt1; this.data.tReady=true;}
					this.data.l-= this.data.bli;
					if (this.data.lCheck()){this.data.l= this.data.bl1; this.data.lReady=true;}
					this.data.h-= this.data.bhi;
					if (this.data.hCheck()){this.data.h= this.data.bh1; this.data.hReady=true;}
					this.data.w-= this.data.bwi;
					if (this.data.wCheck()){this.data.w= this.data.bw1; this.data.wReady=true;}
					changeBox(this.element,this.data.t,this.data.l,this.data.h,this.data.w);
					if(this.data.tReady & this.data.lReady & this.data.hReady& this.data.wReady) this.ready=true;
					break;
// Neue Funktionalität:  .  1. Dec/Inc von this.value oder alternativ von werten in Data,  2. Kontrolle, ob End erreicht -> this.ready = true.  !!! Wichtig 3. Aufruf der eigentlichen Routine , die den CssStyle ändert
		/*		case "-in":		
					break;
				case "-out":
					break;
		*/
				default:
			}
		}
	}
/* Ende */

