//get Window height for explorer
    function getWindowHeight(win) { if (win == undefined) win = window; if (win.innerHeight) { return win.innerHeight; } else { if (win.document.documentElement && win.document.documentElement.clientHeight) { return win.document.documentElement.clientHeight; } return win.document.body.offsetHeight; } }

//get Window width for explorer
    function getWindowWidth(win) { if (win == undefined) win = window; if (win.innerWidth) { return win.innerWidth; } else { if (win.document.documentElement && win.document.documentElement.clientWidth) { return win.document.documentElement.clientWidth; } return win.document.body.offsetWidth; } }

//sizing events

    function setLayout() {
        
        var window_height = document.all ? getWindowHeight() : window.innerHeight;
        var window_width = document.all ? getWindowWidth() : window.innerWidth;

        var headerHeight = document.getElementById('header').offsetHeight;
        var footerHeight = document.getElementById('footer').offsetHeight; 
            
        document.getElementById('OuterShell').style.width = (window_width < 1007) ? '1007px' : 'auto';    
        headerHeight = document.getElementById('header').offsetHeight;
        document.getElementById('content').style.height = window_height - headerHeight - footerHeight + 'px';
        
        var innerContentPadding = (parseInt($('#content').css('width'))-834)/2;
        
        $("#content .innerContent").css('padding', '26px '+innerContentPadding+'px');
        $(".prevnext .prev").css('left',innerContentPadding-75);
        
        (isRunningIE6OrBelow ? $(".prevnext .next").css('right',innerContentPadding-85) : $(".prevnext .next").css('right',innerContentPadding-75));

        $('#navigation ul ul a').removeClass("active");
        $("#navigation .active ul a:first").attr('class','active')
    }

    //window.addEventListener?window.addEventListener("load", setLayout, false):window.attachEvent("onload", setLayout);
    window.addEventListener?window.addEventListener("resize", setLayout, false):window.attachEvent("resize", setLayout);
    

//JQuery LocalSroll
    jQuery(function( $ ){

        /*
        $("#content .prevnext").each(function (i) {
            if ($(this).find('.prev').size()==0) $(this).append('<div class="prev nofx"><a href="" onclick="return false">prev</a></div>')
            if ($(this).find('.next').size()==0) $(this).append('<div class="next nofx"><a href="" onclick="return false">next</a></div>')
        });
        */
        
        setLayout();
        
        $("#navigation .active ul a:first").attr('class','active')

        $.localScroll.defaults.axis = 'x';
        
        // Scroll initially if there's a hash (#something) in the url 
        
        $.localScroll.hash({
            target: '#content', // Could be a selector or a jQuery object too.
            duration:1000,
            onAfter:function( anchor, settings ){
                $('#navigation ul ul a').removeClass("active");
                $('#navigation ul ul a[href$=#'+anchor.id+']').addClass("active");
            }
        });
        
        /**
         * NOTE: I use $.localScroll instead of $('#navigation').localScroll() so I
         * also affect the >> and << links. I want every link in the page to scroll.
         */
        $('#navigation ul ul, #content .prevnext').localScroll({
            target: '#content', // could be a selector or a jQuery object too.
            queue:true,
            duration:1000,
            hash:false,
            onBefore:function( e, anchor, $target ){
                // The 'this' is the settings object, can be modified
            },
            onAfter:function( anchor, settings ){
                // The 'this' contains the scrolled element (#content)
                if ($('#navigation ul ul').find('a[href$=#'+anchor.id+']').size()>0) {
                    $('#navigation ul ul a').removeClass("active");
                    $('#navigation ul ul a[href$=#'+anchor.id+']').addClass("active");
                }
            }
        });
    });

//dropdown menu

    window.addEventListener?window.addEventListener("load",initMenu,false):window.attachEvent("onload",initMenu);
    
    function initMenu() {  
        
        var menuPoints = getmenuPoints();
        
        for (var i in menuPoints) {
            if (menuPoints[i].tagName == 'LI') menuPoints[i].onmouseover = menuPointHover;
            if (menuPoints[i].tagName == 'LI') menuPoints[i].onmouseout = menuPointHoverEnd;
        }
    }
    
    function menuPointHover() {
        closeAll();
        //this.style.position='relative';
        if (this.getElementsByTagName('UL').length > 0) this.getElementsByTagName('UL')[0].style.display = 'block';
    }    
    
    function menuPointHoverEnd() {
        closeAll(1);
        //this.style.position='static';        
    }
    
    function getmenuPoints() {
        
        // get menuPoints
            var menuPointsCollection = document.getElementById('navigation').getElementsByTagName('LI');
            
            var menuPoints = new Array();
            
            for (var i in menuPointsCollection) {
                if (menuPointsCollection[i].tagName == "LI" && menuPointsCollection[i].parentNode.parentNode.id == "navigation") menuPoints.push(menuPointsCollection[i]);
            }   
            
        return menuPoints;
    }
    
    function closeAll(leaveActive) {

            menuPoints = getmenuPoints();
            
            for (var i in menuPoints) {
                if (menuPoints[i].getElementsByTagName('UL').length > 0) {
                    if (leaveActive && menuPoints[i].className != 'active' || !leaveActive) { 
                        menuPoints[i].getElementsByTagName('UL')[0].style.display = 'none'; 
                    } else {
                        menuPoints[i].getElementsByTagName('UL')[0].style.display = 'block'; 
                    }
                }
                //menuPoints[i].style.position = 'static';
            }
            
    }

