var trace = ( window.console || document.console ) ? console.log : alert;

if( typeof( AMAZINGNS ) == 'undefined' )
{
    var AMAZINGNS = {};
}

$(
    function()
    {
        var flashvars = {};
        var params = {};
        var attributes = {};
        params.wmode = 'transparent';

        if ($('.home').length>0) {
            var rotor1 = ['/swf/homepage/Rotating_Animations/SecurityRoom_1.swf', 'security_room_swf'];
            var rotor2 = ['/swf/homepage/Rotating_Animations/Spaceship_1.swf', 'spaceship_swf'];
            var rotor3 = ['/swf/homepage/Rotating_Animations/CoffeeRoom_1.swf', 'coffee_room_swf'];
            var rotor4 = ['/swf/homepage/Rotating_Animations/MapRoom_1.swf', 'map_room1_swf'];
            var rotor5 = ['/swf/homepage/Rotating_Animations/MapRoom_2.swf', 'map_room2_swf'];
            var rotor6 = ['/swf/homepage/Rotating_Animations/Generator_1.swf', 'generator_swf'];
            var rotor7 = ['/swf/homepage/Rotating_Animations/Train_1.swf', 'train_swf'];
            var rotor8 = ['/swf/homepage/Rotating_Animations/UsRoom_1.swf', 'us_room_swf'];
            var rotor9 = ['/swf/homepage/Rotating_Animations/GameRoom_1.swf', 'game_room1_swf'];
            var rotor10 = ['/swf/homepage/Rotating_Animations/GameRoom_2.swf', 'game_room2_swf'];
            var rotor11 = ['/swf/homepage/Rotating_Animations/GameRoom_3.swf', 'game_room3_swf'];
            var rotor12 = ['/swf/homepage/Rotating_Animations/employmentRoom_1.swf', 'employment_room1_swf'];
            var rotor13 = ['/swf/homepage/Rotating_Animations/employmentRoom_2.swf', 'employment_room2_swf'];
    
            var rotor_map = [rotor1, rotor2, rotor3, rotor4, rotor5, rotor6, rotor7, rotor8, rotor9, rotor10, rotor11, rotor12, rotor13];
            var rotor_display = [];
        
            var generating = true;
            var i = 0;
            var r = Math.floor(Math.random()*13);
            var rr = false;
            while (generating == true) {
                if (i == 0) {
                    rotor_display[i] = r;
                    r = Math.floor(Math.random()*13);
                    i = i+1;
                } else if (i>0 && i<6) {
                    var j = rotor_display.length;
                    while (j>=-1) {
                        if (r == rotor_display[j]) {
                            rr = true;
                            break;
                        } else {
                            rr = false;
                            j = j-1;
                        }
                    }
                    if (rr == false) {
                        rotor_display[i] = r;
                        r = Math.floor(Math.random()*13);
                        i = i+1;
                    } else {
                        r = Math.floor(Math.random()*13);
                    }
                } 
                if (i == 6) {
                    generating = false;
                } 
            }

            // hide the bg for swf elements
            function rem_bg(index) {
                $('#' + rotor_map[rotor_display[index]][1]).css('background', 'none');
            }
            
            swfobject.embedSWF( AMAZINGNS.assetPath + '/swf/homepage/Fixed_Animations/City_1.swf', 'cityscape_swf', '100%', '100%', '9.0.0', AMAZINGNS.assetPath + '/swf/expressInstall.swf', flashvars, params, attributes );
            
            swfobject.embedSWF( AMAZINGNS.assetPath + rotor_map[rotor_display[0]][0], rotor_map[rotor_display[0]][1], '100%', '100%', '9.0.0', AMAZINGNS.assetPath + '/swf/expressInstall.swf', flashvars, params, attributes, function(){ rem_bg(0); });
            swfobject.embedSWF( AMAZINGNS.assetPath + rotor_map[rotor_display[1]][0], rotor_map[rotor_display[1]][1], '100%', '100%', '9.0.0', AMAZINGNS.assetPath + '/swf/expressInstall.swf', flashvars, params, attributes, function(){ rem_bg(1); });
            swfobject.embedSWF( AMAZINGNS.assetPath + rotor_map[rotor_display[2]][0], rotor_map[rotor_display[2]][1], '100%', '100%', '9.0.0', AMAZINGNS.assetPath + '/swf/expressInstall.swf', flashvars, params, attributes, function(){ rem_bg(2); });
            swfobject.embedSWF( AMAZINGNS.assetPath + rotor_map[rotor_display[3]][0], rotor_map[rotor_display[3]][1], '100%', '100%', '9.0.0', AMAZINGNS.assetPath + '/swf/expressInstall.swf', flashvars, params, attributes, function(){ rem_bg(3); });
            swfobject.embedSWF( AMAZINGNS.assetPath + rotor_map[rotor_display[4]][0], rotor_map[rotor_display[4]][1], '100%', '100%', '9.0.0', AMAZINGNS.assetPath + '/swf/expressInstall.swf', flashvars, params, attributes, function(){ rem_bg(4); });
        }
        
        swfobject.embedSWF( AMAZINGNS.assetPath + '/swf/homepage/Fixed_Animations/NAV_1.swf', 'the_eye_swf', '100%', '100%', '9.0.0', AMAZINGNS.assetPath + '/swf/expressInstall.swf', flashvars, params, attributes );
        
        if ($('#page_news').length>0) {
            $('#page_news').append('<div id="sub_swf" />');
            swfobject.embedSWF( AMAZINGNS.assetPath + '/swf/subpages/NewsSub_2.swf', 'sub_swf', '100%', '100%', '9.0.0', AMAZINGNS.assetPath + '/swf/expressInstall.swf', flashvars, params, attributes );
        }
        if ($('#page_about').length>0) {
            $('#page_about').append('<div id="sub_swf" />');
            $('#page_about').append('<div id="sub_swf2" />');
            swfobject.embedSWF( AMAZINGNS.assetPath + '/swf/subpages/AboutSub_2.swf', 'sub_swf', '100%', '100%', '9.0.0', AMAZINGNS.assetPath + '/swf/expressInstall.swf', flashvars, params, attributes );
            swfobject.embedSWF( AMAZINGNS.assetPath + '/swf/subpages/AboutSub_3.swf', 'sub_swf2', '100%', '100%', '9.0.0', AMAZINGNS.assetPath + '/swf/expressInstall.swf', flashvars, params, attributes );
        }
        if ($('#page_games').length>0) {
            $('#page_games').append('<div id="sub_swf" />');
            $('#page_games').append('<div id="games_side_sub" />');
            swfobject.embedSWF( AMAZINGNS.assetPath + '/swf/subpages/GameSub_3.swf', 'sub_swf', '100%', '100%', '9.0.0', AMAZINGNS.assetPath + '/swf/expressInstall.swf', flashvars, params, attributes );
        }
        if ($('#page_join').length>0) {
            $('#page_join').append('<div id="sub_swf" />');
            swfobject.embedSWF( AMAZINGNS.assetPath + '/swf/subpages/JoinSub_3.swf', 'sub_swf', '100%', '100%', '9.0.0', AMAZINGNS.assetPath + '/swf/expressInstall.swf', flashvars, params, attributes );
        }


        AMAZINGNS.NAV();

    }
);



