var collectionJanela = new Array();
collectionJanela.length = 0;
var MaxX;
var MaxY;
var MinX;
var MinY;

function setMax( v1, v2, v3, v4 )
{
	MinX = v1;
	MinY = v2;
	MaxX = v3;
	MaxY = v4;
}

function janela7art( vID, vleft, vtop, vwidth, vheight , vContent , vContentMax)
{

	// propriedades:
	this.left = vleft;
	this.top = vtop;
	this.width = vwidth;
	this.height = vheight;
	this.id = vID;
	this.max = false;

	var vXML = GetXmlHttpObjectSync();
	if( vContent != "" )
	{
		vXML.open("GET", vContent , false);
		vXML.send(null) ;
		this.vContent = vXML.responseText;
	} else
		{this.vContent = "";}



	if( vContentMax != "" )
	{
		vXML.open("GET", vContentMax , false);
		vXML.send(null) ;
		this.vContentMax = vXML.responseText;
	} else
		{this.vContentMax = "";}
	


	
	//reserva area (HTML) da Janela:
	document.write( "<div class=\"janela7art\" id=\"" + vID + "\" ></div>" );
	//métodos
	this.draw = draw; //metodo que desenha a janela no Browser
	this.move = move; //método utilizado para movimentar a janela 7art pela tela
	this.setMaxURL = setMaxURL;
	this.setURL = setURL;
	this.loadHTML = loadHTML;

	
	// atribui as propriedades da janela (objeto) para o HTML
	vJanela = document.getElementById( this.id );
	vJanela.style.top = this.top;
	vJanela.style.left = this.left;
	vJanela.style.width = this.width;
	vJanela.style.height = this.height;

	// Adiciona o Objeto janela na coleção de todos os objeto janelas criados
	collectionJanela.push( this );
	this.index = collectionJanela.length - 1;

}

function setMaxURL( vURL )
{
	var vXML = GetXmlHttpObjectSync();
	vXML.open("GET", vURL , false);
	vXML.send(null);
	this.vContentMax = vXML.responseText;

}

function setURL( vURL )
{
	var vXML = GetXmlHttpObjectSync();
	vXML.open("GET", vURL , false);
	vXML.send(null);
	this.vContent = vXML.responseText;

}
	
function loadHTML()
{
	if( this.max )
		{document.getElementById( this.id + "_body").innerHTML = this.vContentMax;}
	else
		{document.getElementById( this.id + "_body").innerHTML = this.vContent;}
}



function draw()
{
	vJanela = document.getElementById( this.id );

	vHTML = "<table width=100% height=100% cellspacing=0 cellpadding=0 colspacing=0 class=\"janela7art\">";
	vHTML += "<tr class=\"janelabarra\">";
	vHTML += "<td class='topleft'>&nbsp;</td>"
	vHTML += "<td class='topmargin'>&nbsp;</td>";
	vHTML += "<td class='topright' width=10px height=10px>&nbsp;</td></tr>";
	vHTML += "<tr>";

//	vHTML += "<td class='bodytd' colspan=3>";
	vHTML += "<td class='leftmargin'>&nbsp;</td>"
	vHTML += "<td class='bodytd'>";

	vHTML += "<div class='body' id='" + ( this.id ) + "_body' style='width:" + ( this.width -30 ) + ";height:" + ( this.height - 30 ) + "'>jdsf jdslkf jdslf sjdifjs ifwjiq jwei jqwei qjeiwq jieqowj oqwj oqwej qj oqwe</div>";
	
	vHTML += "</td><td class='rightmargin'>&nbsp;</td></tr>";

	vHTML += "<tr class=\"janelabarra\">";
	vHTML += "<td class='bottomleft'width=10px height=10px>&nbsp;</td>"
	vHTML += "<td class='bottommargin'>&nbsp;</td>";
	vHTML += "<td class='bottomright'width=10px height=10px>&nbsp;</td></tr>";
	vHTML += "</table>";
	vJanela.innerHTML = vHTML;
	vJanela.style.visibility = "visible"
	this.loadHTML();
}

