window.size = function()
{
	var w = 0;
	var h = 0;

	//IE
	if(!window.innerWidth)
	{
		//strict mode
		if(!(document.documentElement.clientWidth == 0))
		{
			w = document.documentElement.clientWidth;
			h = document.documentElement.clientHeight;
		}
		//quirks mode
		else
		{
			w = document.body.clientWidth;
			h = document.body.clientHeight;
		}
	}
	//w3c
	else
	{
		w = window.innerWidth;
		h = window.innerHeight;
	}
	return {width:w,height:h};
}

function etikette( projectId, contentElement )
{
	// make overlay
	var lOverlay = new Element( "div", {
	    "id": "layerOverlay",
	    "styles": {
			"position": "fixed",
	        "top": "0px",
			"left": "0px",
			"width": "0",
			"height": "0",
			"background-image": "url(img/bg_overlay.png)",
			"z-index": "3700"
	    }
	});
	lOverlay.inject( "contentWrapper", "before" );

	// tween up
	var fx = new Fx.Morph( lOverlay, {
		duration: 1000,
		transition: "quad:out",
		link: "chain"}
	);
	fx.start({
		"width": window.size().width,
		"height": 10
	}).start({
		"height": window.size().height
	}).chain( function() {
	    lOverlay.setStyle( "width", "100%" );
	    lOverlay.setStyle( "height", "100%" );
	});
		
	// find position of project container
	var cPos = $( projectId ).getPosition();
	
	// make new container for flash
	var lFlash = new Element( "div", {
	    "id": "layerFlash",
	    "styles": {
			"position": "absolute",
	        "top": (cPos.y-148)+"px",
			"left": "50%",
			"margin-left": "-384px",
			"width": "868px",
			"height": "596px",
			"z-index": "3701"
	    }
	});
	lFlash.inject( lOverlay, "before" );
	
	// make replacement element for flash
	var lReplace = new Element( "div", {
	    "id": "layerFlashReplace"
	});
	lReplace.inject( lFlash, "top" );

	// load flash
	swfobject.embedSWF(
		"browser/etiketteDisplay.swf",
		"layerFlashReplace",
		"100%", "100%",
		"9",
		false,
		{
			project: projectId,
			displayMode: contentElement
		},
		{
			wmode: "transparent",
			menu: "no",
			quality: "high"
		},
		{}
	);
}

function etiketteRemove()
{
	// tween away
	var fx = new Fx.Morph( "layerOverlay", {
		duration: 1000,
		transition: "quad:out",
		link: "chain"}
	);
	fx.start({
		"width": 0
	}).chain( function() {
	    // remove overlay
		$( "layerOverlay" ).destroy();
		// remove flash
		$( "layerFlash" ).destroy();
	});
}
