var ua = navigator.userAgent.toLowerCase();
var isW3C = (document.getElementById) ? true : false
var isAll = (document.all) ? true : false
var isSafari = false;
if (ua.indexOf("safari") != -1) { isSafari = true; }
var preloadFlag = false;
var loadingFlag = true;

// PRELOADING MOUSEOVER IMAGES
function createObject(imgName,imgSrc) {
    if (loadingFlag) {
        eval(imgName + ' = new Image()');
        eval(imgName + '.src = "' + imgSrc + '"');
        return imgName;
    }
}


// MOUSEOVER IMAGE SWITCHING
function changeImage(layer,imgName,imgObj) {
    if (preloadFlag) {
        if (isW3C) {
            document.getElementById(imgName).src = eval(imgObj+'.src');
        } else {
            document.images[imgName].src = eval(imgObj+'.src');
        }
    }
}


// REMOVES THE LINK BORDER IN IE4+, NS6
function unblur() {
    this.blur();
}

function getLinksToBlur() {
    if ((isW3C) || (isAll)) {
        if (isW3C) {
            links = document.getElementsByTagName("a");
        } else {
            links = document.all.tags("a");
        }
        for(i=0; i<links.length; i++) {
            links[i].onfocus = unblur
        }
    }
}


// GENERIC CLASS SWITCHER
function cSwitcher(thisId,newClass) {
    if (isW3C) {
        d = document.getElementById(thisId);
        d.className = newClass;
    } else {
        d = document.all[thisId];
        d.className = newClass;
    }
}


// DOM / GET PROPERTY
function getIdProperty(id,property) {
    var styleObject = document.getElementById( id );
    if (styleObject != null) {
        styleObject = styleObject.style;
            if (styleObject[property]) {
                return styleObject[ property ];
            }
        }
    return (styleObject != null) ?
    styleObject[property] :
    null;
}


// DOM / SET PROPERTY
function setIdProperty(id,property,value) {
    var styleObject = document.getElementById( id );
    if (styleObject != null) {
        styleObject = styleObject.style;
        styleObject[ property ] = value;
    }
}


// HIDE AND SHOW LAYERS
function hide(id) {
    if (isW3C) {
        setIdProperty(id,"visibility","hidden");
    } else {
        document.all[id].style.visibility = "hidden";
    }
}

function show(id) {
    if (isW3C) {
        setIdProperty(id,"visibility","visible");
    } else { 
        document.all[id].style.visibility = "visible";
    }
}


// CHANGE DISPLAY VALUE FOR LAYERS
function switchDisplay(id,value) {
    if (isW3C) {
        setIdProperty(id,"display",value);
    } else {
        document.all[id].style.display = value;
    }
}


// ANTI-SPAM
function antispam(name,domain) {
    document.location = "mailto:" + name + "@" + domain;
}

// NOTOP FOR LINKS
function notop() {}

// MOOTOOLS FIX
// Fixes Mootools' garbage collecting to not remove document.getElementById
Garbage._trash = Garbage.trash;
Garbage.trash = function(elements) {
    var _getElementById = document.getElementById;
    Garbage._trash(elements);
    document.getElementById = _getElementById;
}

// Domready!

var oScroller;

window.addEvent('domready', function() {
    getLinksToBlur();
    oScroller = new Fx.Scroll(window);
});
