﻿// SAGIA Scripts
(function ($) {
    $(document).ready(function () {
        var minFontChangeTimes = 3;
        var maxFontChangeTimes = 3;
        var normFontSize = 78; /* 12px */
        var pixToPercent = 6.5; /* 78/12px */
        var maxFontSize = normFontSize + (maxFontChangeTimes * pixToPercent);
        var minFontSize = normFontSize - (minFontChangeTimes * pixToPercent);
        var selectedLang = "";

        // Increase Font Size 
        $(".increase-size").click(function () {
            if (normFontSize > 78) {
                minFontChangeTimes++;
                minFontSize = normFontSize - (minFontChangeTimes * pixToPercent);
            }
            if (normFontSize <= maxFontSize) {
                normFontSize += pixToPercent;
                var fontsize = normFontSize + "%";
                $(this).closest("body").css({ "fontSize": fontsize });
                $(".latest-news-list").cycle({ height: 60 });
            }
        });
        // Decrease Font Size 
        $(".decrease-size").click(function () {
            if (normFontSize < 78) {
                maxFontChangeTimes++;
                maxFontSize = normFontSize + (maxFontChangeTimes * pixToPercent);
            }
            if (normFontSize >= minFontSize) {
                normFontSize -= pixToPercent;
                var fontsize = normFontSize + "%";
                $(this).closest("body").css({ "fontSize": fontsize });
            }
        });

        // Language Drop Down
        $(".language-list").hover(function () {
            $(this).find("#languages").show();
        }, function () {
            $(this).find("#languages").hide();
        });

        // Change Language 
        $("#languages li").click(function () {
            if ($(this).hasClass("en")) {
                $("body").removeClass("lang-arabic");
                $(this).parent().prev().html($(this).html());
            } else if ($(this).hasClass("arabic")) {
                $("body").addClass("lang-arabic");
                $(this).parent().prev().html($(this).html());
            }
        });

        // Selected Language
        var windowUrl = window.location.href;
        if (windowUrl.search("/ar/") != -1) {
            $(".selected").text("عربي");
        }
        else if (windowUrl.search("/en/") != -1) {
            $(".selected").text("English");
        }

        // Main Navigation Drop Down
        $(".main-nav-item").hover(function () {
            $(this).find(".sub-nav-list").show();
        }, function () {
            $(this).find(".sub-nav-list").hide();
        });

        // Drop Down Hover 
        $(".inner-nav-item").hover(function () {
            $(this).addClass("inner-nav-item-hover");
            $(this).next().addClass("solid-border");
        }, function () {
            $(this).removeClass("inner-nav-item-hover");
            $(this).next().removeClass("solid-border");
        });

        // Left Nav Selected - Add solid border to Prev Item
        //$(".side-nav-item-selected").prev().addClass("solid-bottom-border");
        $(".side-nav-item-selected").next().addClass("dotted-bottom-border");
        $(".side-nav-item-selected-child").closest(".side-nav-list").addClass("dotted-bottom-border").prev().addClass("no-border");

        // Change Sub Item widths to match Parent Width
        var parentNavWidth = 0;
        $(".main-nav-item").each(function () {
            $(this).find(".sub-nav-list").css("width", $(this).width() + "px");
        });

        // New Promos Hover 
        $(".new-promo-item").hover(function () {
            $(this).find(".promo-content-hover").show();
            $(this).find(".promo-content").hide();
        }, function () {
            $(this).find(".promo-content-hover").hide();
            $(this).find(".promo-content").show();
        });

        // Latest News Cycle
        $(".latest-news-list").cycle({
            fx: 'scrollUp',
            sync: 0,
            delay: -1500
        });

        // Main Slide Show Copy Cycle
        $(".slide-copy-list").cycle({
            fx: 'scrollLeft',
            sync: 0,
            timeout: 6000,
            cleartype: false,
            cleartpyNoBg: false,
            pager: '.slide-copy-nav',
            before: onBefore
        });

        // Before Slide Show Copy Cycle
        function onBefore(curr, next, opts, fwd) {
            var currBg = $(this).closest(".slide-copy-container").next().find("li").eq($(this).index());

            $(this).closest(".slide-copy-container").next().find("li").removeClass("current-slide");

            currBg.fadeIn("slow").css("z-index", 5).addClass("current-slide");
            $(this).closest(".slide-copy-container").next().find("li").not(".current-slide").fadeOut("slow").css("z-index", 4);
        }

        // Resize Window
        //var i = 0;
        $(window).resize(function () {
            $('.slide-copy-item').each(function () {
                $(this).css('width', $(window).width() + 'px');
                this.cycleW = $(window).width();
            });
        });

        // Change Map Container Width on Window Resize on AR site
        /*$(window).scroll(function () {
        var contentMapHeight = $(".content-map").height();
        if (contentMapHeight > 0)
        $(".content-map").css("height", (contentMapHeight -= 50) + "px");
        });*/


        // Pause Both Slides when User Hovers on Slideshow 
        $(".slide-copy-list").hover(function () {
            $(this).cycle('pause');
        }, function () {
            $(this).cycle('resume');
        });

        // Our Partners Widget - Carousel
        $(".partner-list").cycle({
            fx: "scrollLeft",
            timeout: 2000,
            next: '.next-arrow',
            prev: '.prev-arrow'
        });

        // new partner list selectors
        $(".partner-list li:first").addClass("partner-item-first");
        $(".partner-list li:last").addClass("partner-item-last");

        // new main nav selectors
        $(".sub-nav-list li:first").addClass("inner-nav-item-first");
        $(".sub-nav-list li:last").addClass("inner-nav-item-last");

        // new side nav selectors
        $(".side-nav-list li:first").addClass("side-nav-item-first");
        $(".side-nav-list li:last").addClass("side-nav-item-last");

        // new main content nav selectors
        $(".content-nav-list li:first").addClass("content-nav-item-first");
        $(".content-nav-list li:last").addClass("content-nav-item-last");

        // footer logo list 
        $(".logo-list li:first").addClass("logo-item-first");
        $(".logo-list li:last").addClass("logo-item-last");
        $(".logo-item").hover(
	        function () {
	            $(this).addClass('logo-item-hover');
	        },
	        function () {
	            $(this).removeClass('logo-item-hover');
	        }
        );

        // Remove Padding Logo List's First and Last LI
        $(".logo-list-bottom li:first").css({ "paddingLeft": 0 + "px" });
        $(".logo-list-top li:first").css({ "paddingRight": 0 + "px" });
    });

})(jQuery);

