/*
 	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, startExpanded, noExpandButton, noCloseButton, closeButtonFrontText, promptText, expandBackColor, contractBackColor, padding){
	isCSS = (document.body && document.body.style) ? true : false;
	isW3C = (isCSS && document.getElementById) ? true : false;
	if(! isW3C){
		return;
	}
	
	this.ID = id;
	
	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/expand.png" alt="Expand text" title="Expand text"> ';
	this.divObj.closeButton = '<input type="image" id="' + this.divObj.closeButtonID + '" src="./application/html/images/contract.png" alt="Close text" title="Close text"> ';
	this.divObj.closeButtonFrontText = false;
	this.divObj.promptText = '';
	this.divObj.promptText = '';
	this.divObj.expandBackColor = '';
	this.divObj.contractBackColor = '';
	this.divObj.padding = '0';
	
	if(closeButtonFrontText){
		this.divObj.closeButtonFrontText = true;
	}
	
	if(promptText){
		this.divObj.expandButton = promptText + " " + this.divObj.expandButton;
	}		
	
	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;
				}
				this.style.padding= 0;
			}
		}	
	}
	
}
