function detect() {
	var agent 	= navigator.userAgent.toLowerCase();
	// detect platform
	this.isMac		= (agent.indexOf('mac') != -1);
	this.isWin		= (agent.indexOf('win') != -1);
	this.isWin2k	= (this.isWin && (
			agent.indexOf('nt 5') != -1));
	this.isWinSP2	= (this.isWin && (
			agent.indexOf('xp') != -1 || 
			agent.indexOf('sv1') != -1));
	this.isOther	= (
			agent.indexOf('unix') != -1 || 
			agent.indexOf('sunos') != -1 || 
			agent.indexOf('bsd') != -1 ||
			agent.indexOf('x11') != -1 || 
			agent.indexOf('linux') != -1);	
	this.isLinux = agent.indexOf('linux') != -1;
	// detect browser
	this.isSafari	= (agent.indexOf('safari') != -1);
	this.isSafari2 = (this.isSafari && (parseFloat(agent.substring(agent.indexOf("applewebkit/")+"applewebkit/".length,agent.length).substring(0,agent.substring(agent.indexOf("applewebkit/")+"applewebkit/".length,agent.length).indexOf(' '))) >=  300));
	this.isOpera	= (agent.indexOf('opera') != -1);
	this.isNN		= (agent.indexOf('netscape') != -1);
	this.isIE		= (agent.indexOf('msie') != -1);
	this.isFirefox	= (agent.indexOf('firefox') != -1);
}
var browser = new detect();

function winstat(txt){
eval("window.status='"+txt+"'; ");
}
function jsfenster(url,x,y,name) {
window.open(url,name,"width="+x+",height="+y+",screenX=250,screenY=550,scrolling=yes,location=no,toolbar=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes");
}

function showGalleryImage( imgpath )
{
	var theimg = new Image();
	w = window.open("",
		"galleryimage",
		"width=450,height=450,toolbar=no,resizeable=yes,scrollbars=no");
	w.document.writeln(
		"<html><head></head>"+
		"<body style=\"margin:0;padding:0;\" onload=\"opener.sizeWinToImage(window,document.images[0])\">"
		+"<a href=\"#\" onclick=\"self.close();\">"
		+"<img src=\""+imgpath+"\" border=\"0\" /></a>"
		+"</body>"
		+"</html>");
	w.document.close();
	//w.focus();

	theimg.src = imgpath;
	theimg.onload=function () {
		
		var wwidth=theimg.width;
		var wheight=theimg.height;
		w.resizeTo(wwidth,wheight);
		w.focus();
	}
	

	//	w.onload = function() { w.innerWidth=theimg.width+50; w.innerHeight=theimg.height;  };
	
	return false;;
}

function imagePreview( imgpath, title )
{
	if (!title) { title = ""; }
	return showGalleryImage(imgpath,title);
}

var dla = 0;
function sizeWinToImage( win, bild )
{
	if (!win) { return; }
	var x = bild.width;
	var y = bild.height;	
	if (x == 0 && y == 0) {
		if (dla > 10 ) { return; }
		setTimeout( function() { dla++; sizeWinToImage(win,bild); }, 100);
		return;
	}

	if (browser.isSafari > -1)
	{
		// x += 15; 
		y += 23;
	}
	else if (browser.isFirefox)
	{
		if (browser.isWin)
		{
			x -= 1; y+=19;
		}
		else if (browser.isMac) {
			x -= 1; y+=19;
		}
		else
		{
			x -= 1; y+=24;
		}
	}
	else if (browser.isOpera)
	{
		y+=35; 
	}

	if (w.resizeTo) {
		win.resizeTo(x,y);
	}
	else
	{
		win.innerWidth=x;
		win.innerHeight=y;
	}
	return;
}
