

function reloadPage(){
    if (document.getElementById('fullscreenContainer').style.display != 'block')
	window.location.href = window.location.href;
    else if (document.getElementById('fullscreenContainer').src != ''){
	parseCallingURL(frames['fullscreenContainer'].location.href);
	iframeImgID = getValueArray()[0];
	document.getElementById('fullscreenBG').style.background='black url(\'/vrijontwerp-css/loading.gif\') no-repeat center';
	document.getElementById('fullscreenContainer').src = './?imgid='+iframeImgID+'&fullSizeMaxWidth='+getFullSizeDimensions()[0]+'&fullSizeMaxHeight='+getFullSizeDimensions()[1];
    }
}



	var nMaxVars = 0;
	var sVarLine = "";
	var sName = new Array();
	var sValue = new Array();

	function getMaxVars() { return nMaxVars; }
	function getVarString() { return sVarLine; }
	function getNameArray() { return sName; }
	function getValueArray() { return sValue; }

	function parseCallingURL(sCallingURL) {
		//Get the calling URL and parse out variables
		sCallingURL = String(sCallingURL);

		if (sCallingURL.length == 0)
			return;

		// Check if there are any variables
		if (sCallingURL.indexOf('?') != -1) {
			sVarLine = String(sCallingURL.substring(sCallingURL.indexOf('?') + 1, sCallingURL.length));
		} else {
			// No variables
			return;
		}

		var nPos = 0;
		var sChar = "";
		var sWord = "";
		nMaxVars = 0;

		// Parse
		while (nPos < sVarLine.length) {
			sChar = sVarLine.substring(nPos, nPos + 1);

			if (sChar == "=") {
				sName[nMaxVars] = sWord;
				sWord = "";

			} else if (sChar == "&") {
				sValue[nMaxVars] = sWord;
				sWord = "";
				nMaxVars++;

			} else if (nPos == sVarLine.length - 1) {
				sWord += sVarLine.substring(nPos, nPos + 1);
				sValue[nMaxVars] = sWord;
				sWord = "";
				nMaxVars++;

			} else {
				sWord += sChar;
			}
			nPos++;
		}
	}



var qsParm = new Array();

function qs() {
    var query = window.location.search.substring(1);
    var parms = query.split('&');
    for (var i=0; i<parms.length; i++) {
	var pos = parms[i].indexOf('=');
	if (pos > 0) {
	    var key = parms[i].substring(0,pos);
	    var val = parms[i].substring(pos+1);
	    qsParm[key] = val;
	}
    }
}

qsParm['code'] = null;
qsParm['desc'] = null;
qs();

function getFullSizeDimensions() {

            if (window.innerHeight) { // msie 5 + 6
                var fullSizeHeight = window.innerHeight;
                var fullSizeWidth = window.innerWidth;
	    }
	    else if (document.body.clientHeight != 0) { // w3c
                var fullSizeHeight = document.body.clientHeight;
                var fullSizeWidth = document.body.clientWidth;
            }
            else if (getHeight('fiuwac_galerie') != 0){ // msie 7
		var fullSizeHeight = Math.round(getHeight('fiuwac_galerie') / 0.86)
		var fullSizeWidth = Math.round(getWidth('fiuwac_galerie') / 0.92)
            }
	    else { // alles is hopeloos
		var fullSizeHeight = 1000;
                var fullSizeWidth = 640;
	    }

            return [fullSizeWidth,fullSizeHeight];
}

function getFullSizeImgURL(imgURLwithoutExtension,imgExtension) {

            if (window.innerHeight) { // msie 5 + 6
                var fullSizeImageMaxHeight = window.innerHeight;
                var fullSizeImageMaxWidth = window.innerWidth;
	    }
	    else if (document.body.clientHeight != 0) { // w3c
                var fullSizeImageMaxHeight = document.body.clientHeight;
                var fullSizeImageMaxWidth = document.body.clientWidth;
            }
            else if (getHeight('fiuwac_galerie') != 0){ // msie 7
		var fullSizeImageMaxHeight = Math.round(getHeight('fiuwac_galerie') / 0.86)
		var fullSizeImageMaxWidth = Math.round(getWidth('fiuwac_galerie') / 0.92)
            }
	    else { // alles is hopeloos
		var fullSizeImageMaxHeight = 900;
                var fullSizeImageMaxWidth = 700;
	    }

            fullSizeImageMaxHeight = (Math.round((fullSizeImageMaxHeight-50)/100)*100)-150;
            fullSizeImageMaxWidth = (Math.round((fullSizeImageMaxWidth-50)/100)*100)-50;

            if (fullSizeImageMaxHeight < 250) fullSizeImageMaxHeight = 250;
            if (fullSizeImageMaxWidth < 250) fullSizeImageMaxWidth = 250;

            if (fullSizeImageMaxHeight > 1050) fullSizeImageMaxHeight = 1050;
            if (fullSizeImageMaxWidth > 1050) fullSizeImageMaxWidth = 1050;

            var fullSizeImgURL = imgURLwithoutExtension+'!'+fullSizeImageMaxWidth+'x'+fullSizeImageMaxHeight+imgExtension;
            return fullSizeImgURL;

}

