/*****************************************************
* ypSlideOutMenu
* 3/04/2001
*
* a nice little script to create exclusive, slide-out
* menus for ns4, ns6, mozilla, opera, ie4, ie5 on 
* mac and win32. I've got no linux or unix to test on but 
* it should(?) work... 
*
* Revised:
* - 08/29/2002 : added .hideAll()
* - 04/15/2004 : added .writeCSS() to support more 
*                than 30 menus.
*
* --youngpup--
*****************************************************/
ypSlideOutMenu.Registry = []
ypSlideOutMenu.aniLen = 250
ypSlideOutMenu.hideDelay = 1000
ypSlideOutMenu.minCPUResolution = 10
// constructor
function ypSlideOutMenu(id, dir, left, top, width, height)
{
this.ie = document.all ? 1 : 0
this.ns4 = document.layers ? 1 : 0
this.dom = document.getElementById ? 1 : 0
if (this.ie || this.ns4 || this.dom) {
this.id = id
this.dir = dir
this.orientation = dir == "left" || dir == "right" ? "h" : "v"
this.dirType = dir == "right" || dir == "down" ? "-" : "+"
this.dim = this.orientation == "h" ? width : height
this.hideTimer = false
this.aniTimer = false
this.open = false
this.over = false
this.startTime = 0
this.gRef = "ypSlideOutMenu_"+id
eval(this.gRef+"=this")
ypSlideOutMenu.Registry[id] = this
var d = document
var strCSS = "";
strCSS += '#' + this.id + 'Container { visibility:hidden; '
strCSS += 'left:' + left + 'px; '
strCSS += 'top:' + top + 'px; '
strCSS += 'overflow:hidden; z-index:10000; }'
strCSS += '#' + this.id + 'Container, #' + this.id + 'Content { position:absolute; '
strCSS += 'width:' + width + 'px; '
strCSS += 'height:' + height + 'px; '
strCSS += 'clip:rect(0 ' + width + ' ' + height + ' 0); '
strCSS += '}'
this.css = strCSS;
this.load()
}
}
ypSlideOutMenu.writeCSS = function() {
document.writeln('<style type="text/css">');
for (var id in ypSlideOutMenu.Registry) {
document.writeln(ypSlideOutMenu.Registry[id].css);
}
document.writeln('</style>');
}
ypSlideOutMenu.prototype.load = function() {
var d = document
var lyrId1 = this.id + "Container"
var lyrId2 = this.id + "Content"
var obj1 = this.dom ? d.getElementById(lyrId1) : this.ie ? d.all[lyrId1] : d.layers[lyrId1]
if (obj1) var obj2 = this.ns4 ? obj1.layers[lyrId2] : this.ie ? d.all[lyrId2] : d.getElementById(lyrId2)
var temp
if (!obj1 || !obj2) window.setTimeout(this.gRef + ".load()", 100)
else {
this.container = obj1
this.menu = obj2
this.style = this.ns4 ? this.menu : this.menu.style
this.homePos = eval("0" + this.dirType + this.dim)
this.outPos = 0
this.accelConst = (this.outPos - this.homePos) / ypSlideOutMenu.aniLen / ypSlideOutMenu.aniLen 
// set event handlers.
if (this.ns4) this.menu.captureEvents(Event.MOUSEOVER | Event.MOUSEOUT);
this.menu.onmouseover = new Function("ypSlideOutMenu.showMenu('" + this.id + "')")
this.menu.onmouseout = new Function("ypSlideOutMenu.hideMenu('" + this.id + "')")
//set initial state
this.endSlide()
}
}
ypSlideOutMenu.showMenu = function(id)
{
var reg = ypSlideOutMenu.Registry
var obj = ypSlideOutMenu.Registry[id]
if (obj.container) {
obj.over = true
for (menu in reg) if (id != menu) ypSlideOutMenu.hide(menu)
if (obj.hideTimer) { reg[id].hideTimer = window.clearTimeout(reg[id].hideTimer) }
if (!obj.open && !obj.aniTimer) reg[id].startSlide(true)
}
}
ypSlideOutMenu.hideMenu = function(id)
{
var obj = ypSlideOutMenu.Registry[id]
if (obj.container) {
if (obj.hideTimer) window.clearTimeout(obj.hideTimer)
obj.hideTimer = window.setTimeout("ypSlideOutMenu.hide('" + id + "')", ypSlideOutMenu.hideDelay);
}
}
ypSlideOutMenu.hideAll = function()
{
var reg = ypSlideOutMenu.Registry
for (menu in reg) {
ypSlideOutMenu.hide(menu);
if (menu.hideTimer) window.clearTimeout(menu.hideTimer);
}
}
ypSlideOutMenu.hide = function(id)
{
var obj = ypSlideOutMenu.Registry[id]
obj.over = false
if (obj.hideTimer) window.clearTimeout(obj.hideTimer)
obj.hideTimer = 0
if (obj.open && !obj.aniTimer) obj.startSlide(false)
}
ypSlideOutMenu.prototype.startSlide = function(open) {
this[open ? "onactivate" : "ondeactivate"]()
this.open = open
if (open) this.setVisibility(true)
this.startTime = (new Date()).getTime() 
this.aniTimer = window.setInterval(this.gRef + ".slide()", ypSlideOutMenu.minCPUResolution)
}
ypSlideOutMenu.prototype.slide = function() {
var elapsed = (new Date()).getTime() - this.startTime
if (elapsed > ypSlideOutMenu.aniLen) this.endSlide()
else {
var d = Math.round(Math.pow(ypSlideOutMenu.aniLen-elapsed, 2) * this.accelConst)
if (this.open && this.dirType == "-") d = -d
else if (this.open && this.dirType == "+") d = -d
else if (!this.open && this.dirType == "-") d = -this.dim + d
else d = this.dim + d
this.moveTo(d)
}
}
ypSlideOutMenu.prototype.endSlide = function() {
this.aniTimer = window.clearTimeout(this.aniTimer)
this.moveTo(this.open ? this.outPos : this.homePos)
if (!this.open) this.setVisibility(false)
if ((this.open && !this.over) || (!this.open && this.over)) {
this.startSlide(this.over)
}
}
ypSlideOutMenu.prototype.setVisibility = function(bShow) { 
var s = this.ns4 ? this.container : this.container.style
s.visibility = bShow ? "visible" : "hidden"
}
ypSlideOutMenu.prototype.moveTo = function(p) { 
this.style[this.orientation == "h" ? "left" : "top"] = this.ns4 ? p : p + "px"
}
ypSlideOutMenu.prototype.getPos = function(c) {
return parseInt(this.style[c])
}
ypSlideOutMenu.prototype.onactivate = function() { }
ypSlideOutMenu.prototype.ondeactivate = function() { }

