/**
 * @class HD.WidgetView
 * @description Creates a view manager that will hide and show different elements. 
 *              DEPRECATED. In most cases, its easier to just handle this manually using CSS than to use WidgetView
 * @constructor
 * @property {object}	config
 *						The configuration for the widget.
 * @property {string}	[config.navigation]
 *						The ID for the navigation element.
 * @property {string}	[config.canvas]
 *						The ID for the canvas element.
 */
HD.WidgetView = function (config) {
	this.config = config;
	this.observers = [];
	
	this.navigationEl = HD.get(this.config.navigation);
	this.canvasEl = HD.get(this.config.canvas);
};

HD.WidgetView.prototype = {
	/**
	* Shows a given element
	* @param {HTMLElement} div The div to set visible, all other siblings are hidden
	* @param {string} backText The text to show in the back button
	* @param {function} callback The function to execute when back button is pressed
	*/
	showDiv : function(div, text, callback) {
		this.setActiveDiv(HD.get(div));
		this.setupNav(text, callback);
	},
	
	/**
	* Sets the active shown element
	* @param {HTMLElement} divToShow The div to set visible, all other siblings are hidden
	*/
	setActiveDiv : function(divToShow) {
//		HD.util.Common.printStackTrace();
		var wrapperDiv = this.canvasEl;
		if(wrapperDiv.hasChildNodes()) {
			var childNodes = wrapperDiv.childNodes;
			for(var i = 0, len = childNodes.length; i < len; i++) {
				var childNode = childNodes[i];
				// do this ID test because some of the nodes are text nodes
				// and don't support setting class names
				if(childNode.id != null) {
					HD.hide(childNode);
				}
			}
		}
		
		HD.show(divToShow);
	},
	
	/**
	* Changes the navigation text and callback
	* @param {string} text The string to update the navigation text with
	* @param {function} callback The function to call when the navigation element is clicked
	*/
	setupNav : function(text, callback) {
		var classes = HD.CSS_CLASSES;
		// show back button
		HD.addClass(this.navigationEl, classes.CONTROL);
		this.setNavText(text);
		
		if(callback != null) {
			HD.addClass(this.navigationEl, classes.CONTROL);
			this.navigationEl.onclick = callback;
		} else {
			HD.removeClass(this.navigationEl, classes.CONTROL);
		}
		
		/*
		var cb = this;
		navigationEl.onclick = function() {
			HD.removeClass(navigationEl, classes.CONTROL);
			cb.revertNavText.call(cb);
			cb.setActiveDiv.call(cb, cb.canvasDiv, backDiv);
		};
		*/
	},
	
	/**
	* Reverts the navigation text to its previous content
	*/
	revertNavText : function() {
		this.navigationEl.innerHTML = this.previousNavHTML;
	},
	
	/**
	* Changes the navigation text and caches the previous
	* @param {string} text The string to update the navigation text with
	*/
	setNavText : function(text) {
		this.previousNavHTML = this.navigationEl.innerHTML;
		this.navigationEl.innerHTML = text;
	}
};

HD.extend(HD.WidgetView, [HD.util.Observable]);

HD.register('hd_widget_view', HD.WidgetView, {version: "1.0", build: "1"});
