﻿Event.observe(window, "load", OnInitializeApplicationSkin);


var ibrareatop = 84;
var ibrleftmainarea = 200;
var ibrpubviewertop = 128;
var ibrinfobartop = ibrpubviewertop - 2;
var ibrstatusarea = 20;

function OnInitializeApplicationSkin()
{
  Event.observe(document, MAGMA.EVENT.APPLICATION.LOADED, OnApplicationSkinLoaded);
}

function OnApplicationSkinLoaded(host)
{
	host = self;	
	Element.show("headerright_img");
	Proxy.SingleInstance.Register("abonnement", function() {HidePage("abonnement");});
	Proxy.SingleInstance.Register("banenladder", function() {HidePage("banenladder");});
  Proxy.SingleInstance.Register("contact", function() {HidePage("contact");});
  Proxy.SingleInstance.Register("colofon", function() {HidePage("colofon");});

}

function ExpandPanel() 
{  
  window.setTimeout("ShowPage('" + startuppanel + "')", 100);     	
}

function SetScreenElements()
{
	var pw = parseInt(document.body.clientWidth);
	var ph = parseInt(document.body.clientHeight);
	
	// toolbar & logoff
	var spacebefore = 0;
	var spacebetween = 0;
	
	var toolbarbg = $("maintoolbar_background");
	if (toolbarbg) {
		var tbbg_w = pw - 208;
		if (tbbg_w < 0) { tbbg_w = 0; }
	  toolbarbg.style.width = tbbg_w + "px"; 	
	}
 
  var col_toolbar = $("maintoolbar").getElementsByTagName("DIV");
  var div_toolbar = null;
  for (i=1;i< col_toolbar.length;i++) {
    div_toolbar = col_toolbar[i];    
    spacebefore += Element.getWidth(col_toolbar[i-1]); 
    div_toolbar.style.left = (spacebefore - i) + "px";
  }
  
	var dasboardarea = $("dashboardarea");
	if (dashboardarea) {
		dashboardarea.style.left = ibrleftmainarea + "px";
		dashboardarea.style.top = ibrareatop + "px";
		var dbaw = (pw - 8 - ibrleftmainarea);
		if (dbaw < 200) {
		  dbaw = 200;	
		}
		var dbah = ph - ibrareatop - ibrstatusarea;
		if (dbah < 200) {
		  dbah = 200;	
		}		
	  dashboardarea.style.width = dbaw + "px";
	  dashboardarea.style.height = dbah + "px";  	  	
	}
	
	var librarytocarea = $("librarytocarea");
	if (librarytocarea) {
		
		librarytocarea.style.left = ibrleftmainarea + "px";
		librarytocarea.style.top = ibrareatop + "px";
	  
	  
	  var ltah = (ph - 250);
	  if (ltah < 200) {
	    ltah = 200;	
	  }
	  
	  var ltaw = (pw - 8 - ibrleftmainarea);
	  if (ltaw < 200) {
	    ltaw = 200;	
	  }	  
	  librarytocarea.style.height = ltah + "px";  
	  librarytocarea.style.width = ltaw + "px";  	 	
	}
	
	var searcharea = $("searcharea");
	if (searcharea) {
		searcharea.style.left = ibrleftmainarea + "px"
		searcharea.style.top = ibrareatop + "px";
	  var saw = (pw - 8 - ibrleftmainarea);
		if (saw < 200) {
		  saw = 200;	
		}
		var sah = ph - ibrareatop - ibrstatusarea;
		//if (sah > 500) {
		//  sah = 500;	
		//}	
		if (sah < 200) {
		  sah = 200;	
		}
	  searcharea.style.width = saw + "px"; 
	  searcharea.style.height = sah + "px";  	  	
	}	
	
	var contactarea = $("contactarea");
	if (contactarea) {
		contactarea.style.left = ibrleftmainarea + "px"
		contactarea.style.top = ibrareatop + "px";
	  var caw = (pw - 8 - ibrleftmainarea);
		if (caw < 200) {
		  caw = 200;	
		}
		var cah = ph - ibrareatop - ibrstatusarea;
		if (cah > 300) {
		  cah = 300;	
		}	
		if (cah < 100) {
		  cah = 100;	
		}
	  contactarea.style.width = caw + "px"; 
	  contactarea.style.height = cah + "px";  	  	
	}	

	var abonnementarea = $("abonnementarea");
	if (abonnementarea) {
		abonnementarea.style.left = ibrleftmainarea + "px"
		abonnementarea.style.top = ibrareatop + "px";
	  var aaw = (pw - 8 - ibrleftmainarea);
		if (aaw < 200) {
		  aaw = 200;	
		}
		var aah = ph - ibrareatop - ibrstatusarea;
		//if (aah > 300) {
		//  aah = 300;	
		//}	
		if (aah < 100) {
		  aah = 100;	
		}
	  abonnementarea.style.width = aaw + "px"; 
	  abonnementarea.style.height = aah + "px";  	  	
	}	

  var banenladderarea = $("banenladderarea");
	if (banenladderarea) {
		banenladderarea.style.left = ibrleftmainarea + "px"
		banenladderarea.style.top = ibrareatop + "px";
	  var baw = (pw - 8 - ibrleftmainarea);
		if (baw < 200) {
		  baw = 200;	
		}
		var bah = ph - ibrareatop - ibrstatusarea;
		//if (bah > 300) {
		//  bah = 300;	
		//}	
		if (bah < 100) {
		  bah = 100;	
		}
	  banenladderarea.style.width = baw + "px"; 
	  banenladderarea.style.height = bah + "px";  	  	
	}		
	
	var colofonarea = $("colofonarea");
	if (colofonarea) {
		colofonarea.style.left = ibrleftmainarea + "px"
		colofonarea.style.top = ibrareatop + "px";
	  var clfaw = (pw - 8 - ibrleftmainarea);
		if (clfaw < 200) {
		  clfaw = 200;	
		}
		var clfah = ph - ibrareatop - ibrstatusarea;
		//if (clfah > 300) {
		//  clfah = 300;	
		//}	
		if (clfah < 100) {
		  clfah = 100;	
		}
	  colofonarea.style.width = clfaw + "px"; 
	  colofonarea.style.height = clfah + "px";  	  	
	}	

	var sidebar = $("sidebar");
	if (sidebar) {
		sbtop = (ph / 3);
		if (sbtop < 50) {
		  sbtop = 50;	
		}
	  sidebar.style.top = sbtop + "px"; 
	}
	
	var pubviewer = $("publicationviewerframe");
  if (pubviewer) {   
		 var pvh = (ph - ibrpubviewertop - 22);
	   if (pvh < 100) {
	     pvh = 100;	
	   }
	   var pvw = (pw - 236);
	   if (pvw < 200) {
	     pvw = 200;	
	   }  
		 pubviewer.style.left = "8px";
		 pubviewer.style.top =  ibrpubviewertop + "px";
		 pubviewer.style.width = pvw + "px";
		 pubviewer.style.height = pvh + "px";   
  }
  
  var docinfo = $("documentinfobar");
  var docinfotext = $("docinfotext");
  var docinfobuttons = $("docinfobuttons");
  var docinfoextra = $("docinfo_extra");
  var docinfoactivedocs = $("docinfo_activedocs");
  var docinfofavorites = $("docinfo_favoritesarea");

  if ((docinfo) && (docinfotext) && (docinfobuttons) && (docinfoextra) && (docinfoactivedocs) && (docinfofavorites)) {
    var diw = (pw - 236);
	   if (diw < 200) {
	     diw = 200;	
	   }  
	  docinfo.style.height = "26px";
	  docinfo.style.left = "8px";
	  docinfo.style.top = (ibrinfobartop - Element.getHeight(docinfo)) +  "px"; 
	  docinfo.style.width = diw + "px"; 
	  
	  docinfotext.style.top = (ibrinfobartop - Element.getHeight(docinfo) + 2) +  "px"; 
	  docinfotext.style.left = "8px";
	  docinfotext.style.height = "24px";
	  docinfotext.style.width = (diw - 200) + "px"; 
	  
	  docinfobuttons.style.height = "24px";  
	  docinfobuttons.style.top = (ibrinfobartop - Element.getHeight(docinfo) + 2) +  "px"; 
	  docinfobuttons.style.width = "200px";
	  docinfobuttons.style.left = (diw - 196) + "px";
	    
	  docinfoextra.style.top = ibrpubviewertop +  "px";
	  docinfoextra.style.left = "8px";
	  docinfoextra.style.width = diw + "px"; 	
	  docinfoextra.style.height = "150px"; 
	  
	  docinfoactivedocs.style.top = ibrpubviewertop +  "px";
	  docinfoactivedocs.style.left = (diw - 492) + "px";
	  docinfoactivedocs.style.width = "500px"; 
	  docinfoactivedocs.style.height = "400px";  	
	  
	  docinfofavorites.style.top = ibrpubviewertop +  "px";
	  docinfofavorites.style.left = (diw - 492) + "px";
	  docinfofavorites.style.width = "500px"; 
	  docinfofavorites.style.height = "400px";
  }
  
  var stbar = $("statusbar")
  if (stbar) {
    stbar.style.top = (ph - 24) + "px";
    stbar.style.left = "8px";   
    var stbw = (pw - 32);
	  if (stbw < 200) {
	    stbw = 200;	
	  }   
    stbar.style.width = stbw + "px"
  }
  
  var licarea = $("licarea");
  if (licarea) {
    licarea.style.left = (pw - Element.getWidth(licarea) - 8) + "px";
    licarea.style.top = (ph) + "px";	
  }
  
  var releasearea = $("releasearea");
  if (releasearea) {
  	var ral = pw- Element.getWidth(releasearea) - 100;
  	if (ral < 100) {
  	  ral = 100;	
  	}
    releasearea.style.left = (ral) + "px";
    releasearea.style.top = (ph) + "px";	
  }
  
  var rc_spacebetween = 16;
  var rc_banner = $("rightcolumn_banner");
  var rc_recent = $("rightcolumn_recent");
  var rc_directlink = $("rightcolumn_directlink");
  if ((rc_banner) && (rc_recent) && (rc_directlink)) {  
    rcbt = (ibrinfobartop - Element.getHeight(docinfo));
    rc_banner.style.top = rcbt + "px";
    rcrt = rcbt + Element.getHeight(rc_banner) + rc_spacebetween;   	
    rc_recent.style.top = rcrt + "px";
    rcrh = ph - ibrstatusarea - rcrt - Element.getHeight(rc_directlink) - rc_spacebetween - 2;
    if (rcrh < 0) {
      rcrh = 0;	
    }
    rc_recent.style.height = rcrh + "px";
    rcdlt = ph - ibrstatusarea - Element.getHeight(rc_directlink) - 2;
    rc_directlink.style.top = rcdlt + "px";
  }
}

