function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}
function findPosX(obj)
  {
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
  }
function findPosY(obj)
  {
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
  }


function fotogroot()
{

    var theWidth = 0;
    var theHeight = 0;
    var factor =0;
    var lval =0;

    if (window.innerWidth) {
	theWidth = window.innerWidth
    } else if (document.documentElement &&
                document.documentElement.clientWidth) {
	theWidth = document.documentElement.clientWidth
    } else if (document.body) {
	theWidth = document.body.clientWidth
    }

    if (window.innerHeight) {
	theHeight = window.innerHeight
    } else if (document.documentElement &&
                document.documentElement.clientHeight) {
	theHeight = document.documentElement.clientHeight
    } else if (document.body) {
	theHeight = document.body.clientHeight
    }
    theWidth-=50;
    theHeight+=100;

	var ImgId='ToonFoto';
	var d=document.getElementById('container');
	if(!d){return;}
	var Links=d.getElementsByTagName('a');
	for(var i=0;i<Links.length;i++)
	{
		Links[i].onclick=function()
		{
			var soort=Right(this.href.toLowerCase(),3);
			if (soort!='jpg' && soort!='png' && soort!='gif')
			{return;}
			var DivGeplaatst=document.getElementById(ImgId);
			if(DivGeplaatst)
			{
			 DivGeplaatst.parentNode.removeChild(DivGeplaatst);
			}


			var Alts=this.getElementsByTagName('img');
			if (Alts.length >0){
			   AltNaam=this.getElementsByTagName('img')[0].alt;
			}


			var NewDiv=document.createElement('div');

			d.parentNode.insertBefore(NewDiv,d);
			NewDiv.style.display='none';
			NewDiv.style.left='-2600px';
			NewDiv.id=ImgId;


			NewPara=document.createElement('p');						
			NewPara.appendChild(document.createTextNode('[printen / print'));
			NewPara.appendChild(document.createTextNode('] '));
			
			var NewImgP = new Image();
			NewImgP.src='http://www.zingendesnaar.nl/js/print_s.gif';
			NewImgP.style.border="0";
			NewImgP.style.align="absmiddle"

			NewImgP.alt='Print';
			NewImgP.title='Print';
			NewImgP.onclick=function()
			{

				var mywin = window.open('','','width=900,height=5');
				mywin.title=AltNaam;
				mywin.document.open("text/html");
				mywin.document.write('<html><head><title>');
				mywin.document.write(AltNaam);
				mywin.document.write('</title></head><body onLoad="setTimeout(window.close, 5000)">');
				mywin.document.write(' <IMG border="0" src="');
				mywin.document.write(MyHref);
				mywin.document.write('" width="800"></body></html>');
				mywin.document.close();
				mywin.print();
				mywin.close();
			}


			NewPara.appendChild(NewImgP);


			NewPara.appendChild(document.createTextNode('[sluiten / close'));
			NewPara.appendChild(document.createTextNode(']'));


			var NewImgP = new Image();
			NewImgP.src='http://www.zingendesnaar.nl/js/kruisje.gif';
			NewImgP.style.border="0";
			NewImgP.style.align="absmiddle"
			NewImgP.alt='Sluit';
			NewImgP.title='Sluit';
			NewImgP.onclick=function()
			{
			 NewImg.parentNode.parentNode.removeChild(NewImg.parentNode);
			}


			NewPara.appendChild(NewImgP);


			NewDiv.appendChild(NewPara);




			var NewImg = new Image();
			NewImg.onload = function()
			{
			    var WtOrg=NewImg.width;
			    var HtOrg=NewImg.height;

			    if(NewImg.width > theWidth){
				factor=theWidth / NewImg.width;
				lval=NewImg.height;
				NewImg.width=theWidth;
				NewImg.height=lval * factor;
			    }

			    if(NewImg.height > theHeight){
				factor=theHeight / NewImg.height;
				lval=NewImg.width;
				NewImg.height=theHeight;
				NewImg.width=lval * factor;
			    }

			    if (NewImg.width < theWidth-100)
 			        NewDiv.style.left= (theWidth/2-NewImg.width/2)+"px";
			    else 
				NewDiv.style.left="16px";
                            
			}

			NewImg.src=this.href;
			var MyHref=this.href;

			if (AltNaam.length >0){
			   NewImg.alt=AltNaam;
			}
			NewImg.title='Klik hier om te sluiten';
			NewImg.onclick=function()
			{
			 this.parentNode.parentNode.removeChild(this.parentNode);
			}
			NewDiv.appendChild(NewImg);

			NewPara=document.createElement('p');
			if (AltNaam.length >0){
		NewPara.appendChild(document.createTextNode(AltNaam));
			}
			NewDiv.appendChild(NewPara);



			NewDiv.style.display='block';
			NewDiv.style.top= (findPosY(this)+10)+"px";

			return false;
		}
	}		
}

window.onload=function()
{
	if(document.getElementById && document.createTextNode)
	{
		document.body.onmouseover=function()
		{
			fotogroot();	
		}																
		
	}
}
