
//(the first two should be small for Opera's sake)
PositionX = 10;
PositionY = 10;
defaultWidth  = 500;
defaultHeight = 450;

//var AutoClose = true;
// using: popMediaz("mediaurl.wmv","imageTitle" [,AutoClose, mediaWidth, mediaHeight] );
var popMediazWin;
function popMediaz(imageURL, imageTitle, AutoClose, mediaWidth, mediaHeight){
	var BGColor="#E80000";
	if (!mediaWidth) var mediaWidth=defaultWidth;
	if (!mediaHeight) var mediaHeight=defaultHeight;
	var ispic=imageURL.match(/\.(jpg|gif|png|tiff|tif|bmp|ai|wmf)$/);
	popMediazWin = window.open('','popMediazWin','scrollbars=no,resizable=1,width='+defaultWidth+',height='+defaultHeight+',left='+PositionX+',top='+PositionY);
	if( !popMediazWin ) { return true; } //popup blockers should not cause errors
	var doc='<html><head><title>'+imageTitle+'<\/title><script type="text\/javascript">\n'+
		'function resizeWinTo() {\n';
		if (ispic){
			doc+='if( !document.images.length && document.layers[0].images[0] ) { document.images[0] = document.layers[0].images[0]; }\n'+
				'var oH = Number(document.images[0].height), oW = Number(document.images[0].width);\n';
		}else{
			doc+='var obj=document.getElementById("popMediazObj");\n var oH = Number(obj.height), oW = Number(obj.width);\n\n';

		}
		doc+='if( !oH || window.doneAlready ) { return; }\n'+ //in case images are disabled
		'window.doneAlready = true;\n'+ //for Safari and Opera
		'var x = window; x.resizeTo( oW + 200, oH + 200 );\n'+
		'var myW = 0, myH = 0, d = x.document.documentElement, b = x.document.body;\n'+
		'if( x.innerWidth ) { myW = x.innerWidth; myH = x.innerHeight; }\n'+
		'else if( d && d.clientWidth ) { myW = d.clientWidth; myH = d.clientHeight; }\n'+
		'else if( b && b.clientWidth ) { myW = b.clientWidth; myH = b.clientHeight; }\n'+
		'if( window.opera && !document.childNodes ) { myW += 16; }\n'+
		'x.resizeTo( oW = oW + ( ( oW + 200 ) - myW ), oH = oH + ( (oH + 200 ) - myH ) );\n'+
		'var scW = screen.availWidth ? screen.availWidth : screen.width;\n'+
		'var scH = screen.availHeight ? screen.availHeight : screen.height;\n'+
		'if( !window.opera ) { x.moveTo(Math.round((scW-oW)/2),Math.round((scH-oH)/2)); }\n'+
		'}\n'+
		'<\/script>'+
		'<\/head><body bgcolor="'+BGColor+'" onload="resizeWinTo();"'+(AutoClose?' onblur="self.close();"':'')+'>'+

		(document.layers?('<layer left="0" top="0">'):('<div style="position:absolute;left:0px;top:0px;display:table;">'));

		if (ispic){
		// PICTURES:
			doc+='<a href="javascript:void(self.close());" >';//self.opener=null;void(self.close());
			doc+='<img border="0" src='+imageURL+' alt="Loading image ..." title="" onload="resizeWinTo();">';
			doc+='</a>';
		}else{
		// OTHER MEDIA:
			doc+='<a href="javascript:void(self.close());" >';
			doc += '<object width="'+mediaWidth+'" height="'+mediaHeight+'" id="popMediazObj">'; 
			doc += '<param name="SRC" value="' + imageURL + '">';
			doc += '<param name="autoplay" value="true">'; 
			doc += '<param name="controller" value="true">';
			doc += '<param name="bgcolor" value="'+BGColor+'">'; 
			doc += '<embed id="popMediazObj" src="' + imageURL + '" autostart="true" loop="false" width="'+mediaWidth+'" height="'+mediaHeight+'" controller="true" bgcolor="'+BGColor+'"><\/embed>';
			doc += '<\/object>'; 
			doc+='</a>';
			doc += '<p style="font-size:10px;font-family:Verdana,sans-serif;text-align:center"><a href="' + imageURL +'">Download this file<\/a> <SPAN style="font-size:10px">(right-click or Option-click)<\/SPAN><\/p>';
		}

		doc+=(document.layers?'<\/layer>':'<\/div>')+'<\/body><\/html>';

	popMediazWin.document.write(doc);
	popMediazWin.document.close();
	if( popMediazWin.focus ) { popMediazWin.focus(); }

}



