﻿function preLoad() {
    if (document.images) {
        pic1 = loadImage(94,94, "images/btn_boek_hi.jpg");
        pic2 = loadImage(94,94, "images/btn_home_hi.jpg");
        pic3 = loadImage(94,94, "images/btn_galerij_hi.jpg");
        pic4 = loadImage(94,94, "images/btn_info_hi.jpg");
        pic5 = loadImage(94,94, "images/btn_achtergrond_hi.jpg");
        pic6 = loadImage(94,94, "images/btn_konakt.jpg");
        pic7 = loadImage(94,94, "images/btn_overig_hi.jpg");
        pic8 = loadImage(94,94, "images/btn_bg-achtergrond.jpg");
        pic9 = loadImage(94,94, "images/btn_bg-overig.jpg");
        pic9 = loadImage(94,94, "images/btn_bg-kontakt.jpg");
    }
}

function loadImage(width, height, url) {
     pic = new Image(width, height);
     pic.src= url;
     
     return pic
}

function showblock(nr)
{
	vista = (document.getElementById(nr).style.display == 'none') ? 'block' : 'none';
	document.getElementById(nr).style.display = vista;
}

function checkform() {
    var fields = new Array("naam","email","adres","postcode","plaats","telefoon","bericht");
    var isValid = true;
    for (j = 0; j < document.forms[0].elements.length; j++) {
        for (i = 0; i < fields.length; i++) {
            if (document.forms[0].elements[j].name == fields[i]) {
                if (document.forms[0].elements[j].value == '') {
                    document.forms[0].elements[j].style.backgroundColor = '#990000';
                    isValid = false;
                } else {
                    if (fields[i] == 'email') {
                        var validEmail = validateEmail(document.forms[0].email.value);
                        document.forms[0].email.style.backgroundColor = validEmail ? 'transparent' : '#990000';
                        if (!validEmail) isValid = false;
                    } else {
                        document.forms[0].elements[j].style.backgroundColor = 'transparent';
                    }
                }
            }
        }
    }
    return isValid;
}

function validateEmail(strValue) {
    var objRegExp  = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/;
    return objRegExp.test(strValue);
}

/* thumbnails */
function high(url) {
   var imgs = document.getElementsByTagName('img');
   for (i=0; i <= imgs.length; i++) {
        var img = new Image;
        img = imgs[i];
        if (img != null) {
            if (img.src != url) {
                img.style.borderColor = "#242424";
            } else {
                img.style.borderColor = "#6666CC";
            }
        }
   }
}

function getPage(url, title) {
	//makeRequest(url, 'showPage', null);
    var div = document.getElementById('details');

	div.innerHTML = 
	    "<img src=\"" + url.replace(".html", ".jpg") + "\" />" +
	    "<br /><h2>" + title + "</h2>" + 
	    "<div style=\"margin: 0px 50px 0px 50px; width: 500px;\">Adipiscing vero nibh, dolore exerci, ea suscipit. Vel ut augue, suscipit sed. Esse tation molestie luptatum autem eum ut facilisi lobortis. Et ut accumsan vero ut ut nibh consequat blandit illum dolore iriure in dolore at delenit ipsum dolore, dignissim, accumsan. In commodo molestie nisl augue nulla facilisi. Dolor velit nulla accumsan te, consectetuer nulla vulputate in autem, nulla dolore ea.</div>";

    /*
	div.innerHTML = 
	    "<div class=\"thumb r\" onclick=\"showblock('details');\">sluiten</div>" +
	    "<a href=\"#\">&lt;vorige</a> &nbsp; <a href=\"#\">1</a> | <a href=\"#\">2</a> &nbsp; <a href=\"#\">volgende&gt;</a>" + 
	    "<br /><br /><img src=\"" + url.replace(".html", ".jpg") + "\" />" +
	    "<br /><h2>" + title + "</h2>" + 
	    "<div style=\"margin: 0px 50px 0px 50px; width: 500px;\">Adipiscing vero nibh, dolore exerci, ea suscipit. Vel ut augue, suscipit sed. Esse tation molestie luptatum autem eum ut facilisi lobortis. Et ut accumsan vero ut ut nibh consequat blandit illum dolore iriure in dolore at delenit ipsum dolore, dignissim, accumsan. In commodo molestie nisl augue nulla facilisi. Dolor velit nulla accumsan te, consectetuer nulla vulputate in autem, nulla dolore ea.</div>";
	var div = document.getElementById('details');
	var d=document;
	var y=d.documentElement.scrollTop ? d.documentElement.scrollTop:d.body.scrollTop; 
	div.style.display = 'block';
	div.style.top=(160+y)+'px';
	*/
}

/* navigation */
function mainMenu() {
    toButton(makeButton('btn_home','home','index.html',getButtonX(1),18));
    toButton(makeButton('btn_galerij','beeldengalerij','living_sculptures/',getButtonX(2),18));
    toButton(makeButton('btn_info','info verhuur','info.html',getButtonX(3),18));
    toButton(makeButton('btn_boek','boek te koop','living_sculptures/galerij/standbeeldboek.html',getButtonX(4),18));
    toButton(makeButton('btn_achtergrond','achtergrond','living_sculptures/achtergrondinfo.html',getButtonX(5),18));
    toButton(makeButton('btn_overig','overig','overig.html',getButtonX(6),18));
    toButton(makeButton('btn_kontakt','kontakt','kontakt.html',getButtonX(7),18));
}

