// (c) Alex Bokov 2009

function open_window(imgfile,id) 
{
	xposition = (screen.width - 800) / 2;	// default initial position
	yposition = (screen.height - 600) / 2;	// assuming image size 800x600

	args = "resizable=yes,width=800,height=600,screenx="+xposition+",screeny="+yposition+",left="+xposition+",top="+yposition;
	win=window.open('','',args);

	win.document.writeln( "<html>" );
	win.document.writeln( "<head>" );
	win.document.writeln( "	<script type=text/javascript>	" );
	win.document.writeln( "		var	width	= 800;	" );
	win.document.writeln( "		var	height	= 600;	" );
	win.document.writeln( "	function resize()		" );
	win.document.writeln( "	{				" );
	win.document.writeln( "		setTimeout('resize();',100);	" );
	win.document.writeln( "		if ( x.width != document.body.clientWidth || x.height != document.body.clientHeight )	" );
	win.document.writeln( "		{											" );
	win.document.writeln( "			width = width + ( x.width - document.body.clientWidth );			" );
	win.document.writeln( "			height = height + ( x.height  - document.body.clientHeight  );			" );
	win.document.writeln( "			window.resizeTo( width, height );						" ); 
	win.document.writeln( "		}											" );
	win.document.writeln( "		window.moveTo((screen.width-width)/2,(screen.height-height)/2);				" );					
	win.document.writeln( "	}				" );
	win.document.writeln( "	</script>			" );
	win.document.writeln( "</head>" );
	win.document.writeln( "<body bgcolor=#666666 topmargin=0 leftmargin=0 >" );
	win.document.writeln( "	<img id='x' name='x' src='"+imgfile+"' onload='javascript:resize();'  >" );
	win.document.writeln( "</body>" ); 
	win.document.writeln( "</html>" ); 

	dummyimage = new Image();
	dummyimage.src = "openwindow.php?id="+id;
}

function open_window_large(imgfile) 
{
	open_window( imgfile.replace( '.jpg', '-large.jpg' ) );
}

function leadingzero( number )
{
	result = number;
	if ( result.length < 2 ) result = '0'+result;
	if ( result.length < 3 ) result = '0'+result;
	if ( result.length < 4 ) result = '0'+result;
	if ( result.length < 5 ) result = '0'+result;

	alert( result );

	return result;
}

function chim(name,image) { document.images[name].src = image; }

function preloadImages() {
  var d=document; if(d.images){ if(!d.p) d.p=new Array();
    var i,j=d.p.length,a=preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.p[j]=new Image; d.p[j++].src=a[i];}}
}

	function openAWindow( pageToLoad, width, height ) {
	var w, h;
	  w = width+20;
	  h = height+20;

	  xposition = (screen.width - w) / 2;
	  yposition = (screen.height - h) / 2;
	  args = "width=" + w + ","
	  + "height=" + h + ","
	  + "location=0,"
	  + "menubar=0,"
	  + "resizable=1,"
	  + "scrollbars=0,"
	  + "status=0,"
	  + "titlebar=0,"
	  + "toolbar=0,"
	  + "hotkeys=0,"
	  + "screenx=" + xposition + "," //NN Only
	  + "screeny=" + yposition + "," //NN Only
	  + "left=" + xposition + "," //IE Only
	  + "top=" + yposition; //IE Only
	  window.open( pageToLoad, '', args );
	}


