// JavaScript Document

//=============================================================================================
/* Header Loading Function */
var hdrImages = new Array(); //creates an Arrary to store header images
hdrImages[0] = '/images/ccghdr/ccgHdr1.jpg'; //stores header image into array
hdrImages[1] = '/images/ccghdr/ccgHdr2.jpg';
hdrImages[2] = '/images/ccghdr/ccgHdr3.jpg';
hdrImages[3] = '/images/ccghdr/ccgHdr4.jpg';

var len = hdrImages.length; //number of images in the hdrImages array
var b = new Array();
for(i=0; i<len; i++){
	b[i] = new Image();
	b[i] = hdrImages[i];
}

var chooseImage = Math.round(Math.random()*(len-1)); //Random number for array

function hdrLoad(d){
	document.getElementById(d).style.backgroundImage="url(" + hdrImages[chooseImage] + ")";
	//The above code tells the browser to display the randomly selected header image as a background
	//image of the passed DIV. This is done using a DIV ID. The function and div is called in the
	//ccg.htm file (in the onload statement of the body tag)
}

//===============================================================================================
/* Functions for the Update Clock */
/* Sets time to standard 12-Hour Format */
function formatHours(x){
	var hour = x.getHours(); //retrieves the current hour, stores the hour to variable hour
	if(hour > 12){ //if the hour is greater than 12, then the hour will be subtracted by 12 (14 - 12 = 2 o'clock)
		hour = hour - 12;
		return hour;
	} else { //if the hour is 12 or less then the hour is displayed as is
		return hour;
	}
	if(hour == 0){ //This if statement sets the hour to 12 (midnight)
		hour = 12;
		return hour;
	}
}

/* Formats minute correctly */
function checkMin(y){
	var m = y.getMinutes(); //retrieves the current minute, stores the minute to variable m
	if(m < 10){ //if the minute is less than 10, then a 0 is added before the minute (8 [minute]; displays as 08)
		return ("0" + m);
	} else { //if the minute is equal to or greater than 10, then the minute is displayed as is
		return m;
	}
}

//Determines if the time is AM or PM. Writes results to upated line.
function displayAmPm(x){
	var h = x.getHours() //retrieves the current hour, stores the hour to variable h
	if(h < 12){ //if the hour is less than 12, AM is displayed
		document.write(" AM, ")
	} else { //if the hour is equal to or greater than 12, PM is displayed
		document.write(" PM, ")
	}
}
