
//
// JavaScript File that includes all code for rollovers
// Author: Claire Airth
// Created: 05 Oct. 2004
//


///////////////////////////////////
// Get the type of browser used. //
///////////////////////////////////
var ns;

if ( navigator.appName == "Microsoft Internet Explorer" ){
    ns = false;
} else {
    ns = true;
}

var clientEvent;

function rollover(name, capacity, spaces, updated, event){

    clientEvent = event;

    //var spaces = capacity - occupancy;

    var txt = "";

    txt = "<table class='rollover'><tr><td colspan=2 class='carPark'>" + name + "</td></tr>";
    txt += "<tr><td class='fields'>Capacity: </td><td>" + capacity +"</td></tr>";
    txt += "<tr><td class='fields'>Spaces Left: </td><td>" + spaces +"</td></tr>";
    txt += "<tr><td class='fields'>Last Updated: </td><td>" + updated +"</td></tr>";
    txt += "</table>";

    editLayer(txt);

}



///////////////////////////////////
// Control the layers visibility //
///////////////////////////////////

function makeVisible(bool){

    var lyr = document.getElementById("lyr");

    if ( bool == true ){
        lyr.style.visibility = "visible";
    } else {
        lyr.style.visibility = "hidden";
    }
}


//////////////////////////////////////
// Edit the layer with the new text //
//////////////////////////////////////

function editLayer( txt ) {

    var lyr = document.getElementById("lyr");

    lyr.innerHTML = txt;

    moveLayer();
    makeVisible(true);

}



////////////////////////////////////////////////////
// Move the layer to the left of the mouse cursor //
////////////////////////////////////////////////////

function moveLayer() {

    var lyr = document.getElementById("lyr");

    // Set the layer offset depending on the rollover icon
    var lyrOffsetX = 0;
    var lyrOffsetY = 0;

    var cursorX = ( ns ) ? clientEvent.layerX : event.clientX;
    var cursorY = ( ns ) ? clientEvent.layerY : event.clientY;

    // this will stop the cursorY becoming zero
    // this a fix for NN6

    if ( cursorY != 0 ){
        oldCursorY = cursorY;
    } else {
        cursorY = oldCursorY;
    }

    if ( cursorX != 0 ){
        oldCursorX = cursorX;
    } else {
        cursorX = oldCursorX;
    }

    // convert the top coordinate into a integer striping out the "px" ar the end

    var topString = lyr.style.top
    topInteger = parseInt( topString.substr( 0, topString.length -2 ) );


    // if the top coordinate is negative change this coordinate to 0px

    if ( topInteger < 0 ){
        lyr.style.top = 0 + "px";
    }
/*
    cursorX = cursorX - 405;
    if ( cursorY > 250 ){
        cursorY = 250;
    }
*/
    lyr.style.left = cursorX;
    lyr.style.top = cursorY;

}


