var pagebox = 'lightPageContainer';
var pagecont = 'lighPageContent';
var pageshow = false;
var menushow = false;
var cmenushow = '';
var menucont = 'menuoptions_contiainer';

var minTotalHeight = 550;
var minTotalWidth = 900;
var firstLoad = true;
function getSize(){
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  return Array(myWidth,myHeight);
}

function getElementSize(el){
  var obj = $(el);
  myWidth = obj.clientWidth;
  myHeight = obj.clientHeight;	
  return Array(myWidth,myHeight);
}
function resize(){
  var sizes = getSize();
  var myWidth = sizes[0]-2;
  var myHeight = sizes[1]-2;
  
  var IE6 = false /*@cc_on || @_jscript_version < 5.7 @*/;
  if( IE6){
			myHeight =myHeight-9;
      myWidth=myWidth-9;
  }
  if($('head_container')){ myHeight = myHeight-$('head_container').offsetHeight; }
  
  var dHeight = myHeight;
  var dWidth = myWidth;

  if(myHeight < minTotalHeight){  dHeight = minTotalHeight; $('body').style.overflowY='';}else{$('body').style.overflowY='hidden';}
  if(myWidth < minTotalWidth){ dWidth = minTotalWidth;$('body').style.overflowX=''; }else{$('body').style.overflowX='hidden';}

  if($('admin')){
    $('body').style.overflowX='';
    $('body').style.overflowY='';
  }

  if($('head_container')){ $('head_container').style.width = (dWidth)+'px'; }
  if($('menu')){$('menu').style.width = (dWidth-($('head_logo').offsetWidth+10))+'px'; }
  if($('container')){ 
    $('container').style.height = dHeight+'px'; 
    $('container').style.width = dWidth+'px'; 
  }
  if($('menuimage')){ 
    dWidth = (dWidth-$('menuimage').offsetWidth)-2;
    $('menuimage').style.height=dHeight+"px";
  }
  if($('login_container')){
    $('login_container').style.height = (dHeight-10)+'px'; 
    $('login_container').style.width = (dWidth-20)+'px'; 
    $('login_container').style.position='absolute';
    $('login_container').style.left=$('menuimage').offsetWidth+"px";
  }
  if($('holder')){
    $('holder').style.height=(dHeight)+'px';
    $('holder').style.width=(dWidth-5)+'px';
    $('holder').style.position='absolute';
    $('holder').style.left=$('menuimage').offsetWidth+"px";
  }
  moverUpdate();
  //alert($('menuimage').offsetWidth+" : "+$('container').style.width+" : "+sizes[0]+" : "+dWidth+" : "+(dWidth-5)+" : "+$('holder').style.width);
  if($('pagecont') && $('pagecont').innerHTML == ''){renderContentPage();}
}String.prototype.trim = function() {   return this.replace(/^\s+|\s+$/g,"");}
String.prototype.ltrim = function() {   return this.replace(/^\s+/g,"");}
String.prototype.rtrim = function() {   return this.replace(/\s+$/g,"");}

function setCalendar(querys) {
  new Ajax.Updater('calendar_holder', 'calendarRenderer',{parameters:querys } );
}
function showEventDiv(divid) {
 new Effect.Appear(divid, { duration: 0.1});
}
function hideEventDiv(divid) {
 new Effect.Fade(divid, { duration: 0.1});
}
function LightboxDelegate(url,relation,caption) {
 var objLink = document.createElement('a');
 objLink.setAttribute('href',url);
 objLink.setAttribute('rel','lightbox['+relation+']');
 objLink.setAttribute('title',caption); 

 Lightbox.prototype.start(objLink);
}

