/*
 * Author: Vertex Logic, Inc
 * Copyright 2005, 2006, 2007 - All rights reserved
 *
 * Vertex Logic, Inc., California, USA 
 *
 * Vertex Logic grants you ("Licensee") a non-exclusive license to use
 * and modify this source and recompile it in
 * accordance with the terms of the Agreement under which this software is bought
 * and provided that (i) this copyright notice appear on all copies of the Software; 
 * (ii) Licensee does not sale the software as is or with modification without
 * the prior consent of Vertex Logic. (iii) Licensee agrees that it does not have any 
 * title or ownership of the Software.
 *
 * The program is provided "as is" without any warranty express or
 * implied, including the warranty of non-infringement and the implied
 * warranties of merchantibility and fitness for a particular purpose.
 * Vertex Logic will not be liable for any damages suffered 
 * by you as a result of using the Program. 
 * In no event will Vertex Logic be liable for any
 * special, indirect or consequential damages or lost profits even if
 * Vertex Logic have been advised of the possibility of their occurrence. 
 * Vertex Logic will not be liable for any third party claims against you.
 */
 Af.HtmlTitlePane2 = Class.create();

Af.HtmlTitlePane2.prototype = {


	initialize: function(relatedPaneId, titleId, openTitleClass, closeTitleClass, listener) {
		this.relatedPaneId = relatedPaneId;
		this.titleId = titleId;
		this.titleTriggerId = titleId + "Trigger";
		this.openTitleClass = openTitleClass;
		this.closeTitleClass = closeTitleClass;
		this.open = true;
		this.init();
		this.listener = listener;
	},

	init: function() {
	    this.relatedPane = document.getElementById(this.relatedPaneId);
	    if (this.relatedPane == null) {
	       return;
	    }
	    if (this.titleId != null) {
			this.title = document.getElementById(this.titleId);
			this.title.onclick = this.titleSelected.bindAsEventListener(this); 
			this.title.parentNode.onclick = this.titleSelected.bindAsEventListener(this);
			this.titleTrigger = document.getElementById(this.titleTriggerId);
			if (this.titleTrigger != null) {
			   this.titleTrigger.onclick = this.toggleOpenClose.bindAsEventListener(this); 
			}
	    }
	 },
	 
	 toggleOpenClose: function(ev) {
	    this.setPaneState(!this.open);
	    return consumeEvent(ev);
	 },
	 
	 titleSelected: function(ev) {
	    if (this.listener != null && this.listener.viewSelected != null) {
	       this.listener.viewSelected(this);
	    }
	    return consumeEvent(ev);
	 },
	 
	 setPaneState: function(state) {
	    this.open = state;
	    var s;
	    var className;
	    if (this.open) {
	       s = '';
	       className = this.openTitleClass;
	    } else {
	       s = 'none';
	       className = this.closeTitleClass;
	    }
	    //this.title.className = className;
	    if (this.titleTrigger != null) {
	       this.titleTrigger.className = className;
	    }
	    this.relatedPane.style.display = s;
	    if (this.listener != null) {
	       this.listener.paneStateChanged(this);
	    }
	    
	    var oldPrefix;
	    if (this.open) {
	       s = '';
	       oldPrefix = "+ ";
	       prefix = "- ";
	    } else {
	       s = 'none';
	       oldPrefix = '- ';
	       prefix = '+ ';
	    }
	   /*  
	    if (this.titleTrigger != null) {
			var t = this.titleTrigger;
			if (t.childNodes.length > 0) {
			   var ts = t.childNodes[0].nodeValue;			   
			   if(ts != null){
				   var idx = ts.indexOf(oldPrefix);			 	 
				   if (idx > -1) {
					 t.childNodes[0].nodeValue = prefix + ts.substring(idx + oldPrefix.length);
				   }
			   }
			}
	    }		*/   
	 }

}

