// css-related 'constants' 

var WIDTH = 780;
var HEADERHEIGHT = 125;
var COLUMNOFFSET_X = 21; // (not sure why)
var COLUMNOFFSET_Y = -10;
var CONTAINER_OFFSET_Y = 16;

// global variables for tween effect (ugly implementation)

var startX, startY, startWidth, startHeight;
var endX, endY, endWidth, endHeight;
var tweenAt;
var idTween;
var isAnimating;
var dirIsUp;
var assetName;
//var assetBgCol;
var isJavaApplet; // used for handling Java applet instead of Flash

var isMyNemesis;
if (BrowserDetect.browser=="Explorer" && BrowserDetect.version >=5) isMyNemesis = true;


// ============================================================

function makeFlash9String(f)
{
	var s = "";
	
	s+='  	<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'
	s+='			id="llibre" width="100%" height="100%"'
	s+='			codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab">'
	s+='			<param name="movie" value="' + f + '" />'
	s+='			<param name="wmode" value="transparent" />'
	s+='			<embed src="' + f + '"'
	s+='				width="100%" height="100%" name="flashitem" align="middle"'
	s+='				play="true"'
	s+='				loop="false"'
	s+='				wmode="transparent"'
	s+='				type="application/x-shockwave-flash"'
	s+='				pluginspage="http://www.adobe.com/go/getflashplayer">'
	s+='			</embed>'
	s+='	</object>'

	return s;
}

function showBox(pFilename, pWidth, pHeight, pCaller, pIsJavaApplet)
{
	isJavaApplet = pIsJavaApplet;

	cleanupAsset();
	
	isAnimating = true;

	assetFilename = pFilename;
//	assetBgCol = pColor;

	startWidth = 458 - 2; // "-2" b/c of border;
	if (isMyNemesis) startWidth -= 20; // ??
	
	startHeight = 193;
	startX = 115;
	startY = 250;	
	endWidth = pWidth;
	endHeight = pHeight + CONTAINER_OFFSET_Y;
	endX = Math.floor( ((WIDTH) - pWidth )/2 );
	endY = 5;
	if (endY < HEADERHEIGHT) endY = HEADERHEIGHT; // clear flash piece in the header

	tweenAt = 0;
	dirIsUp = true;
	idTween = setInterval(tweenLoop,1000/30, true);
}

function closeBox()
{
	// globals already set by showAsset at this point
	isAnimating = true;

	document.getElementById("assetinside").innerHTML = "";

	tweenAt = 1;
	dirIsUp = false;
	idTween = setInterval(tweenLoop,1000/45);
}

function tweenLoop()
{
	doTween(tweenAt);

	if (document.getElementById("assetcontainer").style.display != "block") {
		document.getElementById("assetcontainer").style.display = "block";	
	}

	if (dirIsUp) 
	{
		if (tweenAt>=1) { finishTween(); return; }	
		tweenAt+= 0.1;
		if (tweenAt>1) tweenAt = 1;
	}
	else 
	{
		if (tweenAt<=0) { finishTween(); return; }	
		tweenAt-= 0.1;
		if (tweenAt<0) tweenAt = 0;
	}
}

function doTween(i)
{
	var o = document.getElementById("assetcontainer");
	var p = document.getElementById("assetinside");

	o.style.left =		Math.floor( startX + ((endX - startX) * i) ) + "px";
	o.style.top = 		Math.floor( startY + ((endY - startY) * i) ) + "px";
	o.style.width =		Math.floor( startWidth + ((endWidth - startWidth) * i) ) + "px";
	o.style.height =	Math.floor( startHeight + ((endHeight - startHeight) * i) ) + "px";

	p.style.width =		Math.floor( startWidth + ((endWidth - startWidth) * i) ) + "px";
	p.style.height =	Math.floor( startHeight + ((endHeight - startHeight) * i) - CONTAINER_OFFSET_Y) + "px";
	
}

function finishTween()
{
	clearInterval(idTween);
	isAnimating = false;
	
	if (tweenAt >=1)
	{
		var s;
		if (! isJavaApplet) 
			s = makeFlash9String("flash/" + assetFilename + ".swf");
		else
			s = makeJavaAppletString("assets/" + assetFilename + ".jar");
			
		document.getElementById("assetinside").innerHTML = s;
	}
	else 
	{
		cleanupAsset();
	}
}

function cleanupAsset()
{
	var o = document.getElementById("assetcontainer");
	var p = document.getElementById("assetinside");
	o.style.display = "none";
	p.innerHTML = "";

}

function treuCapa() {
	if (BrowserDetect.browser == 'Explorer' && BrowserDetect.version <= '7')  {
	document.getElementById("capcal").style.display = "none";
	document.getElementById("ultim_container").style.display = "none";
	document.getElementById("primercontainer").style.display = "none";
	showBox('ex_arsv',936,598,'wrapper');
	//window.open('flashIE6.htm','flash','status=yes,resizable=yes,width=1020,height=520');
	} else {
	showBox('ex_arsv',936,598,'wrapper');
	}
}