var z = 100;
function toTop100(th) {
	curtopID = th.id;
	z = z+100
	var imgnr=$(curtopID).getElement('input').getProperty('value');
	textnr=(imgnr-1);
	$("img"+imgnr).setStyle('z-index',z);
	$('count').set('html',pad2(imgnr));
	$('desctxt').set('html', texts[textnr]);

}

function toBottom(tb) {
	curtopID = tb.id;
	z = 0
	var imgnr=$(curtopID).getElement('input').getProperty('value');
	$("img"+imgnr).setStyle('z-index',z);
	$('count').set('html',pad2(texts.length-1));
	$('desctxt').set('html', texts[texts.length-2]);
}

function pad2(number) { 
     return (number < 10 ? '0' : '') + number
}

function getRealSize(fnm){
	$('pp').setStyle('display','block');
	$('pp').setStyle('top','0');
	$('iw').set('html', '<img src="'+fnm+'" id="iw_img2" />');
	myImageWidth = $('iw_img2').getStyle('width').toInt();
	myImageHeight = $('iw_img2').getStyle('height').toInt();
	if(myImageWidth>size.x || myImageHeight>size.y){
		fotoclass='priveszoom';
		$('iw').set('html', '');
		$('pp').setStyle('display','none');
	}else{
		fotoclass='showfoto';
		$('iw').set('html', '');
		$('pp').setStyle('display','none');
	}
	return fotoclass;
}

function showfoto(fotoname){
		var once=false;
		$('lightbox').setStyle('display','none');
		$('pp').setStyle('display','block');
		$('pp').setStyle('top','0');
		$('iw').set('html', '<img src="'+fotoname+'" id="iw_img">');
		var myImage = new Asset.image(fotoname, {id: 'image', 
			onload:	function(){
				if(once){
					return;
				}else{
					once = true;
					myImageWidth = $('iw_img').getStyle('width').toInt();
					myImageHeight = $('iw_img').getStyle('height').toInt();
					if(myImageWidth>size.x || myImageHeight>size.y){
						$('iw').setStyle('top','0px');						
						$('pp').addEvents({
							'mouseup':function(e){sp(e);},'mousemove':function(e){sp(e);},
							'click':function(e){
								$('pp').removeEvents();
								$('pp').setStyle('display','none');
								$('iw').setStyle('top','-10000px');
								$('iw').set('html', '');
							}
						});
					}else{
						///
						$('lightbox').setStyles({
							'display': 'block',
							'position': 'fixed',
							'top': '0',
							'left': '0',
							'text-align': 'center',
							'width': size.x,
							'height': size.y,
							'background':'black',
							'z-index': '6'
						});
						$('lightbox').setStyle('display', 'block');
						$('lightbox').set('html','<table align="center" height="100%"><tr><td height="100%" valign="middle"><img id="lb_img" src="' + fotoname + '"></td></tr></table><div id=\"lb\">&nbsp;</div>');
						image = $('lightbox').getElement('img');
						image.setStyles({
							'max-height': size.y,
							'position': 'relative',
							'z-index': '5',
							'opacity':'0.97',
							'filter':'alpha(opacity=97)'
						});//einde setStyles 
						$('lightbox').addEvent('click', function () {
							$('lightbox').setStyle('display', 'none');
						})						
						///
						$('pp').removeEvents();
						$('pp').setStyle('display','none');
						$('iw').setStyle('top','-10000px');
						$('iw').set('html', '');
					}
				}
			}
		});		
}

getsize2=function(fnm){
		var once=false;
		$('lightbox').setStyle('display','none');
		$('pp').setStyle('display','block');
		$('pp').setStyle('top','0');
		$('iw').set('html', '<img src="'+fnm+'" id="iw_img">');
		var myImage = new Asset.image(fnm, {id: 'image', 
			onload:	function(){
				if(once){
					return;
				}else{
					once = true;
					myImageWidth = $('iw_img').getStyle('width').toInt();
					myImageHeight = $('iw_img').getStyle('height').toInt();
					if(myImageWidth>size.x || myImageHeight>size.y){
						$('iw').setStyle('top','0px');						
						$('pp').addEvents({
							'mouseup':function(e){sp(e);},'mousemove':function(e){sp(e);},
							'click':function(e){$('pp').removeEvents();$('pp').setStyle('display','none');$('iw').setStyle('top','-10000px');}
						});
					}else{
						$('pp').removeEvents();$('pp').setStyle('display','none');
					}
				}
			}
		});		
}

function si2(fnm){
	getsize2(fnm);
}

function sp(e){
    w=$('pp').getStyle('width').toInt();h=$('pp').getStyle('height').toInt();if(w==100){gs();}
    var iw=myImageWidth;var ih=myImageHeight;
	
    if(iw){
        $('iw').setStyle('left',((iw>w)?((e.client.x/w)*(w-iw)):((w-iw)/2)));
        $('iw').setStyle('top',((ih>h)?((e.client.y/h)*(h-ih)):((h-ih)/2)));
    }
}
function gs() {
    // IE patch
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    w = window.innerWidth;
    h = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    w = document.documentElement.clientWidth;
    h = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    w = document.body.clientWidth;
    h = document.body.clientHeight;
  }
 return Array(w, h);
}	
