//
// Bosgrond.nl - Javascript Image links and popup window
// Copyright (C) Bosgrond.nl
//
// Made by Mm, 2006
// Inspired by Nando, nandOOnline - http://www.nandoonline.com
// 
function newFoto(uerel,titel,positie) {
	var strLok = uerel.indexOf(".jpg");
	if (strLok==-1) strLok = uerel.indexOf(".gif");
	var tmbnl = uerel.substring(0, strLok);
	var pos='', width='';
	
	var img = new Image();
	//img.src = uerel;
	img.src=tmbnl+"_tn"+uerel.substring(strLok);
	if (positie == 'left') {pos = 'floatLeft';}
	else if (positie == 'right') {pos = 'floatRight';}
	else if (positie == 'center') {pos = 'floatCenter';}
	if (positie == '80%') {pos = 'floatLine'; width=img.width*0.8;}
	if (positie == '60%') {pos = 'floatLine'; width=img.width*0.6;}
	if (positie == 'b80') {pos = ''; width=img.width*0.8;}
	//if (positie == 'b') {pos = '';}
	
	var htmCode = "<a href=\"#\" onclick=\"popImageMm('"+uerel+"','"+titel+"');return false;\"";
	//var htmCode = "<a href=\"#\" onclick=\"popUp('', 'perceel','50','50','no','"+titel+"','"+uerel+"');return false;\"";
	htmCode += " onMouseOver=\"window.status='Bosgrond foto (klik voor grote versie)'; return true;\"";
	htmCode += " onMouseout=\"window.status=' '; return true;\">";
	htmCode += "<img class=\""+pos+"\" src=\""+img.src+"\" alt=\"Bosgrond foto (klik voor grote versie)\n"+titel+"\"";
	if(width=='' && img.width>560) htmCode += " width=\"560\"";
	else if (width!='') htmCode += " width=\""+width+"\"";
	htmCode += " /></a>";
	
	document.writeln(htmCode);
}

function newImgLink(uerel,titel, tekst)
{  // maak tekstlink naar image
//	var img = new Image();
//	img.src = uerel;
	
	var sStatus = tekst+" ";
	if(tekst=="hier") sStatus="";
	sStatus+="(klik om in nieuw venster te openen)";
	var htmCode = "<a href=\"#\" onclick=\"popImageMm('"+uerel+"','"+titel+"');return false;\"";
	//var htmCode = "<a href=\"#\" onclick=\"popUp('', 'perceel','50','50','no','"+titel+"','"+uerel+"');return false;\"";
	htmCode += " onMouseOver=\"window.status='"+sStatus+"'; return true;\"";
	htmCode += " onMouseout=\"window.status=' '; return true;\">";
	htmCode += tekst;
	htmCode += "</a>";
	
	document.writeln(htmCode);
}

function newPdfLink(uerel,titel, tekst)
{  // maak tekstlink naar pdf
//	var img = new Image();
//	img.src = uerel;
	
	var htmCode = "<a href=\"#\" onclick=\"newWin=window.open('"+uerel+"','mmPDF','toolbar=no,resizable=yes'); if( window.focus){newWin.focus()} return false;\"";
	htmCode += " onMouseOver=\"window.status='"+tekst+" (klik om PDF in nieuw venster te openen)'; return true;\"";
	htmCode += " onMouseout=\"window.status=' '; return true;\">";
	htmCode += tekst;
	htmCode += "</a>";
	
	document.writeln(htmCode);
}


function popUp(mypage, myname, w, h, scroll, titel, imgName) {

	var winl = 20;
	var wint = 20;
	scroll='yes';
	var winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable=yes';
		
	var newWindow = window.open(mypage, myname, winprops);
	if (!newWindow) return; // popup-blocker
		
	var contentWindow;
	contentWindow = '<?xml version="1.0" encoding="iso-8859-1"?>';
	contentWindow += '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
	contentWindow += '<html xmlns="http://www.w3.org/1999/xhtml">';
	contentWindow += '<head><title>' +titel+ '</title>';
	contentWindow += '<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><meta http-equiv="imagetoolbar" content="no" />';
	contentWindow += '<meta name="Copyright" content="Copyright © Bosgrond.nl" /><meta name="Design" content="Nando, nandOOnline - http://www.nandoonline.com" />';
	contentWindow += '<link href="../css/css.css" rel="stylesheet" type="text/css" />';
	contentWindow += '<style type="text/css" media="screen">body{overflow:none; margin:0px; padding:0px;} img{margin:0px; padding:0px; border:none;}</style>';
	contentWindow += '<script language="JavaScript">';
	contentWindow += 'var NS = (navigator.appName==\"Netscape\")?true:false;';
   contentWindow += 'function autofit() { w=(NS)?window.innerWidth:document.body.clientWidth; h=(NS)?window.innerHeight:document.body.clientHeight; w=Math.min(screen.availWidth-80, document.getElementById(\'afb\').width) - w; h=Math.min(screen.availHeight-80, document.getElementById(\'afb\').height) - h; window.resizeBy(w, h); /*self.focus();*/	} ';
	contentWindow += ' function hide_scroll() {if(document.getElementById(\'afb\').width< (screen.availWidth-20)&&document.getElementById(\'afb\').height<(screen.availHeight-20)){document.body.style.overflow=\'hidden\';}}';
	contentWindow += ' function autosize() {window.resizeTo((Math.min(document.getElementById(\'afb\').width, screen.availWidth-20)),(Math.min(document.getElementById(\'afb\').height, screen.availHeight-20)));}';
	contentWindow += '</script>';
	contentWindow += '</head><body>';
	contentWindow += '<a href="javascript:window.close()">';
	contentWindow += '<img id="afb" src="'+imgName+'" alt="' +titel+ '\n(Klik om venster te sluiten)' +'" onload="javascript:hide_scroll();autofit();" />';
	contentWindow += '</a>';
	contentWindow += '</body></html>';
		
	newWindow.document.writeln(contentWindow);
	newWindow.document.close();			// ???
		
	if (parseInt(navigator.appVersion) >= 4) { newWindow.window.focus(); }
}


