function startList() {
	if (document.getElementById("primary")) {
		navRoot = document.getElementById("primary");
		for (i=0; i < navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			if (node.nodeName == "LI") {
				if(document.all) {
					node.onmouseover=function() {
						this.className += " over";
					}
					node.onmouseout=function() {
						this.className = this.className.replace(" over", "");
					}
				}
			}
		}
	}
}




function toggleSub(who) {
	var x = who.parentNode.getElementsByTagName("UL")[0];
	if(x.style.display != "block") {
		x.style.display = "block";
		who.style.backgroundImage = "url(../images/collapse.gif)";
	} else {
		x.style.display = "none";
		who.style.backgroundImage = "url(../images/expand.gif)";
	}
}

function validateForm(who) {
	var f = who;
	var missing = new Array();
	var msg = "Please be sure to fill out all of the fields marked in red.";
	for(i=0;i<f.elements.length;i++) {
		if(f.elements[i].className.indexOf("required") > -1 && f.elements[i].value.length < 1) {
			missing.push(f.elements[i]);
		}
	}
	if (missing.length > 0) {
		labels = document.getElementsByTagName("LABEL");
		for(h=0;h<labels.length;h++) {
			labels[h].className = "";
		}
		for(j=0;j<missing.length;j++) {
			if(document.getElementById(missing[j].name)) {
				document.getElementById(missing[j].name).className = "required";
			} else {
				missing[j].style.backgroundColor = "#edd2d2";
			}
		}
		
		alert(msg);
		return false;
	}
	else {
		return true;
	}
}

function activate(who,defaultvalue) {
	if(who.value == defaultvalue) {
		who.value = "";
	}
	who.className += " active";
}

function checkValue(who,defaultvalue) {
	if(who.value == "" || who.value == defaultvalue) {
		who.value = defaultvalue;
		who.className = who.className.replace(" active", "");
	}
}

var imgs = new Array();

//insert images

imgs[0] = "images/homebanner/worthington.jpg";
imgs[1] = "images/homebanner/nieves.jpg";
imgs[2] = "images/homebanner/spann.jpg";
imgs[3] = "images/homebanner/pohanka.jpg";
imgs[4] = "images/homebanner/macinnes.jpg";
imgs[5] = "images/homebanner/ricart.jpg";
imgs[6] = "images/homebanner/williams.jpg";
imgs[7] = "images/homebanner/ohearn.jpg";
imgs[8] = "images/homebanner/hassan.jpg";
imgs[9] = "images/homebanner/braatz.jpg";
imgs[10] = "images/homebanner/wilson.jpg";
imgs[11] = "images/homebanner/eakin.jpg";
imgs[12] = "images/homebanner/jenkins.jpg";
imgs[13] = "images/homebanner/underwoods.jpg";

//end insert images

//insert quotes

var content = new Array();

