/* Browser Detection Script */
browserVars = new browserVarsObj();
if(!browserVars.type.getById) document.captureEvents(Event.MOUSEMOVE)
document.onmousemove = new Function('e', 'browserVars.updateMouse(e)');

function browserDetect()
{
this.getById = document.getElementById?true:false;
this.layers = document.layers?true:false;
this.ns4 = ((this.layers) && (!this.getById));
this.ns6 = ((navigator.userAgent.indexOf('Netscape6') != -1) && (this.getById));
this.moz = ((navigator.appName.indexOf('Netscape') != -1) && (this.getById) && (!this.ns6));
this.ie  = ((!this.layers) && (this.getById) && (!(this.ns6 || this.moz)));
this.opera = window.opera?true:false;
}


function browserVarsObj()
{
this.updateMouse = browserVarsObjUpdateMouse;
this.updateVars = browserVarsObjUpdateVars;

this.mouseX = 0;
this.mouseY = 0;

this.type = new browserDetect();
this.width = 0;
this.height = 0
this.screenWidth = screen.width;
this.screenHeight = screen.height;
this.scrollWidth = 0;
this.scrollHeight = 0;
this.scrollLeft = 0;
this.scrollTop = 0;
this.updateVars();
}

function browserVarsObjUpdateMouse(e)
{
if(!this.type.ie)
{
this.mouseX = e.pageX;
this.mouseY = e.pageY;
}
else
{
this.mouseX = window.event.clientX + this.scrollLeft;
this.mouseY = window.event.clientY + this.scrollTop;
}
}

function browserVarsObjUpdateVars()
{
if(!this.type.getById)
{
this.width = window.innerWidth;
this.height = window.innerHeight;
this.scrollWidth = document.width;
this.scrollHeight = document.height;
this.scrollLeft = window.pageXOffset;
this.scrollTop = window.pageYOffset;
if(this.width < this.scrollWidth) this.width -= 16
if(this.height < this.scrollHeight) this.height -= 16
}
else
{
if((!(this.type.ns6 || this.type.moz)) && (document.body))
{
this.width = document.body.offsetWidth;
this.height = document.body.offsetHeight;
this.scrollWidth = document.body.scrollWidth;
this.scrollHeight = document.body.scrollHeight;
this.scrollLeft = document.body.scrollLeft;
this.scrollTop = document.body.scrollTop;
}
if((this.type.ns6 || this.type.moz) && (document.body))
{
this.width = window.innerWidth;
this.height = window.innerHeight;
this.scrollWidth = document.body.scrollWidth;
this.scrollHeight = document.body.scrollHeight;
this.scrollLeft = window.pageXOffset;
this.scrollTop = window.pageYOffset;
}
}
}


/*
Usage:
myDivObj = new divObject('myDivId', 'document.');
onload="activateDivs()"
myDiv.write('text')
myDiv.setBgColour('#xxxxxx')
myDiv.hide()
myDiv.show()
myDiv.swapImage('imgName', 'src')
myDiv.captureEvents('event', 'action')
myDiv.moveTo(x, y)
myDiv.moveby(x, y)
myDiv.resizeTo(x, y)
myDiv.resizeBy(x, y)
myDiv.clip(top, left, width, height)
*/

divObjectArray = new Array();

function activateDivs()
{
for(var x=0; x<divObjectArray.length; x++)
divObjectArray[x].activate();
}

function divObject(divName, parent)
{
if(!browserVars.type.getById)
{
this.div = parent + divName;
this.baseDiv = parent + divName;
this.divName = parent + divName;
this.write = new Function("text", "this.div.document.open(); this.div.document.write(text); this.div.document.close(); this.width = this.div.clip.width; this.height = this.div.clip.height;");
this.setBgColour = new Function("colour", "this.div.bgColor = colour;");
this.setBgImage = new Function("src", "this.div.bgImage = 'url(' + src + ')';");
this.hide = new Function("this.div.visibility = 'hide';");
this.show = new Function("this.div.visibility = 'inherit';");
this.setSize = new Function("left", "top", "width", "height", "this.div.clip.left = left; this.div.clip.top = top; this.div.clip.width = width; this.div.clip.height = height; this.div.width = width; this.div.height = height; this.div.clip.height = height; this.width = width; this.height = height;");
this.swapImage = new Function("image", "src", "this.div.document.images[image].src = src");
this.getImageSrc = new Function("image", "return this.div.document.images[image].src");
}
else
{
this.div = divName;
this.baseDiv = divName;
this.divName = divName;
this.write = new Function("text", "document.getElementById('" + divName + "').innerHTML = text; this.width = this.baseDiv.offsetWidth; this.height = this.baseDiv.offsetHeight;");
this.setBgColour = new Function("colour", "this.div.backgroundColor = colour;");
this.setBgImage = new Function("src", "this.div.backgroundImage = 'url(' + src + ')';");
this.hide = new Function("this.div.visibility = 'hidden';");
this.show = new Function("this.div.visibility = 'inherit';");
this.setSize = new Function("left", "top", "width", "height", "setWidthAndHeight", "this.div.clip = 'rect(' + top + ',' + (left+width) + ',' + (top+height) + ',' + left + ')'; if(setWidthAndHeight != false){this.div.width = width; this.div.height = height; this.width = width; this.height = height;}");
this.swapImage = new Function("image", "src", "document.images[image].src = src");
this.getImageSrc = new Function("image", "return document.images[image].src");
}
this.activate = activateDiv;
this.setXY = new Function("x", "y", "this.div.left = x; this.div.top = y;");
this.captureEvents = captureDivEvents;
this.idNo = divObjectArray.length;
divObjectArray[divObjectArray.length] = this;

this.width = 0;
this.height = 0;
this.originalWidth = 0;
this.originalHeight = 0;
this.left = 0;
this.top = 0;
this.clipLeft = 0;
this.clipTop = 0;

this.moveTo = new Function("x", "y", "this.left=x; this.top=y; this.setXY(x, y)");
this.moveBy = new Function("x", "y", "this.left+=x; this.top+=y; this.setXY(this.left, this.top)");
this.resizeTo = new Function("x", "y", "this.width=x; this.height=y; this.setSize(this.clipLeft, this.clipTop, this.width, this.height)");
this.resizeBy = new Function("x", "y", "this.width+=x; this.height+=y; this.setSize(this.clipLeft, this.clipTop, this.width, this.height)");
this.clip = new Function("left", "top", "width", "height", "setWidthAndHeight", "this.clipLeft=left; this.clipTop=top; this.clipWidth=width; this.clipHeight=height; this.setSize(left, top, width, height, setWidthAndHeight);");
this.setZIndex = new Function("z", "this.div.zIndex=z;");
}


