var agt = navigator.userAgent.toLowerCase();
var is_ie = (agt.indexOf("msie") != -1); 
var is_chrome = (agt.indexOf("chrome") != -1); 
var is_ff = (agt.indexOf("firefox") != -1); 
function showSelectBoxes(){
	var selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "visible";
	}
}
function hideSelectBoxes(){
	var selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "hidden";
	}
}
function openFirst(i) {
	if(i>=2) {
		anterior = theVidV[i-1]+'|'+theVidV[i-2];
	} else if(i==0) {
		anterior = theVidV[theVidV.length-1]+'|'+theVidV[theVidV.length-2];
	} else if(i==1) {
		anterior = theVidV[0]+'|'+theVidV[theVidV.length-1];
	}
	if(i==theVidV.length-1) {
		proximo = theVidV[1]+'|'+theVidV[0];
	} else if(i==theVidV.length-2) {
		proximo = theVidV[0]+'|'+theVidV[theVidV.length-1];
	} else {
		proximo = theVidV[i+2]+'|'+theVidV[i+1];
	}
	$.get("_ajaxAux.php",{
		  tela:'first',
		  idp:proximo,
		  ida:anterior
		  },
	function(r){
		dados = r.split("||||");
		$("#vaise").html(dados[1]);
		$("#jafoi").html(dados[0]);		
	});
	
}
function montaTD(idV,txt,tit,art) {
	monta_td = "";
	monta_td += "<td width=\"120\" align=\"center\">";
	monta_td += "<table width=\"99\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" style=\"margin:25px 0 9px 0\"><tr><td width=\"95\"><img src=\"http://www.portalsmd.com.br/arquivo/tv_video/video_"+idV+".jpg\" alt=\""+txt+"\" width=\"95\" height=\"95\"></td>";
	monta_td += "<td width=\"4\" valign=\"top\" bgcolor=\"#303030\"><img src=\"img/blck.gif\" width=\"4\" height=\"4\"></td></tr><tr><td height=\"4\" colspan=\"2\" align=\"left\" bgcolor=\"#303030\"><img src=\"img/blck.gif\" width=\"4\" height=\"4\"></td></tr></table>";
    monta_td += "<font class=\"detLar\">"+tit+"</font><br>"+art;
	monta_td += "</td>";
	return monta_td;
}
function montaFlash(swf, vars, width, height, id, wmode, cache) {
	noCache = cache || cache == undefined ? "" : "?" + new Date();
	monta_swf = "";
	monta_swf += "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0\" id=\""+ id +"\" width=\""+ width +"\" height=\""+ height +"\" title=\"\">";
	monta_swf += "<param name=\"movie\" value=\""+ swf + noCache +"\" />";
	monta_swf += "<param name=\"FlashVars\" value=\""+ vars +"\" />";
	monta_swf += "<param name=\"quality\" value=\"high\" />";
	monta_swf += "<param name=\"menu\" value=\"false\" />";
	monta_swf += "<param name=\"wmode\" value=\""+ wmode +"\" />";
	monta_swf += "<embed src=\""+ swf + noCache +"\"  FlashVars=\""+ vars + "\" quality=\"high\" menu=\"false\" wmode=\""+ wmode +"\"  pluginspage=\"http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash\" type=\"application/x-shockwave-flash\" id=\""+ id +"\" width=\""+ width +"\" height=\""+ height +"\"></embed>";
	monta_swf += "</object>";
	document.write(monta_swf);
}
function popWin(URL,NAME,WIDTH,HEIGHT,RESIZE,SCROLL) {
   winId = window.open(URL,NAME,'width='+WIDTH+',height='+HEIGHT+',resizable='+RESIZE+',scrollbars='+SCROLL+',menubar=no,toolbar=no,location=no,directories=no,status=no');
	var clientWidth = screen.availWidth;
	var clientHeight = screen.availHeight;
	var xPos = (clientWidth - WIDTH)/2;
	var yPos = (clientHeight - HEIGHT)/2;
	winId.moveTo(xPos,yPos);
}
function popWin2(URL,NAME,WIDTH,HEIGHT,RESIZE,SCROLL) {
   winId = window.open(URL,NAME,'width='+WIDTH+',height='+HEIGHT+',resizable='+RESIZE+',scrollbars='+SCROLL+',menubar=no,toolbar=no,location=no,directories=no,status=no');
}
function checkemail(str){
	var testresults
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	if (filter.test(str)) testresults=false
	else testresults=true
	return (testresults)
}
function ajaxLink(div,pag) { $.get(pag,{qazc:'1'}, function(retorno){ $("#"+div).html(retorno); }); }
function showDets(i) {
	if(i == theVidV.length-2) {
		p = 0;
	} else if(i==theVidV.length-1) {
		p = 1;
	} else {
		p = i+2;
	}
	if(i==0) {
		a = theVidV.length-1;
	} else {
		a = i-1;
	}
	$.get("_ajaxAux.php",{tela:'proximo_anterior',idp:theVidV[p],ida:theVidV[a]}, function(r){ 
		dados = r.split("|!|");
		$("#jafoiTb").width($("#jafoiTb").width()+120);
		$("#jafoi").prepend(montaTD(dados[3],'Vídeos Anteriores',dados[4],dados[5]));
		// -----------------
		$("#vaiseTb").width($("#vaiseTb").width()+120);
		$("#vaise").prepend(montaTD(dados[0],'Vídeos Anteriores',dados[1],dados[2]));
		// -----------------
		$("#arrowxD").show();
		$("#arrowxE").show();
		$("#arrowxD2").hide();
		$("#arrowxE2").hide();
		setTimeout('esconde()', 5000);
		
	});
	
//	noAr(i);
}
function esconde() {
	$("#arrowxD").fadeOut();
	$("#arrowxE").fadeOut();
	$("#arrowxD2").fadeIn();
	$("#arrowxE2").fadeIn();	
}
function some() {
	$("#mark").hide();
}
function noAr(i) {
	$("td[id*='prog_']").removeClass("prog_listOn");
	$.get('_ajaxAux.php',{tela:'noAr',idV:i}, function(r){ 
		dados = r.split("|!|");
		for(aa=0;aa<=theVidV.length;aa++) {
			if(theVidV[aa]==dados[1]) {
				achou = aa;
				break;
			}
		}		
		if(achou<=1) {
			$("#div_content").animate({top: '0px'},1000);
		} else {
			$("#div_content").animate({top: '-'+(((achou+1)*23)-47)+'px'},1000);
		}
		$("#dadosVideo").html(dados[0]);
		$("td[id='prog_"+dados[1]+"']").addClass("prog_listOn");
		$("#ar_fot").attr('src','http://www.portalsmd.com.br/arquivo/tv_video/video_'+dados[1]+'.jpg');
		$("#ar_art").html(dados[2]);
		$("#ar_tit").html(dados[3]);
		$("#tempoTotal").html('/ <strong id="idTotal">'+dados[4]+'</strong>');
	});
	var ext = i.split(".");
	$.get("_ajaxAux.php",{tela:'letreiro',idV:ext[0].slice(6)}, function(r){
		if(r!='') {
			$("#mark").show();
			$("#mark").html(r);
			$("#mark").marquee({yScroll:"bottom",scrollSpeed: 22,pauseOnHover: false,fxEasingShow: "linear", aftershow: some });
		} else {
			$("#mark").hide();
		}
	});
	if(ext[1]=='wmv') {
		$("#smdPlayer").width(636);
		$("#smdPlayer").height(476);
		$("#releases").html('');
		$("#releases").hide();
	
	} else {
		$("#releases").show();
		$("#smdPlayer").width(0);
		$("#smdPlayer").height(0);
		$.get('_ajaxAux.php',{tela:'flvReleases',idV:ext[0].slice(6)}, function(r){ 
			$("#releases").html(r);
		});
	}
}
function closethis() {
	$("#overlay").hide();
	$("#overlay_content").hide();
	$("#overlay_content").html('');
}
$(document).ready(function() {
	$(window).resize(function() {
		if(overOpen==1) {
			  var arrayPageSize = getPageSize();
			  $("#overlay").height(arrayPageSize[1]);
		}
	}); 
	$(".imgOver").hover(function(){
 		theID = $(this).html();
		$(this).children().css("background-position","bottom");
	}, function(){
		$(this).children().css("background-position","top");
	});
	$("#arrowxD").hide();
	$("#arrowxE").hide();
	$(document).pngFix();
	if(is_ie) {
	$("#divVol").width(smdPlayer.settings.volume);
	}
//	noAr(0);

});
// ------------ Dados do scroll programação
function timezera() {
	window.clearTimeout(timeouti);
}
var timeouti = 0;
var pos_atual = 0;
function moveMenos() {
	var pos_atual = $("#div_content").position().top;
	if(pos_atual < 0) {
		$("#div_content").css('top', (pos_atual+5)+'px');
	}
	timeouti = setTimeout('moveMenos()', 50);
}
function moveMais() {
	pos_atual = $("#div_content").position().top;
		if(pos_atual > -(totalh-98)) {
		$("#div_content").css('top', (pos_atual-5)+'px');
	}
	timeouti = setTimeout('moveMais()', 50);
}
function getPageSize(){
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	
	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){ windowWidth = document.documentElement.clientWidth; }
		else { windowWidth = self.innerWidth; }
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){	pageHeight = windowHeight; }
	else { pageHeight = yScroll; }
	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){ pageWidth = xScroll;	}
	else { pageWidth = windowWidth; }
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
	
}
function check_formTv() {
	$("#msgE").html('');
	if($("#fNome").val()=='') {
		$("#fNome").focus();
		$("#msgE").html('<b>Erro:</b> preencha seu nome');
	} else if($("#fCidade").val()=='') {
		$("#fCidade").focus();
		$("#msgE").html('<b>Erro:</b> preencha sua cidade');		
	} else if($("#fUf").val()=='') {
		$("#fUf").focus();
		$("#msgE").html('<b>Erro:</b> preencha seu estado');
	} else if($("#fPais").val()=='') {
		$("#fPais").focus();
		$("#msgE").html('<b>Erro:</b> preencha seu país');
	} else if($("#fEmail").val()=='') {
		$("#fEmail").focus();
		$("#msgE").html('<b>Erro:</b> preencha seu e-mail');
	} else if(checkemail($("#fEmail").val())) {
		$("#fEmail").focus();
		$("#msgE").html('<b>Erro:</b> Digite seu e-mail corretamente');
	} else if($("#fMsg").val()=='') {
		$("#fMsg").focus();
		$("#msgE").html('<b>Erro:</b> preencha sua mensagem');
	} else {
		$("#msgE").html('Aguarde, enviando ...');
		$.post("contato_post.php",{nome:$("#fNome").val(),cidade:$("#fCidade").val(),uf:$("#fUf").val(),pais:$("#fPais").val(),email:$("#fEmail").val(),mensagem:$("#fMsg").val(), act:'enviar'}, function(r){ $("#formTv").reset(); $("#msgE").html('Sua mensagem foi enviada!'); });
	}
	return false;
}