// Auto-Sizing Image Popup Window
// http://www.codelifter.com/main/javascript/autosizeimagepopup.html
// Adjusted for Bosgrond.nl by Mm

// Set the horizontal and vertical position for the popup
PositionX = 20;
PositionY = 20;

// Set these value approximately 20 pixels greater than the
// size of the largest image to be used (needed for Netscape)
defaultWidth  = 500;
defaultHeight = 500;

// Set autoclose true to have the window close automatically
// Set autoclose false to allow multiple popup windows
var AutoClose = true;

// ================================
if (parseInt(navigator.appVersion.charAt(0))>=4){
var isNN=(navigator.appName=="Netscape")?1:0;
var isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}
var optNN='resizable=yes, scrollbars=yes,width='+defaultWidth+',height='+defaultHeight+',left='+PositionX+',top='+PositionY;
var optIE='resizable=yes, scrollbars=yes,width=250,height=100,left='+PositionX+',top='+PositionY;

function popImageMm(imageURL,imageTitle)
{
//alert("imageURL: " +imageURL+ ", imageTitle:" + imageTitle);
	if (isNN){imgWin=window.open('about:blank','',optNN);}
	if (isIE){imgWin=window.open('about:blank','',optIE);}
	with (imgWin.document){
		var htmCode='';
		htmCode += '<html><head><title>Geduld a.u.b. ...</title>';
		htmCode += '<meta name="Copyright" content="Copyright © Bosgrond.nl" />';
		htmCode += '<style type="text/css" media="screen">body{overflow:none; margin:0px; padding:0px;} img{margin:0px; padding:0px; border:none;}</style>';
		htmCode += '<sc'+'ript language="JavaScript">';
		htmCode += 'var isNN,isIE;';
		htmCode += 'if (parseInt(navigator.appVersion.charAt(0))>=4){';
		htmCode += 'isNN=(navigator.appName=="Netscape")?1:0;';
		htmCode += 'isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}';
		htmCode += 'function reSizeToImage(){';
		htmCode += 'if (isIE){';
		htmCode += 'window.resizeTo(100,100);';
		htmCode += 'width=100-(document.body.clientWidth-document.images[0].width);';
		htmCode += 'height=100-(document.body.clientHeight-document.images[0].height);';
		htmCode += 'window.resizeTo(width,height);}';
		htmCode += 'if (isNN){';       
		htmCode += 'window.innerWidth=document.images["mmImage"].width;';
		htmCode += 'window.innerHeight=document.images["mmImage"].height;}}';
   	htmCode += 'function autofit() { w=(isNN)?window.innerWidth:document.body.clientWidth; h=(isNN)?window.innerHeight:document.body.clientHeight; w=Math.min(screen.availWidth-80, document.getElementById(\'mmImage\').width) - w; h=Math.min(screen.availHeight-80, document.getElementById(\'mmImage\').height) - h; window.resizeBy(w, h); /*self.focus();*/	} ';
		htmCode += ' function hide_scroll() {if(document.getElementById(\'mmImage\').width< (screen.availWidth-20)&&document.getElementById(\'mmImage\').height<(screen.availHeight-20)){document.body.style.overflow=\'hidden\';}}';
		htmCode += 'function doTitle(){document.title="'+imageTitle+'";}';
		htmCode += '</sc'+'ript>';
		htmCode += '</head><body bgcolor=000000 scroll="yes" onload="hide_scroll();autofit();doTitle();self.focus()"';
		if (AutoClose)
			htmCode += ' onblur="self.close()"';
		htmCode += '>';
		htmCode += '<a href="javascript:window.close()">';
		htmCode += '<img id="mmImage" src="'+imageURL+'" style="display:block" alt="' +imageTitle+ '\n(Klik om venster te sluiten)' +'"/>';
		htmCode += '</a>';
		htmCode += '</body></html>';
		writeln(htmCode);
		close();		
	}
}