Control = Class.create();

Control.eventStub = function() {
	return false;
}

Control.onfocus = function(element) {
	element.hasFocus = true;
}

Control.onblur = function(element) {
	element.hasFocus = undefined;
}

Control.prototype.initialize = function(eNode, dNode, isShown, isEnabled, action) {
	this.disabledNode = dNode;
	this.disabledNode.onselectstart = Control.eventStub;
	
	this.enabledNode = eNode
	this.enabledNode.onselectstart = Control.eventStub;
	
	this.isShown = isShown;
	this.isEnabled = isEnabled;
	this.action = action;
	//this.isEnabled ? this.doEnable() : this.doDisable();
	//this.isShown ? this.doShow() : this.doHide();
}

/*Control.CLASSES = {
	first : {hidden : "ol_button_border ol_control_hidden", shown : "ol_button_border ol_control_shown"},
	down : {hidden : "ol_button_border ol_control_hidden", shown : "ol_button_border ol_control_shown"},
	up : {hidden : "ol_button_border ol_control_hidden", shown : "ol_button_border ol_control_shown"},
	last : {hidden : "ol_button_border ol_control_hidden", shown : "ol_button_border ol_control_shown"}
};*/

Control.prototype.doShow = function() {
	this.isShown = true;
	if (this.isEnabled) {
		this.doHideNode(this.disabledNode);
		this.doShowNode(this.enabledNode);
	} else {
		this.doHideNode(this.enabledNode);
		this.doShowNode(this.disabledNode);
	}
}

Control.prototype.doHide = function() {
	this.isShown = false;
	this.doHideNode(this.disabledNode);
	this.doHideNode(this.enabledNode);
}

Control.prototype.doEnable = function() {
	this.isEnabled = true;
	this.doHideNode(this.disabledNode);
	this.doShowNode(this.enabledNode);
}

Control.prototype.doDisable = function() {
	this.isEnabled = false;
	
	var nodes = this.enabledNode.select("a[id='" + this.enabledNode.id + "link']");
	
	var newFocusNode = undefined;
	
	if (nodes && nodes[0]) {
		var link = nodes[0];
		if (link.hasFocus) {
			var disNodes = this.disabledNode.select("a[id='" + this.disabledNode.id + "link']");
			if (disNodes && disNodes[0]) {
				newFocusNode = disNodes[0];
			}
		}
	}
	
	this.doHideNode(this.enabledNode);
	this.doShowNode(this.disabledNode);
	if (newFocusNode && newFocusNode.focus) {
		//For IE
		newFocusNode.disabled = false;
		newFocusNode.focus();
		//For IE
		newFocusNode.disabled = true;
	}
}

Control.prototype.doHideNode = function(node) {
	//node.className = Control.CLASSES[this.action].hidden;
	node.hide();
}

Control.prototype.doShowNode = function(node) {
	//node.className = Control.CLASSES[this.action].shown;
	node.show();
}


