/** fla **/
function Flacont(iname, objId, embedId)
{
    this.instanceName = iname;
    this.objElement = document.getElementById( objId );
    this.embedElement = document.getElementById( embedId );
    this.scriptingAccess = null;

    if (navigator.appName.indexOf("Microsoft") != -1) {
	this.scriptingAccess = window[ "mb1" ];
    } else {
	this.scriptingAccess = document[ "mb2" ];
    }


    this.cx = 1000;
    this.cy = 800;
    this.positionElements();

    this.setEventHandler( window, "resize", function() { flactrl.onWindowResized(); } );
}

Flacont.baseWidth = 1000;
Flacont.baseHeight = 800;

Flacont.prototype.positionElements = function()
{
    var mx = this.getDocMetrics();
    var cx, cy;

    mx.height -= 24;

    if( (mx.width >= Flacont.baseWidth) && (mx.height >= Flacont.baseHeight) ) {
	cx = Flacont.baseWidth;
	cy = Flacont.baseHeight;
    } else {
	cx = mx.width;
	cy = cx * (Flacont.baseHeight / Flacont.baseWidth);

	if( cy > mx.height ) {
	    cy = mx.height;
	    cx = cy * (Flacont.baseWidth / Flacont.baseHeight);
	}

	if( (cy < (Flacont.baseHeight / 2)) ||
	    (cx < (Flacont.baseWidth / 2)) ) {
	    // no go, let's scroll...
	    cx = Flacont.baseWidth / 2;
	    cy = Flacont.baseHeight / 2;
	}
    }

    if( this.objElement != null ) {
	if( this.objElement.style !== undefined ) {
	    this.objElement.style.width = cx + "px";
	    this.objElement.style.height = cy + "px";
	}
	this.objElement.width = cx;
	this.objElement.height = cy;
    }

    if( this.embedElement != null ) {
	if( this.embedElement.style !== undefined ) {
	    this.embedElement.style.width = cx + "px";
	    this.embedElement.style.height = cy + "px";
	}

	this.embedElement.width = cx;
	this.embedElement.height = cy;
    }

    this.cx = cx;
    this.cy = cy;

    this.notifyScale();
}

Flacont.prototype.onWindowResized = function()
{
    this.positionElements();
}

Flacont.prototype.getDocMetrics = function()
{
    var metrics = {
	offX : 0,
	offY : 0,
	width : 0,
	height: 0
    };

    if( window.pageXOffset !== undefined ) {
	metrics.offX = window.pageXOffset;
    } else if( document.documentElement.scrollLeft !== undefined ) {
	metrics.offX = document.documentElement.scrollLeft;
    } else if( document.body.scrollLeft !== undefined ) {
	metrics.offX = document.body.scrollLeft;
    }

    if( window.pageYOffset !== undefined ) {
	metrics.offY = window.pageYOffset;
    } else if( document.documentElement.scrollTop !== undefined ) {
	metrics.offY = document.documentElement.scrollTop;
    } else if( document.body.scrollTop !== undefined ) {
	metrics.offY = document.body.scrollTop;
    }

    if( window.innerWidth ) {
	metrics.width = window.innerWidth ;
	metrics.height = window.innerHeight;
    } else if( document.documentElement.clientWidth ) {
	metrics.width = document.documentElement.clientWidth;
	metrics.height = document.documentElement.clientHeight;
    } else if( document.body.clientWidth ) {
	metrics.width = document.body.clientWidth;
	metrics.height = document.body.clientHeight;
    }

    return metrics;
}

Flacont.prototype.setEventHandler = function(element, evt, code)
{
    if( element.addEventListener ) {
        element.addEventListener( evt, code, true );
    } else if( element.attachEvent ) {
        element.attachEvent( "on" + evt, code );
    } else {
        /** this part is hard-coded for obvious reasons **/
        switch( evt ) {
            case        "mouseover"         :
		element.onmouseover = code;
                break;

            case        "mouseout"    :
                element.onmouseout = code;
                break;
        }
    }
}

Flacont.prototype.notifyScale = function()
{
    if( this.scriptingAccess != null ) {
	if( this.scriptingAccess.onMovieScaled !== undefined )
	    this.scriptingAccess.onMovieScaled( this.cx, this.cy );
    }
}

