//STARTS ONLY WHEN THE DOCUMENT IS READY
$(document).ready(function(){

	//HIDE AT START
	$(".tipA").hide();
	$(".keepopen").show();
	
	//Random Picture
	imageSwap();

	//TRIGGER FOR THE GRAY BOXES
	$(".tipQ").click(function(){
		$(this).next().slideToggle();
		});

	//TRIGGER FOR THE COLAPSE ALL
	$(".rollup").click(function(){
		$(".tipA").slideUp();
		});

	/*
	TO BETTER PROTECT YOUR EMAIL ADDRESS FROM BEING SPAMMED ADD
	<span class="ftrEmail">EVERYTHING BETWEEN THIS SPAN TAG GETS REPLACED</span>
	THE SCRIPT BELOW REPLACES THE TEXT WITH AN EMAIL LINK 
	REPLACE EMAIL_ADDRESS WITH THE CORRECT ADDRESS
	*/
	$(".emailInfo").replaceWith("<a href='mailto:info@spectrumdetails.com'>info@spectrumdetails.com</a>");
	$(".emailSales").replaceWith("<a href='mailto:sales@spectrumdetails.com'>sales@spectrumdetails.com</a>");
	$(".emailMedia").replaceWith("<a href='mailto:media@spectrumdetails.com'>media@spectrumdetails.com</a>");
	$(".emailWebcomments").replaceWith("<a href='mailto:webcomments@spectrumdetails.com'>webcomments@spectrumdetails.com</a>");

});

function imageSwap() {

	// Place your images in the images\cycle Folder
	// I used earth.jpg, 1earth.jpg, 2earth.jpg, 3earth.jpg and so on...
	
	// Enter total number of pictures to choose from here
	var numbersOfPics = 8;
	var dir = "images/cycle/";
	var filename = "earth.jpg";
	var h = 185; // Set the default height
	
	// Randomize the Photo
	var randPic=Math.floor(Math.random() * numbersOfPics)
	// Set the Default Height
	document.getElementById("imgSwap").height = h;
	
	if (randPic == 0) {
		// If 0 is selected use the defaults below
		document.getElementById("imgSwap").src = dir + filename;
		} else {
		// if the random number is not 0, display the correct photo (i.e. images/4earth.jpg)
		document.getElementById("imgSwap").src = dir + randPic + filename;
		}
	
	
	// If your picture needs to be a different height enter the photo # and change
	// the value to the correct height
	
	// The example here tells photo 4 needs to be a different height
	if (randPic == 5) {
		document.getElementById("imgSwap").height = "370";
		}


	}

function profitCalc() {
	
	//Set Variables
	var tradPrepTime = Number($("#tradPrepTime").val());
	var tradBasecoat = Number($("#tradBasecoat").val());
	var tradClearcoat = Number($("#tradClearcoat").val());
	var tradMaterials = Number($("#tradMaterials").val());
	var tradTOTAL = Number(tradPrepTime + tradBasecoat + tradClearcoat + tradMaterials).toFixed(2);
		if (tradTOTAL < 33.42) {tradTOTAL = 33.42}

	var cbPrepTime = 10.00;
	var cbBasecoat = 1.92;
	var cbColorBalancer  = 20.00;
	var cbMaterials = 1.50;
	var cbTOTAL = Number(cbPrepTime + cbBasecoat + cbColorBalancer + cbMaterials).toFixed(2); //$("#AverageVehiclesPerWeek").val();

	var AverageVehiclesPerWeek = Number($("#AverageVehiclesPerWeek").val());
	var AveragePanelsPerVehicle = Number($("#AveragePanelsPerVehicle").val());
	var ProfitPerPanel = Number(tradTOTAL - cbTOTAL).toFixed(2);
	var ProfitPerVehicle = Number(ProfitPerPanel * AveragePanelsPerVehicle).toFixed(2);
	var VehiclesPerWeek = AverageVehiclesPerWeek;
	var ProfitPerWeek = Number(ProfitPerVehicle * VehiclesPerWeek).toFixed(2);
	var ProfitPerYear = Number(ProfitPerWeek * 52).toFixed(2);
	var ProfitPerMonth = Number(ProfitPerYear / 12).toFixed(2);

	var ProfitPerMonth2 = ProfitPerMonth;
	
	$("#tradTOTAL").html(tradTOTAL);
	
	$("#ProfitPerPanel").html(ProfitPerPanel);
	$("#ProfitPerVehicle").html(ProfitPerVehicle);
	$("#VehiclesPerWeek").html(VehiclesPerWeek);
	$("#ProfitPerWeek").html(ProfitPerWeek);
	$("#ProfitPerMonth").html(ProfitPerMonth);
	$("#ProfitPerYear").html(ProfitPerYear);
	$("#SavingsPerPanel").html(ProfitPerPanel);
	
	$("#ProfitPerMonth2").html(ProfitPerMonth);
	
	}