var mainMenuShowing = false;
var currentOrb = 1;
var currentParadigm = 0;
var promoTilesRunning = false;
var promoTilesShowing = false;
var blank = new Image();
var paradigmRunning = false;
var newParadigmAnimation;
var oldParadigmAnimation;
var nextParadigmAnimation;
blank.src = '/Images/shim.gif';

// Major version of Flash required
var requiredMajorVersion = 8;
// Minor version of Flash required
var requiredMinorVersion = 0;
// Minor version of Flash required
var requiredRevision = 0;

var hasRequestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);

$(document).ready(function() {

    setTimeout(function() {
        $('ul', 'ul.jd_menu > li').each(function() {
            var dropShadow = $(this).width();
            $(this).append("<img class='delayPNGFilter' src='/Images/menu_hover_shadow.png' style='width:" + (dropShadow - 5) + "px;height:4px;position:absolute;margin-top:0px;clear:both;left:0px;' />");
        });

    }, 100);

    var oldBrowser = (/MSIE ((5\.5)|6)/.test(navigator.userAgent) && navigator.platform == "Win32");
    if (oldBrowser) {
        // get all pngs on page
        $('img[src$=.png]').each(function() {
            if ($(this).hasClass('addPNGFilter')) {
                fixPng(this);
            }
        });
    }
    setTimeout(function() {
        if (oldBrowser) {
            // get all pngs on page
            $('img[src$=.png]').each(function() {
                if ($(this).hasClass('delayPNGFilter')) {
                    fixPng(this);
                }
            });
        }
    }, 250);

//    if ((showMainMenu) || (!hasRequestedVersion)) {
        $('#mainMenuButton').css({ 'display': 'none' });
        $('#whoopLogo').css({ 'top': 42 }).show();
        $('#menuBar').css({ 'top': 0 });
        $('#whoopDog').show();
        $('#bottomMenu').css({ top: 535 });
        $('#promoMenu').css({ 'display': 'none' });
        setTimeout('showPromoTiles()', 100);

        //------------------------------------------


        $('#oldParadigm0').fadeIn(750);
        $('.ParadigmHeader').css({ 'display': 'block' });
        $('#nextParadigmArrow1').css({ 'display': 'block' });
        $('#nextParadigmArrow2').css({ 'display': 'block' });
        $('#flashContainer').css({ 'display': 'none' });
        $('#flashContainer').empty();
        $('#promoMenu').fadeOut(350, function() {

            oldParadigmAnimation = setTimeout(function() {
                if (!paradigmRunning) {
                    $('#ContentCreation').css({ 'color': '#990000' });
                    runParadigm(1);
                }
            }, 5000);
            showPromoTiles();
        });


    $('.whoop').hover(function() {
        //$(this).css({ 'color': 'cc0000' });
        $('#whoopMouth').css({ 'display': 'block' });
    }, function() {
        //$(this).css({ 'color': '' });
        $('#whoopMouth').css({ 'display': 'none' });
    });

    $('#orb1').css({ 'background-position': '0px 0px', 'cursor': 'pointer' });
    $('#orb1 > img').css({ 'top': '0px', 'cursor': 'pointer' });



    $('#ParadigmHeader1').hover(function() {
        $(this).css({ 'color': '#cc0000' });
    }, function() {
        if (currentParadigm == 1) {
            $(this).css({ 'color': '#990000' });
        } else {
            $(this).css({ 'color': '' });
        }
    });
    $('#ParadigmHeader1').bind('click', function() {

            $('.ParadigmHeader').css({ 'color': '' });
            $(this).css({ 'color': '#990000' });
            currentParadigm = 1;
            runParadigm(currentParadigm);
        
    });
    $('#ParadigmHeader2').hover(function() {
        $(this).css({ 'color': '#cc0000' });
    }, function() {
        if (currentParadigm == 2) {
            $(this).css({ 'color': '#990000' });
        } else {
            $(this).css({ 'color': '' });
        }
    });
    $('#ParadigmHeader2').bind('click', function() {

            $('.ParadigmHeader').css({ 'color': '' });
            $(this).css({ 'color': '#990000' });
            currentParadigm = 2;
            runParadigm(currentParadigm);
        
    });
    $('#ParadigmHeader3').hover(function() {
        $(this).css({ 'color': '#cc0000' });
    }, function() {
        if (currentParadigm == 3) {
            $(this).css({ 'color': '#990000' });
        } else {
            $(this).css({ 'color': '' });
        }
    });
    $('#ParadigmHeader3').bind('click', function() {

            $('.ParadigmHeader').css({ 'color': '' });
            $(this).css({ 'color': '#990000' });
            currentParadigm = 3;
            runParadigm(currentParadigm);
        
    });

});

