var max=1024;
var ancho=300;
function progresso_tecla(obj) {
	var progresso = document.getElementById("progresso");
	if (obj.value.length < max) {
		progresso.style.backgroundColor = "#FFFFFF";
		//progresso.style.backgroundImage = "url(textarea.png)"; 
		//progresso.style.color = "#000000";
		progresso.style.color = "#CCCCCC";
		var pos = ancho-parseInt(((ancho*parseInt(obj.value.length))/1024)); 
		progresso.style.backgroundPosition = "-"+pos+"px 0px"; 
	} else {
		//progresso.style.backgroundColor = "#CC0000";
		progresso.style.backgroundImage = "url()";
		//progresso.style.color = "#FFFFFF"; 
		progresso.style.color = "#CC0000"; 
	}  
	//progresso.innerHTML = "("+(1024-obj.value.length)+" / "+max+")";
	progresso.innerHTML = ""+(1024-obj.value.length)+"";
} 

function hideErro() {
	$("#erro").fadeOut(1000);
	$("#errotxt").fadeOut(1000);
}

function hideErroTop() {
	$("#erro-top").fadeOut(1000);
	$("#errotxt-top").fadeOut(1000);
}

$(document).ready(function(){
	//$(".erro").fadeIn(2000);
	//$(".erro-verde").fadeIn(2000);
	//$(".errotxt").fadeIn(2000);
});

function playernormal(exibicoes, hd, normal, qld, leg, img, hdok, vid){
	
	var so = new SWFObject('http://cache.vctb.hgbrasil.com/player.swf',
		    'mpl','640','480','9');
		  so.addParam('allowscriptaccess','always');
		  so.addParam('allowfullscreen','true');
		  so.addVariable('autostart','true');
		  so.addVariable('file', 'http://cache.vctb.hgbrasil.com/resources/vdata/'+normal);
		  so.addVariable('plugins', 'quickkeys-1,accessibility-1');
		  so.addVariable('captions', 'http://cache.vctb.hgbrasil.com/legendas/'+leg);
		  so.addVariable('image', 'http://cache.vctb.hgbrasil.com/imagem/'+img);
		  so.write('mediaspace');

	
	
	  //$("#mpl").animate({ width: '900px' }, 1000);
	  $("#player").animate({ left: '0px' }, 1000);
	  $("#barra").animate({ left: '-319px' }, 1000);
	  $("#promote").animate({ left: '900px', top : '161px' }, 1000);
	  if(hdok == 1){
	  	$("#texto-barra").html('<a href="javascript:void(0);" onclick="player('+exibicoes+', \''+hd+'\', \''+normal+'\', \''+qld+'\', \''+leg+'\', \''+img+'\', \''+hdok+'\', \''+vid+'\')"><font color="#000000">Visualizar em alta qualidade (HD '+qld+')</font></a>');
	  }
	  $("#botao-aumentar").html('<a href="javascript:void(0);" onclick="player('+exibicoes+', \''+hd+'\', \''+normal+'\', \''+qld+'\', \''+leg+'\', \''+img+'\', \''+hdok+'\', \''+vid+'\');" title="Aumentar o player"><span class="ui-icon ui-icon-transferthick-e-w" style="float: right"></span></a>');
	  $("#botao-janela").html('<a href="javascript:void(0);" onclick="popup(\''+vid+'\', 0);" title="Abrir vídeo em modo janela"><span class="ui-icon ui-icon-newwin" style="float: right"></span></a>');
	  $("#botao-email").html('<a href="javascript:void(0);" onclick="email(\''+vid+'\');" title="Enviar por E-Mail"><span class="ui-icon ui-icon-mail-closed" style="float: right"></span></a>');
	  $("#lateralw").animate({ top: '190px' }, 1000);
	  $("#lateraldesc").fadeIn(1000);
	  $("#relacionador-texto").fadeIn(1000);
	  $("#relacionados").fadeIn(1000);
}

