function flash(src,w,h,string_values) {
    if(string_values==undefined)
        document.write('<object type="application/x-shockwave-flash" data="'+src+'" width="'+w+'" height="'+h+'" wmode="transparent"><param name="movie" value="'+src+'" /><param name="wmode" value="transparent" /></object>');
    else
        document.write('<object type="application/x-shockwave-flash" data="'+src+'" width="'+w+'" height="'+h+'" wmode="transparent"><param name="movie" value="'+src+'" /><param name="wmode" value="transparent" /><param name="FlashVars" value="'+string_values+'" /></object>');
}

function flashVersaoOk(){
	if (!$.hasFlashPlayerVersion(9)) {
	   $("#flash-download").slideDown();
	}
}

function equalizeBox(seletor) {
   var maiorHeight = 0;
   var atualHeight = 0;
   
   if (!$.browser.safari) {
       $(seletor).each(function(){
           atualHeight = $(this).height();
           if(atualHeight > maiorHeight){maiorHeight = $(this).height();}
       });
       $(seletor).each(function(){
           $(this).height(maiorHeight);
       });
   }
}

function paginacaoAjax(divPaginacao, retorno) {
   
   $(divPaginacao+" A").each(function () {

      if ($(this).attr("lang")!="evento") {
         $(this).attr("lang", "evento");
         $(this).click(function (){
            if ($(this).attr("href").indexOf("#")==-1) {
                
               if (typeof retorno == 'function') {
                  var divRetorno = retorno($(this));   
               } else {
                  var divRetorno = retorno;
               }
               
               $.get($(this).attr("href"),{},function (data){
                  $(divRetorno).html(data);
               });
            }
            return false;
         });
      }
   });
}


$(document).ready(function() {

   $('#meu-ceat-login').example("Login");
   $('#meu-ceat-senha').example("Senha");
   $('#busque-por-palavra').example("ou busque por palavra");
   $('#busque-por-palavra-acervo').example("ou busque por palavra");
   $('#intranet-login').example("Login");
   $('#intranet-senha').example("Senha");

   $('.external').click(function() { window.open(this); return false; });

   $("#FormularioFaleConosco").RSV({
        errorFieldClass: "FormErro",
        rules: [
          "required,nome,Nome",
          "required,email,E-mail",
          "valid_email,email,E-mail",
          "required,cidade,Cidade",
          "required,area,ï¿½rea",
          "required,assunto,Assunto",
          "required,mensagem,Mensagem"
        ]
    });


    $("#FormularioIntranet").RSV({
        errorFieldClass: "FormErro",
        rules: [
          "required,login,Login",
          "required,senha,Senha"
        ]
    });

   $("#FormularioMeuceat").RSV({
        errorFieldClass: "FormErro",
        rules: [
          "required,login,Login",
          "required,senha,Senha"
        ]
    });


    $("#FormularioBusca").RSV({
        errorFieldClass: "FormErro",
        rules: [
         "required,keyword,Palavra-chave",
         "length>=3,keyword,Palavra-chave deve conter no mínimo 3 caracteres",
        ]
    });
    

    $("#FormularioBuscaAcervo").RSV({
        errorFieldClass: "FormErro",
        rules: [
         "required,atividadeseprojetos,Selecione",
         "required,palavrachave,Palavra Chave"
        ]
    });

    $('.jumpmenu').change(function () {
      if ($(this).val() == "") {
         return false;
      } else {
         window.open($(this).val(),'_self'); return false;
      }
   });
	
   $(".campo-data").each(function (){ $(this).mask("99/99/9999", {placeholder:" "}); });

	$(".galeria").each(function(){
		$(this).jCarouselLite({btnNext:".proxima-imagem", btnPrev:".imagem-anterior", visible:4});
	});
	
   $(".box-play").each(function(){
      obj=$(this).next().children("IMG");
      var w= obj.css("width");
      var h= obj.css("height");
      var wn= (w.length) - 2;
      var hn= (h.length) - 2;
      w= parseInt(w.substr(0,wn));
      h= parseInt(h.substr(0,hn));
      var w2= ((w - 34) / 2) + 8;
      if($.browser.msie){ w2= (w2 + 34) * -1; }
      var h2= ((h - 34) / 2) + 8;
      if(($.browser.safari) && (h2 >= 35)){ h2= h2 + 10; }
      $(this).css("margin-top",h2+"px");
      $(this).css("margin-left",w2+"px");
      //alert("w:"+$(this).css("margin-left")+"\n h:"+$(this).css("margin-top"))
   });

   
   $(".bt-favoritos").click(function () {
      $.get($(this).attr("href"),{},function (data){
         alert(data);
      });
      return false;
   });
   
   $("#form-login, #form-senha").keyup(function() {
      if ($(this).val()=="") {
         $("#login").html("");
      }
   });
   
	$("#formLogin").RSV({
		onCompleteHandler: function(){ 
		   $("#formLogin").hide(); 
		   $("#login-aguarde").show(); 
		   $("#formLogin").attr("lang","valido"); 
		   return false; 
		},
		errorFieldClass: "FormErro",
		rules: ["required,login,Login",
				  "required,senha,Senha"]
	});
	
   $("#formLogin").ajaxForm({
		url: "index.php?option=login&Itemid=10000",
		beforeSubmit: function(){ return ($("#formLogin").attr("lang")=="valido"); },
		success: function (responseText, statusText) { 
		   if (responseText==1) {
		      document.location.href = "index.php?option=meu_ceat&Itemid=95";
		   } else {
		      $("#login-aguarde").hide(); 
		      $("#formLogin").show(); 
		      alert(responseText);
		   }
		}
	});
	
	$("#bt-logout").click(function () {
	   $.get("index.php", { option: "login", task: "logout", Itemid: "10000" },
		function(data){
		   if (document.location.href.indexOf("option=meu_ceat")>0 || document.location.href.indexOf("option=cadastro")>0) {
		      document.location.href = "index.php";
		   } else {
		      document.location.reload();   
		   }
		});
	});
	
	flashVersaoOk();
});