jQuery.validator.addMethod("notEqual", function(value, element, param) {
    return this.optional(element) || value !== param;
}, "Please specify a different (non-default) value.");

var config = {
    feddbackFormOptions : {
        submitHandler : function(form){
            $(form).ajaxSubmit({
                success:function(data){
                    if(data.status)
                    {
                        $('#form_contact_us_submit').remove();
                        $('#success_message').css('display', '');
                    }
                }
            });
        },
        focusInvalid:false,
        focusCleanup:true,
        rules:{
            name:{
                required:true,
                minlength:3,
                maxlength:42,
                notEqual: "Name"
            },
            email:{
                required:true,
                email:true
            },
            phone:{
                required:true,
                minlength:6,
                notEqual: "Phone",
                number:true
            },
            message:{
                required:true,
                minlength:5,
                maxlength:5000,
                notEqual: "Message"
            }
        }
    },
    carousel : {
        animationSpeed : 1000,
        delay: 5000
    },
    accordion : {
        animationSpeed : 500
    },
    innovationCogwheels : {
        animationSpeed : 3000
    }
};


$(function(){

    function initTopSubnav(){
        var isIPad = navigator.userAgent.match(/iPad/i) != null,
            isIphone = navigator.userAgent.match(/iPhone/i) !== null;
            
        //if we on ipad or iphone do not handle subnav stick to top
        if(isIPad || isIphone) return false;
            
        var offsetTopNav = $('#sub_nav').offset().top,
            $submenu = $('#sub_nav'),
            $topSpacer = $('#topSpacer'),
            flag = '',
            scrollTopVal;
            
        function handleTopSubnav(){
        
            scrollTopVal = $(window).scrollTop();
            
            if(scrollTopVal + 75 > offsetTopNav){
                if(flag !== 'fixed'){
                    flag = 'fixed';
                    
                    $topSpacer.css({
                        height:110
                    });
                    $submenu.css({
                        position:'fixed',
                        top:75,
                        left:0,
                        backgroundColor:'#000',
                        zIndex:500
                    });
                }
            }else if(flag !== 'static'){
                flag = 'static';
                
                $topSpacer.css({
                    height:50
                });
                $submenu.css({
                    position:'static',
                    top:0,
                    left:0,
                    backgroundColor:''
                });
            }
        }
        
        $(window).on({
            scroll: handleTopSubnav
        });
    }

    
    // first test impementation
    /*function showElementPlayer(e){
        e.preventDefault();
    
        var target       = e.target,
            $target      = $(target),
            videoWidth   = 550,
            videoHeight  = 335,
            videosrc     = $target.data("videosrc") ? $target.data("videosrc") : $target.parent().data("videosrc"),
            isIdevice    = $target.parent().data('idevice'),
            $body        = $('body'),
            overlayWidth = $body.width(),
            $wrapper     = $('#wrapper-level-0'),
            $overlay     = $('<div></div>').addClass('overlayPlayer'),
            $container   = $('<div><span class="overlayClose"></span></div>').attr('id', 'containerPlayer'),
            $window      = $(window),
            video;
            
        if(!isIdevice){
            video = '<iframe src="http://www.openfilm.com/v/' + videosrc + '?c1=0x767676&c2=0x0F0F0F&menu=0&topbar=0&logo=0" width="' + videoWidth + '" height="' + videoHeight + '" frameborder="0" name="elementPlayer" class="flashContainer"></iframe>';
        }else{
            videoWidth = 595;
            overlayWidth = 1000,
            video = '<video width="'+ videoWidth +'" height="'+ videoHeight +'" controls ><source src="' + videosrc +'" type="video/mp4"></video>';
        }
            
        $overlay
            .width( overlayWidth )
            .height( $wrapper.height() )
            .appendTo( $body )
            .bind('click', function( event ){
                var $this = $(this);

                $('#containerPlayer').remove();

                $window
                    .unbind('scroll.player');

                $this
                    .unbind()
                    .remove();
            });

        $container.find('.overlayClose').bind('click', function() {
            $('.overlayPlayer').trigger('click');
        });

        $window.bind('scroll.player', function(e){
            var $this = $(this);
            
            $container.stop().animate({
                'top': ( $this.scrollTop() + ($this.height() / 2) - (videoHeight / 2 ))
            }, 250);
            
        });

        $container
            .width( videoWidth )
            .height( videoHeight )
            .css({
                'margin-left'   : parseInt( videoWidth / 2) * -1,
                'top'           : $window.scrollTop() + ($window.height() / 2) - (videoHeight / 2 )
            })
            .appendTo( $body )
            .append( video );
    }*/
    
    function showElementPlayer(e){

        var video = e.target,
            $video = $(video),
            response = $video.attr("rel") ? $video.attr("rel") : $video.parent().attr("rel");

            
            
        if(response){
            e.preventDefault();

            switch (response){
                case "video1":
                    video = '<iframe src="http://www.openfilm.com/v/30666?c1=0x767676&c2=0x0F0F0F&menu=0&topbar=0&logo=0" width="550" height="335" frameborder="0" name="elementPlayer" class="flashContainer"></iframe>';
                    break;
                case "video2":
                    video = '<iframe src="http://www.openfilm.com/v/29081?c1=0x767676&c2=0x0F0F0F&menu=0&topbar=0&logo=0" width="550" height="335" frameborder="0" name="elementPlayer" class="flashContainer"></iframe>';
                    break;
                case "video3":
                    video = '<iframe src="http://www.openfilm.com/v/29082?c1=0x767676&c2=0x0F0F0F&menu=0&topbar=0&logo=0" width="550" height="335" frameborder="0" name="elementPlayer" class="flashContainer"></iframe>';
                    break;
                case "video4":
                    video = '<iframe src="http://www.openfilm.com/v/29848?c1=0x767676&c2=0x0F0F0F&menu=0&topbar=0&logo=0" width="550" height="335" frameborder="0" name="elementPlayer" class="flashContainer"></iframe>';
                    break;
                case "video5":
                    video = '<iframe src="http://www.openfilm.com/v/29084?c1=0x767676&c2=0x0F0F0F&menu=0&topbar=0&logo=0" width="550" height="335" frameborder="0" name="elementPlayer" class="flashContainer"></iframe>';
                    break;
                case "video6":
                    video = '<iframe src="http://www.openfilm.com/v/29085?c1=0x767676&c2=0x0F0F0F&menu=0&topbar=0&logo=0" width="550" height="335" frameborder="0" name="elementPlayer" class="flashContainer"></iframe>';
                    break;
                case "video7":
                    video = '<iframe src="http://www.openfilm.com/v/29086?c1=0x767676&c2=0x0F0F0F&menu=0&topbar=0&logo=0" width="550" height="335" frameborder="0" name="elementPlayer" class="flashContainer"></iframe>';
                    break;
                case "launchpad":
                    video = '<iframe src="http://www.openfilm.com/v/28855?c1=0x767676&c2=0x0F0F0F&menu=0&topbar=0&logo=0" width="550" height="335" frameborder="0" name="elementPlayer" class="flashContainer"></iframe>';
                    break;
                case "openfilm":
                    video = '<iframe src="http://www.openfilm.com/v/29735?c1=0x767676&c2=0x0F0F0F&menu=0&topbar=0&logo=0" width="550" height="335" frameborder="0" name="elementPlayer" class="flashContainer"></iframe>';
                    break;
                case "motorsport":
                    video = '<iframe src="http://www.openfilm.com/v/30517?c1=0x767676&c2=0x0F0F0F&menu=0&topbar=0&logo=0" width="550" height="335" frameborder="0" name="elementPlayer" class="flashContainer"></iframe>';
                    break;
                case "music1":
                    video = '<iframe src="http://www.openfilm.com/v/30491?c1=0x767676&c2=0x0F0F0F&menu=0&topbar=0&logo=0" width="550" height="335" frameborder="0" name="elementPlayer" class="flashContainer"></iframe>';
                    break;
                case "yapik":
                    video = '<iframe src="http://www.openfilm.com/v/31014?c1=0x767676&c2=0x0F0F0F&menu=0&topbar=0&logo=0" width="550" height="335" frameborder="0" name="elementPlayer" class="flashContainer"></iframe>';
                    break;
            }

            if ( $(video).is('iframe') ) {
                var newVideo    = $(video),
                    $overlay    = $('<div></div>').addClass('overlayPlayer'),
                    $body       = $('body'),
                    $container  = $('<div><span class="overlayClose"></span></div>').attr('id', 'containerPlayer');

                var width   = parseFloat( newVideo.attr('width') ),
                    height  = parseFloat( newVideo.attr('height') );

                $overlay
                    .width( $body.width() )
                    .height( $('#wrapper-level-0').height() )
                    .appendTo( $body )
                    .bind('click', function( event ){
                        var $this = $(this);

                        $('#containerPlayer').remove();

                        $(window)
                            .unbind('scroll.player');

                        $this
                            .unbind()
                            .remove();
                    });

                $container.find('.overlayClose').bind('click', function() {
                    $('.overlayPlayer').trigger('click');
                });

                $(window).bind('scroll.player', function(){
                    var $this = $(this);
                    
                    $container.stop().animate({
                        'top': ( $this.scrollTop() + ($this.height() / 2) - (height / 2 ))
                    }, 250);
                });

                $container
                    .width( width )
                    .height( height )
                    .css({
                        'margin-left'   : parseInt(width / 2) * -1,
                        'top'           : $(window).scrollTop() + ($(window).height() / 2) - (height / 2 )
                    })
                    .appendTo( $body )
                    .append( newVideo );
            }
        }
    }
    
    function showPopup(params){
    
        var $content   = $(params.content),
            $overlay   = $('<div></div>').addClass('overlayPlayer'),
            $body      = $('body'),
            $container = $('<div><span class="overlayClose"></span></div>').attr('id', 'containerPlayer');

        var width   = params.width ? params.width : parseFloat( $content.attr('width') ),
            height  = params.height ? params.height : parseFloat( $content.attr('height') );

        $overlay
            .width( $body.width() )
            .height( $('#wrapper-level-0').height() )
            .appendTo( $body )
            .bind('click', function( event ){
                var $this = $(this);

                $('#containerPlayer').remove();

                $(window)
                    .unbind('scroll.player');

                $this
                    .unbind()
                    .remove();
            });

        $container.find('.overlayClose').bind('click', function() {
            $('.overlayPlayer').trigger('click');
        });

        $(window).bind('scroll.player', function(){
            var $this = $(this);
            
            $container.stop().animate({
                'top': ( $this.scrollTop() + ($this.height() / 2) - (height / 2 ))
            }, 250);
        });

        $container
            .width( width )
            .height( height )
            .css({
                'margin-left'   : parseInt(width / 2) * -1,
                'top'           : $(window).scrollTop() + ($(window).height() / 2) - (height / 2 )
            })
            .appendTo( $body )
            .append( $content );
    }
    

    
    $.fn.logoCarousel = function(options){
        var defaults = {
            changeDelay: config.carousel.delay,
            animationSpeed: config.carousel.animationSpeed,
            axis: 'horizontal',
            scrollItems: 3
        },
            options = $.extend(defaults, options),
            interval,
            animateProperty = (options.axis == 'horizontal') ? 'left' : 'top',
            $self = $(this),
            items = $self.find('li'),
            itemsCount = items.length,
            firstItem = items.eq(0),
            width = firstItem.width(),
            height= firstItem.height(),
            itemsContainer = $self.find('ul'),
            controlBtns = $('.moveLogoButton');
            
        if(animateProperty == 'left'){
            itemsContainer.width(itemsCount * width);
        }else if(animateProperty == 'top'){
            itemsContainer.height(itemsCount * height);
        }
        
        function moveImages(direction){
            if(!direction || direction == "next"){
                var source = itemsContainer.find('li:lt(' + options.scrollItems + ')'),
                    target = itemsContainer.find('li:last-child'),
                    value;
                    
                if(animateProperty == 'left'){
                    value = '-' + options.scrollItems * width +  'px';
                    
                    itemsContainer.animate({ 'left' : value},options.animationSpeed,function(){
                        source.insertAfter(target);
                        itemsContainer.css('left',0);
                    });
                    
                } else {
                    value = '-' + options.scrollItems * height +  'px';
                    
                    itemsContainer.animate({ 'top' : value},options.animationSpeed,function(){
                        source.insertAfter(target);
                        itemsContainer.css( 'top', '0px');
                    });
                }

            }else if(direction == 'prev'){
                var target = itemsContainer.find('li:first-child'),
                    value;
                
                if(animateProperty == 'left'){
                    value = '-' + options.scrollItems * width + 'px';
                    itemsContainer.css({left:value});
                }else{
                    value = '-' + options.scrollItems * height + 'px';
                    itemsContainer.css({top: value});
                }
                
                    for(var i= 0; i < options.scrollItems; i++){
                        var source = itemsContainer.find('li:last-child');
                        target.before(source);
                    }
                    
                if(animateProperty == 'left'){
                    itemsContainer.animate({left:-1},options.animationSpeed,function(){
                        $(this).css('left','0px');
                    });
                }else{
                    itemsContainer.animate({top:-1},options.animationSpeed,function(){
                        $(this).css('top','0px');
                    });
                }
            }
        }
        
        itemsContainer.hover(
            function(){
                clearInterval(interval);
            },
            function(){
                setCarouselInterval();
            }
        );
        
        controlBtns.on('click',function(){
            var $this = $(this);
            
            if($this.attr('id') == 'prev'){
                if(itemsContainer.css(animateProperty) == '0px'){
                    clearInterval(interval);
                    moveImages('prev');
                    setCarouselInterval();
                }
            }else{
                if(itemsContainer.css(animateProperty) == '0px'){
                    clearInterval(interval);
                    moveImages('next');
                    setCarouselInterval();
                }
            }
            
        });
        
        function setCarouselInterval(){
            interval = setInterval(function(){
                moveImages();
            },options.changeDelay);
        }
        
        setCarouselInterval();
        
        return this;
    };

    $.fn.slidingPanels = function(options){
        var defaults = {
            animationSpeed: config.accordion.animationSpeed,
            axis: 'horizontal'
        },
            options = $.extend(defaults, options),
            isIPad = navigator.userAgent.match(/iPad/i) != null,
            isIphone = navigator.userAgent.match(/iPhone/i) !== null,
            $dl = $(this);
        
        $dl.find('div').hide();
        $dl.find('dd').addClass('ddClose');
        $dl.find('.open').removeClass('open').addClass('closed');

        $dl.find('dd>h3, dt').click(function (event) {
            var $el = $(this);
            if ($el.is('dt')) {
                $el = $el.next().children('h3');
            }

            if ( !$el.parent().is('.ddOpen') ) {
                var $this = $(this);
                $dl.find('.ddOpen').find('div').hide();
                $el.next().show();
                
                if(!isIPad && !isIphone){
                    var offset = $el.offset().top-=140;
                } else {
                    var offset = $el.offset().top-=10;
                }
                
                $el.next().hide();
                $dl.find('.ddOpen').find('div').show();

                if($dl.find('.ddOpen').find('div').length){
                    if($dl.find('.ddOpen').find('h3').is(':in-viewport')){

                    }else{
                        if($dl.find('.ddOpen').find('h3').is(':below-the-fold')){

                        }else{
                            $(window.opera?'html':'html, body').animate({scrollTop:offset},options.animationSpeed);
                        }
                    }
                }

                $dl.find('.ddOpen').removeClass('ddOpen').find('div').slideUp(options.animationSpeed);
                $dl.find('.open').removeClass('open').addClass('closed');

                $el.parent().addClass('ddOpen').find('div').slideDown(options.animationSpeed);
                $el.parent().prev().removeClass('closed').addClass('open');

            }else{
                $dl.find('.ddOpen').removeClass('ddOpen').find('div').slideUp(options.animationSpeed);
                $dl.find('.open').removeClass('open').addClass('closed');
            }
        });
        
        return this;
        
    };
    
    $.fn.updateNews = function(options){
        var defaults = {
            
        },
            options = $.extend(defaults, options),
            preloaderHTML = '<img src="/design/images/preloader.gif" alt="Loading" width="32" height="32" id="preloader"/>';
            
        return this.each(function(){
        
            var $this = $(this),
                id = $this.attr('id'),
                $links = $this.find('a'),
                $newsBlock = $('#' + id + 'target');

            $links.on('click', function(event){
                event.preventDefault();
            
                var $this = $(this),
                    link = '';
            
                if($this.hasClass('on')){
                    return;
                }
                
                link = $this.attr('href');
                
                $newsBlock.html(preloaderHTML);
                
                $links.removeClass('on');
                $this.addClass('on');
                
                $.get(link, function(response){
                    $('#preloader').fadeOut(function(){
                        $newsBlock.html(response.html);
                    });
                });
                
            });
            
            
        }); 
    };
    
    var pages = {
        aboutus: function(){
            initTopSubnav();
            
            $('#panelCenterWrapper').logoCarousel({
                scrollItems: 3
            });
        
            $('#waterwheel-carousel-horizon').waterwheelCarousel({
                startingWaveSeparation: 0,
                centerOffset: 30,
                startingItemSeparation: 100,
                itemSeparationFactor: 0.7,
                itemDecreaseFactor: 0.75,
                opacityDecreaseFactor: 0.75,
                activeClassName :'active_element_of_success',
                movingToCenter :function(){
                    $('.element-current').fadeOut().removeClass('element-current');
                },
                movedToCenter : function(e){
                    var newItem = $(e.context).attr('rel');
                    $('#' + newItem).fadeIn().addClass('element-current');
                }
            });
            
            // handle watewheel carousel video display
            $(".active_element_of_success").live('click',function(e){
                showElementPlayer(e);
            });
        },
        whoweare : function(){
            initTopSubnav();

            $('dl').slidingPanels();
            
            $('#panelRightWrapper').logoCarousel({
                scrollItems: 2
            });
        },
        boardofdirectors : function(){
            initTopSubnav();
            
            $('dl').slidingPanels();
        },
        whatwedo : function(){
            initTopSubnav();
        },
        innovation : function(){
            // Partners and clients carousel 
            $('#panelRightWrapper').logoCarousel({
                scrollItems: 2
            });
            
            /* handle cogwheel's change */ 
            var $desc = $('.cogwheel_desc'),
                descInterval;
                
            $desc.css({display:'none'});

            $('.visible').css({display:'block'});

            $('img.cogwheel').hover(function(){
                var $this = $(this);
                
                clearInterval(descInterval);

                $('.visible').removeClass('visible').fadeOut(50,function(){
                    var targetImg = $this.attr('id')
                    $('#'+targetImg+'_desc').addClass('visible').fadeIn(50);
                });
                
            },function(){
                setDescInterval();
            })

            function setDescInterval(){
                descInterval = setInterval(function(){
                    changeDescCarousel();
                }, config.innovationCogwheels.animationSpeed)
            }

            function changeDescCarousel(){
                if($('.visible').next().length){
                    $('.visible').removeClass('visible').fadeOut().next().addClass('visible').fadeIn();
                }else{
                    $('.visible').removeClass('visible').fadeOut();
                    $($desc[0]).addClass('visible').fadeIn();
                }
            }
            setDescInterval();
            /* end handle cogwheel's change */

            /* handle items open and close*/
            var $dl = $('dl');
            $dl.find('dd>h3, dt').click(function (event) {
                var $el = $(this);
                if ($el.is('dt')) {
                    $el = $el.next().children('h3');
                }

                if($el.parent().prev().hasClass('open')){
                    $el.parent().prev().removeClass('open').addClass('closed');
                    $el.next().slideUp();
                }else{
                    $el.parent().prev().removeClass('closed').addClass('open');
                    $el.next().slideDown();
                }
            });
            /* end handle items open and close*/
            
            
            /* handle click on scientifics*/
            var rightBlock = $('#wrapper-level-1 .right'),
                leftBlock = $('#wrapper-level-1 .left'),
                target;
                
            $('.scientific_preview').click(function(){					
                var $id = $(this).attr('id');
                
                rightBlock.css({display:'none'});
                
                $('#video-player-innovation,dl,h3.title-innovation-007,div#baranskii,div#ushakov').css({display:'none'});
                
                leftBlock.css({width:'100%'});
                target = $('#' + $id + "_full").css({display:'block'});

            });
            
            $('a.full_back').click(function(){
                $('dl').find('div').show();
                $('dl').find('dd').removeClass('ddClose').addClass('ddOpen');
                $('dl').find('dt.open').removeClass('closed').addClass('open');
                $('#video-player-innovation,dl,h3.title-innovation-007,div#baranskii,div#ushakov').css({display:'block'});
                rightBlock.css({display:'block'});
                
                leftBlock.css({width:'630px'});
                target.css({display:'none'});
            });
            /* end handle click on scientifics*/
        },
        mediacenter : function(){
        
            var pageUrl = window.location.href;
            
            if(pageUrl.indexOf('#') !== -1){
                pageUrl = pageUrl.split('#');
                
                var targetAnchor = pageUrl[1],
                    itemScroll = $('span[data-scroll="press_archive"]').offset().top;
                
                $(document).scrollTop(itemScroll - 20);
            }
        
        
            $('#panelRightWrapperMedia').logoCarousel({
                axis: 'vertical',
                scrollItems: 7
            });
            
            $('.intro').updateNews();

            $('#form_contact_us_submit').validate(config.feddbackFormOptions);
        },
        inthenews: function(){
            $('#panelRightWrapperMedia').logoCarousel({
                axis: 'vertical',
                scrollItems: 7
            });
            
            $('.intro').updateNews();
        
            $('#form_contact_us_submit').validate(config.feddbackFormOptions);
        },  
        investors : function(){
            initTopSubnav();
        
            $('#form_contact_us_submit').validate(config.feddbackFormOptions);
            
            $('#company_overview').on('click',function(e){
                e.preventDefault();

                var form =  ['<form id="security_form" method="post" action="/investors/">',
                                '<div class="fieldWrapper">',
                                    '<label for="password">Enter password</label>',
                                        '<input type="textfield" value="" id="password" name="password"/>',
                                '</div>',
                                '<input type="submit" value="">',
                           '</form>'].join('');
                           
                var params = {
                    content : form,
                    width   : 400,
                    height  : 258
                };
                
                showPopup(params);
                
                $('#password','#security_form').focus();
                
                return false;
            });
            
            $('#investors').on('click','#security_form input[type="submit"]',function(e){
                $('#security_form').validate({
                    submitHandler : function(form){

                        $(form).ajaxSubmit({
                            success:function(data){
                                if(data.status)
                                {
                                    window.location = '/investors/reports/';
                                    $('.overlayPlayer').trigger('click');
                                } else {
                                    $('.fieldWrapper','#security_form').append('<label for="password" generated="true" class="error" style="display: block;">Password is incorrect.</label>')
                                }
                            }
                        });
                    },
                    focusInvalid:false,
                    focusCleanup:true,
                    rules:{
                        password:{
                            required:true
                        }
                    }
                });
            });
            
        },
        netelementhistory: function(){
            initTopSubnav();
        },
        corporategovernance: function(){
            initTopSubnav();
        },
        ourproperties : function(){
            initTopSubnav();
            
            // handle video display when logo pressed
            $(".left a").live('click',function(e){
                showElementPlayer(e);
            });
            
        },
        openfilm: function(){
            initTopSubnav();
        },
        motorsport: function(){
            initTopSubnav();
        },
        arlive : function(){
            initTopSubnav();
        },
        music1: function(){
            initTopSubnav();
        },
        yapik: function(){
            initTopSubnav();
        },
        legal: function(){
            initTopSubnav();
        },
        home: function(){
            // handle html5 video poster for Ipad
            $('#fake_poster').click(function(){
                $(this).fadeOut();
                var video = document.getElementById('home_video');
                video.controls = true;
                video.play();
            });
            
            $('#panelRightWrapper').logoCarousel({
                scrollItems: 2
            });
        },
        currentopenings: function(){
            initTopSubnav();
            
            $('dl').slidingPanels();
        },
        benefits: function(){
            initTopSubnav();
        },
        livinginmiami: function(){
            initTopSubnav();
        },
        pitchyourproject: function(){
            $('#pitch_your_project').validate({
                submitHandler:function(form){
                    $(form).ajaxSubmit({
                        success:function(){
                            window.location.href = '/our-properties/pitch-your-project/?thanks';
                        }
                    });
                },
                focusInvalid:false,
                focusCleanup:true,
                rules:{
                    name:{
                        required:true,
                        minlength:3,
                        maxlength:42,
                        notEqual: "Name"
                    },
                    email:{
                        required:true,
                        email:true,
                        notEqual: "Email"
                    },
                    phone:{
                        required:true,
                        minlength:6,
                        notEqual: "Phone",
                        number:true
                    },
                    address:{
                        notEqual: "Address",
                        required : true
                    },
                    message:{
                        required:true,
                        minlength:5,
                        maxlength:5000,
                        notEqual: "Your Project in a Nutshell"
                    }
                }
            });
        }
    };
    
    var page = $('body').attr('id');
        
    if(page.indexOf('-') !== -1){
        page = page.replace(/-/g,'');
    }
    
    if (pages && pages[page]){
        pages[page]();
    }
});
