
var main;
var sub;
var obj= new Object;
var over  = false;
var openX  = false; // Note to utv5: Don't call global vars the same as global functions like window.open ;o)
var hideTime = 1000;
var showTime = 50;
var shim;

function hideSub() {
	if (!over) {
		sub.style.visibility = 'hidden';
		main.className = "";
		openX=false;
		hideShim();
	}
}

function showSub() {
	showShim();
	sub.style.visibility = 'visible';
	sub.style.zIndex = 2;
	main.className = "active";
	openX=true;
}

// shim is the iframe that covers <select> boxes in IE...
function showShim() {
	if (!shim) return
	shim.style.backgroundColor = "red";
	shim.style.width = sub.offsetWidth +'px';
	shim.style.height = sub.offsetHeight +'px';
	shim.style.left = (document.body.clientWidth - sub.offsetWidth - 11) +'px';
	shim.style.top = sub.offsetTop+10 +"px";
	shim.style.display="block";
	
}
function hideShim() {
	if (!shim) return
	shim.style.display="none";
}


// initialise dropdown menu
addLoadEvent(function () {


    try {
        main = document.getElementById("carhistoryMain")
        sub = document.getElementById("carhistorySub");
    }
    catch (e) {
        alert(e.message);
    }

    if (document.all) {
        // temporary remove
        //shim = document.createElement("<iframe scrolling=\"no\" frameborder=\"0\" style=\"position:relative; top:0px; left:0px; display:none; \"></iframe>");
        //shim.id = "shim";
        //document.body.appendChild(shim);
    }

    if ((!main) || (!sub)) return;

    main.onmouseover = function () {
        if (openX) window.clearTimeout(obj);
    }
    main.onmouseout = function () {
        over = false;
        obj = setTimeout("hideSub()", hideTime);
    }

    main.onclick = function () {
        if (openX) {
            over = false;
            hideSub();
        } else {
            over = true;
            var winW = document.body.offsetWidth;
            if (winW > 995) {
                var rightPos = ((winW - 995) / 2) + 28;
                document.getElementById('carhistorySub').style.right = rightPos + 'px';
                //document.getElementById('carInformationDockDiv').style.marginTop = '0px';
            }
            else {
                document.getElementById('carhistorySub').style.right = '0px';
            }
            document.getElementById('carhistorySub').style.width = '600px';
            //document.getElementById('carhistorySub').style.hight = '600px';
           
            obj = setTimeout("showSub()", showTime);
        }
    }

    sub.style.width = sub.offsetWidth + 'px';
    sub.className += ' init';

    sub.onmouseover = function () {
        over = true;
        window.clearTimeout(obj);
        showSub();
    }

    sub.onmouseout = function () {
        over = false;
        obj = setTimeout("hideSub()", hideTime);
    }
});

