jQuery.noConflict();

//Define variables used across functions
var selects = new Array();
var boxes = new Array();
var setupfee = null;
var monthlyfee = null;

function setCurrentTab()
{	
		current_tab = jQuery("#HouseMenuH > li#HouseMenuHCurrentItem");
		
		if(location.pathname == "/" || location.pathname.toLowerCase() == "/default.aspx")
		{
			current_tab = jQuery("#HouseMenuHItemHome")
		}	
		if(current_tab.length == 0)
		{
			current_tab = jQuery("#HouseMenuHCurrentItem").parent().parent(); 
		}
		current_tab.addClass("here");
}

function setFormButtonClasses()
{
		if(jQuery(".contactform").length > 0)
		{
			buttons = jQuery(".contactform").parent().find(".CommandButton");
			for(i=0; i < buttons.length; i++)
			{
					button = buttons[i];
					if(button.innerHTML == "Submit") jQuery(button).addClass("submit-button");
					if(button.innerHTML == "Cancel") jQuery(button).addClass("cancel-button");
			}
		}
		if(jQuery(".cssform").length > 0)
		{
			buttons = jQuery(".cssform").parent().find(".CommandButton");
			for(i=0; i < buttons.length; i++)
			{
					button = buttons[i];
					if(button.innerHTML == "Submit") jQuery(button).addClass("order-button");
					if(button.innerHTML == "Cancel") jQuery(button).addClass("order-cancel-button");
			}
		}
		
}

function setupFormMasks()
{
	jQuery("div.mask").hide();
	selector = jQuery("select.mask");
  jQuery(selector).bind("change",function(){
																							currentOption = this.options[this.selectedIndex].value;
																							maskBlocks = jQuery("div.mask");
																							if(currentOption != "")
																							{
																		  					for(i=0; i < maskBlocks.length; i++)
																			  				{
																				  				if(jQuery(maskBlocks[i]).css("display") == "block" && !jQuery(maskBlocks[i]).hasClass(currentOption))
																					  			{
																						  			jQuery(maskBlocks[i]).slideUp();
																										maskoptions = jQuery(maskBlocks[i]).find("input[type=checkbox]");
																										for(x=0; x < maskoptions.length; x++)
																										{
																											maskoptions[x].checked = false;
																										}
																							  	}
							  																	else if(jQuery(maskBlocks[i]).css("display") == "none" && jQuery(maskBlocks[i]).hasClass(currentOption))
								  																{
									  																jQuery(maskBlocks[i]).slideDown();
										  														}
											  												}
																							}
																							else
																							{
																								jQuery(maskBlocks).slideUp();
																							}
																						});
}

function getLabelValue(element)
{
	label = jQuery("label[for=" + element.id + "]");
	return label[0].innerHTML;
}


function setupFormCalculator()
{
	if(jQuery(".cssform").length > 0)
	{
		selects = jQuery(".cssform select");
		boxes = jQuery(".cssform input[type=checkbox]");
		setupfee = jQuery(".cssform input[name$=orderSetupFee]")[0];
		monthlyfee = jQuery(".cssform input[name$=orderMonthlyFee]")[0];
		
		//Add and event handler to select dropdowns and checkboxes
		jQuery(".cssform select").bind("change", findCurrentPrice);
		jQuery(boxes).bind("change", findCurrentPrice);
		jQuery(boxes).bind("click", findCurrentPrice);
		
		findCurrentPrice();
	}
}

function findCurrentPrice()
{
	setup = 0.00;
	monthly = 0.00;
	
	//Add up Option Values
	for(i=0; i < selects.length; i++)
	{
		if(selects[i].value != "")
		{
			if(PricingRules[selects[i].value] != null)
			{
				setup += parseFloat(PricingRules[selects[i].value][0]);
				monthly += parseFloat(PricingRules[selects[i].value][1]);
			}
		}
	}
	
	// Add up Checkbox Values
	for(i=0; i < boxes.length; i++)
	{
		if(boxes[i].checked)
		{
			if(PricingRules[getLabelValue(boxes[i])] != null)
			{
				setup += parseFloat(PricingRules[getLabelValue(boxes[i])][0]);
				monthly += parseFloat(PricingRules[getLabelValue(boxes[i])][1]);
			}
		}
	}
	
	//Update the display boxes
	setupfee.value = "$" + setup.toFixed(2);
	monthlyfee.value = "$" + monthly.toFixed(2);
}

jQuery(document).ready(function() {
		jQuery("ul#HouseMenuH").superfish({
									hoverClass	: "sfHover",
									pathClass	: "overideThisToUse",
									delay		: 500,
									animation	: {opacity:"show",height:"show"},
									speed		: "normal",
									onShow		: function(){ /*your callback function here*/ }
								});
		setCurrentTab();
		setFormButtonClasses();
		setupFormMasks();
		setupFormCalculator();
});