$(document).ready(function() {
	try{
		$('#customscroller').jScrollPane({animateTo:true, animateInterval:50, animateStep:5, showArrows:true, scrollbarWidth:20, dragMaxHeight:20, scrollbarMargin:22});
	} catch(err){}
	
	var odate = new Date();
	$('#copyright').html('&copy; '+odate.getFullYear()+' Aerofficient LLC');
	try{
		$('#ulDemoVideos').accordion({ 
			autoHeight: true,
			header: "a.demolink"
		});
	} catch(err){	}
	$('#ulDemoVideos li a.details').click(function(){
		var theText = $(this).text();
		var therel = $(this).attr("rel");
		var marginleft = 82;
		if(therel == "engineering"){
			marginleft = 35;
		}
		
		if(theText == "Details +"){
			$(this).text("Details -");
			$("." + therel + " .detailsdiv").css("margin","0px 0px 0px "+marginleft+"px");
			$("." + therel + " .detailsdiv").fadeIn('slow');
		} else {
			$(this).text("Details +");
			$("." + therel + " .detailsdiv").fadeOut('slow');
		}
	});
	$('#mainnav li div.subnav').eq(0).css("background-position","top");
	/*$('#mainnav li div').mouseover(function(){
		$(this).css("z-index","10000");
	});
	$('#mainnav li div').mouseout(function(){
		$(this).css("z-index","5000");
	});*/
	$('input#hoursperman').keyup(function(event){
		try{
			if($('input#hoursperman').val() != "" && $('input#costmanhour').val() != "")
				DoInstallationCost();
		}catch(err){}
	});
	$('input#costmanhour').keyup(function(event){
		try{
			if($('input#costmanhour').val() != "" && $('input#hoursperman').val() != "")
				DoInstallationCost();
		}catch(err){}
	});
	
	$('input#mpg').keyup(function(event){
		try{
			if($('#milesperyear').val() != "" && $('#mpg').val() != "" && parseFloat($('#mpg').val()) > 1 && $('#costoffuel').val()!="" && parseFloat($('#costoffuel').val()) > 1)
				DoFuelCost();
		}catch(err){}
	});
	$('input#milesperyear').keyup(function(event){
		try{
			if($('#milesperyear').val() != "" && $('#mpg').val() != "" && parseFloat($('#mpg').val()) > 1 && $('#costoffuel').val()!="" && parseFloat($('#costoffuel').val()) > 1)
				DoFuelCost();
		}catch(err){}
	});
	$('input#costoffuel').keyup(function(event){
		try{
			if($('#milesperyear').val() != "" && $('#mpg').val() != "" && parseFloat($('#mpg').val()) > 1 && $('#costoffuel').val()!="" && parseFloat($('#costoffuel').val()) > 1)
				DoFuelCost();
		}catch(err){}
	});
});

function DoFuelCost(){
	$('#averageconsumption').html(addCommas((parseFloat($('#milesperyear').val().replace(',',''))/parseFloat($('#mpg').val().replace(',',''))).toFixed(2)));
	$('#fuelcostpertrailer').html('$'+addCommas((parseFloat($('#averageconsumption').html().replace(',',''))*parseFloat($('#costoffuel').val().replace(',',''))).toFixed(2)));
	//$('#fuelsavings').html(addCommas(parseFloat($('#fuelcostpertrailer').html())).toFixed(2)*.07);
	$('#fuelsavings').html('$'+addCommas((parseFloat($('#fuelcostpertrailer').html().replace(',','').replace('$',''))*parseFloat($('#fuelsavingsmodel').val())).toFixed(2)));
}
function DoInstallationCost(){
	//hoursperman
	$('#totalmanhours').html(parseFloat($('#hoursperman').val().replace(',','')*2));
	$('#totalmancost').html('$'+parseFloat($('#costmanhour').val().replace(',',''))*parseFloat($('#hoursperman').val().replace(',','')*2));
}



function addCommas(nStr)
{
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}

