/**
 * The build script for OSx86 Library
 * 
 * @author	Tim Smart
 * @copyright	2008
 * 
 * Please leave this header here
 */

function build ()
{
	/*---------------------*/
	// Set up the variables
	/*---------------------*/
	
	/**
	 * What step are we on
	 * 
	 * @var	integer
	 */
	this.step = 1;
	
	/**
	 * Location of AJAX PHP file
	 * 
	 * @var	string
	 */
	this.ajaxPhpFile = "/hardware/includes/hw/ajax.php";
	
	/**
	 * The class attribute for set/get functions
	 * 
	 * @var	integer
	 */
	if (BrowserDetect.browser == "Explorer")
	{
		this.classAttribute = "className";
	}
	else
	{
		this.classAttribute = "class";
	}

	/**
	 * AJAX Splitter
	 * 
	 * @var	string
	 */
	this.splitter = '#O#S#x#8#6#L#i#b#5#4#3#2#1#';
	
	/**
	 * Build basic variables
	 */
	this.numberOfSteps = 7;
	this.item = new Array();
	this.currentMan = new Array();
	this.manufacturerListing = new Array();
	this.currentMod = new Array();
	this.question = new Array();
	this.questionAnswer = new Array();
	this.skipStep = new Array();
	this.skipToStep = 0;
	this.lastSetStep = 0;
	this.currentHardwareID = 0;
	this.lastAjaxHtml = new Array();
	this.dontFadeOverview = new Array ();
	
	/**
	 * Optional Steps set up
	 */
	this.optionalStep = new Array();
	this.optionalStep[4] = true;
	this.optionalStep[5] = true;
	this.optionalStep[6] = true;
		
	/**
	 * Document elements
	 * 
	 * @var	object
	 */
	this.dom = {
		get: function(element)
		{
			if (typeof element === 'string')
			{
				return document.getElementById(element);
			}
			else
			{
				return element;
			}
		},
		
		add: function(element, destination)
		{
			var element = this.get(element);
			var destination = this.get(destination);
			destination.appendChild(element);
		},
		remove: function(element)
		{
			var element = this.get(element);
			element.parentNode.removeChild(element);
		},
		replace: function (elementOne, elementTwo)
		{
			elementOne = this.get(elementOne);
			var theParent = elementOne.parentNode;
			
			this.remove(elementOne);
			this.add(elementTwo, theParent);
		}
	};
	
	
	/**
	 * Events
	 * 
	 * @var	object
	 */
	this.event = {
		add: function() {
			if (window.addEventListener)
			{
				return function(element, type, fn)
				{
					build.dom.get(element).addEventListener(type, fn, false);
				};
			}
			else if (window.attachEvent)
			{
				return function(element, type, fn)
				{
					var fn2 = function() {
						fn.call(build.dom.get(element), window.event);
					};
					build.dom.get(element).attachEvent('on' + type, fn2);
				};
			}
		}()
	};
	
	
	/**
	 * The AJAX
	 * 
	 * @var	object
	 */
	
	this.ajax = {
		newRequest: function ()
		{
			var xmlObject = nwOb();
			
			if (xmlObject == null)
			{
				alert("Sorry, but your browser will not support the build feature.");
				return false;
			}
			
			return xmlObject;
		},
		get: function(object, url)
		{
			$("span#buildNavLoader").show();
			this.object = object;
			this.object.onreadystatechange = this.fn;
			this.object.open("GET", url, true);
			this.object.send(null);
		}
	};
	
	/**
	 * Takes us to the next step!
	 * 
	 * @param	integer	Where are we going?
	 * @return	true	Did we succeed?
	 */
	this.slideToStep = function (thestep)
	{
		// Transition amount in pixels
		this.stepWidth = 665;
		
		// Leave the rest to function
		// Make sure we don't clog up the queue with repeats
		if (this.step == thestep)
		{
			return false;
		}
		
		// Translate the command
		if (thestep == "next")
		{
			this.step = this.step + 1;
		}
		else if (thestep == "previous")
		{
			this.step = this.step - 1;
		}
		else
		{
			this.step = thestep;
		}
			
		// Are we out of bounds?
		if (this.step == (this.numberOfSteps + 1))
		{
			this.step = 1;
		}
		else if (this.step == 0)
		{
			this.step = this.numberOfSteps;
		}
		
		var transitionAmount = (this.step * this.stepWidth) - this.stepWidth;
		var leftPosition = 0 - transitionAmount;
		
		// Is next step skippable?
		if (this.optionalStep[this.step] == true && (!this.item[this.step] > 0))
		{
			this.assignSkipMouseEvents(this.step);
			$('div#buildBrowserNextStep' + (this.step)).show();
		}
		
		// Set current hardware ID
		if (this.item[this.step] > 0)
		{
			this.currentHardwareID = this.item[this.step];
		}
		
		// Lets do it!
		$(document).ready(function()
		{
			$("div.sliderContent ul").css({overflowY: "visible", overflowX: "visible", overflow: "hidden"});
			$("span#buildNavItem" + build.step).fadeIn(770);
			$("div#buildSlider").animate({
					left: leftPosition + "px"
				}, 770, function()
				{
					$("div.sliderContent ul").css({overflow: "visible", overflowY: "auto", overflowX: "hidden"});
				});
		});
		
		return true;
	}
	
	/**
	 * Assign click to list objects from id
	 * 
	 * @param	string	The element id
	 * @return	true
	 */
	this.assignListingsMouseEvents = function (elementID)
	{
		// Set the current list
		this.currentList = elementID.replace(/buildBrowserList/, "");
		this.currentListStep = this.currentList.charAt(this.currentList.length - 1);
		this.currentList = this.currentList.replace("Step" + this.currentListStep, "");
		// Get the element
		this.currentListElement = this.dom.get(elementID);
		// Get the list elements
		var listings = this.currentListElement.getElementsByTagName("li");
		
		// Loop thorugh list elements and assign click etc
		for (var i = 0; i < listings.length; i++)
		{
			// Its want to know where it is
			listings[i].surroundingListings = listings;
			listings[i].listNumber = this.currentList;
			listings[i].step = this.currentListStep;
			listings[i].number = i;
			if (listings[i].step == 1)
			{
				listings[i].step++;
			}
			
			this.event.add(listings[i], 'click', function ()
				{
					// Take away from previous selected
					for (var i = 0; i < this.surroundingListings.length; i++)
					{
						if (this.surroundingListings[i].getAttribute(build.classAttribute) == 'buildListingSelected')
						{
							// We want this element not selected anymore!
							this.surroundingListings[i].setAttribute(build.classAttribute, '');
							this.surroundingListings[i].selected = false;
						}
					}
					
					this.selected = true;
					this.setAttribute(build.classAttribute, 'buildListingSelected');
					
					// We load the stuff now
					build.ajaxProcess (this.step, this.listNumber, this.innerHTML, this.number);
				}
			);
			
			// Mouse Overs
			this.event.add(listings[i], 'mouseover', function ()
				{
					this.setAttribute(build.classAttribute, 'buildListingHover');
				}
			);
			
			// Mouse outs
			this.event.add(listings[i], 'mouseout', function ()
				{
					// Are we selected?
					if (this.selected == true)
					{
						// Put it back where it belongs
						this.setAttribute(build.classAttribute, 'buildListingSelected');
					}
					else
					{
						this.setAttribute(build.classAttribute, '');
					}
				}
			);
			
			// Mouse downs
			this.event.add(listings[i], 'mousedown', function ()
				{
					this.setAttribute(build.classAttribute, 'buildListingActive');
				}
			);
		}
		
		return true;
	}
	
	/**
	 * AJAX processing
	 * 
	 * @param	integer, integer, string	What step?, What list?, What contents?
	 * @return	true
	 */
	this.ajaxProcess = function (step, list, data, listingNumber)
	{
		step = parseInt(step);
		list = parseInt(list);
		
			// We are on list 1
			if (list == 1)
			{
				// Set variables
				var newList = list + 1;
				this.currentMan[step] = data;
				this.manufacturerListing[step] = listingNumber;
				
				// Do the request
				if (step == 2)
				{
					var url = this.ajaxPhpFile + "?step=" + step + "&list=" + list + "&hwMan=" + data;
				}
				else if (step == 3)
				{
					var url = this.ajaxPhpFile + "?step=" + step + "&list=" + list +
						"&hwMan=" + data+ "&hwMod=" + this.item[2];
				}
				else
				{
					var url = this.ajaxPhpFile + "?step=" + step + "&list=" + list +
						"&motherboard=" + build.item[3] + "&hwMan=" + data;
				}
				
				this.currentListAjax = this.ajax.newRequest();
				this.ajax.fn = function()
				{
					if (build.ajax.object.readyState == 4)
					{
						var nextStep = step + 1;
						// Get the HTML
						var htmlString = build.ajax.object.responseText;				
						var html = htmlString.split(build.splitter);
				
						// Get the html variables
						var i = 0;
						var listTwoHtml = html[i];
						
						// Update the page
						var divID = "buildBrowserList2Step" + step;
						var theDiv = build.dom.get(divID).getElementsByTagName('div');
						var theUl = build.dom.get(divID).getElementsByTagName('ul');
													
						var listElement = document.createElement('ul');
						listElement.innerHTML = listTwoHtml;
						
						if (theDiv.length == 1)
						{
							build.dom.replace(theDiv[0], listElement);
						}
						else
						{
							build.dom.replace(theUl[0], listElement);
						}
						build.assignListingsMouseEvents ('buildBrowserList2Step' + step);
						
						// Update the details div
						var detailsID = "buildBrowserDetailsStep" + step;
						var detailsDiv = build.dom.get(detailsID).childNodes[1];
						if (build.optionalStep[step])
						{
							detailsDiv.innerHTML = '<p class="buildBrowserFill">Select A Model</p><div class="buildBrowserNextStep" id="buildBrowserNextStep' + step + '"><img src="images/build/nextArrow.png" alt="Next Step" /><span>Skip Step</span></div>';
							build.assignSkipMouseEvents(step);
							$('div#buildBrowserNextStep' + step).show();
						}
						else
						{
							detailsDiv.innerHTML = '<p class="buildBrowserFill">Select A Model</p>';
						}
						
						if (build.item[nextStep] > 0 && build.optionalStep[nextStep] != true)
						{
							// Replace next step model list if there
							var nextModelList = build.dom.get("buildBrowserList2Step" + nextStep);
							nextModelListUl = nextModelList.getElementsByTagName('ul');
							
							if (nextModelListUl.length == 1)
							{
								var nextModelListDiv = document.createElement('div');
								nextModelListDiv.innerHTML = "<p class='buildBrowserFill'>Select A Manufacturer</p>";
								build.dom.replace(nextModelListUl[0], nextModelListDiv);
							}
							
							// Replace next step details if there
							var nextDetailsList = build.dom.get("buildBrowserDetailsStep" + nextStep);
							nextDetailsDiv = nextDetailsList.getElementsByTagName('div');
							if (build.optionalStep[step])
							{
								detailsDiv.innerHTML = '<div class="buildBrowserNextStep" id="buildBrowserNextStep' + nextStep + '"><img src="images/build/nextArrow.png" alt="Next Step" /><span>Skip Step</span></div>';
								build.assignSkipMouseEvents(nextStep);
								$('div#buildBrowserNextStep' + nextStep).show();
							}
							else
							{
								nextDetailsDiv[0].innerHTML = "";
							}
						}
						$("span#buildNavLoader").hide();
					}
				}
				this.ajax.get(this.currentListAjax, url);
			}
			// List 2
			else if (list == 2)
			{
				// Set up the variables
				var newList = list + 1;
				this.currentMod[step] = data;
				
				// Do the request
				if (step == 2)
				{
					var url = this.ajaxPhpFile + "?step=" + step + "&list=" + list + "&hwMan=" +
						this.currentMan[step] + "&hwMod=" + data;
				}
				else
				{
					if (this.step == 3)
					{
						var motherboard = "none";
					}
					else
					{
						var motherboard = this.item[3];
					}
					var url = this.ajaxPhpFile + "?step=" + step + "&list=" + list +
						"&motherboard=" + motherboard + "&hwMan=" + this.currentMan[this.step] +
						"&hwMod=" + data;
				}
				this.currentListAjax = this.ajax.newRequest();
				this.ajax.fn = function ()
				{
					if (build.ajax.object.readyState == 4)
					{
						// Get the HTML
						var htmlString = build.ajax.object.responseText;
						var html = htmlString.split(build.splitter);
						build.lastAjaxHtml = html;
						
						// Get ready for next step
						var nextStep = step + 1;
						var nextStepList = 1;
						
						// Assign the values
						if (build.step == step)
						{
							var detailsHtml = html[0];
							build.currentHardwareID = parseInt(html[1]);
						}
						
						// Update Details
						if (build.step == step)
						{
							var detailsID = "buildBrowserDetailsStep" + step;
							var detailsDiv = build.dom.get(detailsID).childNodes[1];
							detailsDiv.innerHTML = detailsHtml;
							
							if (build.currentHardwareID == build.item[step])
							{
								$('span#buildBrowserDetailsTickStep' + step).show();
								$('div#buildBrowserTickStep' + step).show();
								$('div#buildBrowserNextStep' + step).show();
							}
							
							build.assignDetailsMouseEvents();
						}
						
						// Were we checked before? Mouse events needed before check.
						if (build.questionAnswer[step] == true && build.question[step] == true)
						{
							build.dom.get('buildBrowserQuestionFormStep' + step).question[0].checked = true;
						}
						$("span#buildNavLoader").hide();
					}
				}
				this.ajax.get(this.currentListAjax, url);
			}
			
		return true;
	}
	
	/**
	 * Assign Details mouse events
	 * 
	 * @param	integer	The step
	 * @return	true
	 */
	this.assignDetailsMouseEvents = function ()
	{
		// Set up the variables
		var step = this.step;
		var moreLink = this.dom.get('buildBrowserDetailsMoreStep' + step);
		var addLink = this.dom.get('buildBrowserDetailsAddStep' + step);
		var nextLink = this.dom.get('buildBrowserNextStep' + step);
		var questionDiv = this.dom.get('buildBrowserDetailsQuestionStep' + step);
		
		// Have we got a question?
		if (questionDiv.innerHTML == "")
		{
			this.question[step] = false;
		}
		else
		{
			this.question[step] = true;
		}
		
		// Add the events
		this.event.add(moreLink, 'click', function ()
			{
				view(build.currentHardwareID, 'build');
			}
		);
		
		// Question events
		if (this.question[step] == true)
		{
			// Get the form elements
			var questionForm = this.dom.get('buildBrowserQuestionFormStep' + step);
			questionForm.step = step;
			
			this.event.add(questionForm, 'click', function()
				{
					// Reset step hardwareID if not on already added hardware
					if (build.currentHardwareID != build.item[step])
					{
						build.item[step] = 0;
						$("span#buildListItem" + step).fadeOut(1000);
					}
					
					var questionAnswer = this.question[0].checked;
					if (questionAnswer == build.questionAnswer[this.step])
					{
						var questionChanged = false;
					}
					else
					{
						var questionChanged = true;
					}
					build.questionAnswer[this.step] = questionAnswer;
					
					// Set up variables depending on step
					if (this.step == 3)
					{
						var stepToSkip = 4;
						var overviewHtml = "<info>Using Onboard Graphics</info>";
					}
					else
					{
						var stepToSkip = build.step + 1;
						var overviewHtml = "<info>Skipped</info>";
					}
					
					// Update stuff
					if (build.questionAnswer[this.step] == true)
					{
						build.clearStep(stepToSkip);
						build.skipStep[stepToSkip] = true;
						build.dontFadeOverview[stepToSkip] = true;
						
						$(document).ready(function ()
							{
								$('span#buildListItem' + stepToSkip).fadeIn(1000);
								$('span#buildNavItem' + stepToSkip).fadeOut(1000);
								build.dom.get('buildListItem' + stepToSkip).innerHTML = overviewHtml;
							}
						);
					}
					else if (questionChanged == true)
					{
						build.skipStep[stepToSkip] = false;
						build.dontFadeOverview[stepToSkip] = false;
						$(document).ready(function ()
							{
								$('span#buildListItem' + stepToSkip).fadeOut(1000);
								$('span#buildNavItem' + stepToSkip).fadeOut(1000);
							}
						);
					}
					
					build.lastSetStep = build.step;
				}
			);
		}
		
		if (build.currentHardwareID != this.item[step])
		{
			this.event.add(addLink, 'click', function ()
				{
					// Fade in tick sign, show next step, update overview
					
					// Set the item hardware ID values
					build.currentOverviewItemID = "buildListItem" + step;
					build.item[step] = build.currentHardwareID;
					
					// Set HTML
					var html = build.lastAjaxHtml;
					var nextStepList = 1;
					
					// Set amount of steps to update
					if (build.step == 3)
					{
						var updateSteps = 3;
					}
					else if (build.step < 4)
					{
						var updateSteps = 1;
					}
					else
					{
						var updateSteps = 0;
					}
											
					// Update next step
					for (var i = 1; i <= updateSteps; i++)
					{
						var updateStep = step + i;
						
						var nextStepListID = "buildBrowserList" + nextStepList + "Step" + updateStep;
						var nextStepListDiv = build.dom.get(nextStepListID).getElementsByTagName('div');
						var nextStepListUl = build.dom.get(nextStepListID).getElementsByTagName('ul');
													
						var listElement = document.createElement('ul');
						listElement.innerHTML = html[1 + i];
						
						if (nextStepListDiv.length == 1)
						{
							build.dom.replace(nextStepListDiv[0], listElement);
						}
						else
						{
							build.dom.replace(nextStepListUl[0], listElement);
						}
						
						// Assign Mouse events
						build.assignListingsMouseEvents(nextStepListID);
					}
					
					// Update question details
					if (build.question[step] != true)
					{
						build.questionAnswer[step] = false;
						build.skipStep[step + 1] = false;
					}
					
					// Update Overview
					var currentOverviewItem = build.dom.get(build.currentOverviewItemID);
					currentOverviewItem.step = build.step;
					
					currentOverviewItem.innerHTML = "<span>" + build.currentMan[build.step] +
						" " + build.currentMod[build.step] + "</span>";
					
					
					build.event.add(build.currentOverviewItemID, 'click', function ()
					{
						if (build.item[this.step] == 0)
						{
							this.removeEventListener('click',arguments.callee,false);
						}
						else
						{
							view(build.item[this.step], 'build');
						}
					});
					
					$(document).ready(function ()
					{
						$('span#buildBrowserDetailsTickStep' + build.step).fadeIn(1000, function ()
						{
							$('div#buildBrowserNextStep' + build.step).show();
							return;
						});
						$('span#' + build.currentOverviewItemID).fadeIn(1000);
					});
					
					if ((step + 1) != build.numberOfSteps && build.optionalStep[step] != true)
					{
						build.clearFollowingSteps(step);
					}
					// Last minute jobs
					build.lastSetStep = build.step;
					this.removeEventListener('click',arguments.callee,false);
				}
			
			);
		}
		
		// Assign Next link step and event
		nextLink.step = step;
		this.event.add(nextLink, 'click', function ()
			{
				// Has manufacturer been selected before? Only for manufacurers on next step
				if ((typeof build.currentMan[build.step + 1]) == "undefined" ||
					build.manufacturerListing[build.step + 1] == false)
				{
					var changeManufacturerStyle = false;
				}				
				else if ((typeof build.currentMan[build.step + 1]) != "undefined")
				{
					var changeManufacturerStyle = true;
				}
				else if (build.currentMan[build.step + 1].length > 0)
				{
					var changeManufacturerStyle = true;
				}
				
				if (changeManufacturerStyle == true)
				{
					var nextManList = build.dom.get('buildBrowserList1Step' + (step + 1));
					var nextManListings = nextManList.getElementsByTagName('li');
					var i = build.manufacturerListing[step + 1];
					nextManListings[i].setAttribute(build.classAttribute, 'buildListingSelected');
					nextManListings[i].selected = true;
				}
				
				// Go to next step
				if (build.skipStep[build.step + 1] == true)
				{
					build.slideToStep(build.step + 2);
				}
				else
				{
					build.slideToStep(this.step + 1);
				}
			}
		);
		
		return true;
	}
	
	/**
	 * Assign Skip Step with mouse events
	 * 
	 * @return	true
	 */
	this.assignSkipMouseEvents = function (step)
	{
		var skipStepDiv = this.dom.get('buildBrowserNextStep' + step);
		skipStepDiv.step = step;
		
		this.event.add(skipStepDiv, 'click', function()
			{
				build.dom.get('buildListItem' + this.step).innerHTML = "<info>Skipped</info>";
				$('span#buildListItem' + this.step).fadeIn(1000);
				
				// Go to next step
				build.slideToStep(this.step + 1);
			}
		);
	}
	
	/**
	 * Function that clears all following steps
	 * 
	 * @param	integer	Step to wipe from
	 * @return	boolian
	 */
	this.clearFollowingSteps = function (step)
	{
		for (var i = (step + 1); i <= (this.numberOfSteps - 1); i++)
		{
			// Reset Model list
			var modelList = this.dom.get("buildBrowserList2Step" + (i));
			if (modelList)
			{
				var modelListUl = modelList.getElementsByTagName('ul');
			}
			else
			{
				var modelListUl = "";
			}
			
			if (modelListUl.length == 1)
			{
				var modelListDiv = document.createElement('div');
				modelListDiv.innerHTML = "<p class='buildBrowserFill'>Select A Manufacturer</p>";
				this.dom.replace(modelListUl[0], modelListDiv);
				
				// Reset the next list hardware ID + question + manaufacturer listing
				this.item[i] = 0;
				this.currentMan[i] = "";
				this.currentMod[i] = "";
				this.question[i] = false;
				this.questionAnswer[i] = false;
				this.manufacturerListing[i] = false;
			}
			
			// Fade out overview item and Nav item
			if (this.dontFadeOverview[i] != true)
			{
				$("span#buildListItem" + i).fadeOut(1000);
			}
			$("span#buildNavItem" + i).hide();
			
			// Unassign any selected manufacturers
			if (this.dom.get('buildBrowserList1Step' + i))
			{
				var manufacturerListings = this.dom.get('buildBrowserList1Step' + i).getElementsByTagName('li');
			}
			else
			{
				var manufacturerListings = "";
			}
			
			for (var c = 0; c < manufacturerListings.length; c++)
			{
				if (manufacturerListings[c].getAttribute(this.classAttribute) == 'buildListingSelected')
				{
					manufacturerListings[c].setAttribute(this.classAttribute, '');
					manufacturerListings[c].selected = false;
				}
			}
			
			// Reset details
			var detailsList = this.dom.get("buildBrowserDetailsStep" + i);
			if (detailsList)
			{
				var detailsListDiv = detailsList.getElementsByTagName('div');
			}
			else
			{
				var detailsListDiv = false;
			}
			
			if (this.optionalStep[step] == true || detailsListDiv != false)
			{
				detailsListDiv[0].innerHTML = '<div class="buildBrowserNextStep" id="buildBrowserNextStep' + (i) + '"><img src="images/build/nextArrow.png" alt="Next Step" /><span>Skip Step</span></div>';
				this.assignSkipMouseEvents(i);
			}
			else if (detailsListDiv != false)
			{
				detailsListDiv[0].innerHTML = "";
			}
		}
		
		// Hide Finish Nav
		$("span#buildNavItem" + this.numberOfSteps).hide();
	}
	
	/**
	 * Clear a step
	 * 
	 * @param	integer	Step to clear
	 * @return	boolian
	 */
	this.clearStep = function (step)
	{
		// Reset Model list
		var modelList = this.dom.get("buildBrowserList2Step" + step);
		
		if (modelList)
		{
			modelListUl = modelList.getElementsByTagName('ul');
		}
		else
		{
			modelListUl = "";
		}
		
		if (modelListUl.length == 1)
		{
			var modelListDiv = document.createElement('div');
			modelListDiv.innerHTML = "<p class='buildBrowserFill'>Select A Manufacturer</p>";
			this.dom.replace(modelListUl[0], modelListDiv);
			
			// Reset the next list hardware ID + question + manaufacturer listing
			this.item[step] = 0;
			this.currentMan[step] = "";
			this.currentMod[step] = "";
			this.question[step] = false;
			this.questionAnswer[step] = false;
			this.manufacturerListing[step] = "";
		}
		
		// Fade out overview item
		if (this.dontFadeOverview[step] != true)
		{
			$("span#buildListItem" + step).fadeOut(1000);
		}
		
		// Unassign any selected manufacturers
		if (this.dom.get('buildBrowserList1Step' + step))
		{
			var manufacturerListings = this.dom.get('buildBrowserList1Step' + step).getElementsByTagName('li');
		}
		else
		{
			var manufacturerListings = "";
		}
		
		for (var c = 0; c < manufacturerListings.length; c++)
		{
			if (manufacturerListings[c].getAttribute(this.classAttribute) == 'buildListingSelected')
			{
				manufacturerListings[c].setAttribute(this.classAttribute, '');
				manufacturerListings[c].selected = false;
			}
		}
		
		// Reset details
		var detailsList = this.dom.get("buildBrowserDetailsStep" + step);
		if (detailsList)
		{
			var detailsListDiv = detailsList.getElementsByTagName('div');
		}
		else
		{
			var detailsListDiv = false;
		}
		
		if (this.optionalStep[step] == true || detailsListDiv != false)
		{
			detailsListDiv[0].innerHTML = '<div class="buildBrowserNextStep" id="buildBrowserNextStep' + (step) + '"><img src="images/build/nextArrow.png" alt="Next Step" /><span>Skip Step</span></div>';
			this.assignSkipMouseEvents(step);
		}
		else
		{
			detailsListDiv[0].innerHTML = "";
		}
		
		return true;
	}
	
	/**
	 * Assign Nav Mouse events
	 * 
	 * @return	boolean
	 */
	this.assignNavMouseEvents = function ()
	{
		// Assign click to start span
		var element = this.dom.get("buildNavStart");
		this.event.add(element, 'click', function ()
			{
				build.slideToStep(1);
			}
		);
		
		// Loop through other span's
		for (var i = 2; i <= build.numberOfSteps; i++)
		{
			var element = this.dom.get("buildNavItem" + i);
			element.step = i;
			this.event.add(element, 'click', function ()
				{
					build.slideToStep(this.step);
				}
			);
		}
	};
	this.get_build_link=function()
	{
		$("span#buildNavLoader").show();
		$("#build_get_link").fadeOut(500);
		var notes=$('#build_notes').val();
		if(notes=="Notes...")
		{
			notes='';
		}
		var data="act=save_build&item2="+this.item[2]+"&item3="+this.item[3]+"&item4="+this.item[4]+"&item5="+this.item[5]+"&item6="+this.item[6]+"&notes="+encodeURIComponent(notes);
		$.ajax({
			type:"POST",
			url:this.ajaxPhpFile,
			data:data,
			success:function(resp)
			{
				var link=location.href.match(new RegExp('^.*?/hardware/'))[0]+'view_build.php?id='+resp;
				$("span#buildNavLoader").hide();
				$("#build_get_link").html('<input type="text" value="'+link+'" />').fadeIn(500);
				return;
			}
		});
		return;
	};
}

// Set me up
var build = new build();

$(document).ready(function()
{
	build.assignListingsMouseEvents('buildBrowserList1Step2');
	build.assignNavMouseEvents();
	var getStarted = build.dom.get("buildGetStarted");
	build.event.add(getStarted, 'click', function ()
	{
		build.slideToStep(2);
	});
	$('#build_get_link span').click(function()
	{
		build.get_build_link();
		return;
	});
	$('#build_notes').mousedown(function()
	{
		if(this.value=='Notes...')
		{
			this.value='';
		}
		return;
	}).blur(function()
	{
		if(this.value.length<=0)
		{
			this.value='Notes...';
		}
		return;
	});
});
