document.write("<script type=\"text/javascript\" src=\"/themasites/javascript/beeldvergroting.js\"></script>");
document.write("<script type=\"text/javascript\" src=\"/themasites/javascript/overlib417/overlib.js\"><!-- overLIB (c) Erik Bosrup --></script>");
document.write("<script type=\"text/javascript\" src=\"/themasites/javascript/overlib417/overlib_cssw3c.js\"></script>");
document.write("<script type=\"text/javascript\" src=\"/themasites/javascript/roundcorner/roundcorner.js\"></script>");


//
var DEBUG_PRINT = false;
var daynames = new Array("zo","ma","di","wo","do","vr","za");

// Omroep.nl menu positionering
var PoAlignment = "porighttop";
var PoVSpace = -38;
var PoHSpace = 17;
var PoLogoType = 2;
var PoFloatX = false;
var PoFloatY = false;

/* adapted from http://www.quirksmode.org/js/cross_dhtml.html */
/* wordt gebruikt bij het archief in-uitklap script */
var DHTML = (document.getElementById || document.all || document.layers);
function getObj(name) {
    if (document.getElementById) {
        this.obj = document.getElementById(name);
        this.style = (document.getElementById(name)!=null?document.getElementById(name).style:"");
    } else {
        if (document.all) {
            this.obj = document.all[name];
            this.style = document.all[name].style;
        } else {
            if (document.layers) {
                this.obj = document.layers[name];
                this.style = document.layers[name];
            }
        }
    }
}

function getAttribute(element, attributeName) {
    for( var x = 0; x < element.attributes.length; x++ ) {
        if( element.attributes[x].nodeName.toLowerCase() == attributeName ) {
            return element.attributes[x].nodeValue;
        }
    }
    return null;
}

/** testje van Rob */
function move(pos) {
    edgy;
    if (pos > 100) {
        return;
    }
    var x = new getObj("test");
    x.style.clip = "rect(0px " + pos + "px 150px 0px)";
    pos = pos + 10;
    setTimeout("move(" + pos + ")", 5);
}

function switchcal(tab) {
    if (!DHTML) {
        return;
    }
    var calendar = document.getElementById("calendar");
    if(calendar != null) {
        var tabs = calendar.getElementsByTagName("a");
        for(var i=0; i<tabs.length;i++) {
            // if( tabs[i].getAttribute("id") == "tab"+tab) {

            if(getAttribute(tabs[i], 'id') == "tab"+tab) {
                tabs[i].setAttribute("class","opentab");
            } else {
                tabs[i].setAttribute("class","closedtab");
            }
        }
    }
}

function switchtab(tab) {
    if (!DHTML) {
        return;
    }

    for (i = 0; i < daynames.length; i++) {
        var xt = new getObj("tab" + daynames[i]);
        var xtb = new getObj("tabblad" + daynames[i]);
        if (tab == daynames[i]) {
            if(xt!=null && xt.obj!=null) {
                xt.obj.className = "opentab";
            }
            if(xtb!=null && xtb.obj!=null) {
                xtb.obj.className = "opentabblad";
            }
        } else {
            if(xt!=null && xt.obj!=null) {
                xt.obj.className = "closedtab";
            }
            if(xtb!=null && xtb.obj!=null) {
                xtb.obj.className = "closedtabblad";
            }
        }
    }
}

var vouw = false;
function klapInUit(dag) {
    if(vouw) {
        var prevnext=document.getElementById("previously_next");
        if(prevnext!=null) {
            prevnext.innerHTML="vanaf nu";
            vouwAgendaIn(dag);
            vouw = false;
        }
    } else {
        var prevnext=document.getElementById("previously_next");
        if(prevnext!=null) {
            prevnext.innerHTML="eerder vandaag";
            vouwAgendaUit(dag);
            vouw = true;
        }
    }
}

function vouwAgendaIn(dag) {
    setDisplayStyle(dag, "visible");
}
function vouwAgendaUit(dag) {
    setDisplayStyle(dag, "invisible");
}

function setDisplayStyle(dag, style) {
    var today=new Date();
    var h=today.getHours();
    var m=today.getMinutes();

    var agendaitems = document.getElementById("tabblad"+dag).getElementsByTagName("div");
    for(var i=0; i<agendaitems.length; i++) {
        if(getAttribute(agendaitems[i],"class")=="agendaitem") {
            var span = agendaitems[i].getElementsByTagName("span")[0];
            var time = span.innerHTML;
            time = time.substring(time.indexOf("-")+2);
            var htime = time.substring(0,time.indexOf(":"));
            var mtime = time.substring(time.indexOf(":")+1);
            if((htime < h) || (htime == h && mtime < m)) {
                if(style == "visible") {
                    agendaitems[i].style.display = "";
                    // agendaitems[i].style.visibility="visible";
                } else {
                    agendaitems[i].style.display = 'none';
                    // agendaitems[i].style.visibility="hidden";
                }
            }
        }
    }
}

function display(ding) {
    if (!DHTML) {
        return;
    }
    var x = new getObj("months" + ding);
    if (!x.style.display || x.style.display == "block") {
        x.style.display = "none";
    } else {
        x.style.display = "block";
    }
    var x = new getObj("icon" + ding);
    if (x.obj.className == "icon open") {
        x.obj.className = "icon closed";
    } else {
        x.obj.className = "icon open";
    }
}