function getButtonX(i) {
    var offset = 20;
    var btnwidth = 94;
    var spacing = 46;
    return offset + ((i - 1) * btnwidth) + ((i - 1) * spacing);
}

function loadImage(width, height, url) {
     pic = new Image(width, height);
     pic.src= url;
     
     return pic
}

function makeButton(id, alt, url, buttonX, buttonY) {
    var button = new Object;
    button.id = id;
    button.alt = alt;
    button.url = url;
    button.buttonX = buttonX;
    button.buttonY = buttonY;
    
    return button;
}

function toButton(button) {
    isActive = isActiveButton(button.url);
    var nav = "\n\n";
    
    if (!isActive) nav += "<a href=\"/" + button.url + "\" title=\"" + button.alt + "\">";

    nav += "<img src=\"/images/" + button.id;
    //if (isActive) nav += "_on";
    if (isActive) nav += "_hi";
    nav += ".jpg\" id=\"" + button.id + "\" alt=\"" + button.alt + "\" class=\"navbtn\" style=\"top: " + button.buttonY + "px; left: " + button.buttonX + "px;\"";
    if (!isActive) nav += " onmouseover=\"hover(this.id);\" onmouseout=\"restore(this.id)\"";
    nav += " />";
    nav += "<span class=\"navbtn\" style=\"top: " + (button.buttonY + 97) + "px; left: " + button.buttonX + "px;\">" + button.alt + "</span>";
    if (!isActive) nav += "</a>";
    
    document.getElementById('nav').innerHTML += nav;
}

function isActiveButton(buttonUrl) {
    //if (currentPage() == '' && buttonUrl == 'LIVING_STATUES' && (document.location.href.indexOf('LIVING%5FSTATUES') > -1 || document.location.href.indexOf('LIVING_STATUES') > -1)) {
    //    return true
    //} else {
        return currentPage() == buttonUrl;
    //}
}

function currentPage() {
    currentUrl = document.location.href.substring(7, document.location.href.length);
    currentUrl = currentUrl.substring(currentUrl.indexOf("/")+1, currentUrl.length).replace('%5F','_');
    return currentUrl;
}

function hover(id) {
    img = document.getElementById(id);
    img.src = "/images/" + id + "_hi.jpg";
}

function restore(id) {
    img = document.getElementById(id);
    img.src = "/images/" + id + ".jpg";
}

function showfoto(name) {
    var div = document.getElementById("foto");
    switch(name) {
        case "eveline":
            div.innerHTML = "<img src=\"/images/eef-met-bodybeeld.jpg\" alt=\"eveline\" />";
            break;
        case "groep":
            div.innerHTML = "<img src=\"/images/groepsfoto_2007.png\" onload=\"fixPNG(this)\" width=\"480\" height=\"380\" alt=\"Groepsfoto 2007\" />";
            break;
        case "zilvertjes":
            div.innerHTML = "<img src=\"/images/overig/zilvertjes.png\" onload=\"fixPNG(this)\" alt=\"Zilvertjes\" />";
            break;
        case "prijs":
            div.innerHTML = "<img src=\"/images/overig/1e-prijs.jpg\" alt=\"1e prijs\" />";
            break;
        case "katja":
            div.innerHTML = "<img src=\"/images/overig/katja-vs-birgit.gif\" alt=\"Katja vs. Birgit\" />";
            break;
        case "keizer":
            div.innerHTML = "<img src=\"/images/overig/keizer.gif\" alt=\"Keizer\" />";
            break;
        case "microsoft":
            div.innerHTML = "<img src=\"/images/overig/microsoft.gif\" alt=\"Microsoft\" />";
            break;
        case "tour":
            div.innerHTML = "<img src=\"/images/overig/M-tour.gif\" alt=\"M-tour\" />";
            break;
        case "tentoon":
            div.innerHTML = "<img src=\"/images/overig/tentoon.jpg\" alt=\"tentoonstelling\" />";
            break;
        case "gala":
            div.innerHTML = "<img src=\"/images/overig/vvhjgala.jpg\" alt=\"Voetballer van het Jaar Gala\" />";
            break;
        case "valkhof":
            div.innerHTML = "<img src=\"/images/overig/valkhof.jpg\" alt=\"'Herculaneum' -tentoonstelling Valkhof museum Nijmegen\" />";
            break;
        case "beatrix":
            div.innerHTML = "<img src=\"/images/overig/beatrix.jpg\" alt=\"Beelden voor Beatrix\" />";
            break;
        case "tvshow":
            div.innerHTML = "<img src=\"/images/overig/TROStvshow.gif\" alt=\"TROS TV-show\" />";
            break;
    }
    div.style.display = "block";
}

function fixPNG(myImage) 
{
    if ((version >= 5.5) && (version < 7) && (document.body.filters)) 
    {
       var imgID = (myImage.id) ? "id='" + myImage.id + "' " : ""
	   var imgClass = (myImage.className) ? "class='" + myImage.className + "' " : ""
	   var imgTitle = (myImage.title) ? 
		             "title='" + myImage.title  + "' " : "title='" + myImage.alt + "' "
	   var imgStyle = "display:inline-block;" + myImage.style.cssText
	   var strNewHTML = "<span " + imgID + imgClass + imgTitle
                  + " style=\"" + "width:" + myImage.width 
                  + "px; height:" + myImage.height 
                  + "px;" + imgStyle + ";"
                  + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
                  + "(src=\'" + myImage.src + "\', sizingMethod='scale');\"></span>"
	   myImage.outerHTML = strNewHTML	  
    }
}