
var DropDownInterval = new Array();
var DropDownActive = new Array();
var DropDownIntervalCounter = 0;
function CDropDownAction(elementname,maxHeight,speed,status,cssOpen,cssClose)
{
	this.element;
	this.elementname;
	this.maxHeight;
	this.speed;
	this.Status;
	this.cssOpen;
	this.cssClose;

	this.setConig = function (elementname,maxHeight,speed,status,cssOpen,cssClose)
	{	
		this.elementname = elementname;
		this.Status = "close";		
		this.cssOpen = (cssOpen) ? cssOpen : false;
		this.cssClose = (cssClose) ? cssClose : false;
		
		if(document.getElementById(elementname))
		{
			this.element = document.getElementById(elementname);	
			this.elementname = elementname;
			//------  Display none erzeugt eine Höhe von 0px - muss also ausgestellt werden, wenn die Maximale Höhe errechnet wird
			var display = "";
			if(this.element.offsetHeight == 0)
			{
				this.element.style.display = "block";
				display = "none";
			}			
			this.maxHeight = this.element.offsetHeight;					//---- Maximale Höhe automatisch bestimmen
			this.element.style.display = display;
		}else{
			alert("Element ID: "+elementname+" existiert (noch) nicht!");
			this.element = false;
		}

		if(maxHeight)
		{
			this.maxHeight = maxHeight;
		}

		this.speed = this.maxHeight / 10;									//---- Speed automatisch bestimmen
		if(speed)
		{
			this.speed = speed;
		}

		if(status)
		{
			this.Status = status;
		}
	}

	this.setConig(elementname,maxHeight,speed,status,cssOpen,cssClose);
	
	this.DropDownAction = function (status)
	{
		if(status)
		{
			this.Status = status;
		}
		if(this.element && !DropDownActive[this.elementname])
		{
			if(this.Status == "close")
			{
				GoDown(this.elementname,this.maxHeight,this.speed);
				this.Status = "open";						
				return this.getStatus();
			}else{
				GoUp(this.elementname,this.maxHeight,this.speed);
				this.Status = "close";
				return this.getStatus();
			}
		}
	}
	
	//--- setzt das Element auf Anfang
	this.DropDownSetBeginning = function(status)   
	{				
		if(status)
		{
			this.Status = status;
		}
		if(this.element)
		{
			this.element.style.overflow = "hidden";						
			if(this.Status == "open")
			{
				this.element.style.height = this.maxHeight + "px";
				this.element.style.display = "";
			}else{					
				this.element.style.height = "0px";		
				this.element.style.display = "none";
			}
		}
	}
	
	this.getStatus = function()
	{
		return this.Status;
	}

	this.setStatus = function(status)
	{
		this.Status = status;
	}

	this.DropDownSetBeginning();
}

function GoDown(elementname,maxHeight,speed)
{
	element = document.getElementById(elementname);
	element.style.display = "";
	element.style.height = parseFloat(element.style.height) + 1 + "px";				
	DropDownActive[elementname] = true;
	DropDownIntervalCounter++;
	DropDownInterval[DropDownIntervalCounter] = window.setInterval("IntervalGoDown("+DropDownIntervalCounter+", '"+elementname+"','"+maxHeight+"', "+speed+")",1);		
}

function GoUp(elementname,maxHeight,speed)
{
	element = document.getElementById(elementname);
	DropDownActive[elementname] = true;
	DropDownIntervalCounter++;
	DropDownInterval[DropDownIntervalCounter] = window.setInterval("IntervalGoUp("+DropDownIntervalCounter+",'"+elementname+"',"+speed+")",1);		
}

function IntervalGoDown(Intervalcounter, elementname,maxHeight, speed)
{
	var makefunction = "action";
	var element = document.getElementById(elementname);
	if(parseFloat(element.style.height) + speed >= maxHeight)
	{
		element.style.height = maxHeight + "px";
		clearInterval(DropDownInterval[Intervalcounter]);				
		DropDownActive[elementname] = false;
		return;				
	}
	
	element.style.height = parseFloat(element.style.height) + speed + "px";
}

function IntervalGoUp(Intervalcounter,elementname,speed)
{
	element = document.getElementById(elementname);
	
	if(parseFloat(element.style.height) - speed  <= 0)
	{
		element.style.height = "0px";
		element.style.display = "none";
		clearInterval(DropDownInterval[Intervalcounter]);
		DropDownActive[elementname] = false;
		return;
	}
	element.style.height = parseFloat(element.style.height) - speed + "px";
}


