function OpenImage() {
    if (arguments.length > 2) {
        var ID = isNaN(arguments[0]) ? 0 : parseInt(arguments[0], 10);
        var x = isNaN(arguments[1]) ? 600 : parseInt(arguments[1], 10) + 17;
        var y = isNaN(arguments[2]) ? 600 : parseInt(arguments[2], 10) + 63;
        var n = (arguments.length > 3) ? arguments[3] : 'unknown';
        var topWin = getOpenerTop();
        if (typeof (topWin.singleImageWin) == 'undefined' || topWin.singleImageWin == null || topWin.singleImageWin.closed) {
            x = (x > screen.availWidth) ? screen.availWidth : x;
            y = (y > screen.availHeight) ? screen.availHeight : y;
            topWin.imgsToShow = self.imgsToShow;
            topWin.singleImageWin = self.open("/usergalerie/singleimage.asp?ID=" + ID + '&n=' + n, "showimage", 'toolbar=no,status=yes,scrollbars=yes,resizable=yes,width=' + x + ',height=' + y + ',screenX=0,screenY=0,top=0,left=0');
            topWin.singleImageWin.focus();
        } else {
            try {
                topWin.imgsToShow = self.imgsToShow;
                topWin.singleImageWin.GoTo(1, this, ID);
                topWin.singleImageWin.focus();
            }
            catch (e) { topWin.singleImageWin = null; OpenImage(arguments); }
        }
    }
}

function getOpenerTop(){
    return getImgOpener(top, 10).top;
}

function getImgOpener() {
    var w = arguments.length > 0 ? arguments[0] : self;
    var i = 0; var j = arguments.length > 1 ? arguments[1] : 10;var x;
    try {
        while (w.opener && !w.opener.closed && i < j) {
            if (typeof (w.opener.top) == 'object' && typeof (w.opener.top.location) == 'object' && (x = w.opener.top.singleImageWin))
            { w = w.opener.top; i++;} else { i = j; } 
        }
            } catch (e) {
        if (typeof (w) != 'object' || typeof (w.location) != 'object') w = self;
    }
    return w;
}
