/*
 	The first part is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    A copy of the GNU General Public License can be obtained from http://www.gnu.org/licenses/.
*/

/*
* 	Copyright (c) 2002 Thinking Arts Ltd (contact via http://www.thinkingarts.com/).
*/


//Expander Class 
function TaExpanderBox(id, expandImage, contractImage, startExpanded, noExpandButton, noCloseButton, closeButtonFrontText, openText, closeText, expandBackColor, contractBackColor, padding){
	isCSS = (document.body && document.body.style) ? true : false;
	isW3C = (isCSS && document.getElementById) ? true : false;
	if(! isW3C){
		return;
	}
	
	this.ID = id;
	
	if(! expandImage){
		expandImage = 	'expand.png';
	}	
	
	if(! contractImage){
		contractImage = 'contract.png';
	}	
	
	
	this.divObj = document.getElementById(id);
	this.divObj.expandButtonID = this.ID + 'ExpandButton';
	this.divObj.closeButtonID = this.ID + 'CloseButton';
	//this.divObj.expandButton = '<input type="image" id="' + this.divObj.expandButtonID + '" src="./application/html/images/' + expandImage + '" alt="Expand text" title="Expand text"> ';
	//this.divObj.closeButton = '<input type="image" id="' + this.divObj.closeButtonID + '" src="./application/html/images/' + contractImage + '" alt="Close text" title="Close text"> ';
	this.divObj.expandButton = '<a href="#"><image id="' + this.divObj.expandButtonID + '" src="./application/html/images/' + expandImage + '" alt="Expand text" title="Expand text" border="0"> </a>';
	this.divObj.closeButton = '<a href="#"><image type="image" id="' + this.divObj.closeButtonID + '" src="./application/html/images/' + contractImage + '" alt="Close text" title="Close text" border="0"></a> ';

	this.divObj.closeButtonFrontText = false;
	this.divObj.openText = '';
	this.divObj.expandBackColor = '';
	this.divObj.contractBackColor = '';
	this.divObj.padding = '0';
	
	if(closeButtonFrontText){
		this.divObj.closeButtonFrontText = true;
	}
	
	if(openText){
		if( openText.substr(0,1) == ' '){
			openText = '&nbsp;' + openText;
		}	
		
		openText = '<span class="expanderPromptText">' + openText + '</span> &nbsp;';
		this.divObj.expandButton = openText + " " + this.divObj.expandButton;
	}	
	
	if(closeText){
		if( closeText.substr(0,1) == ' '){
			closeText = '&nbsp;' + closeText;
		}	
		
		closeText = '<span class="ExpanderPromptText">' + closeText + '</span> &nbsp;';
		this.divObj.closeButton = closeText + " " + this.divObj.closeButton;
	}			
	
	if(expandBackColor){
		this.divObj.expandBackColor  = expandBackColor;
	}
	
	if(padding){
		this.divObj.padding = padding;
	}	
	
	if(contractBackColor){
		this.divObj.contractBackColor = contractBackColor;
	}		
	
	if(noExpandButton){
		this.divObj.expandButton = '';
	}	
	
	if(noCloseButton){
		this.divObj.closeButton = '';
	}	
	
	if(startExpanded){
		this.divObj.savedHTML = this.divObj.innerHTML;
		if(this.divObj.closeButtonFrontText){
			this.divObj.innerHTML = this.divObj.closeButton + '<br>' +  this.divObj.innerHTML ;
		}
		else{	
			this.divObj.innerHTML = this.divObj.innerHTML + '<br>' +  this.divObj.closeButton;
		}	
		if(this.divObj.expandBackColor){
			this.divObj.style.backgroundColor = this.divObj.expandBackColor;
		}	
		this.divObj.style.padding= this.divObj.padding;
	}
	else{	
		this.divObj.savedHTML = this.divObj.innerHTML;
		this.divObj.innerHTML = this.divObj.expandButton;
		if(this.divObj.contractBackColor){
			this.divObj.style.backgroundColor = this.divObj.contractBackColor;
		}	
	}
	
	this.divObj.onmouseup = function(evt){
		evt = (evt) ? evt : ((window.event) ? window.event : null);
		if(evt){
			var elem = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
			if(elem.id == this.expandButtonID){
				//alert ("ElemID: " + elem.id + " ButtonID:" + this.expandButtonID);
				if(this.closeButtonFrontText){
					this.innerHTML = this.closeButton + '<br>' + this.savedHTML ;
				}
				else{
					this.innerHTML = this.savedHTML + '<br>' +  this.closeButton;	
				}		
				if(this.expandBackColor){
					this.style.backgroundColor = this.expandBackColor;
				}
				this.style.padding= this.padding;
			}
			if(elem.id == this.closeButtonID){
				//alert ("ElemID: " + elem.id + " ButtonID:" + this.expandButtonID);
				this.innerHTML = this.expandButton;
				if(this.contractBackColor){
					this.style.backgroundColor = this.contractBackColor;
				}
				else{
					this.style.backgroundColor = '';
				}	
				this.style.padding= 0;
			}
		}	
	}
	
}
