var pictureWindow;

function showPicture (url, title, width, height) {
    if(pictureWindow) pictureWindow.close();
    
    if(screen.availWidth < (width+50) || screen.availHeight < (height+50)) {
        if((screen.availWidth / width) < (screen.availHeight / height)) {
            var ratio = (screen.availWidth / width);
            width = width * ratio;
            height = height * ratio;
            url = url.substr(0,url.lastIndexOf("/")) + '/' + Math.round((width>height)?(width * ratio):(height * ratio)) + url.substr(url.lastIndexOf("/"));
            alert(url);
        } else {
            var ratio = (screen.availHeight / height);
            width = width * ratio;
            height = height * ratio;
            url = url.substr(0,url.lastIndexOf("/")) + '/' + Math.round((width>height)?(width * ratio):(height * ratio)) + url.substr(url.lastIndexOf("/"));
            alert(url);            
        }
    } else {
        pictureWindow = window.open(url, title, "dependent=yes,location=no,innerWidth=" + width + ",innerHeight=" + height + ",screenX=100,screenY=200,menubar=no,status=no");
    }
	return false;
}