	function target_popup(form) {
		window.open('', 'formpopup', 'width=800,height=730,resizeable,scrollbars');
		form.target = 'formpopup';
    }


$(document).ready(function(){
	var stepValue = '';
	var step=1;
	var units="";
	var optNew=false;
	var optApt=false;
	var optHouse=false;
	var optSpecial=false;
	var optReplacement=false;
	var fourUnits = true;


////////////////////////////////////STEPS////////////////////////////////////

	
	$("#hwdguide #steps .stepBtn").click(function() {
		var stepValue = $(this).attr("alt");
		fadeUnits(stepValue);
	});	

	function nextStep(){
		
		$("#step"+step+"content").slideUp( 300, function(){
			step++;
			if(step==6) results();
			if(step==2)$("#hwdguide a.stepBtn.stepNav").fadeIn();
			$("#hwdguide #steps h3.current").removeClass('current');
			$("#hwdguide #steps h3#step"+step).addClass('current');
			$("#step"+step+"content").slideDown();
		});
	};


	function fadeUnits(stepValue){
		
		switch (stepValue) {//select units
			case "New": 
				optNew=true;
				units="#3star22"; 
			break;
			case "Replacement": 
				optReplacement=true;
				units="#3star22"; //fake ID
			break;
			case "Apartment": 
				optApt=true;
				units="#5star4, #heat1, #heat2, #heat3, #electric1, #electric2, #electric3";
				if(optNew)units+=",#5star4,#solar1, #solar3";	
				if(optReplacement)units+=",#solar1,#solar2, #solar3, #solar4, #solar5, #solar6";	
			break;
			case "House":
				optHouse=true;
				units="#5star4, #electric4, #electric5,#electric6,#electric7";
				if(optNew)units+=",#3star1, #3star2, #3star3, #3star4, #3star5, #electric1, #electric2, #electric3";	
			break;
			case "Gas": 
				units="#heat1,#heat2,#heat3, #electric1, #electric2, #electric3, #electric4, #electric5, #electric6, #electric7"; 
				if(!optReplacement){units+=",#3star1,#3star2,#3star3"; fourUnits = false;};
				if(optApt){units+=",#5star1,#5star2,#5star3, #5star4, #5star5";};
				if(optReplacement&&optHouse){units+=",#5star4, #5star5";};
			break;
			case "NoGas": 
				if(optNew&&optApt){ $("#heat2, #heat3").fadeOut(function() { $(this).remove() } ); optSpecial=true;} //in the condition of a New Apartment
				units="#continuous1,#continuous2,#continuous3,#continuous4,#5star1,#5star2,#5star3,#3star1,#3star2,#3star3,#3star4,#3star5";
				if(optApt){ units+=",#solar4, #solar5, #solar6" };
				fourUnits = false;
			break;
			case "Light":
				if(prevValue == "Gas") units="#solar1, #solar2, #solar3, #solar4, #solar5, #continuous2, #continuous3, #continuous4, #5star2, #5star3"; 
				if(prevValue == "Gas" && optApt) units+=", #3star1, #3star2, #3star3, #3star5"; 
				if(prevValue == "Gas" && optHouse) units+=", #3star2, #3star3, #3star4, #3star5"; 
				if(prevValue == "NoGas") units="#heat2, #heat3, #solar1, #solar2, #solar4, #solar5, #solar6"; 
				if(prevValue == "NoGas") units+=",#heat2,#heat3";
				if(prevValue == "NoGas" && optHouse) units+=",#electric2,#electric3,#electric5,#electric6,#electric7";
				if(prevValue == "NoGas" && optApt) units+=",#electric1,#electric2,#electric3,#electric5,#electric6,#electric7";
			break;
			case "Moderate":
				if(prevValue == "Gas") units="#solar1, #solar2, #solar3, #solar5, #solar6, #continuous1, #continuous3, #continuous4, #5star1, #5star3, #3star1, #3star3"; 
				if(prevValue == "Gas" && optApt) units+=", #3star1, #3star2, #3star3, #3star5"; 
				if(prevValue == "Gas" && optHouse) units+=", #3star1, #3star3, #3star4, #3star5"; 
				if(prevValue == "NoGas") units="#solar1, #solar2, #solar3, #solar4, #solar6,#electric4,#electric6,#electric7";
				if(prevValue == "NoGas") units+=",#heat1,#heat3"; 
				if(prevValue == "NoGas" && optHouse) units+=",#electric1,#electric3,#electric5,#electric6,#electric7";
			break;
			case "Heavy":
				if(prevValue == "Gas") units="#solar1, #solar3, #solar4, #solar5, #solar6, #continuous2, #continuous1, #5star2, #5star1, #3star2, #3star1"; 
				if(prevValue == "Gas" && optApt) units+=", #3star1, #3star2, #3star3, #3star4, #continuous3"; 
				if(prevValue == "Gas" && optHouse) units+=", #3star1, #3star2, #3star4, #3star5, #continuous4"; 
				if(prevValue == "NoGas") units="#solar2, #solar3, #solar4, #solar5, #solar6,#electric4,#electric5,#electric7"; 
				if(prevValue == "NoGas") units+=",#heat2,#heat1";
				if(prevValue == "NoGas" && optHouse) units+=",#electric1,#electric2,#electric5,#electric6,#electric7";
				if(prevValue == "NoGas" && optApt) units+=",#solar1";
			break;
			
			default: units="#3star22"; //fake ID
			
		}
		
		prevValue = stepValue;
		
		//fade units
		$(units).fadeOut(function() { $(this).remove() } );

		nextStep();
		
	};


////////////////////////////////////RESULTS///////////////////////////

	function results(){

		var results = [];
		$("#hwdguide #units .type").find("img").each(function(){ results.push(this.id); });
		
		$.each(results, function(num, thisid) { 
		  $("#hwdguide-result #unit-"+thisid).show();
		  $("#resultsPrint").append("<input type='hidden' name='"+thisid+"' value='"+thisid+"''/>");
		});
		
		
		if(fourUnits == true) $("#hwdguide-result #unitContainer ").css( "width", "925px" ); 
		$("#hwdguide").fadeOut(function(){$("#hwdguide-result").fadeIn()});
	};


	$("#hwdguide-result .techBtn").click(function(event) {
		event.preventDefault();
		$("#"+$(this).parent().parent().attr("id")+" .techDetails").slideToggle();		
	});	

	$(".backBtn").click(function(event) {
		event.preventDefault();
		location.reload(true);
	});	

	$("#hwdguide-result .printBtn").click(function(event) {
		event.preventDefault();
		$("#resultsPrint").submit();
		
	});	


////////////////////////////////////QTIPS///////////////////////////

	$('#info5star').qtip({
		show: 'mouseover', hide: 'mouseout', position: { corner: { target: 'topMiddle', tooltip: 'bottomMiddle' }}, style: { tip: 'bottomMiddle', name: 'dark'},
		content: "<strong>Provides efficent and economical hot water with fast recovery rates to give you more hot water.</strong><br/>  The higher the star rating the cheaper the unit will be to run." });
	$('#infoheatpumps').qtip({
		show: 'mouseover', hide: 'mouseout', position: { corner: { target: 'topMiddle', tooltip: 'bottomMiddle' }}, style: { tip: 'bottomMiddle', name: 'dark'},
		content: "<strong>Heat Pumps are a relatively new technology that are becoming very popular.</strong><br/>They work by removing heat from the ambient air to warm water. Heat Pumps attract RECs and government rebates." });
	$('#infosolar').qtip({
		show: 'mouseover', hide: 'mouseout', position: { corner: { target: 'topMiddle', tooltip: 'bottomMiddle' }}, style: { tip: 'bottomMiddle', name: 'dark'},
		content: "<strong>Solar is the most energy efficeint option for hot water, particularly with gas boosted.</strong><br/>Panels need to be installed on a north-facing roof for maximum efficiency.  Tank can be installed either on the roof or on the ground." });
	$('#infocontinuous').qtip({
		show: 'mouseover', hide: 'mouseout', position: { corner: { target: 'topMiddle', tooltip: 'bottomMiddle' }}, style: { tip: 'bottomMiddle', name: 'dark'},
		content: "<strong>Hot water as required and don't run-out.</strong><br/>  Some low-flow tapware with a continous flow unit can result in reduced water pressure.  Most units require a 20mm gas line so an upgrade may be required." });
	$('#info3star').qtip({
		show: 'mouseover', hide: 'mouseout', position: { corner: { target: 'topMiddle', tooltip: 'bottomMiddle' }}, style: { tip: 'bottomMiddle', name: 'dark'},
		content: "Cheaper to purchase than a 5 star gas storage system or continuous flow, but higher ongoing running costs and not as environementally friendly." });
	$('#infoelectric').qtip({
		show: 'mouseover', hide: 'mouseout', position: { corner: { target: 'topMiddle', tooltip: 'bottomMiddle' }}, style: { tip: 'bottomMiddle', name: 'dark'},
		content: "<strong>While Electric storage heaters are generally cheaper to purchase and install</strong>, they usually have the highest ongoing energy cost if on a continuous tariff and have the highest rate of carbon emmissions." });
	$('#btnNew').qtip({
		show: 'mouseover', hide: 'mouseout', position: { corner: { target: 'topMiddle', tooltip: 'bottomMiddle' }}, style: { tip: 'bottomMiddle', name: 'dark'},
		content: "I'm looking for a hot water unit<br/> for a <strong>new</strong> home" });
	$('#btnReplacement').qtip({
		show: 'mouseover', hide: 'mouseout', position: { corner: { target: 'topMiddle', tooltip: 'bottomMiddle' }}, style: { tip: 'bottomMiddle', name: 'dark'},
		content: "I'm looking to <strong>replace</strong><br/> an existing hot water unit." });
	$('#btnHouse').qtip({
		show: 'mouseover', hide: 'mouseout', position: { corner: { target: 'topMiddle', tooltip: 'bottomMiddle' }}, style: { tip: 'bottomMiddle', name: 'dark'},
		content: "<strong>House</strong> includes any detatched, terrace or town house (also referred to as Class  1 dwelling)." });
	$('#btnApartment').qtip({
		show: 'mouseover', hide: 'mouseout', position: { corner: { target: 'topMiddle', tooltip: 'bottomMiddle' }}, style: { tip: 'bottomMiddle', name: 'dark'},
		content: "<strong>Apartment</strong> includes any flats or apartments (also referred to as Class 2 dwelling)" });




	
	
});
