var PhotoBig=null;

function fMakePopUpWindow(handler,url,windowName,width,height,toolbar,location,directories,status,menubar,scrollbars,resizable,top,left) {
	if (!handler) var handler=null;
	if (!windowName) title='no_windowName';
	if (!width) width=200;
	if (!height) height=200;

  var x=(typeof(left)=='undefined')?(screen.availWidth - width)/2   : left;
  var y=(typeof(top) =='undefined')?(screen.availHeight - height)/2 : top;

	var windowFeatures = "width=" +width+ ",height=" +height+ ",screenX=" +x+ ",screenY=" +y+ ",top=" +y+ ",left=" +x+ ",toolbar="+toolbar+",location="+location+",directories="+directories+",status="+status+",menubar="+menubar+",scrollbars="+scrollbars+",resizable="+resizable;
	handler=window.open(url,windowName,windowFeatures);
	if (handler) {
		handler.focus();
		if (handler.opener == null) handler.opener = window;
	}
	
	return handler;
}

function FitPic() {
	var NS=document.all;

	window.moveTo(0,0)

	//var left_border=28;
	var left_border=28;
	var top_border=51;


	maxWidth=screen.width-left_border - 250;
	maxHeight=screen.height-top_border - 250;

	iWidth = (!NS)?window.innerWidth:document.body.clientWidth; 
	iHeight = (!NS)?window.innerHeight:document.body.clientHeight; 

	imageWidth = document.images[0].width; 
	imageHeight = document.images[0].height; 

	var newWidth= (imageWidth >maxWidth)?maxWidth :imageWidth;
	var newHeight=(imageHeight>maxHeight)?maxHeight : imageHeight;

	//var newWidth	=(imageWidth >(maxWidth-left_border)?maxWidth :imageWidth +left_border)+(imageHeight>(maxHeight-top_border) ?scroll_bar:0);
	//var newHeight =(imageHeight>(maxHeight-top_border)?maxHeight:imageHeight+top_border) +(imageWidth >(maxWidth -left_border)?scroll_bar:0);		

	window.resizeTo(newWidth+left_border, newHeight+top_border); 

	if (!NS) { 
		window.moveTo((self.screen.width - self.outerWidth)/2, (self.screen.height - self.outerHeight)/2);
	} 
	else {
		self.moveTo((self.screen.width-document.body.clientWidth)/2, (self.screen.height-document.body.clientHeight)/2);
	}
	self.focus();
}


function OnPhotoClick(photo) {
	width=180;
	height=30;

	src= (typeof(photo)=="object")?photo.src:photo;
	if (PhotoBig) PhotoBig.close();

	PhotoBig=fMakePopUpWindow(PhotoBig,'/photos_fullview.php?photo_src='+escape(src),'PhotoViewer',width,height,0,0,0,0,0,1,1,0,0);
	if (PhotoBig) PhotoBig.focus();
	return false;
}
