// Content Fixes and Interactions

(function ($) {
    $.extend({
        equalHeight: function () {
            $('.EqualHeight').children().height('auto');
            $('.EqualHeight').each(function () {
                var maxHeight = 0;
                $(this).children().each(function () {

                    if ($(this).height() > maxHeight) {

                        maxHeight = $(this).height();
                    }

                });

                $(this).children().height(maxHeight);

            });
        },
        equalHeight01: function () {
            //$('.EqualHeight').children().height('auto');
            $('.HomeBlock .Inside ul.Items').each(function () {
                var maxHeight = 0;
                $(".Info", this).each(function () {

                    if ($(this).height() > maxHeight) {

                        maxHeight = $(this).height();
                    }

                });

                $(".Info", this).height(maxHeight);

            });
        },
        menuHover: function () {
            $(".MainContainer .Header .Menu li.Item").hover(
                function () {
                    $(this).addClass("Hover");
                },
                function () {
                    $(this).removeClass("Hover");
                }
            );
        },
        cycleBlock: function () {
            $(".CycleBlock ul.Items").cycle({
                fx: 'scrollHorz',
                speed: 1000,
                timeout: $("#hdnBannerTiming").val(),
                prev: '.CycleBlock .NavigationBlock span.Prev',
                next: '.CycleBlock .NavigationBlock span.Next',
                pager: '.CycleBlock .Navigation',
                pagerAnchorBuilder: function (idx, slide) {
                    // return selector string for existing anchor
                    return '.CycleBlock .Navigation li:eq(' + idx + ') a';
                }
            });

            $(".CustomersCarousel").cycle({
                fx: 'fade',
                speed: 1000,
                timeout: $("#hdnCustomersTiming").val()
            });
        },
        shareBlock: function () {
            $("a.Share").click(function () {
                $(".ShareBlock").hide();
                var parentEl = $(this).parent();
                $(".ShareBlock", parentEl).show();
                return false;
            });
            $(".ShareBlock a.Close").click(function () {
                $(".ShareBlock").has(this).hide();
                return false;
            });
            $('html').click(function () {
                $(".ShareBlock").hide();
            });

            $(".ShareBlock").click(function (event) {
                event.stopPropagation();
            });
        },
        selectReplace: function () {
            $(".ContactForm .FormRow select").selectbox();
        },
        init: function () {
            $(window).resize(function () {

            });

            $(window).scroll(function () {

            });

            $(window).load(function () {

                $.equalHeight();
                $.equalHeight01();
                $.menuHover();
                $.cycleBlock();
                $.shareBlock();
                $.selectReplace();

                //Clear inputs on focus -------------------------------------------------------
                var inputs = $("input[type='text']");
                //alert(inputs.length);
                for (var i = 0; i < inputs.length; i++) {
                    inputs[i].onfocus = function () {
                        if ($(this).attr("alt") && this.value.indexOf($(this).attr("alt")) == 0) { this.value = ''; }
                    };
                    inputs[i].onblur = function () {
                        if (this.value == '') { this.value = $(this).attr("alt"); }
                    };
                }


            });

            $("a.Location").click(function () {
                if ($(this).attr("href").indexOf("#") == 0)
                    Callback($(this).attr("href").replace("#", ""))
                return true;
            });
        }

    });


})(jQuery);

jQuery(function ($) {
    $.init(); // Inits content fixes
});