function runParadigm(whichParadigm) {
        $('.ParadigmHeader').css({ 'color': '' });
        $('#ParadigmHeader' + whichParadigm).css({ 'color': '#990000' });
        clearTimeout(newParadigmAnimation);
        clearTimeout(oldParadigmAnimation);
        clearTimeout(nextParadigmAnimation);
        currentParadigm = whichParadigm;
        $('.paradigms').fadeOut(200);
        oldParadigmAnimation = setTimeout(function() {
            $('#oldParadigm' + whichParadigm).fadeIn(750);
            newParadigmAnimation = setTimeout(function() {
                $('#newParadigm' + whichParadigm).fadeIn(750);
                paradigmRunning = false;
                nextParadigmAnimation = setTimeout(function() {
                    var nextParadigm = whichParadigm + 1;
                    if (nextParadigm > 3) { nextParadigm = 0 };
                    runParadigm(nextParadigm);


                }, 7500);
            }, 3000);
        }, 750);

}



function showDogAndLogo() {
    $('#whoopLogo').fadeIn(750);
    $('#whoopDog').fadeIn(750);
}

function showPromoTiles() {

    $('#mainMenuButton').fadeOut(350, function() {
        promoTilesShowing = true;
        promoTilesRunning = true;
        $('.orbDiv').each(function() {
            var tempOrb = $(this).attr('id').toString().split('orb');
        });
        $('#bottomMenu').animate({ top: 535 }, 'fast', 'swing');
        $('#menuBar').animate({ top: 0 }, 350, 'swing');
        mainMenuShowing = true;
        $('#whoopLogo').animate({ top: 42 }, 350, 'swing');
        $('#promoMenu').animate({ top: 295 }, 350, 'swing', function() {
            $('#whoopLogo').fadeIn(350);
            $('#whoopDog').fadeIn(350);
            $('#promoGroup').css({ 'display': 'block' });
            setTimeout(function() {
                $('#promoGroup > div:nth-child(1)').css({ 'background-color': '#ffffff', 'visibility': 'visible', 'display': 'block' }).stop().animate({ top: 1 }, 'fast', 'swing');
            }, 200);
            setTimeout(function() {
                $('#promoGroup > div:nth-child(2)').css({ 'background-color': '#ffffff', 'visibility': 'visible', 'display': 'block' }).stop().animate({ top: 1 }, 'fast', 'swing');
            }, 400)
            setTimeout(function() {
                $('#promoGroup > div:nth-child(3)').css({ 'background-color': '#ffffff', 'visibility': 'visible', 'display': 'block' }).stop().animate({ top: 1 }, 'fast', 'swing');
            }, 600);
            setTimeout(function() {
                $('#promoGroup > div:nth-child(4)').css({ 'background-color': '#ffffff', 'visibility': 'visible', 'display': 'block' }).stop().animate({ top: 1 }, 'fast', 'swing');
            }, 800);
        });
    });


}

function fixPng(png) {
    // get src
    var src = png.src;
    // set width and height
    if (!png.style.width) { png.style.width = $(png).width(); }
    if (!png.style.height) { png.style.height = $(png).height(); }
    // replace by blank image
    png.src = blank.src;
    // set filter (display original image)
    png.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "',sizingMethod='scale')";
}
