var url = '';
var current_article;

function pause(numberMillis) {
	var now = new Date();
	var exitTime = now.getTime() + numberMillis;
	while (true) {
		now = new Date();
		if (now.getTime() > exitTime)
			return;
	}
}

function setupInfoBox(pageurl)
{
    url = pageurl;

    current_article = 1;
}

function showInfoBox(width,height)
{
    $("#infobox").css( "visibility", "visible");
    $("#overlay").css("visibility", "visible");
    
    resizeInfoBox(width,height)
}

function showTab(index)
{
    $("#a"+current_article).css( "visibility", "hidden");

    current_article = index;

    $("#a"+current_article).css("visibility", "visible");
}

function printArticle()
{
    
}

function resizeInfoBox(width,height)
{
    $("#infobox").css("width", width);
    $("#infobox").css( "height", height);
    
    var top = (window.innerHeight - height)/4;

    if(top > 250) top = 250;

    $("#infobox").css( "top", top +"px");
}


function loadAnimation()
{
     $("#infobox").empty();

     $("#infobox").append("<img id='loader' src='http://www.buchenstein.de/media/layoutimg/loader.gif'");
}

function stopLoadAnimation()
{
    $("#loader").remove();
}

function getHttpRequest(request)
{
    response = '';

    dojo.xhrGet({
    url: request
    ,
    load: function(response, ioArgs){

       stopLoadAnimation();
       
      //Dojo recommends that you always return(response); to propagate
      //the response to other callback handlers. Otherwise, the error
      //callbacks may be called in the success case.
      return response;
    },
    error: function(response, ioArgs){
      $("#infobox").html("Fehler: Der Boxinhalt konnte nicht geladen werden.<br><a href='javascript:hideInfoBox()'>Schlie&szlig;en</a>");
        
      return response;
    }

  });

  return response;

  
} 


function showLoginBox()
{
    loadAnimation();

    response = getHttpRequest(url + "account/loginform");
    
    showInfoBox(200,150);
}

function showRegisterBox()
{

    loadAnimation();

    response = getHttpRequest(url + "account/registerform");

    showInfoBox(200,150);
}



function hideInfoBox()
{
    $("#infobox").empty();
    $("#infobox").css("visibility", "hidden");
    $("#overlay").css("visibility", "hidden");
    $("#infobox").css("height", "0px");
    $("#infobox").css("width", "0px");
}


function printPage(id)
{
    window.open(url + "page/print/" + id, "Druckansicht", "toolbar=no,scrollbars=yes,menubar=yes");
    
}


