/* Flash XML App */
/* Is called after an onclick on a flash thumbnail */
function loadXMLPage(app, data) {}

// ****************************************************************
// openviewer
// ****************************************************************
function openViewer(albumId)
{
  var width = 730;
  var height = 580;

  var url = "/pictureviewer.html";

  var viewerWindow = window.open(url,'ElsevierViewer','toolbar=no,menubar=no,resizable=no,top=30,left=30,width=' + width + ',height=' + height);
  viewerWindow.focus();
}

function showIboxByParameter(ibox){
  //alert('ibox:'+ibox)
  if (ibox == 0){
    var url = global_url_vogelvlucht;
    var title = "Vandaag in vogelvlucht";
    var params1 = "ibox&amp;width=" + global_width_vogelvlucht + "&amp;height=" + global_height_vogelvlucht;
    var params = parseQuery(params1.substr(5,999));
    showBG();
    showIbox(url,title,params); // show ibox
    window.onscroll = maintPos;
    window.onresize = maintPos;
  } else {
    var url = global_url_fotovandeweek;
    var title = "";
    var params1 = "ibox&amp;width=" + global_width_fotovandeweek + "&amp;height=" + global_width_fotovandeweek;
    var params = parseQuery(params1.substr(5,999));
    showBG();
    showIbox(url,title,params); // show ibox
    window.onscroll = maintPos;
    window.onresize = maintPos;
  }
}


/* Flash XML App */
function loadXMLpage(id){
  alert(id);
}

/* Automatically Stripe table (t) */
function stripeTable() {
  /* jQuery: http://15daysofjquery.com/examples/zebra/ */
  /* stripe on hover */
  $(".gestreept tr").mouseover(function(){$(this).addClass("over");}).mouseout(function(){$(this).removeClass("over");});

  /* stripe even rows */
  $(".gestreept tr:even").addClass("alt");
}

/* turn checkboxes on active/inactive */
function toggleRubriekVolgorde() {
    // Add a class to all unchecked checkboxes in that layer
    $("#ibox p.volgorde_items input").each(function(i){
      if($(this).is(":checked")){
        $(this.parentNode).removeClass("inactive").addClass("active");
      }else{
        $(this.parentNode).removeClass("active").addClass("inactive");
      }
    });

    // Change the class on all selected checkboxes on click
    $("#ibox p.volgorde_items input").bind("click",function(e){
      if($(this).is(":checked")){
        $(this.parentNode).removeClass("inactive");
        $(this).checked = "true";
        //console.log("check!");
        //hv.mutated by gx:
        gxToggleShow(this);
      }else{
        $(this.parentNode).addClass("inactive");
        $(this).checked = "false";
        //console.log("uncheck!");
        gxToggleShow(this);
      }
    });
}


/* Init and Load UFO Flash movies */
function initUfoVogelvlucht(){
  var FO = { movie:"/static/elsevier/swf/vogelvlucht.swf", width:"607", height:"95", majorversion:"6", build:"40", quality:"high", bgcolor:"#F0F1F2", align:"middle", allowScriptAccess:"sameDomain"  };
  UFO.create(FO, "vogelvlucht_popup");
}
function initUfoFotoWeek(){
  var FO2 = { movie:"/static/elsevier/swf/vogelvlucht.swf", width:"607", height:"95", majorversion:"6", build:"40", quality:"high", bgcolor:"#F0F1F2", align:"middle", allowScriptAccess:"sameDomain"  };
  UFO.create(FO2, "foto_week_popup");
}

/* Inline Quotation Popups */
var popup = false;

function showPopup(e, naam) {
  var popup = document.getElementById("popup_" + naam)
  if (popup) {
    var doc = document.documentElement.clientWidth? document.documentElement: document.body;
    var event = (typeof window.event != "undefined")? window.event: e;
    var clientX = event.clientX? event.clientX: (event.pageX? event.pageX: (event.x? event.x: 0));
    var clientY = event.clientY? event.clientY: (event.pageY? event.pageY: (event.y? event.y: 0));
    var scrollX = typeof window.pageXOffset != 'undefined'? window.pageXOffset: doc.scrollLeft;
    var scrollY = typeof window.pageYOffset != 'undefined'? window.pageYOffset: doc.scrollTop;
    var innerHeight = window.innerHeight? window.innerHeight: doc.clientHeight;
    var innerWidth = window.innerWidth? window.innerWidth: doc.clientWidth;

    if (clientY + popup.clientHeight + 50 > innerHeight) {
      popup.style.top = (innerHeight + scrollY - popup.clientHeight - 30) + 'px'
    } else {
      popup.style.top = (scrollY + clientY - 10) + 'px'
    }

    if (clientX + popup.clientWidth > innerWidth + scrollX) {
      popup.style.left = (innerWidth + scrollX - popup.clientWidth - 30) + 'px'
    } else {
      popup.style.left = (scrollX + clientX - 10) + 'px'
    }
    popup.style.display = "block"
    if (popup.offsetHeight > 185) {
      var inner = (popup.firstChild.tagName == 'DIV')? popup.firstChild: popup.childNodes[1];
      inner.style.height = '185px';
    }
  } else {
    alert('Popup ' + naam + ' niet gevonden');
  }
}

function overPopup(name) {
  clearTimeout(popup);
}

function outPopup(name) {
  popup = setTimeout("hidePopup('" + name + "')", 1000);
}


function hidePopup(naam) {
  var popup = document.getElementById("popup_" + naam)
  if (popup) {
    popup.style.display = "none";
  } else {
    alert('Popup ' + naam + ' niet gevonden');
  }
}
/* End Inline Quotation Popups */


/* Needed from iBox */
function iBoxCallback(){
  // Check to see if the "rubrieken_volgorde_layer" container layer exist (only on homepage?)
  if($("p.volgorde_items input").length > 0){
    toggleRubriekVolgorde();
  }
  // Check to see if the 'Foto van de week' "foto_layer" container layer exist (only on homepage?)
  if($("#fotoweek_layer").length > 0){
    initFotoWeek();
  }
  // Check to see if the 'Vandaag In Vogelvlucht' layer container layer exist (only on homepage?)
  if($("#vogelvlucht_layer").length > 0){
    initUfoVogelvlucht();
  }
}

/* Init functions on load */
$(window).bind("load",stripeTable);

/* needed for dart */
function getTimestamp () {
  d=new Date();

  year = d.getYear();
  if (year < 2000)
    year = year + 1900;

  month = d.getMonth()+1;
  if (month < 10)
    month = "0" + month;

  date = d.getDate();
  if (date < 10)
    date = "0" + date;

  hour = d.getHours();
  if (hour < 10)
    hour = "0" + hour;

  minute = d.getMinutes();
  if (minute < 10)
    minute = "0" + minute;

  second = d.getSeconds();
  if (second < 10)
    second = "0" + second;

  return year+month+date+hour+minute+second;
}