content[0] = new Array("I was pleased my wife was able to get credit through Credit Acceptance. She needed to build credit because of my health problems.","Anne &amp; Earl Worthington, Credit Acceptance Approved","secondary.html");
content[1] = new Array("With the Guaranteed Credit Approval Program I can control financing and increase my cash flow.","Ricardo Nieves, Kissimmee Auto Sales, Inc. - Dealer-Partner since 2005","secondary.html");
content[2] = new Array("Nobody would extend any credit to me after my bankruptcy... until I found a Credit Acceptance dealer.","Janet Spann, Credit Acceptance Approved","secondary.html");
content[3] = new Array("This program has really helped us eliminate turndowns. We've written more than 3,100 Credit Acceptance contracts to date!","Steve Parker &amp; Geoff Pohanka, The Pohanka Group - Dealer-Partner since 1991","secondary.html");
content[4] = new Array("Since I got my car and paid it off without being late or missing a payment, I can now get credit on my own.","Jessica MacInnes, Credit Acceptance Approved","secondary.html");
content[5] = new Array("With Credit Acceptance I can say &lsquo;YES&rsquo; to every customer and capture incremental and referral business I was losing.","Rhett Ricart, Ricart Automotive - Dealer-Partner since 2004","secondary.html");
content[6] = new Array("My Credit Acceptance dealer was my last stop! They took care of me. Now we can look forward to a better future.","Nikietta Williams, Credit Acceptance Approved","secondary.html");
content[7] = new Array("The Guaranteed Credit Approval Program has changed my life as well as my customers&rsquo; lives.","Patrick O&rsquo;hern, One Way Enterprises - Dealer-Partner since 1996","secondary.html");
content[8] = new Array("I went to a couple of dealers. Then I heard about a Credit Acceptance dealer. I walked in and the guy said, &lsquo;I will get you approved.&rsquo;","Oumar Hassan, Credit Acceptance Approved","secondary.html");
content[9] = new Array("I&rsquo;ve done more than 5,000 contracts with customers no other company would finance.","Jeff Braatz, Paradise Motor Sales Inc. - Dealer-Partner since 1991","secondary.html");
content[10] = new Array("My credit has improved by making on-time payments through Credit Acceptance.","Tonya Wilson, Credit Acceptance Approved","secondary.html");
content[11] = new Array("Guaranteed Credit Approval has allowed me to finance every customer who comes into my dealership.","Daniel Mink, Dennis Eakin Second Chance - Dealer-Partner since 2001","secondary.html");
content[12] = new Array("We wanted a newer, dependable vehicle and to rebuild our credit... we got both!","Jenkins Family, Credit Acceptance Approved","secondary.html");
content[13] = new Array("We have given more than 3,600 customers the opportunity to change their lives by turning empathy into action.","Roderick, Anthony &amp; Broderick Underwood, Anthony Underwood Automotive - Dealer-Partner since 1995","secondary.html");

//end insert quotes

var j = 0;

var cache = new Array();

for (i=0;i<imgs.length;i++) {
   cache[i] = new Image();
   cache[i].src = imgs[i];
}

function showPics(){
	if(document.getElementById("banner")) {
		
		fadeItem(50);
		document.getElementById("banner").src = cache[j].src;
		document.getElementById("banner").onclick = function() { document.location.href=content[j][2]; }
		document.getElementById("quote").getElementsByTagName("H3")[0].innerHTML = "&ldquo;"+content[j][0]+"&rdquo;";
		document.getElementById("quote").getElementsByTagName("P")[0].innerHTML = "&mdash;"+content[j][1];
		fadeItem(100);
		
		j = j + 1;
		
		if (j>(imgs.length-1)) {
			j=0;
		}
		
		setTimeout('showPics()',9000);
	}
}

function setOpacity(obj,opacity) {
  opacity = (opacity==100) ? 99.999 : opacity;
  // IE/Win
  obj.style.filter = "alpha(opacity:"+opacity+")";
  // Safari<1.2, Konqueror
  obj.style.KHTMLOpacity = opacity/100;
  // Older Mozilla and Firefox
  obj.style.MozOpacity = opacity/100;
  // Safari 1.2, newer Firefox and Mozilla, CSS3
  obj.style.opacity = opacity/100;
}

function fadeItem(opacity) {
  if (document.getElementById("banner")) {
    obj = document.getElementById("banner");
    if (opacity <= 100) {
      setOpacity(obj, opacity);
      opacity += 10;
      window.setTimeout("fadeItem("+opacity+")", 100);
    }
  }
}

function setMenu() {
	if(document.getElementById("tertiary")) {
		var x = document.getElementById("tertiary").getElementsByTagName("A");
		for(i=0;i<x.length;i++) {
			if(x[i].href == document.location.href) {
				x[i].className += " current";
				if(x[i].parentNode.parentNode.parentNode.nodeName == "LI") {
					toggleMenu(x[i].parentNode.parentNode.parentNode.getElementsByTagName("A")[0]);
				}
				break;
			}
		}
	}
}

    var map = null;
    var geocoder = null;

    function load() {
      if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("map"));
        map.setCenter(new GLatLng(37.4419, -122.1419), 13);
        geocoder = new GClientGeocoder();
      }
    }

    function showAddress(address) {
      if (geocoder) {
        geocoder.getLatLng(
          address,
          function(point) {
            if (!point) {
              alert(address + " not found");
            } else {
              map.setCenter(point, 13);
              var marker = new GMarker(point);
              map.addOverlay(marker);
              marker.openInfoWindowHtml(address);
            }
          }
        );
      }
    }

function init() {
	startList();
//	showPics();
	setMenu();
//	load();
}

window.onload = init;