function pc3Accordion( accordionId, parameters ){	var self = this;	this.accordion = $(accordionId);	this.parameters = parameters;	this.parentWidget = '';		this.init = function(){		this.tangens = this.parameters.tangens;		this.degrees = (Math.atan(this.tangens) * 360) / (Math.PI * 2);		this.activeBox = null;		this.fixedHeight = false;		if ( this.parameters.action == "onmouseover" || ( this.parameters.action == "onclick" && this.parameters.fixHeight == 1 ) ) this.fixedHeight = true;		//gather all boxes		var firstBoxToOpen = null;		var maxTitleHeight = 0;		var maxContentHeight = 0;		var maxOuterTitleHeight = 0;		var maxOuterContentHeight = 0;				this.boxes = this.accordion.childElements();		this.boxes.each( function( box, position ){			var childs = box.childElements();			var boxOuterDimension = pc3Widget.getOuterDimension(box, true);			box.position = position;			box.boxTitle = childs[0];			box.boxTitle.box = box;			if ( !self.firstBoxToOpen ) self.firstBoxToOpen = box.boxTitle;			var outerDimension = pc3Widget.getOuterDimension(box.boxTitle, true);			box.titleHeight = outerDimension.height;			if ( outerDimension.innerHeight > maxTitleHeight ) maxTitleHeight = outerDimension.innerHeight;			if ( box.titleHeight > maxOuterTitleHeight ) maxOuterTitleHeight = box.titleHeight;						box.boxContent = childs[1];			outerDimension = pc3Widget.getOuterDimension(box.boxContent, true);			box.contentHeight = outerDimension.height + boxOuterDimension.offsetsY;			if ( outerDimension.innerHeight > maxContentHeight ) maxContentHeight = outerDimension.innerHeight;			if ( box.contentHeight > maxOuterContentHeight ) maxOuterContentHeight = box.contentHeight;						Element.observe(box.boxTitle, (self.parameters.action=='onmouseover'?'mouseover':'click'), function( event ){ self.toggle(this, event)});		});				var height = parseInt(this.accordion.style.height);		if ( height > 0 ){			this.fixedHeight = true;			maxOuterContentHeight = height - (this.boxes.size() * maxOuterTitleHeight);			if ( maxOuterContentHeight < 20 ) maxOuterContentHeight = 20;		}		//set defaults for boxes		this.boxes.each( function( box, position ){			if ( self.fixedHeight ){				box.titleHeight = maxOuterTitleHeight;				if ( box.contentHeight > maxOuterContentHeight ) box.boxContent.setStyle({'overflowY':'scroll', 'overflowX':'hidden'});				box.contentHeight = maxOuterContentHeight;				box.boxTitle.setStyle({height:maxTitleHeight+'px'});				box.boxContent.setStyle({height:maxContentHeight+'px'});			}						box.direction = "";			box.currentHeight = 0;			box.displayedHeight = 0;			box.setStyle({overflow:'hidden', height:box.titleHeight+'px', position:'relative'});			box.closedClass = box.className;			box.openedClass = self.parameters.boxes[position];		});				this.accordion.lastHeight = this.accordion.getHeight();				this.steps = 1;		this.toggle(this.firstBoxToOpen, '');		this.steps = (this.parameters.animationDuration * 25) / 1000;	}		this.toggle = function( boxTitle, event ){		if ( !this.parentWidget ) this.parentWidget = pc3Widget.getParentWidget(this.accordion);		if ( event ) event.stop();		box = boxTitle.box;		if ( this.activeBox != box ){			this.toggleStyles(this.activeBox,'closed');			this.activeBox = box;			this.toggleStyles(this.activeBox,'opened');						this.activeBoxes = new Array();			this.boxCounter = 0;			this.boxes.each( function( box, position ){				if ( self.activeBox.position == box.position ){					if ( box.direction == 'close' && box.displayedHeight > 0 ) self.setBoxReverse(box);					if ( box.displayedHeight < box.contentHeight ) box.direction = 'open';					else box.direction = '';				} else {					if ( box.direction == 'open' && box.displayedHeight < box.contentHeight ) self.setBoxReverse(box);					if ( box.displayedHeight > 0 ) box.direction = 'close';					else box.direction = '';					if ( box.direction ){						self.activeBoxes[self.boxCounter] = box.position;						self.boxCounter++;					}				}			});						if ( this.fixedHeight ) this.boxSlideFixed( box );			else this.boxSlide( box );		}	}		this.toggleStyles = function( box, state ){		if ( !box ) return;		if ( state == 'opened' ){			if ( box.openedClass ) box.className = box.openedClass;		} else {			if ( box.closedClass ) box.className = box.closedClass;		}	}		this.boxSlideFixed = function( box ){		if ( box != this.activeBox ) return;		var step = box.contentHeight / this.steps;		if ( step < 0.5 ) step = 0.51;		box.currentHeight = Math.round(box.currentHeight + step);		var displayedHeight = this.getDisplayHeight(box, box.direction);		var totalMove = displayedHeight - box.displayedHeight;		if ( displayedHeight >= box.contentHeight || totalMove <= 0 ){			box.currentHeight = box.contentHeight;			box.displayedHeight = box.currentHeight;			totalMove = 10000;			box.direction = '';		} else {			box.displayedHeight = displayedHeight;		}		box.setStyle({height:(box.titleHeight + box.displayedHeight)+'px'});		var totalMoveHeight = 0;		var remainingTotalMove = totalMove;		var numberOfActiveBoxes = this.activeBoxes.length;		for(var i = 0; i < numberOfActiveBoxes; i++) totalMoveHeight = totalMoveHeight + this.boxes[this.activeBoxes[i]].displayedHeight;				var removeBoxes = new Array();		var removeBoxesCounter = 0;						for(var i = 0; i < numberOfActiveBoxes; i++){			if ( box != this.activeBox ) continue;						var currentBox = this.boxes[this.activeBoxes[i]];			if ( i == (numberOfActiveBoxes - 1) ){				currentBox.displayedHeight = currentBox.displayedHeight - remainingTotalMove;			} else {				move = Math.round((totalMove * currentBox.displayedHeight) / totalMoveHeight);				if ( move > remainingTotalMove ) move = remainingTotalMove;				remainingTotalMove = remainingTotalMove - move;				currentBox.displayedHeight = currentBox.displayedHeight - move;			}			if ( currentBox.displayedHeight <= 0 ){				currentBox.displayedHeight = 0;				currentBox.currentHeight = 0;				currentBox.direction = '';				removeBoxes[removeBoxesCounter] = i;				removeBoxesCounter++;			} else {				currentBox.currentHeight = this.getCurrentHeight(currentBox);			}			currentBox.setStyle({height:(currentBox.titleHeight + currentBox.displayedHeight)+'px'});		}		for(var i = 0; i < removeBoxes.length; i++) this.activeBoxes.splice((removeBoxes[i]-i),1);		if ( this.activeBoxes.length > 0 || box.contentHeight != box.displayedHeight ) setTimeout(function() { self.boxSlideFixed( box ); },40);	}	this.boxSlide = function( box ){		if ( box != this.activeBox ) return;				var allBoxesMoved = true;		this.boxes.each( function( box, position ){			if ( !box.direction ) return;						var step = box.contentHeight / self.steps;			if ( step < 0.5 ) step = 0.51;			if ( self.activeBox.position == box.position ){				box.currentHeight = Math.round(box.currentHeight + step);				if ( box.currentHeight >= box.contentHeight ){					box.currentHeight = box.contentHeight;					box.displayedHeight = box.currentHeight;					box.direction = '';				} else {					box.displayedHeight = self.getDisplayHeight(box, box.direction);					allBoxesMoved = false;				}			} else {				box.currentHeight = Math.round(box.currentHeight - step);				if ( box.currentHeight <= 0 ){					box.currentHeight = 0;					box.displayedHeight = box.currentHeight;					box.direction = '';				} else {					box.displayedHeight = self.getDisplayHeight(box, box.direction);					allBoxesMoved = false;				}			}			box.setStyle({height:(box.titleHeight + box.displayedHeight)+'px'});		});		if ( this.accordion.lastHeight != this.accordion.getHeight() ){			this.parentWidget.update();			this.accordion.lastHeight = this.accordion.getHeight();		}		if ( !allBoxesMoved ) setTimeout(function() { self.boxSlide( box ); },40);	}		this.setBoxReverse = function( box ){		degrees = (Math.atan(this.tangens - (this.getFactor( box, box.direction ) * this.tangens)) * 360) / (Math.PI * 2);		if ( box.direction == "open" ) box.currentHeight = Math.round((box.contentHeight * degrees) / this.degrees);		else box.currentHeight = box.contentHeight - Math.round((box.contentHeight * degrees) / this.degrees);	}	this.getFactor = function( box, direction ){		if ( direction == "open" ) pastDegrees = this.degrees - ((box.currentHeight * this.degrees) / box.contentHeight);		else pastDegrees = (box.currentHeight * this.degrees) / box.contentHeight;		if ( pastDegrees > this.degrees ) pastDegrees = this.degrees;		if ( pastDegrees < 0 ) pastDegrees = 0;		return Math.tan((pastDegrees * (Math.PI * 2)) / 360) / this.tangens;	}	this.getDisplayHeight = function( box, direction ){		if ( direction == "open" ) return box.contentHeight - Math.round(box.contentHeight * this.getFactor( box, box.direction ));		else return Math.round(box.contentHeight * this.getFactor( box, box.direction ));	}	this.getCurrentHeight = function( box ){		degrees = (box.displayedHeight * this.degrees) / box.contentHeight;		tangens = (degrees * this.tangens) / this.degrees;		return Math.round((((Math.atan(tangens) * 360) / (Math.PI * 2)) * box.contentHeight) / this.degrees);	}		this.init();}