// JavaScript Document
/* This script and many more are available free online at
The JavaScript Source :: http://javascript.internet.com
Created by: Lee Underwood :: http://javascript.internet.com/ */

var bannerImg = new Array();
  // Enter the names of the images below
  bannerImg[0]="/images/graphics/web_copy_friedrich_jones_v3.jpg";
  bannerImg[1]="/images/graphics/web_copy_west_suburban_v1.jpg";
  bannerImg[2]="/images/graphics/web_copy_robert_pigott_v1.jpg";
  bannerImg[3]="/images/graphics/web_copy_cool_flow_v1.jpg";
var imgSubText = new Array();
  // Enter the names of the corresponding subtitles for each image
  imgSubText[0] = "Click the ad to goto www.Friedrich-Jones.com";
  imgSubText[1] = "Click for a special offer!";
  imgSubText[2] = "";
  imgSubText[3] = "Click the ad to goto www.CoolFlowAutomotive.com";
  
var newBanner = 0;
var totalBan = bannerImg.length;
var whichimg = 0;

var running = false;
var endTime = null;
var timerID = null;
var cnt = 0;
var delta = new Date();


function cycleBan() {
  var elem;
  if (!document.images)
    return
  document.images.cycler.src=bannerImg[newBanner];
  document.getElementById("cyclertxt").innerHTML=imgSubText[newBanner];

  whichimg=newBanner;
  newBanner++;
  if (newBanner == totalBan) {
    newBanner = 0;
  }
  // set the time below for length of image display
  // i.e., "4*1000" is 4 seconds
  setTimeout("cycleBan()", 6*1000);
  //setTimeout("showCountDown()", 1000);
}

function pickImg() {
	if (whichimg==0)
      window.open("http://www.friedrich-jones.com");
    else if (whichimg==1)
      window.open("/pw_wsea.htm");
    else if (whichimg==2)
      window.open("/pw_bp.htm");
	else if (whichimg==3)
      window.open("http://www.coolflowautomotive.com");
}

function getSrc(itemarea,pagenum) {
	switch (itemarea) {
		case "HH": 
	      if (pagenum == 0) 
	         return("/images/graphics/web_side_copy_kathy_rogers_v1.jpg");
			 break;
		case "HG":
		  if (pagenum == 0) 
	         return("/images/graphics/web_side_copy_kathy_rogers_v1.jpg");
			 break;
	}
}

function stopTimer() {
	clearTimeout(timerID);
	running = false;
	document.getElementById("timedisplayer").innerHTML = "Days:0 Hours:00 Minutes:00" + "Stopped";
}

function showCountDown(){
	 var now = new Date();
	//now.setTime();

	if (endTime - now <= 0) {
		stopTimer();
		document.getElementById("timedisplayer").innerHTML = endTime + " Stopped";
	}
	else {
		document.getElementById("timedisplayer").innerHTML = now + " in else";
		//now = now.getTime();
		//endTime = endTime.getTime();
		delta.setTime(endTime - now);
		var theHours = delta.getTime()/1000/60/60;
		var theSecs = delta.getSeconds();
		var theDays = Math.floor(((theHours < 24) ? 0  : (theHours / 24)));
		var theRemainingHours = Math.floor(theHours % 24);
		
		var theRemainingMinutes = Math.floor(((theHours % 24) % 1) * 60);
		var theTime = theDays + " Days ";
		theTime += theRemainingHours + " Hrs ";
		theTime += theRemainingMinutes + " Mins ";
		theTime += theSecs + " Secs ";
		document.getElementById("timedisplayer").innerHTML = theTime;
		if (running) {
			//showCountDown();
			timerID = setTimeout("showCountDown()", 1000);
		}
	}
}

function startTimer() {
	running = true;
	var now = new Date();
	//now = now.getTime();
	// change last multiple for the number of minutes
	endTime = new Date("November 7, 2009 18:00:00");
	document.getElementById("timedisplayer").innerHTML = endTime + " Started";
	showCountDown();
}




window.onload=cycleBan;
window.onload=startTimer;