/*---- DropDown Manager ----*/
function CDropDown(speed,status,mussStatus,managment)  //---- !!!!! nur eine Instanz möglich !!!! (Stand 15.09.2008)
{
	this.arDropDown = new Array();
	this.arDropDownObj = new Array();		
	this.status = false;
	this.mussStatus = "close";
	this.management = false;
	if(managment)
	{
		this.management	= managment;
	}	
	if(mussStatus)
	{
		this.mussStatus = mussStatus;	
	}
	this.speed = false;
	if(speed)
	{
		this.speed = speed;
	}
	if(status)
	{
		this.status = status;
	}
	
	this.loadDropDown = function(openElement)
	{
		for (clickElement in this.arDropDown)
		{									
			if(!this.arDropDownObj[clickElement])
			{
				this.arDropDownObj[clickElement] = new CDropDownAction	(	this.arDropDown[clickElement]["element"]
																	  , this.arDropDown[clickElement]["maxHeight"] 
																	  , this.arDropDown[clickElement]["speed"]
																	  , this.arDropDown[clickElement]["status"]
																	  , this.arDropDown[clickElement]["cssOpen"]
																	  , this.arDropDown[clickElement]["cssClose"]
																	);
				this.arDropDown[clickElement]["status"] = this.arDropDownObj[clickElement].getStatus();				
				this.loadOnClick(clickElement);
				if(this.arDropDown[clickElement]["cssOpen"] && this.arDropDown[clickElement]["status"] == "open")
				{			
					document.getElementById(clickElement).className = this.arDropDown[clickElement]["cssOpen"];
				}				
			}
		}
		
		if(openElement)
		{
//			this.editDropDown(openElement,false,false,false,"open");
			this.arDropDownObj[openElement].setStatus("close");			
			this.DropDownManager(openElement);
		}
	}	
	
	this.click = function(clickElement) 
	{
		this.DropDownManager(clickElement);
	}
	
	//--- wird für Datenkaspelung benätigt, sonst wird immer das letzte ClickElement benutzt
	this.loadOnClick = function(clickElement)
	{
		if(document.getElementById(clickElement))
		{
//			var that = this	
			window.document.getElementById(clickElement).onclick = this.click.bind(this, [clickElement]);
		}
	}
	
	this.DropDownManager = function(clickElement)
	{				
		if(!this.management)
		{
			for (allClickElements in this.arDropDown)
			{		
				if(!this.arDropDownObj[allClickElements])
				{
					continue;
				}
				this.arDropDown[allClickElements]["status"] = this.arDropDownObj[allClickElements].getStatus();
				if(this.arDropDown[allClickElements]["status"] != this.mussStatus)
				{
					if(this.arDropDown[allClickElements]["cssClose"])
					{
						document.getElementById(allClickElements).className = this.arDropDown[allClickElements]["cssClose"];						
					}
					this.arDropDown[allClickElements]["status"] = this.arDropDownObj[allClickElements].DropDownAction();
				}
				
			}
		}		
		this.arDropDown[clickElement]["status"] = this.arDropDownObj[clickElement].DropDownAction();		
		if(this.arDropDown[clickElement]["cssOpen"] && this.arDropDown[clickElement]["status"] == "open")
		{			
			document.getElementById(clickElement).className = this.arDropDown[clickElement]["cssOpen"];
		}
	}
	
	this.newDropDown = function(clicker,element,maxHeight,speed,status,cssOpen,cssClose)
	{
		if(!element)
		{
			return;
		}
		this.arDropDown[clicker] = new Array();
		this.arDropDown[clicker]["element"] = element;
		this.arDropDown[clicker]["maxHeight"] = maxHeight;
		this.arDropDown[clicker]["speed"] = "";
		this.arDropDown[clicker]["status"] = "";
		this.arDropDown[clicker]["cssOpen"] = cssOpen;
		this.arDropDown[clicker]["cssClose"] = cssClose;

		if(this.speed)
		{
			this.arDropDown[clicker]["speed"] = this.speed;
		}
		if(speed)
		{
			this.arDropDown[clicker]["speed"] = speed;
		}

		if(this.status)
		{
			this.arDropDown[clicker]["status"] = this.status;
		}
		if(status)
		{
			this.arDropDown[clicker]["status"] = status;
		}
	}	
	
	this.deleteDropDown = function(clicker,height,display)
	{
		if(this.arDropDownObj[clicker] && document.getElementById(clicker))
		{
			if(height)
			{
				document.getElementById(this.arDropDown[clicker]["element"]).style.height = height;
			}
			if(display)
			{
				document.getElementById(this.arDropDown[clicker]["element"]).style.display = display;
			}
			document.getElementById(clicker).onclick = "";
			this.arDropDownObj[clicker] = null;
			delete this.arDropDown[clicker];
		}
	}	

	this.editDropDown = function(clicker,element,maxHeight,speed,status)
	{		
		if(this.arDropDownObj[clicker])
		{
			if(maxHeight)
			{				
				this.arDropDown[clicker]["maxHeight"] = maxHeight;
			}
			if(element)
			{
				this.arDropDown[clicker]["element"] = element;
			}
			if(speed)
			{
				this.arDropDown[clicker]["speed"] = speed;
			}
			if(status)
			{
				this.arDropDown[clicker]["status"] = status;
			}
			
			
			this.arDropDownObj[clicker].setConig(
												 this.arDropDown[clicker]["element"]
												,this.arDropDown[clicker]["maxHeight"]
												,this.arDropDown[clicker]["speed"]
												,this.arDropDown[clicker]["status"]
											);
		}
	}	
}


Function.prototype.bind = function(obj, inputs)
{
    if (inputs == null)
        inputs = new Array();

    var method = this,
    temp = function()
    {
        return method.apply(obj,inputs);
    };
    return temp;
}

