var infoPages = new Array();

$(document).ready(
    function() {
        $('#info-menu').children('.position').each(
            function(i) {
                $(this).click (
                    function () {
                        $('#info-menu').children('.position').each(
                            function(i) {
                                $(this).removeClass('select');
                                $(this).children('a').blur();
                            }
                        )
                        $('#info-content').children('div').each( function(i) { $(this).hide(); } )
                        $('#info-load').show();

                        //$(this).addClass('select');
                        hash   = $(this).children('a').attr('href');
                        tmpId  = $(this).attr('id');
                        tmpId  = tmpId.split('-');
                        thisId = tmpId[1];
                        location.hash = hash;
                        hash = hash.replace("#", "");

                        if (infoPages[thisId]!= null) {
                            $('#subpage-' + thisId + '').addClass('select');
                            $('#info-load').hide();
                            $('#infocont-' + thisId + '').show();
                            return false;
                        }

                        urlToLoad = location.href;
                        urlToLoad = urlToLoad.replace(".html", "");
                        urlToLoad = urlToLoad.replace("#", "/");

                        $.get(
                            urlToLoad, 'ajax=1', 
                            function(data){
                                $('#info-content').append(data);
                                infoPages[thisId] = hash;
                                $('#subpage-' + thisId + '').addClass('select');
                                $('#info-load').hide();
                                $('#infocont-' + thisId + '').show();
                            }
                        );
                        return false;
                    }
                )
            }

        )


        if  (location.hash != '') {
            hash   = location.hash;
            thisId = 0;
            $('#info-menu').children('.position').each(
                function(i) {
                    mHash   = $(this).children('a').attr('href');
                    mTmpId  = $(this).attr('id');
                    mTmpId  = mTmpId.split('-');
                    mThisId = mTmpId[1];
                    if (mHash == hash) { thisId = mThisId; }
                }
            )
            hash = hash.replace("#", "");

            if (hash == infoPages[0]) {
                $('#subpage-0').addClass('select');
                $('#info-load').hide();
                $('#infocont-0').show();
            } else {
                urlToLoad = location.href;
                urlToLoad = urlToLoad.replace(".html", "");
                urlToLoad = urlToLoad.replace("#", "/");
                $.get(
                    urlToLoad, 'ajax=1',
                    function(data){
                        $('#info-content').append(data);
                        infoPages[thisId] = hash;
                        $('#subpage-' + thisId + '').addClass('select');
                        $('#info-load').hide();
                        $('#infocont-' + thisId + '').show();
                    }
                );
            }
        } else {
            if  (document.getElementById('infocont-0') != null) {
            //if  ( $('#infocont-0') != null ) {
                //$('#subpage-0').addClass('select');
                $('#info-load').hide();
                $('#infocont-0').show();
            } else {
                hash   = $('#info-menu').children('.position:first').children('a').attr('href');
                tmpId  = $('#info-menu').children('.position:first').attr('id');
                tmpId  = tmpId.split('-');
                thisId = tmpId[1];
                //location.hash = '' + hash + '';
                //urlToLoad = location.href;
                urlToLoad = location.href + '' + hash + '';
                urlToLoad = urlToLoad.replace(".html", "");
                urlToLoad = urlToLoad.replace("#", "/");
                $.get(
                    '' + urlToLoad + '', 'ajax=1',
                    function(data){
                        $('#info-content').append(data);
                        infoPages[thisId] = hash;
                        $('#subpage-' + thisId + '').addClass('select');
                        $('#info-load').hide();
                        $('#infocont-' + thisId + '').show();
                    }
                );               
            }
        }
    }

);