//thanks to http://www.quirksmode.org/js/findpos.html

function findPos(element) {
	obj = document.getElementById(element);
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) { // not a syntax error!
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

function getHeight(element){
        return elementHeight = document.getElementById(element).clientHeight;
}

function getWidth(element){
        return document.getElementById(element).clientWidth;
}

function getOffsetLeft(element){
        return document.getElementById(element).offsetLeft;
}
function getOffsetTop(element){
        return document.getElementById(element).offsetTop;
}

function showFullscreenImage (imgID){
    document.getElementById('fullscreenBG').style.background='black url(\'/vrijontwerp-css/loading.gif\') no-repeat center';
    document.getElementById('fullscreenContainer').src = './?imgid='+imgID+'&fullSizeMaxWidth='+getFullSizeDimensions()[0]+'&fullSizeMaxHeight='+getFullSizeDimensions()[1];
    document.body.style.overflow = 'hidden';
    document.getElementById('fullscreenBG').style.display = 'block';
    document.getElementById('fullscreenContainer').style.display = 'block';
}

function mOverAct(imgID){

     var navi = navigator.appVersion;
     var oldMSIE = false;

    if(navi.indexOf("MSIE")>-1){
	var navAr = navi.split(";");
	if(parseFloat(navAr[1].split(" ")[2])< 6) oldMSIE = true;
    }

    if (!oldMSIE) document.getElementById('thumb'+imgID).style.cursor='pointer';
        document.getElementById('thumb'+imgID).style.border='1px inset #cababb';
}


function mOutAct(imgID){
    document.getElementById('thumb'+imgID).style.border='1px #cabcbc outset';
}

function parentHideFullscreenURL(imgID){

    var parentURL = parent.location.href;
    parseCallingURL(parentURL);
    parentVarString = getVarString();
    if (parentVarString == ''){
	parentVarString = 'page=1';
	parentURL = parentURL + '?' + parentVarString;
    }
    return parentURL.replace(parentVarString,'page='+parent.pWithImg[imgID]);
}

function parentHideFullscreenImage(imgID){

    if (parent.location.href != parentHideFullscreenURL(imgID)){
	top.location.href = parentHideFullscreenURL(imgID);
    }
    else {
	parent.document.getElementById('fullscreenContainer').style.display='none';
	parent.document.getElementById('fullscreenBG').style.display='none';
	parent.document.getElementById('fullscreenContainer').src = '';
	parent.document.body.style.overflow = 'auto';
    }
}

function hideFullscreenImage(){
    document.getElementById('fullscreenContainer').style.display='none';
    document.getElementById('fullscreenBG').style.display='none';
    document.getElementById('fullscreenContainer').src='';
    document.body.style.overflow = 'auto';
}

function arrayMax(array){
  var narray = [];
  for ( var i = 0; i < array.length; i++ )
    if ( array[i] != null )
      narray.push( array[i] );
  return Math.max.apply( Math, narray );
};

function oldBrowser(){
    var navi = navigator.appVersion;
    if(navi.indexOf("MSIE")>-1){
	var navAr = navi.split(";");
	if(parseFloat(navAr[1].split(" ")[2])< 5.5) {
        return true;
        }
    else return false;
    }
else return false;
}

function showTh(imgID,thumbWidth,imgName,imgThumbSRC){
    var imgURLprefix = document.getElementById('imageFolder').value;
    document.write('<img id="thumb'+imgID+'" "onmouseover="mOverAct('+imgID+'); "onmouseout=\"mOutAct('+imgID+'); "style="width:'+thumbWidth+'px; "title="'+imgName+'" "alt="'+imgName+'" src=\"'+imgURLprefix+imgThumbSRC+'" onclick="showFullscreenImage('+imgID+');"/>');
}
