//
// Scripts for Needlecraft.
//
// @author Tom Ryder <tom@prodev.co.nz>
// @copyright 2010 Professional Development
//
"use strict";
$(window).addEvent("domready", function () {

	// Focus class setup.
    $$("input,select").addEvent("focus", function () {
        this.addClass("focus");
    }).addEvent("blur", function () {
        this.removeClass("focus");
    });

    // Keep faded grey text in the search box when empty.
    (function () {
        var message = "Enter keywords here",
            active = {"color": "#000000"},
            inactive = {"color": "#959595"},
            empty = "",
            text = $("search-keywords"),
            form = $(text.form);
        if (text && form) {
            text.addEvents({
                "focus": function () {
                    this.setStyles(active);
                    if (this.get("value") === message) {
                        this.set("value", empty);
                    }
                },
                "blur": function () {
                    if (this.get("value") === empty || this.get("value") === message) {
                        this.setStyles(inactive);
                        this.set("value", message);
                    }
                }
            });
            text.fireEvent("blur");
            form.addEvent("submit", function () {
                if (text.get("value") === message) {
                    text.set("value", empty);
                }
            });
        }
    }());
});

