if (typeof (Tody) === "undefined") var Tody = {};

(function($) {

    Tody.ContentMenu = new function() {

        var self = this;
        var cookieName = "contentMenuVisibility";
        var allowedPages = ['comanda', 'paidorder', 'freeorder'];
        var modulesOpenedPages = ['requestspecialoffer'];
        self.init = function() {

            var module = Tody.Common.getUrlParameter("m");

            if ($("div.modulesContainer").is(':not(:visible)') || $("div.modulesContainer").length == 0) {                
                $('#showHideModulesLink').html('<h3 class="orange">ARATA GAME</h3>');
            }
            else {                
                $('#showHideModulesLink').html('<h3 class="orange">ASCUNDE GAME</h3>');
            }      

            showHideModules();

        };

        var hideModules = function() {
            $('#showHideModulesLink').html('<h3 class="orange">ARATA GAME</h3>');
            $("div.modulesContainer").hide();
        };

        var setMenuShouldBeClosed = function() {
            var data = $.JSONCookie(cookieName);
            if (!data) {
                data = {};
            }
            $.JSONCookie(cookieName, data, { path: '/' });
        };

        var setMenuShouldBeVisible = function() {
            var crtPage = getPageName();
            var data = $.JSONCookie(cookieName);
            if (!data) {
                data = {};
            }

            data["showHide"] = true;
            $.JSONCookie(cookieName, data, { path: '/' });
        };

        var resetCookieMenu = function() {
            var data = {};
            $.JSONCookie(cookieName, data);
        }

        var getPageName = function() {
            return window.location.pathname;
        };

        var getQuerystring = function(key, default_) {
            if (default_ == null) default_ = "";
            key = key.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
            var regex = new RegExp("[\\?&]" + key + "=([^&#]*)");
            var qs = regex.exec(window.location.href);
            if (qs == null)
                return default_;
            else
                return qs[1];
        }

        var showHideModules = function() {

            $('#showHideModulesLink').click(function() {
                var crtPage = getQuerystring('pagesize');
                if ($("div.modulesContainer").is(':not(:visible)') || $("div.modulesContainer").length == 0) {
                    setMenuShouldBeVisible();
                    $('#showHideModulesLink').html('<h3 class="orange">ASCUNDE GAME</h3>');
                }
                else {
                    setMenuShouldBeClosed();
                    $('#showHideModulesLink').html('<h3 class="orange">ARATA GAME</h3>');
                }      
                window.location = window.location;
            });
        };

        self.deleteCookie = function() {
            $.removeJSONCookie(cookieName);
        };

    };
})(jQuery);


jQuery(document).ready(function() {
    Tody.ContentMenu.init();
});
