(function ($) {

    $.fn.extend({
        outerHTML: function (value) {

            // Replaces the content
            if (typeof value === "string") {
                var $this = $(this),
					$parent = $this.parent();

                var replaceElements = function () {

                    // For some reason sometimes images are not replaced properly so we get rid of them first
                    var $img = $this.find("img");
                    if ($img.length > 0) {
                        $img.remove();
                    }

                    var element;
                    $(value).map(function () {
                        element = $(this);
                        $this.replaceWith(element);
                    })

                    return element;

                }

                return replaceElements();

                // Returns the value
            } else {
                return $("<div />").append($(this).clone()).html();
            }

        }
    });

})(jQuery);

$(document).ready(function () {
    //    Top Icons Nav
    //    $(".ico-fontsize").click(function () {
    //        $(".header-panels-fontsize").slideToggle("slow");
    //    });
    //    $(".ico-fontsize-close").click(function () {
    //        $(".header-panels-fontsize").slideToggle("slow");
    //    });

    //    $(".ico-search").click(function () {
    //        $(".header-panels-search").slideToggle("slow");
    //    });
    //    $(".ico-search-close").click(function () {
    //        $(".header-panels-search").slideToggle("slow");
    //    });

    //    $(".ico-newsletter").click(function () {
    //        $(".header-panels-newsletter").slideToggle("slow");
    //    });
    //    $(".ico-newsletter-close").click(function () {
    //        $(".header-panels-newsletter").slideToggle("slow");
    //    });

    //Category Nav
    $(".block-story-navigation, .block-connect-navigation, .block-category-navigation").hover(showChilds, hideChilds);

    $(".product-grid .product-item .add-info").hover(function () {
        var title = $(this).children(".product-title");
        title.css("background-image", "url('/App_Themes/Sabi/images/arrow_open.png')");
    }, function () {
        var title = $(this).children(".product-title");
        title.css("background-image", "url('/App_Themes/Sabi/images/arrow_probox.png')");
    });
    //    $(".block-story-navigation, .block-category-navigation").hoverIntent({
    //        sensitivity: 1,
    //        interval: 1,
    //        over: showChilds,
    //        timeout: 500,
    //        out: hideChilds
    //    });
    //    $('.header-menu-item .listbox li a').mouseover(function () {
    //        $(this).animate({ paddingLeft: "7px" }, 50);
    //    });
    //    $('.header-menu-item .listbox li a').mouseout(function () {
    //        $(this).animate({ paddingLeft: "5px" }, 50);
    //    });

    $(".f12,.f14,.f16").click(function () {
        //$(".f12,.f14,.f16").css('font-weight', 'normal');
        //$(this).css('font-weight', 'bold');
        $(".f12").css("background-image", "url('/App_Themes/Sabi/images/size_01_off.gif')");
        $(".f14").css("background-image", "url('/App_Themes/Sabi/images/size_02_off.gif')");
        $(".f16").css("background-image", "url('/App_Themes/Sabi/images/size_03_off.gif')");
        switch ($(this)[0].className) {
            case "f12":
                $(this).css("background-image", "url('/App_Themes/Sabi/images/size_01_on.gif')");
                break;
            case "f14":
                $(this).css("background-image", "url('/App_Themes/Sabi/images/size_02_on.gif')");
                break;
            case "f16":
                $(this).css("background-image", "url('/App_Themes/Sabi/images/size_03_on.gif')");
                break;
        }
        $('.master-wrapper-center-1').css('font-size', $(this).css('font-size'));
        return false;
    });
});

function showChilds() {
    var menu = $(this);
    var list = menu.children(".listbox");
    var title = menu.children(".title");
    list.show();
    menu.mouseover(function () {
        title.css("background-image", "url('/App_Themes/Sabi/images/arrow_open.png')");
        title.css("color", "#26C1E4");
    });
    menu.mouseout(function () {
        if (title.hasClass("open"))
            return;
        title.css("background-image", "url('/App_Themes/Sabi/images/arrow.png')");
        title.css("color", "#fff");
    });
//    var pHeader = menu.children(".title");// menu.parent();
//    if (pHeader.css("background-image") == "" || $('.header-menu-categories').css("background-image") == "none")
//        pHeader.css("background-image", "url('/App_Themes/Sabi/images/arrow_open.png')");
//    else
//        pHeader.css("background-image", "");
}

function hideChilds() {
    var menu = $(this);
    var list = menu.children(".listbox");
    var title = menu.children(".title");
    list.hide();
 //    var pHeader = menu.children(".title");// menu.parent();
//    if (pHeader.css("background-image") == "" || $('.header-menu-categories').css("background-image") == "none")
//        pHeader.css("background-image", "url('/App_Themes/Sabi/images/arrow_open.png') no-repeat scroll left bottom transparent");
//    else
//        pHeader.css("background-image", "");
}

function getE(name) {
    if (document.getElementById)
        var elem = document.getElementById(name);
    else if (document.all)
        var elem = document.all[name];
    else if (document.layers)
        var elem = document.layers[name];
    return elem;
}

function OpenWindow(query, w, h, scroll) {
    var l = (screen.width - w) / 2;
    var t = (screen.height - h) / 2;

    winprops = 'resizable=0, height=' + h + ',width=' + w + ',top=' + t + ',left=' + l + 'w';
    if (scroll) winprops += ',scrollbars=1';
    var f = window.open(query, "_blank", winprops);
}

