function buttonOver() {
    thewrap = document.getElementById('wrapper');
    buttons = thewrap.getElementsByTagName('input');
    preLoadBtns = new Array();

    for (i = 0; i < buttons.length; i++) {
        if(buttons[i].getAttribute('type') == 'image') {
            preLoadBtns[i] = new Image;
            preLoadBtns[i].src = buttons[i].src.substring(0, buttons[i].src.length - 4) + "2.jpg";

            buttons[i].onmouseover = function() {
                this.src = this.src.substring(0, this.src.length - 4) + "2.jpg";
            }
            buttons[i].onmouseout = function() {
                if (this.src.substring( (this.src.length - 5) , (this.src.length) ) == "2.jpg" ) {
                    this.src = this.src.substring(0, this.src.length - 5) + ".jpg";
                }
            }
        }
    }
}

function imageOver() {
    thewrap = document.getElementById('wrapper');
    images = thewrap.getElementsByTagName('img');
    preLoadImgs = new Array();

    for (i = 0; i < images.length; i++) {
        if(images[i].className.substring(0, 5) == "hover") {
            preLoadImgs[i] = new Image;
            preLoadImgs[i].src = images[i].src.substring(0, images[i].src.length - 4) + "2.jpg";

            images[i].onmouseover = function() {
                this.src = this.src.substring(0, this.src.length - 4) + "2.jpg";
            }
            images[i].onmouseout = function() {
                if (this.src.substring( (this.src.length - 5) , (this.src.length) ) == "2.jpg" ) {
                    this.src = this.src.substring(0, this.src.length - 5) + ".jpg";
                }
            }
        }
    }
}

function doBookmark(title, url) {
    if (window.sidebar) { // Mozilla Firefox Bookmark
        window.sidebar.addPanel(title, url,"");
    } else if ( window.external ) { // IE Favorite
        window.external.AddFavorite( url, title); 
    } else if (window.opera && window.print) { // Opera Hotlist
        return true;
    }
}

function searchWidget() {
    if(objExists('search')) {
        var search = document.getElementById('search');
        if(search.value == "" || search.value == "Enter search term") {
            search.style.color = "#C1C1C1";
            search.value = "Enter search term";
        }
        search.onblur = function() {
            if(this.value == "") {
                this.style.color = "#C1C1C1";
                this.value = "Enter search term";
            }
        }
        search.onfocus = function() {
            if(this.value == "Enter search term") {
                this.value = "";
                this.style.color = "#1F6976";
            }
        }
    }
}

function swapImage(image) {
    document.getElementById('mainImage').src = image;
}

function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    } else {
        window.onload = function() {
            oldonload();
            func();
        }
    }
}

function addUnloadEvent(func) {
    var oldonunload = window.onunload;
    if (typeof window.onunload != 'function') {
        window.onunload = func;
    } else {
        window.onunload = function() {
            oldonunload();
            func();
        }
    }
}

function objExists(theVal) {
    if (document.getElementById(theVal) != null) {
        return true;
    } else {
        return false;
    }
}

addLoadEvent(buttonOver);
addLoadEvent(imageOver);
addLoadEvent(searchWidget);