var leftimage=new Array();
var rightimage=new Array();
var blurb=new Array();
var price=new Array();
var link=new Array();
leftimage[1-1]="/cars/JH2RC46A72M400274_1.jpg";
rightimage[1-1]="/cars/JH2RC46A72M400274_2.jpg";
blurb[1-1]="<B>HONDA VFR 800 F-2</B><BR> 800cc, registered 2003 (03 plate), insurance group 14, 13,500 miles";
price[1-1]="<B STYLE='font-size: 10pt; color: red;'>SAVE &pound;200</B><BR><B>&pound;4,795</B><BR><B STYLE='font-size: 10pt; color: red;'>WAS &pound;4,995";
link[1-1]="/cgi-bin/details.pl?v_vin=2RC46A72M400274JH";
leftimage[2-1]="/cars/JH2SC26C1TM000400_3.jpg";
rightimage[2-1]="/cars/JH2SC26C1TM000400_7.jpg";
blurb[2-1]="<B>HONDA ST PAN EUROPEAN ABS/TCS</B><BR> 1100cc, registered 1999 (S plate), insurance group 13, 33,000 miles";
price[2-1]="<B STYLE='font-size: 10pt; color: red;'>&nbsp;</B><BR>&pound;4,395";
link[2-1]="/cgi-bin/details.pl?v_vin=2SC26C1TM000400JH";
leftimage[3-1]="/cars/2006_1.jpg";
rightimage[3-1]="/cars/2006_2.jpg";
blurb[3-1]="<B>SUZUKI GSX 1300 - R HYABUSA</B><BR> 1300cc, registered 2006 (06 plate), insurance group 16, 2 owners, 4,500 miles";
price[3-1]="<B STYLE='font-size: 10pt; color: red;'>SAVE &pound;600</B><BR><B>&pound;5,995</B><BR><B STYLE='font-size: 10pt; color: red;'>WAS &pound;6,595";
link[3-1]="/cgi-bin/details.pl?v_vin=1a111100106207js";
leftimage[4-1]="/cars/JYARN041000011138_4.jpg";
rightimage[4-1]="/cars/JYARN041000011138_1.jpg";
blurb[4-1]="<B>YAMAHA YZF-R1 </B><BR> 1000cc, registered 2001 (Y plate), insurance group 16, 13,009 miles";
price[4-1]="<B STYLE='font-size: 10pt; color: red;'>&nbsp;</B><BR>&pound;3,995";
link[4-1]="/cgi-bin/details.pl?v_vin=ARN041000011138JY";
leftimage[5-1]="/cars/QUAD1_1.jpg";
rightimage[5-1]="/cars/QUAD1_4.jpg";
blurb[5-1]="<B>YAMAHA YF Z450</B><BR> 450cc, 1 owner, 200 miles";
price[5-1]="<B STYLE='font-size: 10pt; color: red;'>&nbsp;</B><BR>&pound;2,895";
link[5-1]="/cgi-bin/details.pl?v_vin=AD1QU";
leftimage[6-1]="/cars/SMTTF6905J6248878_5.jpg";
rightimage[6-1]="/cars/SMTTF6905J6248878_1.jpg";
blurb[6-1]="<B>TRIUMPH SPRINT ST1050 ABS</B><BR> 1050cc, registered 2005 (55 plate), insurance group 15, 2 owners, 12,200 miles";
price[6-1]="<B STYLE='font-size: 10pt; color: red;'>&nbsp;</B><BR>&pound;5,695";
link[6-1]="/cgi-bin/details.pl?v_vin=TTF6905J6248878SM";
	var carnum=Math.floor(Math.random() * (leftimage.length));
	var version=0;
	getBrowser();

	var myMenu1 = new ypSlideOutMenu("sales", "up", 0, -315, 160, 285)
	var myMenu2 = new ypSlideOutMenu("company", "up", 0, -265, 160, 205)
	var myMenu3 = new ypSlideOutMenu("contact", "up", 0, -180, 160, 150)
	var myMenu4 = new ypSlideOutMenu("location", "up", 0, -100, 160, 70)
	/*
	var myMenu1 = new ypSlideOutMenu("sales", "up", 0, -260, 160, 275)
	var myMenu2 = new ypSlideOutMenu("company", "up", 0, -210, 160, 195)
	var myMenu3 = new ypSlideOutMenu("contact", "up", 0, -125, 160, 140)
	var myMenu4 = new ypSlideOutMenu("location", "up", 0, -45, 160, 60)
	*/

	ypSlideOutMenu.writeCSS();

