var interval_to_chech_if_should_redirect;

jQuery(document).ready(function () {

    jQuery('body').append('<div id="installing_background"></div>');
    jQuery('#installing_background')
        .css('background', '#000000')
        .css('opacity', '0.5')
        .css('z-index', 999999)
        .css('top', 0)
        .css('left', 0)
        .css('width', jQuery(window).width() + 'px' )
        .css('height', jQuery(window).height() + 'px' )
        .css('position','fixed');

    jQuery('body').append('<div id="installing_front"><p></p></div>');
    jQuery('#installing_front p').append("<span>Wise Guys Installation - step 3/4</span>");
    jQuery('#installing_front p').append("<span>Required plugins installation</span>");
    jQuery('#installing_front p').append("<span> &nbsp; </span>");
    //jQuery('#installing_front p').append("<span style='text-align: right'><a href='#' id='autoinstall_abort' style='color:#FF0000'>Abort</a> | <a href='#' id='autoinstall_continue'>Next Step</a></span>");
    jQuery('#installing_front p').append("<span style='text-align: right'><a href='#' id='autoinstall_continue'>Next Step</a></span>");


    jQuery('#installing_front p')
        .css('border-radius', '20px')
        .css('border', '2px solid #AAAAAA')
        .css('line-height', '30px')
        .css('font-size', '23px')
        .css('font-family', "HelveticaNeue-Light, 'Helvetica Neue Light', 'Helvetica Neue', sans-serif")
        .css('background', '#FFFFFF')
        .css('z-index', 9999999)
        .css('top', '200px')
        .css('left', (jQuery(window).width() - 500)/2 + 'px' )
        .css('padding', '20px 40px')
        .css('width', '400px' )
        .css('position','fixed');

    jQuery('#installing_front span').css('display','block');
    jQuery('#installing_front p a').css('text-align','right').css('text-decoration','none');

    jQuery('#installing_front #autoinstall_abort').click( function(){
        location.replace("./admin.php?page=foptions&all_plugins_installed=true");
    });

    jQuery('#installing_front #autoinstall_continue').click( function(){
        interval_to_chech_if_should_redirect = setInterval( function() {
            jQuery(".tgmpa>p>a").each( function(){
                if( 'Return to Required Plugins Installer' == jQuery(this).html() ){
                    clearInterval( interval_to_chech_if_should_redirect );
                    location.replace('./plugins.php');
                }
            });
        }, 300);
    });
});