function LightboxStart(pic){
 Lightbox.prototype.start($(pic));
}
function menuShowUp(fin){
  //var ny = (0-$(menucont).offsetHeight);
  var ny = 125;
  if(fin == ''){ var fin = function(){} }
  new Effect.Move (menucont ,{ x: 0, y: ny, mode: 'absolute',duration: 1.0,beforeStart:function(){$(menucont).style.top=$('menuimage').offsetHeight+"px";},afterFinish:function(){fin();menushow=true;}});
  menushow = true;
}
function menuShowDown(fin){
  if(fin == ''){  var fin = function(){} }
  //var ny = $(menucont).offsetHeight;
  var ny = $('menuimage').offsetHeight;
  new Effect.Move (menucont ,{ x: 0, y: ny, mode: 'absolute',duration: 0.5,afterFinish:function(){fin();menushow=false;} });
  menushow = false;
}
function switchMenuShow(){
  if($(menucont)){
    var top =$(menucont).offsetTop; 
    //alert(top);
    if(menushow && top <= 125){
    //if(top <= 125){
      menuShowDown('');
    }else if( !menushow && top >= 524){
    //}else if( top >= 524){
      menuShowUp('');
    }
  }
} 
function resetMenu(){
  var ny = $(menucont).offsetHeight;
  new Effect.Move (menucont ,{ x: 0, y: ny, mode: 'relative',duration: 1.2,afterFinish:switchMenuShow });
  menushow = false;
}
function showMenu(fname){
  if(!$(menucont)){
    if( fname =="actie" || fname == "special_offer"){
      return false;
    }
    else if(fname=='menukaart_home'){
      return false;
    }
    else{
      window.location = "/";
      return false;
    }
  }
  if(fname=='menukaart_home'){
    fname = 'menukaart';
  }
  if(menushow && cmenushow != fname){
    var fin=function(){showMenu(fname);};
    menuShowDown(fin);
    return false;
  }
  else if(cmenushow == fname){
    switchMenuShow('');
  }
  else{
    /*if(fname =="actie"){
    $(menucont).style.background='transparent url(/actie_background.gif) no-repeat';
    }
    else if(fname =="special_offer"){
    $(menucont).style.background='transparent url(/actie_background_en.gif) no-repeat';
    }else{*/
    $(menucont).style.background='transparent url(/logo_back6_overlay.gif) no-repeat';
    //}
    if(fname == "menukaart" && pageshow){
      closeContentPage();
    }
    if(fname == "contact" && pageshow){
      moverenableSelect();
    }else{
      moverdisableSelect();
    }

    new Ajax.Updater(menucont,"/getMenuOptions", { parameters:"id="+fname,onComplete:function(){RedrawSifr('h4.sifr');switchMenuShow('');showFirstPages(fname);} } );
    //switchMenuShow('');
  }
  cmenushow = fname;
  return false;
}
function RedrawSifr(e){
  if(typeof sIFR == "function"){
    sIFR.replaceElement(named({sSelector:e,sWmode:"transparent" ,sFlashSrc:"flash/sifr-marydale.swf", sColor:"#FFFFFF", sLinkColor:"#FFFFFF", sBgColor:"#FFFFFF", sHoverColor:"#FFFFFF", nPaddingTop:0, nPaddingBottom:0, sFlashVars:"textalign=left&offsetTop=0"}));
  };
}
function showFirstMenuOption(){
  var list = $('menuoptions_contiainer').select('a');
  if(list.length>=1){
    var item = list[0];
    showContentPage(item);
  }
}
function showFirstPages(page){
  if(page != 'menukaart' && page != 'special_offer' && page != 'actie' && page != 'vacatures'){
    showFirstMenuOption();
  }
}

function showContentPage(e){
 var src = e.pathname;
 var id = e.id
 var pid =id.substr(5,id.length);
 var url = src+"/showContentPage"
 new Ajax.Updater(pagecont,url,{onComplete:function(){renderContentPage();}});
}
function renderContentPage(){
 disableControls();
 var e = $(pagebox).parentNode;
 var height= e.offsetHeight;
 var width = e.offsetWidth;
 $(pagebox).style.width=width+"px";
 $(pagebox).style.height=height+"px";
 $(pagecont).style.width=(width-250)+"px";
 $(pagecont).style.height=(height-100)+"px";
 var closebtn = function(i){return "<div id=\"closebtn_"+i+"\" class=\"lgh_closebtn\"><img onclick=\"closeContentPage();return false;\" src=\"close.gif\" \/><\/div>";}
 $(pagecont).insert({ after: closebtn(0)});
 $('closebtn_0').style.right=((250/2)-20)+"px";
 $('closebtn_0').style.top=((100/2)-16)+"px";
 new Effect.Appear($(pagebox), { duration: 0.1, afterFinish:function(){ RedrawSifr('h1.page_sifr');pageshow=true;}});
}
function closeContentPage(){
 new Effect.Fade($(pagebox), { duration: 0.1, afterFinish:function(){  enableControls(); pageshow=false;}});
}
