/*****************************************************
* 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/025003_1.jpg";
rightimage[1-1]="/cars/025003_4.jpg";
blurb[1-1]="<B>YAMAHA MT-03 </B><BR> 660cc, registered 2010, insurance group 10";
price[1-1]="<B STYLE='font-size: 10pt; color: red;'>&nbsp;</B><BR>&pound;5,999";
link[1-1]="/cgi-bin/details.pl?v_vin=500302";
leftimage[2-1]="/cars/JKAZX600PPA007319_1.jpg";
rightimage[2-1]="/cars/JKAZX600PPA007319_2.jpg";
blurb[2-1]="<B>KAWASAKI ZX -6R  NINJA</B><BR>registered 2007 (07 plate), insurance group 16, 1 owner, 1,800 miles";
price[2-1]="<B STYLE='font-size: 10pt; color: red;'>SAVE &pound;500</B><BR><B>&pound;5,295</B><BR><B STYLE='font-size: 10pt; color: red;'>WAS &pound;5,795";
link[2-1]="/cgi-bin/details.pl?v_vin=AZX600PPA007319JK";
leftimage[3-1]="/cars/JYARJ199000002837_5.jpg";
rightimage[3-1]="/cars/JYARJ199000002837_1.jpg";
blurb[3-1]="<B>YAMAHA XJ 6 DIVERSION F</B><BR> 600cc, registered 2010 (10 plate), insurance group 10";
price[3-1]="<B STYLE='font-size: 10pt; color: red;'>&nbsp;</B><BR>&pound;6,295";
link[3-1]="/cgi-bin/details.pl?v_vin=ARJ199000002837JY";
leftimage[4-1]="/cars/JYARN221000001625_1.jpg";
rightimage[4-1]="/cars/JYARN221000001625_2.jpg";
blurb[4-1]="<B>YAMAHA YZF-R1 2009 / 2010 RACE BIKE</B><BR> 1000cc, registered 2009, 1 owner, 500 miles";
price[4-1]="<B STYLE='font-size: 10pt; color: red;'>SAVE &pound;4</B><BR><B>&pound;9,995</B><BR><B STYLE='font-size: 10pt; color: red;'>WAS &pound;9,999";
link[4-1]="/cgi-bin/details.pl?v_vin=ARN221000001625JY";
leftimage[5-1]="/cars/QUAD3_1.jpg";
rightimage[5-1]="/cars/QUAD3_3.jpg";
blurb[5-1]="<B>YAMOTO PY80 110</B><BR> 110cc, 1 owner, 500 miles";
price[5-1]="<B STYLE='font-size: 10pt; color: red;'>&nbsp;</B><BR>&pound;895";
link[5-1]="/cgi-bin/details.pl?v_vin=AD3QU";
leftimage[6-1]="/cars/SMTTF6915J6276313_5.jpg";
rightimage[6-1]="/cars/SMTTF6915J6276313_2.jpg";
blurb[6-1]="<B>TRIUMPH SPRINT ST 1050 A.B.S.</B><BR> 1050cc, registered 2006 (06 plate), insurance group 15, 1 owner, 6,900 miles";
price[6-1]="<B STYLE='font-size: 10pt; color: red;'>&nbsp;</B><BR>&pound;6,495";
link[6-1]="/cgi-bin/details.pl?v_vin=TTF6915J6276313SM";
	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;
}