sales_off=new Image(100,100)
sales_off.src="/graphics/dealer/sales.png"
sales_on=new Image(100,100)
sales_on.src="/graphics/dealer/sales_on.png"
company_off=new Image(100,100)
company_off.src="/graphics/dealer/company.png"
company_on=new Image(100,100)
company_on.src="/graphics/dealer/company_on.png"
contact_off=new Image(100,100)
contact_off.src="/graphics/dealer/contact.png"
contact_on=new Image(100,100)
contact_on.src="/graphics/dealer/contact_on.png"
location_off=new Image(100,100)
location_off.src="/graphics/dealer/location.png"
location_on=new Image(100,100)
location_on.src="/graphics/dealer/location_on.png"

function filter(imagename,objectsrc){
// alert("filter(" +imagename+ "," +objectsrc+ ")" );
if (document.images)
document.images[imagename].src=eval(objectsrc+".src")
}

function picrotate(){
    if(carnum!=999){
        if(version){
            document.picleft.filters["blendTrans"].apply();
            document.picleft.src=leftimage[carnum];
            document.picleft.filters["blendTrans"].play();
            document.picright.filters["blendTrans"].apply();
			document.getElementById("plref").href=link[carnum];
            document.picright.src=rightimage[carnum];
            document.picright.filters["blendTrans"].play();
			document.getElementById("prref").href=link[carnum];
            document.getElementById("blurb").innerHTML=blurb[carnum];
            document.getElementById("price").innerHTML=price[carnum];
        }else{
            document.picleft.src=leftimage[carnum];
			document.getElementById("plref").href=link[carnum];
            document.picright.src=rightimage[carnum];
			document.getElementById("prref").href=link[carnum];
            document.getElementById("blurb").innerHTML=blurb[carnum];
            document.getElementById("price").innerHTML=price[carnum];
        }
        carnum++;
        if(carnum==leftimage.length){
            carnum=0;
        }
    }else{
        carnum=1;
    }
    setTimeout("picrotate();", 4500);
}

function getBrowser(){
    //Detect IE5.5+
    if (navigator.appVersion.indexOf("MSIE")!=-1){
    temp=navigator.appVersion.split("MSIE")
    version=parseFloat(temp[1])
    }

    if (version>=5.5) //NON IE browser will return 0
        version=1;
}
