leafBrightness =0;

function updateGraph()
{
	
	
    new Effect.Morph('costEl',{
        style:'width:'+cost,
            duration:1
    });
    
    new Effect.Morph('ecoRebateEl',{
        style:'width:'+ecoRebate,
            duration:1
    });
    
    new Effect.Morph('newCostEl',{
        style:'width:'+newCost,
            duration:1
    });
  
    new Effect.Opacity('leaf', {duration:0.5, to:leafBrightness});
    new Effect.Opacity('skydiv', {duration:0.5, to:Math.min(Math.max(leafBrightness,0.2),0.75)});
}

function fUpdateGraph(leafBrightness,cost,ecoRebate,newCost)
{
	
	
    new Effect.Morph('costEl',{
        style:'width:'+cost,
            duration:1
    });
    
    new Effect.Morph('ecoRebateEl',{
        style:'width:'+ecoRebate,
            duration:1
    });
    
    new Effect.Morph('newCostEl',{
        style:'width:'+newCost,
            duration:1
    });
  
    new Effect.Opacity('leaf', {duration:0.5, to:leafBrightness});
    new Effect.Opacity('skydiv', {duration:0.5, to:Math.min(Math.max(leafBrightness,0.2),0.75)});
}

function hideLeaf()
{
	
	if (leafBrightness <=0.5)
	{
		new Effect.Opacity('leaf', {duration:1.5, to:leafBrightness});
		
	}
	window.setTimeout("showLeaf()", 10000);	
}

function showLeaf()
{
	if (leafBrightness <=0.5)
	{
		new Effect.Opacity('leaf', {duration:3, to:1});
	}
	else
	{
		new Effect.Opacity('leaf', {duration:0.5, to:leafBrightness});
	}
	window.setTimeout("hideLeaf()", 8000);	
}


var groupIndex=0;

function finish()
{
	document.frm.action = "eco-calculator/eco-calculator-results.php";
	document.frm.submit();
	
	
}



function nextGroup()
{
	groupIndex++;
	new Effect.Fade($("group"+(groupIndex-1)));
	new Effect.Appear($("group"+(groupIndex)));
}

function prevGroup()
{
	groupIndex--;
	new Effect.Fade($("group"+(groupIndex+1)));
	new Effect.Appear($("group"+(groupIndex)));
}

function selectionChanged(index, pcost, label, text)
{
	var tlabel = "hd_label_selection"+(index + 11);
	var combo = "hd_selection"+(index + 11);
	var ar = pcost.split(",");
	
	costs[index]=parseFloat(ar[0]);
	rebates[index]=parseFloat(ar[1]);
	var totalCost = 0;
	var totalRebates=0;
	for(var i=0;i<costs.length;i++)
	{
		totalCost+=parseFloat(costs[i]);
		totalRebates+=parseFloat(rebates[i]);
	}
	var newCostNum = (totalCost-totalRebates);
	
	
	// newCost = ((newCostNum/(maxSpend) * 620)) + "px";
	
  newCost = ((newCostNum/(maxSpend) * 320)) + "px";
  
	// cost = ((totalCost/maxSpend)*620) + "px"; 
	
  cost = ((totalCost/maxSpend)*320) + "px"; 
  
	leafBrightness = (totalCost/maxSpend);
	
	// ecoRebate = ((totalRebates/maxRebate) * 620) +"px";
	
  ecoRebate = ((totalRebates/maxRebate) * 320) +"px";
  
	eleml = document.getElementById(tlabel);
 	eleml.value = label;
	
	elem = document.getElementById(combo);
 	elem.value = text;
	
	gcost = document.getElementById("hd_cost");
 	gcost.value = totalCost;
	
	rebate = document.getElementById("hd_rebate");
 	rebate.value = totalRebates;
	
	new_cost = document.getElementById("hd_new_cost");
 	new_cost.value = newCostNum;
	
	wcost = document.getElementById("wd_cost");
 	wcost.value = cost;
	
	wrebate = document.getElementById("wd_rebate");
 	wrebate.value = ecoRebate;
	
	wnew_cost = document.getElementById("wd_new_cost");
 	wnew_cost.value = newCost;
	
	hleafBrightness = document.getElementById("hd_leafBrightness");
 	hleafBrightness.value = leafBrightness;
	
	$("costEl").innerHTML = "$" + totalCost;
	$("ecoRebateEl").innerHTML = "$" + totalRebates;
	$("newCostEl").innerHTML = "$" + (newCostNum);
	
	percentBetter = 0.8;
	updateGraph();
}

