var large =1;
var zoomfactor=0.02 //Enter factor (0.05=5%)
var orgHeight;
var orgWidth;
var whatcache;

function zoomhelper() {
    if (parseInt(whatcache.style.width)>10&&parseInt(whatcache.style.height)>10) {
        whatcache.style.width=(parseInt(whatcache.style.width)+parseInt(whatcache.style.width)*zoomfactor*prefix)+"px";
        whatcache.style.height=(parseInt(whatcache.style.height)+parseInt(whatcache.style.height)*zoomfactor*prefix)+"px";
    }
}

function zoom(originalW, originalH, what, state){
    if (!document.all&&!document.getElementById) return;
    if(!(orgHeight && orgWidth)) {
        orgHeight = originalH;
        orgWidth = originalW;
    }
    whatcache=eval("document.images['"+what+"']");
    prefix=(state=="in")? 1 : -1;
    if (whatcache.style.width==""||state=="restore") {
        whatcache.style.width=orgWidth+"px";
        whatcache.style.height=orgHeight+"px";
        if (state=="restore") {
            if(orgLeft || orgTop) {
                whatcache.style.left = orgLeft;
                whatcache.style.top = orgTop;
            }
            return;
        }
    } else {
        zoomhelper();
    }
    beginzoom=setInterval("zoomhelper()",100);
}

function clearzoom(){
    if (window.beginzoom) {
        clearInterval(beginzoom);
    }
}

function scaleImage() {
    img = document.images['myimage'];
    if( img.height > 0 && img.width > 0 ) {
        img.height = (img.height/img.width)*775;
        img.width  = 775;
        img.style.height = img.height+"px";
        img.style.width = img.width+"px";
    }
}

function scaleImage2() {
    img = document.images['myimage'];
    if( img.complete ) {
        clearInterval(si);
        if( img.height > 0 && img.width > 0 ) {
            img.height = ((img.height/img.width)*1000);
            img.width  = 1000;
            img.style.height = img.height+"px";
            img.style.width = img.width+"px";
        }
    } 
}

function setImage(name) {
    if(!(document.images['myimage'].src==name)) {
        /*document.images['myimage'].width=100;
        document.images['myimage'].height=100;
        document.images['myimage'].src=name;
        document.getElementById('afbeelding').innerHTML = '<img src="'+name+'" id="myimage" style="left: 0px; top: 0px" class="title" />';
        */
        if( document.getElementById ) {
            afb = document.getElementById('afbeelding');
        } else if( document.all ) {
            afb = document.all['afbeelding'];
        } else {
            return true;
        }
        delete(orgHeight); delete(orgWidth);
        afb.innerHTML = '<img src="'+name+'" id="myimage" style="left: 0px; top: 0px" class="title" onload="scaleImage()" />';
        //scaleImage();
    }
    //document.all['transcriptie'].style.display='none';
    //document.all['afbeelding'].style.height= '100%';
}

function popImage() {
    var imWin;
    if(!(document.images['myimage'].src=='')) {
       imWin = window.open('', imWin, "toolbar=no,menubar=no,resizable=yes");
       imWin.window.location = document.images['myimage'].src;
    }
}

var enLarged=false;
function enLarge() {
    port = document.getElementById('afbeelding');
    size = parseInt(port.style.height);
    if(enLarged) {
        port.style.height = size/2+"px";
    } else {
        port.style.height = size*2+"px";
    }
    enLarged=!enLarged;
}

var dragapproved=false;
var z,x,y,orgLeft, orgTop;
function move(e){ 
    if ((event.button==1||event.button==0)&&dragapproved){ 
        z.style.pixelLeft=temp1+event.clientX-x;
        z.style.pixelTop=temp2+event.clientY-y;
        return false;
    }
} 

var topIndex = 0;
function bringToFront(el) {
    el.style.zIndex = ++topIndex;
}

function toggleLayer(layerId) {
    var l;
    if(document.all) {
        l = document.all[layerId]; 
    } else if(document.getElementById) {
        l = document.getElementById(layerId);
    } else { return; }
    if(!l) return;
    if(l.style.display=='' || l.style.display=='none') {
        l.style.display='block';
        l.style.zIndex=++topIndex;
    } else {
        l.style.display='none';
    }
    return;
}

function drags(){ 
/*    if (!document.all) return; */
    event.cancelBubble = false;
    if (event.srcElement.className=="title"){ 
        if( event.srcElement.tagName=="IMG" ) {
            z=event.srcElement;
            if(!dragapproved && (!orgTop && !orgLeft)) {
                orgTop=z.style.top;
                orgLeft=z.style.left;
            }
        } else {
            z=event.srcElement.parentNode;
        }
        bringToFront(z);
        dragapproved=true;
        temp1=parseInt(z.style.left);
        temp2=parseInt(z.style.top);
        x=event.clientX;
        y=event.clientY;
        document.onmousemove=move;
    }
} 

function drags2(e) {
    if(e.target.className=="title") {
        if(e.target.tagName=="IMG") {
            z = e.target;
            if(!dragapproved && (!orgTop && !orgLeft)) {
                orgTop=z.style.top;
                orgLeft=z.style.left;
            }
        } else {
            z = e.target.parentNode;
        }
        bringToFront(z);
        dragapproved=true;
        temp1=parseInt(z.style.left);
        temp2=parseInt(z.style.top);
        x=e.clientX;
        y=e.clientY;
        document.onmousemove=move2;
    }
}

function move2(e){ 
    if (e.button==0&&dragapproved){ 
        z.style.left=(temp1+e.clientX-x)+"px";
        z.style.top=(temp2+e.clientY-y)+"px";
        return false;
    }
} 

function BladerVeld( param ) {
    frm = document.forms['zoek'];
    frm.action.value = 'Bladeren';
    frm.veld.value = param;
    frm.submit();
}

function clearForm(frm) {
    for( i=0; i < frm.elements.length; i++ ) {
        el = frm.elements[i];
        if( el.type == "text" ) {
            el.value = "";
        } else if( el.type == "checkbox" ) {
            el.checked = false;
        } else if( el.type == "select-one" ) {
            el.selectedIndex = 0;
        }
    }
}
function helpText(item,txt) {
    if( document.all ) {
        div = document.all['help'];
    } else if( document.getElementById ) {
        div = document.getElementById('help');
    } else {
        alert(txt);
        return;
    }
    div.innerHTML = '<div class=\"help\">Uitleg: '
        +item+'</div><div class=\"helptext\">'
        +txt+'<a href=\"/content/view/16/37/#'+item+'\">Lees verder..</a>'
        +'</div>';
}

function getNode(id) {
    if( document.all ) {
        div = document.all[id];
    } else if( document.getElementById ) {
        div = document.getElementById(id);
    } else {
        return false;
    }
    return div;
}

function resizeTrans() {
    if( trans = getNode('transcriptie') ) {
        if( trans.innerHTML.toLowerCase() == '<h4>geen transcriptie beschikbaar</h4>' ) {
            trans.style.height = 'auto';
            if( afb = getNode('afbeelding') ) {
                afb.style.height = '340px';
            }
        }
    }
}

if( typeof(window.event)=="object" ) {
    document.onmousedown=drags;
} else {
    document.onmousedown=drags2;
}
document.onmouseup=new Function("dragapproved=false");

