/* Function for Window
 *  - Window open
 */


/* Window open */
function openNewWindow(url, title)
{
	var newWin = window.open(url, title, "scrollbars=yes,toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,resizable=yes,dependent=yes");
	newWin.focus();
	return newWin;
}

function openSubWindow(url, title, width, height)
{
	var newWin = window.open(url, title, "width="+width+",height="+height+",scrollbars=yes,toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=yes,dependent=no");
	newWin.focus();
	return newWin;
}


/* Window for photo */
var photoWindow = null;
var photoTimer = null;

function adjustPhotoWindow()
{
	/* Stop timer */
	if(photoTimer != null)  clearTimeout(photoTimer);

	/* check window status */
	if(photoWindow == null  ||  photoWindow.closed)  return;

	/* check photo loading */
	if(! photoWindow.document.images[0].complete){
		photoTimer = setTimeout("adjustPhotoWindow()", 200);
		return;
	}

	/* Browser type */
	var isNS = navigator.appName.charAt(0) == "N";

	/* Get photo size */
	width  = photoWindow.document.images[0].width;
	height = photoWindow.document.images[0].height;

	/* Calc window size */
	if(isNS){
		width  = width + 33;
		height = height + 58;
	}else{
		width  = width + 55;
		height = height + 70;
	}

	/* Slide window */
	screenWidth  = screen.availWidth;
	if(width > screenWidth){
		width = screenWidth;
		photoWindow.moveTo(0, isNS ? photoWindow.screenY : photoWindow.screenTop);
	}

	screenHeight = screen.availHeight;
	if(height > screenHeight){
		height = screenHeight;
		photoWindow.moveTo(isNS ? photoWindow.screenX : photoWindow.screenLeft, 0);
	}

	/* Resize */
	photoWindow.resizeTo(width, height);	
	photoWindow.focus();
}

function openPhotoWindow(photo)
{
	photoWindow = window.open("", "photoWindow", "width=300,height=300,scrollbars=yes,toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=yes,dependent=no");
	photoWindow.document.open();
	photoWindow.document.bgColor="#ffffff";
	photoWindow.document.write("<img src='"+photo+"'>");
	photoWindow.document.close();
	adjustPhotoWindow();
}
