﻿
GetWindowsWizard = function(servicePath, recommendation, userOs)
{
	this._servicePath = servicePath;
	this._selectedOs = userOs;
	this._section1Elem = jQuery("#getWiz #recommend .buyPC");
	this._section2Elem = jQuery("#getWiz #recommend .buyOS");
	this._section3Elem = jQuery("#getWiz #recommend .notSure");
	this._section1Elem.data("name", "buyPC");
	this._section2Elem.data("name", "buyOS");
	this._section3Elem.data("name", "notSure");
	//this._sectionOverride = parseInt(option);
	this._activeSection = null;
	this._sectionElems = [this._section1Elem, this._section2Elem, this._section3Elem];
}

GetWindowsWizard.prototype = 
{

	/**
	* Initializer - treat as private.  Invoke via static initializer.
	*/	
	_initialize: function()
	{
		// wire events
		for (var i=0; i<this._sectionElems.length; i++)
		{
			this._sectionElems[i].bind("click", { sectionElemIndex: i, loadDetails: true }, GetWindowsWizard.ActivateSection)
				.bind("mouseenter mouseleave", function(e) { jQuery(this).toggleClass("on"); });
		}
		jQuery("#getWiz #optionTitles .buyPCTitle").bind("click", { sectionElemIndex: 0, loadDetails: true }, GetWindowsWizard.ActivateSection);
		jQuery("#getWiz #optionTitles .buyOSTitle").bind("click", { sectionElemIndex: 1, loadDetails: true }, GetWindowsWizard.ActivateSection);
		jQuery("#getWiz #optionTitles .notSureTitle").bind("click", { sectionElemIndex: 2, loadDetails: true }, GetWindowsWizard.ActivateSection);
		
		// set page elem states
		this.setRecommended(this._selectedOs);
		jQuery("#getWiz #expandedContent").addClass("hidden");
		jQuery("#getWiz #getWizardNextSteps").addClass("hidden");
		jQuery("#getWiz #recommend div").addClass("on");
		
		//if (this._sectionOverride < 0)
		//	this._sectionOverride = 0;
		this.activate(0, true);
	},
	
	/**
	* Load html content
	*/
	loadUpgradeDetails: function (sectionId)
	{
		jQuery("#details").load("/windows/Framework/Services/SectionedContent.ashx", { 
			action: "sectionedContentAsHtml",
			contentPath: "windows/windows-7/GA/get/p_default/default.xml", 
			section: sectionId },
			function () {
				if (typeof("f_display_generic") != "undefined")
				{
					f_display_generic.bindTooltipsTo(jQuery("#details .win7_generic"));
				}
			}
		);
		
		jQuery("#getWiz #expandedContent").removeClass("hidden");
		jQuery("#getWiz #getWizardNextSteps").removeClass("hidden");
	},

	setRecommended: function(os)
	{
		jQuery("#getWiz #recommend div").removeClass("rec");
		var recId;
		
		switch (os)
		{
			case "WinXP":
				recId = ".buyPC";
				break;
		}
				
		jQuery("#getWiz #recommend " + recId).addClass("rec");
	},
	
	activate: function (sectionIndex, loadDetails)
	{
		var elem = this._sectionElems[sectionIndex];
		
		// check if already selected
		if (this._activeSection != null && this._activeSection.data("name") == elem.data("name"))
		{
			return;
		}
		
		// update the active elem
		this._activeSection = elem;
		
		// toggle on/off states
		jQuery("#getWiz #recommend div").removeClass("on").addClass("off");
		jQuery("#getWiz #blurbs").addClass("hidden");
		jQuery("#getWiz #optionTitles div").removeClass("on");
		jQuery("#getWiz #optionTitles ." + this._activeSection.data("name") + "Title").addClass("on");
		elem.removeClass("off").addClass("on");
		
		// update details / accordion
		if (loadDetails)
		{
			this.loadUpgradeDetails(this.get_ActiveSectionId());
			this.refreshActiveAccordion();
		}
	},
	
	refreshActiveAccordion: function ()
	{
		var accId = "#acc_" + this._activeSection.data("name") + "_cntr";
		jQuery("#accordions .accordion").addClass("hidden");
		jQuery(accId).removeClass("hidden");
	},



	/////////////////////
	// Properties
	/////////////////////
	
	get_ActiveSectionId: function ()
	{
		return "upgradeDetails." + this._selectedOs + "." + this._activeSection.data("name");
	}
}


GetWindowsWizard.Initialize = function(servicePath, rec, os)
{
	GetWindowsWizard._staticInstance = new GetWindowsWizard(servicePath, rec, os);
	GetWindowsWizard._staticInstance._initialize();
}

GetWindowsWizard.ActivateSection = function (param)
{
	GetWindowsWizard._staticInstance.activate(parseInt(param.data.sectionElemIndex), param.data.loadDetails);
}