﻿/// <reference path="jquery-1.4.1-vsdoc.js" />


function SiteLib() { }

SiteLib.Property1 = "value";

SiteLib.ConfirmMsg = function ConfirmMsg(txt, funcOK, funcCancel) {
    ///	<summary>
    /// Shows a confirmation message, with callback functions
    ///	</summary>
    var result = confirm(txt);

    if (result)
        if (funcOK) funcOK();
        else
            if (funcCancel) funcCancel();

    return result;
}



SiteLib.TextBoxWatermark = function TextBoxWatermark(id, text) {
    var el = $("#" + id);
    el.addClass("inputUnactive");
    el.val(text);

    el.focusin(function () {
        $(this).val("");
        $(this).addClass("inputFocus");
    });

    el.focusout(function () {
        var vl = $(this).val();
        if (!vl) {
            $(this).val(text);
            $(this).removeClass("inputFocus");
        }
    });
}


SiteLib.Windowize = function Windowize(id) {
    ///	<summary>
    /// Surrounds an element with a "window" style.
    /// make element id starts with win_, and define some width.
    ///	</summary>
    var win = $(id);
    var content = win.html();

    var ld = document.createElement("DIV");
    var md = document.createElement("DIV");
    var rd = document.createElement("DIV");

    win.addClass("win");
    $(ld).addClass("l");
    $(md).addClass("m");
    $(md).width(win.width() - (21 * 2) - 40); // 40 = padding
    $(md).html(content);
    $(rd).addClass("r");

    win.html("");
    win.append(ld);
    win.append(md);
    win.append(rd);
}

/*inits*/
$(function () {
    SiteLib.TextBoxWatermark("q", "Search Site...");

    $("div[id^=win_]").each(function (e) {
        SiteLib.Windowize(this);
    });

    $('div[move-to]').each(function () {
        $(this).appendTo($(this).attr('move-to'));
    });
});
