﻿jQuery.fn.exists = function () { return jQuery(this).length > 0; }

function UrlEscape(str) {
    str = str.replace("%", "%25");
    str = str.replace(" ", "%20");
    str = str.replace("<", "%3C");
    str = str.replace(">", "%3E");
    str = str.replace("#", "%23");
    str = str.replace("{", "%7B");
    str = str.replace("}", "%7D");
    str = str.replace("|", "%7C");
    str = str.replace("\\", "%5C");
    str = str.replace("^", "%5E");
    str = str.replace("~", "%7E");
    str = str.replace("[", "%5B");
    str = str.replace("]", "%5D");
    str = str.replace("`", "%60");
    str = str.replace(";", "%3B");
    str = str.replace("/", "%2F");
    str = str.replace("?", "%3F");
    str = str.replace(":", "%3A");
    str = str.replace("@", "%40");
    str = str.replace("=", "%3D");
    str = str.replace("&", "%26");
    str = str.replace("$", "%24");
    return str;
}
$(document).ready(function () {
    $(".search-field-text").val("Search Website");
});
$(".search-field-text").focus(function () {
    if ($(this).val() == "Search Website") {
        $(this).val("");
    }
});
$(".search-field-text").blur(function () {
    if ($(this).val() == "") {
        $(this).val("Search Website");
    }
});
if ($(".btn-email").exists()) {
    $(".btn-email").click(function () {
        window.open("mailto:?subject=" + UrlEscape("From the Pretty in Pink Foundation Website") + "&body=" + UrlEscape("This information might interest you: ") + window.location);
    });
}
if ($(".btn-print").exists()) {
    $(".btn-print").click(function () {
        window.print();
    });
}
if ($(".btn").exists() && $(".btn-hover").exists()) {
    $(".btn").mouseover(function () {
        $(this).css("display", "none");
        $(this).next(".btn-hover").css("display", "inline");
    });
    $(".btn-hover").mouseout(function () {
        $(this).css("display", "none");
        $(this).prev(".btn").css("display", "inline");
    });
}
if ($("#shop-tab-ShopPink").exists() && $("#shop-tab-ShopToGive").exists()) {
    $("#shop-tab-ShopPink .shop-tab-btn").click(function () {
        $("#shop-tab-ShopPink").css("display", "none");
        $("#shop-tab-ShopToGive").css("display", "block");
    });
    $("#shop-tab-ShopToGive .shop-tab-btn").click(function () {
        $("#shop-tab-ShopToGive").css("display", "none");
        $("#shop-tab-ShopPink").css("display", "block");
    });
}
var booShopPinkIsScrolling = false;
if ($("#shop-tab-ShopPink .product-thumbnails").exists()) {
    var scroller = $("#shop-tab-ShopPink .scroller");
    if (scroller.children("a").length <= 2) {
        $("#shop-tab-ShopPink .left-button").css("visibility", "hidden");
        $("#shop-tab-ShopPink .right-button").css("visibility", "hidden");
        if (scroller.children("a").length == 1) {
            $("#shop-tab-ShopPink .scroller a").css("margin-left", "50px");
        }
    } else {
        $("#shop-tab-ShopPink .left-button").click(function () {
            if (!booShopPinkIsScrolling) {
                booShopPinkIsScrolling = true;
                scroller.css("left", "-100px").prepend(scroller.children("a:last")).animate({ left: '+=100' }, 500, function () {
                    booShopPinkIsScrolling = false;
                });
            }
        });
        $("#shop-tab-ShopPink .right-button").click(function () {
            if (!booShopPinkIsScrolling) {
                booShopPinkIsScrolling = true;
                scroller.animate({ left: '-=100' }, 500, function () {
                    scroller.append(scroller.children("a:first")).css("left", "0px");
                    booShopPinkIsScrolling = false;
                });
            }
        });
    }
}
if ($(".EnlargeThumbnail-container").exists()) {
    $(".EnlargeThumbnail-container").prepend("<div class='EnlargeThumbnail-close2' style='text-align:right;'><img src='ControlPanel/images/btn_X_gray.gif' alt='Close' onclick='HideFullsize()' /></div>");
}
