// "Namespace"-Objekt "ibb"
if (typeof ibb == "undefined")
    var ibb = new Object();

ibb.window = function (setCoord) {
    this.coord = setCoord; // new Array(4);
    this.offset = [0,0,0,0]; // offset zu vom Browser ermittelten Werten;
    this.isIE = (navigator.plugins && navigator.mimeTypes &&
		 navigator.mimeTypes.length) ? false : true;
}

ibb.window.prototype = {

    // String-Repräsentation für Koordinaten erzeugen
    //
    toString: function () {
	return this.coord.join(",");
    },

    // Koordinaten aus String ermitteln
    //
    fromString: function (str) {
	if (! str)
	    return false;

	var newCoord = new Array();
	var strCoord = str.split(",");
	for (var i=0; i<4; i++) {
	    if (strCoord.length > i) {
		var c = parseInt(strCoord[i]);
		if (isNaN(c))
		    return false;
		if (c < 0)
		    return false;
		newCoord.push(c);
	    } else
		newCoord.push(this.coord[i]);
	}
	for (var i=0; i<4; i++)
	    this.coord[i] = newCoord[i];
	return true;
    },

    // Parameterstring für window.open() erzeugen
    //
    paramString: function () {
	return "left="+this.coord[0]+
		",top="+this.coord[1]+
		",width="+this.coord[2]+
		",height="+this.coord[3];
    },

    // Koordinaten ermitteln (ohne Offset-Berücksichtigung)
    //
    getCoords: function (win) {
	if (this.isIE)
	    return new Array(win.screenLeft, win.screenTop, win.document.body.clientWidth, win.document.body.clientHeight);
	else
	    return new Array(win.screenX, win.screenY, win.outerWidth, win.outerHeight);
    },

    // Offsets aus gesetzten und ermittelten Koordinaten berechnen
    //
    calcOffset: function (win) {
	var coords = this.getCoords (win);
	for (var i=0; i<4; i++)
	    this.offset[i] = coords[i] - this.coord[i];
	//alert ("calcOffset:\ngesetzt: "+this.coord.join(",")+"\nerhalten: "+coords.join(",")+"\noffsets: "+this.offset.join(","));
    },
    
    updateCoords: function (win) {
	var coords = this.getCoords (win);
	for (var i=0; i<4; i++)
	    this.coord[i] = coords[i] - this.offset[i];
    }
}
