function guardCalculator()
{
	valid = true;
	this.own = false;
	
	PTZ_UNIT_COST = 2550;
	FIXED_UNIT_COST = 750;
	PTZ_INSTALL_COST = 0;
	FIXED_INSTALL_COST = 0;
	IVERIFY_MONTHLY_RATE = 380;	
	RANGE = 0.025;
	
	var obj = this;
	
	//contact link
	$('#contact_button').bind('click',function(e){
		obj.showForm.apply(obj);
		e.stopPropagation();
		return false;		
	});
	
	//contact link
	$('#contact_button2').bind('click',function(e){
		obj.showForm.apply(obj);
		e.stopPropagation();
		return false;		
	});
	
	//action button
	$('#actionbutton').bind('click',function(e){
		obj.showResults.apply(obj);
		e.stopPropagation();
		return false;		
	});
	
	//validate for numeric
	$('#guard_hours').bind('change',function(e){
		obj.compute.apply(obj);
		e.stopPropagation();
		return false;
	});
	
	//validate for numeric
	$('#guard_rate').bind('change',function(e){
		obj.compute.apply(obj);
		e.stopPropagation();
		return false;
	});

	//validate for numeric
	$('#other_expenses').bind('change',function(e){
		obj.compute.apply(obj);
		e.stopPropagation();
		return false;
	});
	
	$('#own_yes').bind('change',function(e){
		obj.compute.apply(obj);
		e.stopPropagation();
		return false;
	});
	
	$('#own_no').bind('change',function(e){
		obj.compute.apply(obj);
		e.stopPropagation();
		return false;
	});
	
	$('#fixed_cameras').bind('change',function(e){
		obj.compute.apply(obj);
		e.stopPropagation();
		return false;
	});
	
	$('#pan_tilt_zoom_cameras').bind('change',function(e){
		obj.compute.apply(obj);
		e.stopPropagation();
		return false;
	});
	
	$('#ns_fixed_cameras').stepper({
		max: 1000,
		step: 1,
		change: function(event, ui){
			obj.compute.apply(obj);
		}
	});
	
	$('#ns_pan_tilt_zoom_cameras').stepper({
		max: 1000,
		step: 1,
		change: function(event, ui){
			obj.compute.apply(obj);
		}
	});
		
}

guardCalculator.prototype.showResults = function()
{
	$('#infopanel').slideDown();
	this.compute();
}

guardCalculator.prototype.save = function()
{
	$('#hidden_guard_hours').val($('#guard_hours').val());
	$('#hidden_guard_rate').val($('#guard_rate').val());
	$('#hidden_other_expenses').val($('#other_expenses').val());
	$('#hidden_own').val(this.own);
	$('#hidden_fixed_cameras').val($('#fixed_cameras').val());
	$('#hidden_pan_tilt_zoom_cameras').val($('#pan_tilt_zoom_cameras').val());
	$('#hidden_savings').val(savings);
}

guardCalculator.prototype.showForm = function()
{
	$('#form_wrapper').slideDown('normal',function(){
		$('#calculator_user_input').slideUp();
	});
	
	return false;
}

guardCalculator.prototype.hideForm = function()
{
	$('#form_wrapper').slideUp('normal',function(){
		$('#calculator_user_input').slideDown();
	});
	
	return false;
}

guardCalculator.prototype.bound = function(num)
{
	var r = Math.round(num);
	if(r >= 100){		
		r = 99;
	}
	return r;
}

guardCalculator.prototype.compute = function(){
	savings = 0;
	this.own = false;
	if(valid == true){
		
		var costCustomer = Number($('#guard_hours').val()) * 52 * Number($('#guard_rate').val())
		costCustomer += Number($('#other_expenses').val()) * 12;
		
		var cams = 0;
		if($('#own_yes').attr('checked')){
			this.own = true;
		}	
		
		var c_int = Number($('#fixed_cameras').val());
		var c_ext = Number($('#pan_tilt_zoom_cameras').val());
		
		var c_tot = c_int + c_ext;
		if(c_tot >= 1 && c_tot <= 8){
			//DVR
			costIverify += 4350;
			//Audio
			costIverify += 1500;
		}
		if(c_tot >= 9 && c_tot <= 15){
			//DVR
			costIverify += 6200;
			//Audio
			costIverify += 2000;
		}
		if(c_tot >= 16){
			//DVR
			costIverify += 6400;
			//Audio
			costIverify += 3000;
		}
		
		if(this.own){
			//install fee only - might be different
			cams += c_int * FIXED_INSTALL_COST;
			cams += c_ext * PTZ_INSTALL_COST;
		}else{
			//unit
			cams += c_int * FIXED_UNIT_COST;
			cams += c_ext * PTZ_UNIT_COST;			
			//installation
			cams += c_int * FIXED_INSTALL_COST;
			cams += c_ext * PTZ_INSTALL_COST;
		}
		
		
		var costIverify = cams + (IVERIFY_MONTHLY_RATE * 12);
		
		if(costIverify < costCustomer){
		
			var p = costIverify / costCustomer;
			savings = 1 - p;
			
			var c = costCustomer - costIverify;
			
			//calc range
			//$('#results span').text( this.bound((savings - RANGE) * 100)  + '-' + this.bound((savings + RANGE) * 100) + '%');
			
			//calc exact
			savings = '$' + this.addCommas(c) + ' (' + this.bound(savings * 100) + '%)';
			$('#results span').text(savings);
			
		}else{
			
			//you might not actually save money :)
			$('#results span').text('N/A');
		}		
		
	}else{
		//throw error
		$('#results span').text('N/A');
	}
	
	//$('#results').effect("highlight", {color:'#000000'}, 500);
	this.save();
}

guardCalculator.prototype.addCommas = function(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;
}
