function openUrl(url){
	window.open(url, 'photo_popup', 'left=20,top=20,width=783,height=655,toolbar=0,location=0,status=0,menubar=0');
}



//global topnav image array
aImages = new Array();

//more abstract rollover script
function genRollovers(boxId){
	if (!document.getElementById) return
	
	var aPreLoad = new Array();
	var sTempSrc;

	if(document.getElementById(boxId)){	
		aImages = document.getElementById(boxId).getElementsByTagName('img');	

		for (var i = 0; i < aImages.length; i++) {		
			//if (aImages[i].className == 'imgover') {
			if(aImages[i].className.indexOf('imgover') >= 0){
				var src = aImages[i].getAttribute('src');
				var ftype = src.substring(src.lastIndexOf('.'), src.length);

				//if current tab is selected, no rollover
				if(src.indexOf('_on') >= 0)
					var hsrc = src;
				else
					var hsrc = src.replace(ftype, '_on'+ftype);

				aImages[i].setAttribute('hsrc', hsrc);
	
                	//download the rollover image
				aPreLoad[i] = new Image();
				aPreLoad[i].src = hsrc;
			
				aImages[i].onmouseover = function() {
					sTempSrc = this.getAttribute('src');
					this.setAttribute('src', this.getAttribute('hsrc'));					
				}	
			
				aImages[i].onmouseout = function() {
					if (!sTempSrc) sTempSrc = this.getAttribute('src').replace('_on'+ftype, ftype);
					this.setAttribute('src', sTempSrc);
				}
			}
		}
	}
}
//this function starts topnav rollovers now
function initRollovers() {
	genRollovers("topnav");
}

function top_sub_nav(sect)
{

 var sub_nav = document.getElementById("top_sub_nav");
 var ul_arr = new Array();
 var arr_counter = 0;
 if(sect == "bestvalue"){
        sect = "bestdeals";
 } else if(sect == "preowned"){
        sect = "usedcars";
 } else if(sect.indexOf("finance")>=0){
        sect = "finance";
 }
 //extract ULs from top_sub_nav
 for(var i=0; i < sub_nav.childNodes.length; i++)
 {
  if(sub_nav.childNodes[i].tagName == "UL")
  {
   ul_arr[arr_counter] = sub_nav.childNodes[i];
   arr_counter++;
  }
 }

 var matched = false;

 //try to match sect with id here
 for(var i=0; i < ul_arr.length; i++)
 {
  if(sect == ul_arr[i].id)
  {
   ul_arr[i].style.display = "block";
   matched = true;
   aImages[i].style.borderBottom = "1px solid #fff";
  }
 }

 //if match is not found, just display "home"
 if(!matched){
  ul_arr[0].style.display = "block";
  aImages[0].style.borderBottom = "1px solid #fff";
 }
}

function iehover(){
        var leftnav = document.getElementById("leftnav").getElementsByTagName("li");

        for(var i=0; i < leftnav.length;i++)
        {
                leftnav[i].onmouseover = function()
                {
this.style.border = '1px solid #15435d';
this.style.backgroundColor = '#bbd1f6';
this.style.marginRight = "1px";
                }

                leftnav[i].onmouseout = function()
                {
this.style.border = '1px solid #fff';
this.style.backgroundColor = '#fff';
this.style.marginRight = "1px";
                }
        }
}

//this feature is frozen until after launch
function hp_top10table()
{                                     
 var top10cells = document.getElementById("top10table").getElementsByTagName("th");

 if(top10cells.length > 0){

 for(var i=0; i<top10cells.length; i++)
 {
  
 } 
 }
}

function h6_hover()
{
 var hp = document.getElementById("content_well");

 if(hp){

 if(hp.className == "hp")
 {
  var h6 = hp.getElementsByTagName("h6");
  
  for(var i=0; i < h6.length; i++)
  {
   if(h6[i].className == "tail")
   {
    h6[i].onmouseover = function(){
      this.className +=" rollover";
    }

    h6[i].onmouseout = function(){
     this.className = "tail";
    }
   }
  }
 }
}
}

function popup(popUrl)
{
	var popWin = window.open(popUrl, "popWindow", "toolbar=no,width=600,height=625"); 
	return false;
}


function testIframe()
{
var tmpFrame = document.getElementsByTagName("iframe");

if(tmpFrame.length > 0)
{
 for(var i=0; i < tmpFrame.length; i++){
  if(tmpFrame[i].parentNode.className.indexOf("bottom_ad") >= 0)
   tmpFrame[i].style.width = "300px";
 }
}
}


function startList() 
{
	if(document.all && document.getElementById){
		var navArr = new Array("review_nav_top", "review_nav_bottom");
		if( document.getElementById(navArr[0]) || document.getElementById(navArr[1]) ){
			for(j=0; j<navArr.length; j++){
				navRoot = document.getElementById(navArr[j]);
				
				for(i=0; i<navRoot.childNodes.length; i++){
					node = navRoot.childNodes[i];
					if (node.nodeName=="LI") {
						node.onmouseover=function() {
							this.className+=" over";
  						}
  						node.onmouseout=function() {
  							this.className=this.className.replace(" over", "");
  	 					}
						if(node.childNodes.length > 0)
							listMenuRollovers(node);
   				}
  				}
			}
 		}
	}
}

function listMenuRollovers(node)
{
	for(var i=0; i < node.childNodes.length; i++){
		if(node.childNodes[i].tagName == "UL"){
			var menu = node.childNodes[i];
			
			for(var j=0; j<menu.childNodes.length; j++){
				if(menu.childNodes[j].tagName == "LI"){
					menu.childNodes[j].onmouseover = function(){
						this.className+=" over";
					}
					menu.childNodes[j].onmouseout = function(){
						this.className=this.className.replace(" over", "");
					}
				}
			}
		}
	}
}

function abbr(abbrId)
{
abbrObj = document.getElementById(abbrId);

if((!abbrObj.style.display.length > 0) || abbrObj.style.display == "none")
 abbrObj.style.display = 'block';
else
 abbrObj.style.display = "none";

//alert(abbrObj.style.display.length);
}

window.onload = function(){

//initRollovers();
//iehover();
testIframe();
h6_hover();

genRollovers("prev_next");
genRollovers("fpq1");
genRollovers("fpq2");
genRollovers("explain");
genRollovers("review_nav_top");
genRollovers("review_nav_bottom");
genRollovers("photos_nav_top");
genRollovers("photos_nav_bottom");
genRollovers("popup_buttons");
genRollovers("photos_enlarge");
startList();

// feature frozen until after launch
//hp_top10table();
}
