var myWidth = myHeight = pos = 0;
var minHeight = 700;

// ################################################################################################
// RESIZE
// ################################################################################################

function atualizar ()
{
	getResolution ();
	var h = (myHeight < minHeight) ? myHeight + pos : myHeight;
	(navigator.appName.indexOf("Microsoft") != -1 ? window["simulador"] : document["simulador"]).resizeNow(myWidth, h);
}

function resizeSimulador ()
{
	getResolution ();	
	if (myHeight < minHeight)
		document.getElementById("flash").style.height = minHeight + "px";
	else
		document.getElementById("flash").style.height = myHeight + "px";
}

function getResolution()
{	
	if (typeof( window.innerWidth ) == 'number')
	{
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	}
	else if (document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ))
	{
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	}
	else if (document.body && ( document.body.clientWidth || document.body.clientHeight ))
	{
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
}

// ################################################################################################
// SET_INTERVAL
// ################################################################################################

function scrollingDetector()
{
	if( typeof( window.pageYOffset ) == 'number' )
	{
		//Netscape compliant
		pos = window.pageYOffset;
	}
	else if( document.body && document.body.scrollTop )
	{
		//DOM compliant
		pos = document.body.scrollTop;
	}
	else if( document.documentElement && document.documentElement.scrollTop )
	{
		//IE6 standards compliant mode
		pos = document.documentElement.scrollTop;
	}
	atualizar ();
}

function startInterval(){loop = setInterval("scrollingDetector()", 1);}
function closeInterval(){clearInterval(loop);}


// ################################################################################################
// INIT
// ################################################################################################

function init ()
{
	startInterval ();
	resizeSimulador ();
}

// window.onload = init;
window.onresize = resizeSimulador;

// ################################################################################################
// POP UP
// ################################################################################################

function popup (url,name,features)
{
	// Tamanho da janela
	var width = /width=(\d+)/i.exec(features);
	wwidth = width[1];
	var height = /height=(\d+)/i.exec(features);
	wheight = height[1];
	
	// Tamanho da tela
	swidth  = screen.availWidth;
	sheight = screen.availHeight;
	
	// Distância do topo esquerdo
	_left = parseInt((swidth / 2) - (wwidth / 2));
	_top = parseInt((sheight / 2) - (wheight / 2));
	
	features.replace("/top=\d+,?/","");
	features.replace("/left=\d+,?/","");
	
	features += ',top='+ _top +',left='+ _left;
	
	//Abre a Janela
	jan = window.open(url,name,features);
	jan.focus();
}