AMAZINGNS.NAV = function()
{
    var MENUSPEED = 1000;

    AMAZINGNS.el = $( '#robot_container' );
    AMAZINGNS.menuYlocation = parseInt( AMAZINGNS.el.css( 'top' ).substring( 0, AMAZINGNS.el.css( 'top' ).indexOf( 'px' ) ) );

    $( window ).scroll(
        function()
        {
            var offset = AMAZINGNS.menuYlocation + $( document ).scrollTop() + 'px';
            AMAZINGNS.el.clearQueue().delay(400).animate( { top: offset }, { duration: 600, easing: 'swing' });
        }
    );

    // wrapper for nav plate bg, creates extra image layer for us to use on wp genereated menu
    $( 'li.page_item a' ).wrap('<div class="plate" />')
    // submenus
    $( 'li.page_item ul' ).hide();
    $( 'li.page_item ul' ).append('<li><div class="plate">&nbsp;</div></li>');
    $( 'li.page_item ul li:nth-child(odd) div.plate' ).css( 'background-position', 'left  -522px' );
    // show submenu on current subpages
    $( 'li.current_page_parent' ).find('ul').show();
    // submenu hovers
    $( 'li.page_item:not(li.page_item.current_page_parent)' ).has('ul').hover(function() {
                                                        $(this).find('ul:not(:animated)').clearQueue().slideDown(MENUSPEED);
                                                    },
                                                    function() {
                                                        $(this).find('ul:not(:animated)').clearQueue().delay(500).slideUp(MENUSPEED);
                                                    });
    // last nav item
    $( 'li.page_item' ).last().css( 'height', '47px').css('background-position', 'left -210px');
    $( 'li.page_item a' ).last().css( 'height', '37px');
}

AMAZINGNS.IEVersion = function()
{
    return ( navigator.appName == 'Microsoft Internet Explorer' ) ? parseFloat( ( new RegExp( "MSIE ([0-9]{1,}[.0-9]{0,})" ) ).exec( navigator.userAgent )[1] ) : -1;    
}

