function WizardWidget() {
	this.onLeaveListeners = new Array();
	this.onEnterListeners = new Array();
	this.currentPanel = 0;
	this.panels = new Array();	
	for (var i = 0; i<arguments.length; i++) {
		this.panels.push(arguments[i]);
	}	
}

WizardWidget.prototype.clearPreListeners = function() {
	this.onLeaveListeners = new Array();
}

WizardWidget.prototype.clearPostListeners = function() {
	this.onEnterListeners = new Array();
}

WizardWidget.prototype.addOnLeaveListener = function(listener) {
    	this.onLeaveListeners.push(listener);
}

WizardWidget.prototype.addOnEnterListener = function(listener) {
	this.onEnterListeners.push(listener);
}

WizardWidget.prototype.fireOnLeaveListeners = function(index) {
	for(var i = 0; i < this.onLeaveListeners.length; i++) {
		try {
			if(!this.onLeaveListeners[i].onPanelLeave(index))
				return false;
		} catch(e){
			return false;
		}
	}
	return true;
}

WizardWidget.prototype.fireOnEnterListeners = function(index) {
	for(var i = 0; i < this.onEnterListeners.length; i++) {
		try {
			if(!this.onEnterListeners[i].onPanelEnter(index))
				return false;
		} catch(e){
			return false;
		}
	}
	return true;
}

WizardWidget.prototype.showNext = function() {
	if(this.fireOnLeaveListeners(this.currentPanel)) {
		if (this.currentPanel < (this.panels.length-1)) {
			this.currentPanel++;
		}
		new GeneralScript().showComponent(this.getCurrentPanel());
		new GeneralScript().hideComponent(this.getPanel(this.currentPanel-1));
		this.fireOnEnterListeners(this.currentPanel);
	}
}

WizardWidget.prototype.showPrev = function() { 
	if(this.fireOnLeaveListeners(this.currentPanel)) {
		if (this.currentPanel > 0) {
			this.currentPanel--;
		}
		new GeneralScript().showComponent(this.getCurrentPanel());
		new GeneralScript().hideComponent(this.getPanel(this.currentPanel+1));
		this.fireOnLeaveListeners(this.currentPanel);
	}
}

WizardWidget.prototype.getCurrentPanel = function() { 
	return $(this.panels[this.currentPanel]);
}

WizardWidget.prototype.getPanel = function(index) { 
	return $(this.panels[index]);
}

WizardWidget.prototype.init = function() { 
	this.currentPanel = 0;
	for (var i = 0; i < this.panels.length; i++) {
		new GeneralScript().hideComponent(this.getPanel(i));
	}
	new GeneralScript().showComponent(this.getPanel(0));
	this.fireOnEnterListeners(this.currentPanel);
}