function activateDiv()
{
if(typeof(this.div) != 'string') return;

if(!browserVars.type.getById)
{
this.baseDiv = eval(this.div);
this.div = this.baseDiv

this.width = this.div.clip.width;
this.height = this.div.clip.height;
this.left = this.div.left;
this.top = this.div.top;
}
else
{
this.baseDiv = document.getElementById(this.div);
this.div = this.baseDiv.style;

this.width = this.baseDiv.offsetWidth;
this.height = this.baseDiv.offsetHeight;
this.left = this.baseDiv.offsetLeft;
this.top = this.baseDiv.offsetTop;
}

this.clipWidth = this.width;
this.clipHeight = this.height;
this.originalWidth = this.width;
this.originalHeight = this.height;
}


function captureDivEvents(eventName, action)
{
if(!browserVars.type.getById)
eval('this.div.captureEvents(Event.' + eventName.toUpperCase() + ')');
eval('this.baseDiv.on' + eventName + ' = new Function("e", "' + action + '")');
}

hintArray = new Array();

myHint = new hint(false, '#C0C0C0', 1);
myHint2 = new hint(true);



function hint(moveWithMouse, bgColour, delay)
{
        this.id = hintArray.length;
        hintArray[this.id] = this;
        this.CSS = '#hintDiv' + this.id + ' {position:absolute; padding:5px; border:1px #47CD56 solid; visibility:hidden;z-index:100;}';
        this.HTML = '<div id="hintDiv' + this.id + '"> </div>';
        this.div = new divObject('hintDiv' + this.id, 'document.');
        this.activate = new Function("this.div.activate(); this.div.setBgColour(this.backgroundColour);");
        this.show = hintShow;
        this.shown = false;
        this.backgroundColour = bgColour!=null?bgColour:'#FFFFE1';
        this.delay = delay!=null?delay:0;
        this.showTimer = false;
        this.setBackgroundColour = new Function("bgColour", "this.backgroundColour = bgColour; this.div.setBgColour(bgColour);");
        this.move = hintMove;
        this.moveTimer = setInterval('if(hintArray[' + this.id + '].moveWithMouse) hintArray[' + this.id + '].move();', 50);
        this.moveWithMouse = moveWithMouse;
        this.width = 0;
}



function hintShow(message)
{
        if(typeof(message) == 'undefined')
        {
                if(this.showTimer) clearTimeout(this.showTimer);
                this.showTimer = false;
                this.div.hide();
                this.shown = false;
                return;
        }

        this.div.write('<nobr>' + message + '</nobr>');
        this.move();

        if(browserVars.type.ns4) this.width = this.div.div.clip.width;
        else this.width = this.div.baseDiv.offsetWidth;

        this.showTimer = setTimeout('hintArray[' + this.id + '].div.show(); hintArray[' + this.id + '].shown = true;', this.delay);
}



function hintMove()
{
        browserVars.updateVars();
        var screenRight = browserVars.scrollLeft + browserVars.width - 30;
        var x = browserVars.mouseX + 16;
        var y = browserVars.mouseY + 16;

        if(x + this.width > screenRight)
        {
                x = screenRight - this.width - 20;
                y += 16;
        }

        if(x < 0) x = 0;

        this.div.moveTo(x, y);
}



function writeHints()
{
        var CSS = '';
        var HTML = ''
        for(var x=0; x<hintArray.length; x++)
        {
                CSS += hintArray[x].CSS;
                HTML += hintArray[x].HTML;
        }
        return '<style>' + CSS + '</style>' + HTML;
}



function activateHints()
{
        for(var x=0; x<hintArray.length; x++)
                hintArray[x].activate();
}


