function Wizard()
{
	//vars
	var _me = this;
	this._forceSelectedHint = null;
	this._$allClips = [];
	this._hintDetailsOpen = []; //of 3 Boolean values, tracking which hintDetails are open
	this._stepsComplete = [];

	Wizard.prototype.init = function()
	{
		this._forceSelectedHint = 1;
		this._$allClips = $(".hintButton");
        this.getStateCookie();
        var showPollResults = false;
		//_me._stepsComplete = [null, false, false, false]; //dummy data. this should be set by the cookie instead.
		if(_me._stepsComplete.length > 0){
			for(var i=0; i<_me._stepsComplete.length; i++){
				if(_me._stepsComplete[i]){
					_me.checkCheckbox(i);
					if (i == 1) {
					    showPollResults = true;
					}
				}
			}
			_me.selectNextStep();
		}else{
			this.selectButton(1);
		}
		this.onResize();

		// wizard buttons mouseover/mouseout/click
		$(".hintButton").hover(this.hintButton_onOver, this.hintButton_onOut);
		$(".hintButton").click(this.hintButton_onClick);

		// show tooltips when rolling over the related area on the left
		$(".poll").hover(this.generalAreas_onOver, this.generalAreas_onOut);
		$(".addComment").hover(this.generalAreas_onOver, this.generalAreas_onOut);
		$(".discussion_post:first").hover(this.generalAreas_onOver, this.generalAreas_onOut);

		$(".poll").click(function(){
			_me.stepActionItem_onClick(1);
		})
		$(".captcha input").click(function(){
			_me.stepActionItem_onClick(2);
		})
		$(".ratingArea").click(function(){
			_me.stepActionItem_onClick(3);
		})
		
		if (showPollResults) {
		    $(".pollImagery").css("display","none");
		    updateDisplay();
		} else {
		    $(".pollImagery").css("display","none");
		}
	}

	Wizard.prototype.stepActionItem_onClick = function(i)
	{
	    // don't track clicks here; they're being clicked elsewhere
		if(this._stepsComplete[i]) return;
		this._stepsComplete[i] = true;
		this.setStateCookie();
		_me.checkCheckbox(i);
		this.selectNextStep();
	}

	Wizard.prototype.checkCheckbox = function(i)
	{
		$(".hint"+i+" .checkbox").addClass("checkboxChecked");
	}

	Wizard.prototype.selectNextStep = function()
	{
		this.deselectButton(1);
		this.deselectButton(2);
		this.deselectButton(3);
		if(!this._stepsComplete[1]){
			this._forceSelectedHint = 1;
			this.selectButton(1, false, false);
		}else if(!this._stepsComplete[2]){
			this._forceSelectedHint = 2;
			this.selectButton(2, false, false);
		}else if(!this._stepsComplete[3]){
			this._forceSelectedHint = 3;
			this.selectButton(3, false, false);
		}else{
			this._forceSelectedHint = null;
		}
	}

	Wizard.prototype.hintButton_onOver = function(event)
	{
		var clip = this;//event.currentTarget;
		var $clip = $(clip);
		var i = _me.getIndexByHintButton($clip[0]);
		_me.selectButton(i+1);
	}

	Wizard.prototype.hintButton_onOut = function(event)
	{
		var clip = this;//event.currentTarget;
		var $clip = $(clip);
		var i = _me.getIndexByHintButton($clip[0]);
		_me.deselectButton(i+1);
		if(_me._forceSelectedHint){
			_me.selectButton(_me._forceSelectedHint, false, false);
		}
	}

	Wizard.prototype.hintButton_onClick = function(event)
	{
		trackClick("hintButtonClick");
		var clip = this;//event.currentTarget;
		var i = _me.getIndexByHintButton(clip);
		var $hint = $(".hint" + (i+1));

		if(_me._hintDetailsOpen[i]){
			_me.closeHintDetails(i+1);
		}else{
			_me.openHintDetails(i+1);
		}
	}

	Wizard.prototype.getIndexByHintButton = function(clip)
	{
		for(var k=0; k<_me._$allClips.length; k++){
			var clip2 = this._$allClips[k];
			if(clip == clip2){
				return k;
			}
		}
		return null;
	}

	// show tooltips when rolling over the related area on the left
	Wizard.prototype.generalAreas_onOver = function(event)
	{
		var clip = this;//event.currentTarget;
		var i = _me.getIDByGeneralArea(clip);
		var isStepCompleted = _me._stepsComplete[i];
		if(!isStepCompleted) { 
		  _me.selectButton(i);
		} else {
		  if (_me._forceSelectedHint) {
		    _me.hideToolTip(_me._forceSelectedHint);
		  }
		}
		_me.onResize();
	}

	Wizard.prototype.generalAreas_onOut = function(event)
	{
		var clip = this;//event.currentTarget;
		var i = _me.getIDByGeneralArea(clip);
//		if(i != _me._forceSelectedHint){
			_me.deselectButton(i);
//		}
		if(_me._forceSelectedHint){
			_me.selectButton(_me._forceSelectedHint, false, false);
		}
	}

	Wizard.prototype.getIDByGeneralArea = function(clip)
	{
		if(clip == $(".poll")[0]){
			return 1;
		}else if(clip == $(".addComment")[0]){
			return 2;
		}else{
			return 3;
		}
		return null;
	}



	Wizard.prototype.selectButton = function(i, exclusive, showIt)
	{
//		this.showToolTip(i, showIt);
		this.showToolTip(i, false);
		//_forceSelectedHint = $('.wizard_buttons div.hintButton')[0];
		//Using the jQuery object as an array [ex: $('.selector')[0]] returns the HTMLElement; eq(0) returns an object
		for(var k=1; k<4; k++){
			if(k == i){
				$(".hint"+ i ).addClass("hintSelected");
			}else{
				if(exclusive) this.deselectButton(k);
			}
		}
	}

	Wizard.prototype.deselectButton = function(i)
	{
		this.hideToolTip(i);
		$(".hint"+i).removeClass("hintSelected");
	}

	Wizard.prototype.openHintDetails = function(i)
	{
		this._hintDetailsOpen[i-1] = true;
		//var $hintDetails = $(".hintDetails:eq("+ (i-1) +")");
		var $hintDetails = $(".hint"+i+" .hintDetails");
		$hintDetails.slideDown(300);
	}

	Wizard.prototype.closeHintDetails = function(i)
	{
		this._hintDetailsOpen[i-1] = false;
		//var $hintDetails = $(".hintDetails:eq("+ (i-1) +")");
		var $hintDetails = $(".hint"+i+" .hintDetails");
		$hintDetails.slideUp(200);
	}

	Wizard.prototype.showToolTip = function(i, showItParm)
	{
		if (showItParm == null || showItParm) {
			$(".tooltips div").hide(); //automatically hides all tooltips, since there can be only 1 tooltip at a time
			var showIt = true;
			if (i == 3) {
				var rTipY = $(".discussion_post:first");
				if (rTipY == null || rTipY.offset() == null) {
					showIt = false;
				}
			}

			if (showIt) {
				$(".tooltips div:eq("+ (i-1) +")").show();
			}
		}
	}

	Wizard.prototype.hideToolTip = function(i)
	{
		$(".tooltips div:eq("+ (i-1)+")").hide();
	}

	Wizard.prototype.onResize = function()
	{
		//dynamically place tooltips based on height of page elements
		//use this to check what the initial offset is
		//$(".sparkword_actions").html( offset.top );
		var pTipY = $(".sparkword_actions");
		var offset = pTipY.offset();
		$(".pollHint").css({ position: "absolute", top: offset.top-156, left: "100px" });

		var oTipY = $(".addComment");
		var offset2 = oTipY.offset();
		$(".opinionHint").css({ position: "absolute", top: offset2.top-159, left: "100px" });

		var rTipY = $(".discussion_post:first");
		var offset3 = rTipY.offset();
		var y = -160; //-116
		if($.browser.msie) y = -163;
		if (offset3 != null) {
			$(".rateHint").css({ position: "absolute", top: offset3.top+y, left: "140px" });
		}
	}
	
	Wizard.prototype.setStateCookie = function() {
	    var stateStr = JSON.stringify(this._stepsComplete);
		//alert(stateStr);
	    document.cookie = "wizardstate=" + stateStr + "; path=/";
	}
	
	Wizard.prototype.getStateCookie = function() {
	    var state = null;
	    var ca = document.cookie.split(';');
	    var nameEq = "wizardstate=";
	    for (var i=0; i < ca.length; i++) {
	        var c = ca[i];
	        while (c.charAt(0)==' ') c = c.substring(1,c.length); // delete spaces
	        if (c.indexOf(nameEq) == 0) state = c.substring(nameEq.length,c.length);
	    }
	    //alert(state);
	    if (state != null) {
	        this._stepsComplete = JSON.parse(state);
	    } else {
	        this._stepsComplete = [null, false, false, false];
	    }
	}

	this.init();
}
