﻿/* Scripts common to all pages */

document.observe("dom:loaded", function() {
    setImgBtnHover();
    searchTextClearOnClick();

    /* watch click on lightwindow anchors, and store rel for target pages to read (such as lightwindow) */
    $$('a.lightwindow').invoke("observe", "mousedown", function(e) {
        var ancElement = e.element();
        var ancRel = ancElement.getAttribute("rel");
        location.hash = ancRel;
        Event.stop(e);
    });



});

function clearInput(defaultTxt) {
    if (defaultTxt == $F("search-q")) { $("search-q").clear(); }
}

function resetInput(defaultTxt) {
    if ($F("search-q") == "") { $("search-q").value = defaultTxt; }
}

function setImgBtnHover() {
    var goBtn = $$("fieldset#search_form button")[0];
    if (goBtn) {
        var hoverImg = goBtn.down("img");
        var origImgSrc = hoverImg.src;
            
        goBtn.observe("mouseover", function() {
            var splitImgPath = hoverImg.src.split(".");
            hoverImg.src = splitImgPath[0] + "_hover." + splitImgPath[1];
        });

        goBtn.observe("mouseout", function() {
            hoverImg.src = origImgSrc;
        });
    }
}

function searchTextClearOnClick() {
    var searchTextBox = $$("fieldset#search_form input[name=query]")[0];
    
    if (searchTextBox) {
        searchTextBox.observe("focus", function() {
            if(this.value == "Search") {
                this.value = "";
            }
        });
        
        searchTextBox.observe("blur", function() {
            if(this.value == "") {
                this.value = "Search"
            }
        });
    }
}