// voorpagina: nu op hollanddoc
function setAgendaNowNext() {
    agenda.nownextHollanddoc(agendaNowNextCallback);
    setTimeout("setAgendaNowNext()",300000);
}
var agendaNowNextCallback = function (agendas) {
    var divs = document.getElementsByTagName("div");
    if(agendas != null) {
        for (var i = 0; i < divs.length; i++) {
            if (getAttribute(divs[i], 'class') == "nowandnext") {
                divs[i].innerHTML = "";
                if(agendas.length>0 && agendas[0]!=null) {
                    divs[i].appendChild(divAgenda("now", "Nu op Holland Doc:", agendas[0].title, agendas[0].number, agendas[0].startTime + "-" + agendas[0].stopTime));
                }
                if(agendas.length>1 && agendas[1]!=null) {
                    divs[i].appendChild(divAgenda("next", "Straks:", agendas[1].title, agendas[1].number, agendas[1].startTime + "-" + agendas[1].stopTime));
                }
            }
        }
    }
};
function divAgenda(divTitel, kopTekst, titel, link, tijd) {
    var div = document.createElement("div");
    div.setAttribute("class", divTitel);
    var spanOntv = document.createElement("span");
    spanOntv.setAttribute("class", "ontv");
    spanOntv.appendChild(document.createTextNode(kopTekst));
    div.appendChild(spanOntv);
    var strong = document.createElement("strong");
    strong.appendChild(document.createTextNode(titel));
    div.appendChild(strong);
    var spanTijd = document.createElement("span");
    spanTijd.setAttribute("class", "time");
    spanTijd.appendChild(document.createTextNode(tijd));
    div.appendChild(spanTijd);
    return div;
}

// voorpagina: documentaire agendaitems
function setDocuzenders() {
    agenda.weekoverzichtDocumentaires(docuCallback);
}
var docuCallback = function (agendas) {
    var docuzenders = document.getElementById("docuzenders");

    tweedagenknip = (new Date().getTime() - (new Date().getTime() % (1000*60*60*24)))  + (1000*60*60*24*2) + (1000*60*60*6);

    // plaats nieuw overzicht
    for (var i=0; i<agendas.length; i=i+1) {

        if(agendas[i].startDate < tweedagenknip) {


            var divEpisode = document.createElement("div");
            divEpisode.setAttribute("class", "episode");
            docuzenders.appendChild(divEpisode);

            if(agendas[i].websiteUrl != null && agendas[i].websiteUrl != "") {
                var ahref = document.createElement("a");
                ahref.setAttribute("href", agendas[i].websiteUrl);

                var strong = document.createElement("strong");
                strong.appendChild(document.createTextNode(agendas[i].title));

                ahref.appendChild(strong);
                divEpisode.appendChild(ahref);

            } else {

                var strong = document.createElement("strong");
                strong.appendChild(document.createTextNode(agendas[i].title));
                divEpisode.appendChild(strong);
            }

            var span = document.createElement("span");
            span.setAttribute("class", "time "+agendas[i].zender.toLowerCase().replace(" ",""));
            span.appendChild(document.createTextNode(agendas[i].fullTime));
            divEpisode.appendChild(span);
        }
    }
};

// /gids
function setGidsDocuzenders() {
    agenda.weekoverzichtDocumentaires(docuGidsCallback);
}
var docuGidsCallback = function (agendas) {
    var docuzenders = document.getElementById("weekagenda");

    for (var i=0; i<agendas.length; i++) {
        var divEpisode = document.createElement("div");
        divEpisode.setAttribute("class", "agendaitem");
        docuzenders.appendChild(divEpisode);

        var spanTime = document.createElement("span");
        spanTime.setAttribute("class", "time");
        spanTime.appendChild(document.createTextNode(agendas[i].fullTime));
        divEpisode.appendChild(spanTime);

        var spanTitle = document.createElement("span");
        spanTitle.setAttribute("class", "title");
        spanTitle.appendChild(document.createTextNode(agendas[i].title));
        divEpisode.appendChild(spanTitle);

        var spanBody = document.createElement("span");
        spanBody.setAttribute("id", "body"+agendas[i].number);
        spanBody.appendChild(document.createTextNode(agendas[i].body));
        divEpisode.appendChild(spanBody);
    }
};



// printfire console meldingen
function printfire() {
    if (!DEBUG_PRINT) {
        return;
    }
    switch (typeof console) {
      case "object":
//		console.log.apply(this, arguments);
        break;
      case "function":
                //console.log(arguments[0]);
        var arg = [];
        for (var i = 0; i < arguments.length; i++) {
            arg.push(arguments[i]);
        }
        //console.log(arguments[0]+(arguments.length>1?arguments[1]:''));
        //console.log(arg.join(", "));
        break;
    }
}
if (!window.console && DEBUG_PRINT) {
  window.console = {
    timers: {},
    openwin: function() {
      window.top.debugWindow =
          window.open("",
                      "Debug",
                      "left=0,top=0,width=300,height=700,scrollbars=yes,"
                      +"status=yes,resizable=yes");
      window.top.debugWindow.opener = self;
      window.top.debugWindow.document.open();
      window.top.debugWindow.document.write('<html><head><title>debug window</title></head><body><hr /><pre>');
    },

    log: function(entry) {
      window.top.debugWindow.document.write(entry+"\n");
    },

    time: function(title) {
      window.console.timers[title] = new Date().getTime();
    },

    timeEnd: function(title) {
      var time = new Date().getTime() - window.console.timers[title];
//      console.log(['<strong>', title, '</strong>: ', time, 'ms'].join(''));
    }

  }

  if (!window.top.debugWindow) { console.openwin(); }
}