function player(exibicoes, hd, normal, qld, leg, img, hdok, vid){
	
	var so = new SWFObject('http://cache.vctb.hgbrasil.com/player.swf',
		    'mpl','900','480','9');
		  so.addParam('allowscriptaccess','always');
		  so.addParam('allowfullscreen','true');
		  so.addVariable('autostart','true');
		  so.addVariable('file', 'http://cache.vctb.hgbrasil.com/resources/vdata/'+hd);
		  so.addVariable('plugins', 'quickkeys-1,accessibility-1');
		  so.addVariable('captions', 'http://cache.vctb.hgbrasil.com/legendas/'+leg);
		  so.addVariable('image', 'http://cache.vctb.hgbrasil.com/imagem/'+img);
		  so.write('mediaspace');

	
	
	  //$("#mpl").animate({ width: '900px' }, 1000); 
	  $("#player").animate({ left: '28px' }, 1000);
	  $("#barra").animate({ left: '-33px' }, 1000);
	  $("#promote").animate({ left: '858px', top : '164px' }, 1000);
	  if(hdok == 1){
	  	$("#texto-barra").html('<a href="javascript:void(0);" onclick="playernormal('+exibicoes+', \''+hd+'\', \''+normal+'\', \''+qld+'\', \''+leg+'\', \''+img+'\', \''+hdok+'\', \''+vid+'\')"><font color="#000000">Visualizar em baixa qualidade (ST 320)</font></a>');
	  }
	  $("#botao-aumentar").html('<a href="javascript:void(0);" onclick="playernormal('+exibicoes+', \''+hd+'\', \''+normal+'\', \''+qld+'\', \''+leg+'\', \''+img+'\', \''+hdok+'\', \''+vid+'\');" title="Aumentar o player"><span class="ui-icon ui-icon-transferthick-e-w" style="float: right"></span></a>');
      $("#botao-janela").html('<a href="javascript:void(0);" onclick="popup(\''+vid+'\', 1);" title="Abrir vídeo em modo janela"><span class="ui-icon ui-icon-newwin" style="float: right"></span></a>');
      $("#botao-email").html('<a href="javascript:void(0);" onclick="email(\''+vid+'\');" title="Enviar por E-Mail"><span class="ui-icon ui-icon-mail-closed" style="float: right"></span></a>');
	  $("#lateralw").animate({ top: '720px' }, 1000);
	  $("#lateraldesc").fadeOut(1000);
	  $("#relacionador-texto").fadeOut(1000);
	  $("#relacionados").fadeOut(1000);
	  //$("#mediaspace").animate({ height: '478px', width: (width - 1), backgroundColor: '#FFFFFF', 'border': '1px solid #FFFFFF' }, 1000);
	  //$("#mediaspace").html('');
}

function mostrar(){
	$(".commentdiv").fadeIn(500);
	$("#exibemais").fadeOut(100);
}

function popup(vid, hd) {

  var width = 640;
  var height = 480;
  var url = 'http://vocetubo.hgbrasil.com/janela?vid='+vid;

  var left = 200;
  var top = 200;
  
  if(hd == 1){
  	width = 900;
  	url = 'http://vocetubo.hgbrasil.com/janela?vid='+vid+'&hd=1';
  }
	
  window.open(url,'janela', 'width='+width+', height='+height+', top='+top+', left='+left+', scrollbars=yes, status=no, toolbar=no, location=no, directories=no, menubar=no, resizable=no, fullscreen=no');
  
  
  //$("#mediaspace").animate({ height: '479px', width: (width - 1), backgroundColor: '#FFFFE5', 'border': '1px solid #F5E082' }, 1000);
  $("#mediaspace").html('<div style="height: 478px; width: '+width+'px; background-color: #FFFFE5; border: 1px solid #F5E082"><div style="padding: 7px; top: 200px; position: relative;"><p align="center">O Player foi alternado para o modo janela.<br /><br />Feche a janela que foi aberta para retornar o vídeo à esta página.</p></div></div>');
  
  $("#texto-barra").html('<font color="#000000">Modo Janela ativo </font>');
  $("#botao-aumentar").html('<span class="ui-icon ui-icon-transferthick-e-w" style="float: right"></span>');
  $("#botao-janela").html('<span class="ui-icon ui-icon-newwin" style="float: right"></span>');
  $("#botao-email").html('<span class="ui-icon ui-icon-mail-closed" style="float: right"></span>');

}

function email(vid) {

  var width = 454;
  var height = 620;

  var left = 200;
  var top = 200;
  
  window.open('http://vocetubo.hgbrasil.com/email?vid='+vid,'janela', 'width='+width+', height='+height+', top='+top+', left='+left+', scrollbars=yes, status=no, toolbar=no, location=no, directories=no, menubar=no, resizable=no, fullscreen=no');
}

/**/ 

function aumentar(){
	$("#mediaspace").animate({ width: '900px' }, 1000);
	$("#mpl").animate({ width: '900px' }, 1000);
	$("#player").animate({ left: '28px' }, 1000);
	$("#barra").animate({ left: '-33px' }, 1000);
	$("#promote").animate({ left: '858px', top : '164px' }, 1000);
	//$("#botao-aumentar").html('');
	$("#lateralw").animate({ top: '720px' }, 1000);
	$("#lateraldesc").fadeOut(1000);
	$("#relacionador-texto").fadeOut(1000);
	$("#relacionados").fadeOut(1000);
	
}


function findPos() {
	
	obj = document.getElementById('mediaspace');
	
	var curleft = curtop = 0;

if (obj.offsetParent) {
	do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
	alert(curleft+'-'+curtop);
}

}
/**/



/*function verde() {
	$("#lateralw").animate({backgroundColor: '#C2F0C1', color: '#fff', height: 410}, 1000);
}*/

function erro(mensagem){
	$("#erro-top").fadeIn(1000);
	$("#errotxt-top").fadeIn(1000);
	$("#errotxt-top").html('<h2 align="center">'+mensagem+'</h2>');
}
