var _timeout;
function init_layer(file, language) {
  div_BG();
  div_SWF(language);
  _timeout = setTimeout('unload()', 50000);
  document.getElementById('hfVideo').value = file;
}

function unload() {
  clearTimeout(_timeout);
  // Remove os elementos Html
  document.body.removeChild(document.getElementById("divBG"));
  document.body.removeChild(document.getElementById("divSWF"));
  // Esconde o painel com a imagem do primeiro frame do vídeo
  document.getElementById("divImagem").style.visibility = "hidden";
  document.getElementById("divImagem").style.display = "none";
  // Apresenta o painel do vídeo  
  document.getElementById("divFlash").style.visibility = "visible";
  document.getElementById("divFlash").style.display = "block"; 
}

function div_BG() {
  // cria o objecto DIV que permite escurecer o website
  var div = document.createElement('div');
  var _width = document.body.scrollWidth;
  var _height = window_height();
  if(document.body.scrollHeight > _height) _height = document.body.scrollHeight;
  // define as propriedades do objecto
  with(div) {
    id = "divBG";
    className = "divBG";
	style.width = _width+"px";
	style.height = _height+"px";
  }
  // adiciona o objecto à página
  document.body.appendChild(div);
}

function div_SWF(language) {
  var _close="";
  // cria o objecto DIV que permite apresentar o ficheiro de novidades
  var div = document.createElement('div');
  div.id = "divSWF";
  div.className = "divSWF";

  switch(language) {
	case "PT":
	  _close = "Fechar"
	  break;
	case "EN":
	  _close = "Close"
	  break;
	case "FR":
	  _close = "Fermer"
	  break;
  }

  var _path = self.location.href.toLowerCase();
  var _page = _path.substring(_path.lastIndexOf("/") + 1);
  var _homepage = (_page == "");
  var _src = "pt/intro.aspx";

  // cria a estrutura HTML
  var _html = new Array();
  with(_html) {
    push("<table width='100%' height='93%' border='0' cellpadding='0' cellspacing='0' >");
	push("<tr>");
	push("<td width='100%' height='93%' align='center'>");
	push("<table width='500' border='0' cellpadding='0' cellspacing='0' align='center' class='nov_tabela'>");
	if(!_homepage) {
	  push("<tr class='nov_close'>");
	  push("<td width='409' height='22' valign='top'></td>");
	  push("<td width='91' valign='middle' align='center'><span onclick='unload()' class='close'>[X] "+_close+"</span></td>");
	  push("</tr>");
	  _src = _src.substring(_src.lastIndexOf("/") + 1)
	}
	push("<tr>");
	push("<td height='300' colspan='2' align='center' valign='middle'>");
	push("<iframe id='ifIntro' name='ifIntro' width='100%' height='100%' marginheight='0' marginwidth='0' frameborder='0' scrolling='no' src='" + _src + "'></iframe>");
	push("</td>");
	push("</tr>");
	push("</table>");
	push("</td>");
	push("</tr>");
	push("</table>");
  }
  div.innerHTML = _html.join('');
	
  // aodiciona o objecto à página
  document.body.appendChild(div);
}

function window_height() {
  var _height=0;
  if(typeof(window.innerWidth) == 'number') {
    _height = window.innerHeight;
  } else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
    _height = document.documentElement.clientHeight;
  } else if(document.body && (document.body.clientWidth || document.body.clientHeight)) {
    _height = document.body.clientHeight;
  }
  return _height;
}

function loadVideo() {
  var _file = parent.document.getElementById('hfVideo').value;
  var _name = _file.substring(0, _file.indexOf(".swf"));
  var _ext = _file.substring(_file.lastIndexOf(".") + 1);
  
  var _html = new Array();
  with(_html) {
    switch(_ext) {
      case "swf":
		push("<script type='text/javascript'>");
		push("runFlash('codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0','width','500','height','300','src','../docs/"+_name+"','quality','high','pluginspage','http://www.macromedia.com/go/getflashplayer','movie','../docs/"+_name+"');");
		push("<"+"/script>");
		push("<noscript>");
		push("<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0' width='500' height='300'>");
		push("<param name='movie' value='../docs/"+_file+"'>");
		push("<param name='quality' value='high'>");
		push("<embed src='../docs/"+_file+"' quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width='500' height='300'></embed>");
		push("</object>");
		push("</noscript>");	
	    break;
  	  case "gif":
  	  case "jpg":
	  case "png":
		push("<img src='/docs/"+_file+"' width='500' height='300' border='0' usemap='#Map' />");
		push("<map name='Map' id='Map'>");
		push("<area shape='rect' coords='50,18,200,33' href='/pt/produtos.aspx' target='_parent' title='Antenas e Suportes' />");
		push("<area shape='rect' coords='40,57,209,71' href='/en/products.aspx' target='_parent' title='Antennas and Suports' />");
		push("<area shape='rect' coords='39,94,209,108' href='/fr/produits.aspx' target='_parent' title='Antennes et Supports' />");
		push("<area shape='rect' coords='274,191,476,208' href='/pt/subcontratacao.aspx' target='_parent' title='Divisão de Subcontratação' />");
		push("<area shape='rect' coords='282,230,465,244' href='/en/subcontracting.aspx' target='_parent' title='Subcontraction Division' />");
		push("<area shape='rect' coords='287,269,461,283' href='/fr/sous-traitance.aspx' target='_parent' title='Division Sous-Traitance' />");
		push("</map>");
	    break;
    }
  }
  document.write(_html.join(''));  
}