function janelaMax( vIndex )
{
	v = collectionJanela[ vIndex ];
	if( v.max )
	{	
		v.move( v.left , v.top ,v.width ,v.height );
		v.loadHTML();
		collectionJanela[ vIndex ].max = false;
		
	}
	else
	{
		for( i = 0 ; i < collectionJanela.length ;  i ++ )
		{
			if( i == vIndex)
			{
				v.move( MinX , MinY , MaxX ,MaxY );
				v.max = true;
				document.getElementById( v.id ).style.zIndex = 2;
			}else
			{
				document.getElementById( collectionJanela[i].id ).style.zIndex = 1;
				collectionJanela[i].max = false;
				collectionJanela[i].move( collectionJanela[i].left , collectionJanela[i].top ,collectionJanela[i].width ,collectionJanela[i].height );
				collectionJanela[i].loadHTML();
			}
		}
	}
	
}

	
function move( vleft, vtop, vwidth, vheight )
{	
	var vOBJ = this.id;
	var obj = document.getElementById( this.id );
	speed = 25;
	
	if( Math.abs( parseInt(obj.style.top) - vtop ) < speed )
		{obj.style.top = vtop;}	
	else if( parseInt(obj.style.top) < vtop )
		{ obj.style.top = parseInt(obj.style.top) + speed;}
	else if( parseInt(obj.style.top) > vtop )
		{ obj.style.top = parseInt(obj.style.top) - speed;}
	
	if( Math.abs( parseInt(obj.style.left) - vleft ) < speed )
		{obj.style.left = vleft;}
	else if( parseInt(obj.style.left) < vleft )
		{ obj.style.left = parseInt(obj.style.left) +speed ; }
	else if( parseInt(obj.style.left) > vleft )
		{ obj.style.left = parseInt(obj.style.left) - speed ;}


	if( Math.abs( parseInt(obj.style.height) - vheight ) < speed )
		{obj.style.height = vheight;}
	else if( ( parseInt(obj.style.top) + parseInt(obj.style.height) ) < (vtop + vheight) )
		{ obj.style.height = Math.abs( parseInt(obj.style.height) + speed ) ; }
	else if( ( parseInt(obj.style.top) + parseInt(obj.style.height) ) > (vtop + vheight))
		{ obj.style.height = Math.abs(parseInt(obj.style.height) - speed) ;}


	if( Math.abs( parseInt(obj.style.width) - vwidth ) < speed )
		{obj.style.width = vwidth;}
	else if( ( parseInt(obj.style.left) + parseInt(obj.style.width) ) < (vleft + vwidth) )
		{ obj.style.width = parseInt(obj.style.width) + speed; }
	else if( ( parseInt(obj.style.left) + parseInt(obj.style.width) ) > (vleft + vwidth) )
		{ obj.style.width = Math.abs( parseInt(obj.style.width) - speed ) ;}

	vcorpo = document.getElementById( vOBJ + "_body" );
	vcorpo.style.width = parseInt( obj.style.width ) -30;
	vcorpo.style.height = parseInt( obj.style.height ) -30;
	
	// alert( parseInt(obj.style.width) +"/" + parseInt(obj.style.top) );

	if( parseInt(obj.style.left) != vleft || parseInt(obj.style.top) != vtop || parseInt(obj.style.width) != vwidth || parseInt(obj.style.height) != vheight )
	{ 
		vfunction = "collectionJanela["+ this.index + "].move(" + vleft + "," + vtop + "," + vwidth + "," + vheight + ")";
		t = setTimeout(vfunction,1);
	}else
		{
			v.loadHTML();}

			
}


function GetXmlHttpObjectSync()
{
	var objXmlHttp=null;

	if (navigator.userAgent.indexOf("Opera")>=0)
	{
		alert("Atenção! esse site não funciona no Browser Opera! recomendamos o FireFox ou Internet Explorer") ;
		return;
	}
	if (navigator.userAgent.indexOf("MSIE")>=0)
	{ 
		var strName="Msxml2.XMLHTTP";
		if (navigator.appVersion.indexOf("MSIE 5.5")>=0)
		{
			strName="Microsoft.XMLHTTP";
		} 
		try
		{ 
			objXmlHttp = new ActiveXObject(strName);
			return objXmlHttp;
		} 
		catch(e)
		{ 
			alert("Não é possível abrir o conteúdo da página, verifique se o seu browser permite scripts e ActiveX") 
			return 
		} 
	} 
	if (navigator.userAgent.indexOf("Mozilla")>=0)
	{
		objXmlHttp=new XMLHttpRequest();
		return objXmlHttp;
	}
}