﻿function emailFieldFocus(target) {
    if (target.value == "enter email address")
        target.value = "";
}
function emailFieldBlur(target) {
    if (target.value == "")
        target.value = "enter email address";
}

function searchFieldFocus(target) {
    if (target.value == "search this site")
        target.value = "";
}
function searchFieldBlur(target) {
    if (target.value == "")
        target.value = "search this site";
}

function MM_findObj(n, d) { //v4.01
    var p, i, x; if (!d) d = document; if ((p = n.indexOf("?")) > 0 && parent.frames.length) {
        d = parent.frames[n.substring(p + 1)].document; n = n.substring(0, p);
    }
    if (!(x = d[n]) && d.all) x = d.all[n]; for (i = 0; !x && i < d.forms.length; i++) x = d.forms[i][n];
    for (i = 0; !x && d.layers && i < d.layers.length; i++) x = MM_findObj(n, d.layers[i].document);
    if (!x && d.getElementById) x = d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
    var i, j = 0, x, a = MM_swapImage.arguments; document.MM_sr = new Array; for (i = 0; i < (a.length - 2); i += 3)
        if ((x = MM_findObj(a[i])) != null) { document.MM_sr[j++] = x; if (!x.oSrc) x.oSrc = x.src; x.src = a[i + 2]; }
}
function MM_swapImgRestore() { //v3.0
    var i, x, a = document.MM_sr; for (i = 0; a && i < a.length && (x = a[i]) && x.oSrc; i++) x.src = x.oSrc;
}

function MM_preloadImages() { //v3.0
    var d = document; if (d.images) {
        if (!d.MM_p) d.MM_p = new Array();
        var i, j = d.MM_p.length, a = MM_preloadImages.arguments; for (i = 0; i < a.length; i++)
            if (a[i].indexOf("#") != 0) { d.MM_p[j] = new Image; d.MM_p[j++].src = a[i]; }
    }
}
function getf2OverImageUrl(url) {
    var newUrl = url.substring(0, url.lastIndexOf("."));

    return newUrl + "_f2" + url.substring(url.lastIndexOf("."));

}
function getf2UpImageUrl(url) {
    var newUrl = url.substring(0, url.lastIndexOf("."));
    if (newUrl.substr(newUrl.length - 3, 3) == "_f2") {
        return newUrl.substr(0, newUrl.length - 3) + url.substring(url.lastIndexOf("."));
    } else {
        return url;
    }
}
function getOverImageUrl(url) {
    var newUrl = url.substring(0, url.lastIndexOf("."));
    if (newUrl.substr(newUrl.length - 2, 2) == "Up") {
        return newUrl.substr(0, newUrl.length - 2) + "Over" + url.substring(url.lastIndexOf("."));
    } else {
        return url;
    }
}
function getUpImageUrl(url) {
    var newUrl = url.substring(0, url.lastIndexOf("."));
    if (newUrl.substr(newUrl.length - 4, 4) == "Over") {
        return newUrl.substr(0, newUrl.length - 4) + "Up" + url.substring(url.lastIndexOf("."));
    } else {
        return url;
    }
}
if (window.jQuery) {
    jQuery.noConflict();
    function f2Over() {
        this.src = getf2OverImageUrl(this.src);
    }
    function f2Out() {
        this.src = getf2UpImageUrl(this.src);
    }
    function overUpOver() {
        this.src = getOverImageUrl(this.src);
    }
    function overUpOut() {
        this.src = getUpImageUrl(this.src);
    }
    function loadImages() {
        var overUpImages = jQuery(".overUp img, input.overUp, img.overUp");
        for (var i = 0; i < overUpImages.length; i++) {
            var img = new Image;
            img.src = getOverImageUrl(overUpImages[i].src);

        }
        var f2Images = jQuery(".f2 img, input.f2, img.f2");
        for (var i = 0; i < f2Images.length; i++) {
            var img = new Image;
            img.src = getf2OverImageUrl(f2Images[i].src);
        }
        jQuery(".f2 img, input.f2, img.f2").unbind("mouseover", f2Over);
        jQuery(".f2 img, input.f2, img.f2").unbind("mouseout", f2Out);
        jQuery(".f2 img, input.f2, img.f2").mouseover(f2Over);
        jQuery(".f2 img, input.f2, img.f2").mouseout(f2Out);
        jQuery(".overUp img, input.overUp, img.overUp").unbind("mouseover", overUpOver);
        jQuery(".overUp img, input.overUp, img.overUp").unbind("mouseout", overUpOut);
        jQuery(".overUp img, input.overUp, img.overUp").mouseover(overUpOver);
        jQuery(".overUp img, input.overUp, img.overUp").mouseout(overUpOut);
    }
    function ValidateEmail(source, arguments) {
        if (jQuery("select.method").val() == "E-Mail") {
            arguments.IsValid = (jQuery("input.emailField").val().length);
        } else {
            arguments.IsValid = true;
        }
    }
    function ValidatePhone(source, arguments) {

        if (jQuery("select.method").val() == "Phone Number") {
            arguments.IsValid = (jQuery("input.phoneField").val().length);
        } else {
            arguments.IsValid = true;
        }
    }
    function ValidateVp(source, arguments) {

        if (jQuery("select.method").val() == "VP Number") {
            arguments.IsValid = (jQuery("input.vpField").val().length);
        } else {
            arguments.IsValid = true;
        }
    }
    function ValidateFax(source, arguments) {

        if (jQuery("select.method").val() == "Fax Number") {
            arguments.IsValid = (jQuery("input.faxField").val().length);
        } else {
            arguments.IsValid = true;
        }
    }
    function s() {
        var emailBox = jQuery(".EmailBox")[0];
        if ((emailBox.value.length > 0) && (emailBox.value.indexOf("@", 0) > 0)) {
            subscribe(emailBox.value);
            alert("Thank you for subscribing");
        }
    }
    jQuery(document).ready(function () {

        loadImages();
        if (jQuery("div.rotation").length > 0) {
            jQuery("div.rotation").cycle({
                fx: 'fade',
                speed: 2500,
                timeout: 300
            });
        }
        var leafs = jQuery('.AspNet-Menu-Leaf');
        var parentHtml = null;
        var parent = null;
        var width = 0;
        for (var i = 0; i < leafs.length; i++) {
            if (!(jQuery(leafs[i]).parent().hasClass("AspNet-Menu"))) {
                if (parentHtml != jQuery(leafs[i]).parent().html()) {
                    if (parentHtml != null) {
                        jQuery(parent).css("width", width);
                        jQuery(parent).children().css("width", width);
                    }
                    parentHtml = jQuery(leafs[i]).parent().html();
                    parent = jQuery(leafs[i]).parent();
                    width = 0;
                }
                if (width < jQuery(leafs[i]).width()) {
                    width = jQuery(leafs[i]).width();
                }
            }
        }
        if (parent != null) {
            jQuery(parent).css("width", width);
            jQuery(parent).children().css("width", width);
        }
    });
}


function BubbleSort(arr) {
    var temp;
    var exchange;
    for (var i = 0; i < arr.length; i++) {
        exchange = false;
        for (var j = arr.length - 2; j >= i; j--) {
            if (GalleryFormatTimeHTML(arr[j + 1].Time) > GalleryFormatTimeHTML(arr[j].Time)) {
                temp = arr[j + 1];
                arr[j + 1] = arr[j];
                arr[j] = temp;
                exchange = true;
            }
        }
        if (!exchange) break;
    }
    return arr;
}







function subscribe(email) {
    StonehouseMedia.Alternatives.Web.UI.Site.Subscribe(email, "");
}
