// JavaScript Document

var nummer = 1;
//	alert("Stap: "+nummer); nummer++;

function setupprev() {
	changeOpac(0, 'prev_bg');
	changeOpac(0, 'prev'); 
	}
	
function setupcontainer() {
	var c = document.getElementById('container');

	var bodysize = getbodysize();
	var hei = bodysize[1];
	
	hei = (hei/2) - (540 / 2);
	
	c.style.top = hei+"px";	
	setfullscreen();
	}

function showprev(id, url) {
	
	setfullscreen()
	
	blockElement('prev');
	blockElement('prev_bg');
	blockElement('prev_buttons');
	
	blockElement('meerinfo_'+id);
	hidePrevious(id); 
	putCookie('meerinfo', String(id));
		
	shiftOpacity('prev_bg',300, 1, 75);
	setTimeout("shiftOpacity('prev',500, 1, 100);", 500);
	 
	setprevdivs();
	setTimeout("replaceimage('"+id+"', '"+url+"');", 10);
	}
	
		function replaceimage(id, url) { 
			var url = "phpthumb/phpThumb.php?src=../"+url+"&w=320&h=300&down=nosave";
			MM_swapImgRestore('swapimage');
			MM_swapImage('swapimage','',url,1);	
			swapdone(); // swapImages.js
			}

function hideprev() { 
	shiftOpacity('prev',500, 0);
	setTimeout("shiftOpacity('prev_bg',300, 0);MM_swapImgRestore('swapimage');noneElement('prev_buttons');", 500);
	}
	
	
	
function handleimages(switchop) {
	var curid = getCookie('meerinfo');
	if (curid) {
		var imgCur = document.getElementById('meerinfo_'+curid);
		
		var imgList = document.forms['currentimagesform'].elements['currentimages'];
		
		var imgNum = imgList.length;
		for (var i = 0; i < imgNum; i ++) { if (imgList[i].value == curid) { var r = i; } }
		
		var newid = Number(r) - (Number(switchop) * -1);
			if (newid >= imgNum) { newid = 0; }
			if (newid < 0) { newid = imgNum - 1; }
		
		var imgNewEl = 'img_'+imgList[newid].value+'_url';
		var imgUrl = document.forms['currentimagesform'].elements[imgNewEl];
		
		noneElement('prev_butt_extralarge'); noneElement('prev_butt_previous'); noneElement('prev_butt_next');
		showprev(imgList[newid].value, imgUrl.value);
		}
	

	}

function openfullimage() {
	var id = getCookie('meerinfo');
	window.location.href='rejhgallery.php?fullview=1&id='+String(id);
	}
	
function setprevdivs() {
		var div = document.getElementById('prev_window');
		var divbutt = document.getElementById('prev_buttons');
		
		if (!div || !divbutt) { alert("Javascript:showprev() > setprevdivs() : Could not find element"); }
		
		var pos = findPos(div);
		
		divbutt.style.left =(Number(pos[0]) )+"px";
		divbutt.style.top = (Number(pos[1]) ) + "px";
	}
	
function setfullscreen() {

	var bodysize = getbodysize();
	var myWidth = bodysize[0] - 1;
	var myHeight = bodysize[1] - 1;
	  
	 document.getElementById('prev').style.width = myWidth + "px";
	 document.getElementById('prev').style.height = myHeight + "px";
	 document.getElementById('prev_bg').style.width = myWidth + "px";
	 document.getElementById('prev_bg').style.height = myHeight + "px";
	 document.getElementById('prev_screen').style.width = myWidth + "px";
	 document.getElementById('prev_screen').style.height = myHeight + "px";
	 
	 
	setbgsize();				  
	}
	
function setbgsize() {
	var bodysize = getbodysize();
	var bgwid = bodysize[0];
	var bghei = bodysize[1] - 100;
	
	bgwid = (4*bghei) / 3;
	
	if (bgwid > bodysize[0]) { bgwid = bodysize[0] - 50; }
	
	document.getElementById('backgroundimage').style.width = bgwid + "px";
	document.getElementById('backgroundimage').style.height = bghei + "px";
}
	
// ----------------------------------------------------------------------------------
	
// Get wid / hei
function getbodysize() {
	  var myWidth = 0, myHeight = 0;
	  if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	  }
	  return [myWidth, myHeight]
	 }
	
// ----------------------------------------------------------------------------------
	
function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
	}
	return [curleft,curtop];
}
	
// ----------------------------------------------------------------------------------

function shiftOpacity(id, millisec, switchop, amount) {
	//alert("currentOpac: "+nummer); nummer++;
	
    //if an element is invisible, make it visible, else make it ivisible
    if(switchop == 1) { currentOpac(id, amount, millisec); } 
	else { currentOpac(id, 0, millisec); }
} 

//change the opacity for different browsers
function changeOpac(opacity, id) {
	//alert("currentOpac: "+nummer); nummer++;
	
	var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";	
}

function currentOpac(id, opacEnd, millisec) {
	//alert("currentOpac: "+nummer); nummer++;
	
    //standard opacity is 100
    var currentOpac = 100;
    
    //if the element has an opacity set, get it
    if(document.getElementById(id).style.opacity < 100) {
        currentOpac = document.getElementById(id).style.opacity * 100;
    }

    //call for the function that changes the opacity
    opacity(id, currentOpac, opacEnd, millisec);
} 

function opacity(id, opacStart, opacEnd, millisec) {
	//alert("opacity: "+nummer+" "+id+" "+opacStart+" "+opacEnd+" "+millisec); nummer++;
	
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;

    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        } setTimeout("noneElement('"+id+"')",(timer * speed)); }
    else if(opacStart < opacEnd) {
		blockElement(id);
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
	
} 
