// Popup window



popup_width = 924;
margin = 30;
popup_height = $(window).height() - 40;
var module;

$(document).ready(function() { 
    
    var obj = document.getElementById('flash_module');
    if(obj != null){
        module = $('#module_id').html();
        startProject(module);
    }
});


function displayLoginScreen () {
    //$('#login_screen').height(popup_height);
    $.blockUI({
        message: $('#login_screen'),
        css: { 
            top:  ($(window).height() - popup_height) /2 + 'px', 
            left: ($(window).width() - popup_width) /2 + 'px', 
            width: popup_width + 'px',
            overflow: 'auto'
        } 
    });
    fitUI();
    //$('.blockOverlay').attr('title','Click to unblock').click($.unblockUI);
}

function fitUI(){
    //alert('fit');
    $('#login_screen').css('max-height', popup_height);
    changeDimensions($('.blockMsg'), popup_width, $('#login_screen').height());
}

function closeWindow(){
    testEditor();
}

function gotoEditor(){

    $('#main_content').show();
    $('html, body').animate({ 
      scrollTop: $('#main_content').offset().top + 32 
  }, 1000);
  
    resizeMediaClipPage();
    $.unblockUI();
}

function resizeMediaClipPage(){
    // Check if it should fit to the window
    if($('#flash_module_frame').attr('width') == "100%"){
        var h = $(window).height();
        var w = $(window).width()
        $('#flash_module_frame').attr('width', w);
        $('#flash_module_frame').attr('height', h);
        
        // Resize the page as well
        $('#resizeMe').height(h);
		$('#resizeMe2').height(h);
        $('#main_content').height(h);
    }
  }

$(window).resize(function() {
    resizeMediaClipPage();
});

function testEditor(){
    startProject();
}

// Automatic called from the profile.js
function loggedIn() {
    // Hide the test button
    $('#test_container').hide();
    $('#to_do_question').hide();
    $('#about_login').hide();
    $('#login_header').hide();
    $('#login_table').width(popup_width - margin);
    $('#login_below_field').html('');
    fitUI();
}

function refresh_session(){
    window.document.getElementById('main_content_refresh_frame').src = window.document.getElementById('main_content_refresh_frame').src;
}
setInterval('refresh_session()', 1000*60*10); // Calling after each 10 minutes