function ShowPage(id)
{ 
  if (allowtogglemainpage) { 
	  Proxy.SingleInstance.Show(id);  
		var area = $(id + "area");
		var linkbutton = $("linkbutton_" + id);
		if ((area) && (linkbutton)) { 
		  if (area.getAttribute("status") != "show") { 
		  	allowtogglemainpage = false;	
		  	linkbutton.setAttribute("status", "selected");
		  	linkbutton.className = "largelinkbuttonselected";  	
		  	Effect.SlideDown(area, {duration: 0.5, afterFinish:AllowToggleMainPage});	  	
		    area.setAttribute("status", "show");	          	    
		  }
		}
  }
}

function HidePage(id)
{ 
	if (allowtogglemainpage) {
		var area = $(id + "area");
		var linkbutton = $("linkbutton_" + id);
		if ((area) && (linkbutton)) {
			if (area.getAttribute("status") == "show") {
				allowtogglemainpage = false;
		  	linkbutton.setAttribute("status", "");  
		  	linkbutton.className = "largelinkbutton";
		  	Effect.SlideUp(area, {duration: 0.5, afterFinish:AllowToggleMainPage});	
		    area.setAttribute("status", "hide");  	    
		  }
		}
  }
}

function OpenExternal(id)
{

}

function RegisterCustomElements()
{
  Proxy.SingleInstance.Register("dashboard", function() {HidePage("dashboard");});	
  Proxy.SingleInstance.Register("opendocsarea", CollapseOpenDocsArea);    
  Proxy.SingleInstance.Register("favoritesarea", CollapseFavoritesArea); 
  
  var hlinks = $("headerlinks");
  if (hlinks) {
    Element.show(hlinks);
  }	
  
  var rc_banner = $("rightcolumn_banner");
  var rc_recent = $("rightcolumn_recent");
  var rc_directlink = $("rightcolumn_directlink");
  if ((rc_banner) && (rc_recent) && (rc_directlink)) {
    Element.show(rc_banner);
    Element.show(rc_recent);
    Element.show(rc_directlink);  	
  } 
}

function ShowFootNote(fnobj)
{   
  var rightcolumnwidth = 200;
  var correction = 56;
  var contentframe = Proxy.GetContext().UPlatform.GetContentFrame();
  if (contentframe) {
    if (contentframe.document) {
    	var notetextinner = "Geen voetnoottekst gevonden";
    	var fnid = fnobj.id.substr(3) 
    	var notetext = contentframe.document.getElementById("fntxt_" + fnid);
    	if ((notetext) && (notetext.innerHTML != '')) {
    	  notetextinner = notetext.innerHTML;	
    	} 
    	
    	var fnleft  = parseInt(document.body.clientWidth) - rightcolumnwidth - correction - parseInt(contentframe.document.body.clientWidth);
		  new Tip(fnobj, notetextinner,  {title:'Voetnoot ' + fnid, style: 'elegant', hideAfter: 0.5,
		  	hook: { tip: 'topLeft', target: 'bottomRight' }, offset: { x:fnleft, y:132 } });		  		
		  try {
		    Event.observe(fnobj, 'prototip:hidden', RemoveFootNote);
		  } catch(e) {
  		}
		}	   
  } 	
}

function RemoveFootNote(event) {
  
    Tips.remove( event.element() );
  
}
