/* lapis */
var cor = $.cookie('cor') == null ? Number(5) : Number($.cookie('cor'));
var loginEstado; // 0 ou 1
var loginPaisEstado; // 0 ou 1
var cores = [['#e4312a', '#fff', '#f8b41d'], ['#f8b41d', '#fff', '#009ee1'], ['#ffd500', '#fff', '#e4312a'], ['#5ca731', '#fff', '#ffd500'], ['#009ee1', '#fff', '#f8b41d'], ['#05246d', '#fff', '#ffd500'], ['#43007e', '#fff', '#f8b41d']]; // cor, cor de fundo, hover
var coresA = ['#e4312a', '#f8b41d', '#5ca731', '#009ee1', '#7359c4']; // cor, cor de fundo , hover
var numbersTel='+()1234567890 ';
var numbersCP='-1234567890';
var numbers='1234567890';
function lapis() {
    $('.corInOutSearch li').each(function(intIndex){
        $(this).bind("click", function () {
            if (intIndex != cor) {
                $(this).stop().animate({ top: '14px' }, 300, "easeOutQuad");
                $('.corInOutSearch li:nth-child(' + Number(cor + 1) + ')').stop().animate({ top: '0' }, 300, "easeOutQuad");
                cor = intIndex;
                mudaCores();
                $.cookie('cor', intIndex);
            }
            return false;
        });
        $(this).bind("mouseenter", function () {
            $(this).stop().animate({ top: '14px' }, 300, "easeOutQuad");
        });
        $(this).bind("mouseleave", function () {
            if (intIndex != cor) $(this).stop().animate({ top: '0' }, 200, "easeOutQuad");
        });
    });
  $('.corInOutSearch li:nth-child(' + Number(cor + 1) + ')').stop().animate({ top: '14px' }, 300, "easeOutQuad");
  mudaCores();  
  setTimeout(menu, 400);
}
function mudaCores() {
    var cor1 = cores[cor][0];
    var cor2 = cores[cor][1];
    var cor3 = cores[cor][2];
    $('.header').css({'backgroundPosition': '0px ' + (-Number(cor * 100)) + 'px','top':'0'});
    $('.subHeader').css('top', '60px');
    $('.footer').css({'backgroundPosition': '0px ' + (-Number(cor * 100)) + 'px','bottom':'0'});
    $('#homeLinksSlider h2, .footer, #nav .on a').css('color', cor1);
    $('#init').hide();
     setTimeout(function(){shadowIE()},400);  
}
/* aleatorio */
function aleatorio() {
    if (existe('.cHome')) { // home
        $('.wrapper').css('backgroundColor', '#f6f6f7');
        $('.cont1').each(function (intIndex) {
            var a1 = randomNr(1, 5);
            var corAB1 = coresA[a1 - 1];
            $('.data, h3', this).css('color', corAB1);
            $('.btn2', this).removeClass('btn2Cor2').addClass('btn2Cor' + a1);
        });
        $('.contMrec .btn2').removeClass('btn2Cor2').addClass('btn2Cor' + randomNr(1, 5));
        $('.contProg .btn2').removeClass('btn2Cor2').addClass('btn2Cor' + randomNr(1, 5));
    $('.contAmigos .btn2').removeClass('btn2Cor3').addClass('btn2Cor' + randomNr(1, 5));
        var a2 = randomNr(1, 5);
        var corA2 = coresA[a2 - 1];
        $('.contProg').css('color', corA2);
        $('.contProg li').each(function () {
            var a3 = randomNr(1, 5);
            var corAB3 = coresA[a3 - 1];
            $(this).find('h4, h5').css('color', corAB3);
        });
        $('.contAmigos li').each(function () {
            var a4 = randomNr(1, 5);
            var corAB4 = coresA[a4 - 1];
            $(this).find('h4, h5').css('color', corAB4);
        });    
    }
    progAleat();
    pbnsAleat();
}
function progAleat() {
    if (existe('#contProg2DiasSlider')) { // programacao
        var progsList = $('#pageContent li');
        progsList.each(function (intIndex) {
            var a4 = randomNr(1, 5);
            var corAB4 = coresA[a4 - 1];
            $('h3, h4', this).css('color', corAB4);
        });
    }  
}
function pbnsAleat() {
    if (existe('.pbns .col9')) { // parabes listagem
      var parabensList = $('.cont2').not('.cont2Nav');
      parabensList.each(function (intIndex) {
          var a1 = randomNr(1, 5);
          var corAB1 = coresA[a1 - 1];
          $('h3, h4', this).css('color', corAB1);
      });
     }
} 
function randomNr(prim, ult) {
    return prim + Math.floor(Math.random() * (ult - prim + 1));
}
/* menu */
function menu() {
    var menuList = $('#nav li').not('.home, .parabens, .facebook');
    var baloesDims = [[72, -1, 67], [80, -81, 81], [101, -176, 94], [114, -283, 109], [132, -403, 126], [142, -544, 136], [520, -692, 156]]; // dimensao maxima, bgposition, largura
    var leftLi = 70;
    menuList.each(function (intIndex) {
        var larg = $(this).outerWidth();
        loop1:
        for (i = 0; i < 7; i++) {
            if (larg < baloesDims[i][0]) {
                menuItem(Number(intIndex + 1), Number(baloesDims[i][2]), Number(baloesDims[i][1]), Number(leftLi - 8));  // index, largura, bgposition, leftLi
                leftLi += larg;
                break loop1;
            }
        }
    });
}

/* menuItem */
function menuItem(index, largura, bgposition, leftLi) {  // atribui a cada elemento do menu posicionamentos absolutos/baloes de fundo/hovers
    $('#nav').append('<div id="nuvem' + index + '" class="nuvem"></div>');
    $('#nuvem' + index).css({ 'width': largura, 'backgroundPosition': bgposition + 'px -165px', 'left': leftLi + 'px', 'display': 'block' });
    if ($('#nav li:nth-child(' + Number(index + 1) + ')').hasClass('on')) {
        $('#nuvem' + index).css('top', '10px');
        $('#nav .on a').css('color', cores[cor][0]);
    } else {
        $('#nav li:nth-child(' + Number(index + 1) + ') a').css('color', cores[cor][1]);
        $('#nav li:nth-child(' + Number(index + 1) + ') a').mouseenter(function () {
            $(this).css('color', cores[cor][0]);
            $('#nuvem' + index).css('top', '10px');
        });
        $('#nav li:nth-child(' + Number(index + 1) + ') a').mouseleave(function () {
            $(this).css('color', cores[cor][1]);
            $('#nuvem' + index).css('top', '-600px');
        });
    }
}
/* smallMenu */
function smallMenu() {
    var oMenu;
    if (existe('.pst')) { oMenu = '#pstNav' } else { oMenu = '#paisNav' }
    var subMenuList = $(oMenu + ' li');
    var baloesDims = [[72, -1, 67], [80, -81, 81], [101, -176, 94], [114, -283, 109], [132, -403, 126], [142, -544, 136], [520, -692, 162]]; // dimensao maxima, bgposition, largura
    var leftLi = 0;
    subMenuList.each(function (intIndex) {
        var larg2 = $(this).outerWidth();
        loop2:
        for (i = 0; i < 7; i++) {
            if (larg2 < baloesDims[i][0]) {
                smallMenuItem(oMenu, Number(intIndex + 1), Number(baloesDims[i][2]), Number(baloesDims[i][1]), Number(leftLi - 8));  // oMenu, index, largura, bgposition, leftLi
                leftLi += Number(larg2 + 8);  // 8px de margin-right q cada elemento tem
                break loop2;
            }
        }
    });
}
/* smallMenuItem */
function smallMenuItem(oMenu, index, largura, bgposition, leftLi) {  // atribui a cada elemento do menu posicionamentos absolutos/baloes de fundo/hovers
    $(oMenu).append('<div id="nuvem2' + index + '" class="nuvem2"></div>');
    $('#nuvem2' + index).css({ 'width': largura, 'backgroundPosition': bgposition + 'px -250px', 'left': leftLi + 'px', 'display': 'block' });
    if ($(oMenu + ' li:nth-child(' + index + ')').hasClass('on')) {
        $('#nuvem2' + index).css('top', '10px');
        $(oMenu + ' .on a').css('color', '#fff');
    } else {
        $(oMenu + ' li:nth-child(' + index + ') a').css('color', '#009ee1');
        $(oMenu + ' li:nth-child(' + index + ') a').bind("mouseenter", function () {
            $(this).css('color', '#fff');
            $('#nuvem2' + index).css('top', '10px');
        });
        $(oMenu + ' li:nth-child(' + index + ') a').bind("mouseleave", function () {
            $(this).css('color', '#009ee1');
            $('#nuvem2' + index).css('top', '-600px');
        });
    }
}
/* login */
function login(x) {
  if(x) {
    $('#msgLoggedOut, #btnLoggedOut').hide();
    $('#msgLoggedIn, #btnLoggedIn').show();    
  } else {
    $('#msgLoggedOut, #btnLoggedOut').show();
    $('#msgLoggedIn, #btnLoggedIn').hide();
  }
}
function logEvents() {
  $('#btnLoggedIn').bind("click",function(){
    loginEstado = 0;
    login(loginEstado);  
  });    
  $('#btnLoggedOut').bind("click",function(){
    $('#loginSubmit, #recPassSubmit').removeAttr('disabled');
    $('#loginForm, .login .btn2, .login p:first').show();
    $('#recPassForm, #sucessRecPass').hide();
    $('.subHeader').stop().animate({top: '-60px'}, 500, "easeInOutExpo");
    $('.login').stop().delay(50).animate({top: '60px'}, 900, "easeInOutExpo");
  });
  $('#closeLogin').bind("click",function(){
    $('.login').stop().animate({top: '-220px'}, 900, "easeInOutExpo");
    $('.subHeader').stop().delay(400).animate({top: '60px'}, 500, "easeInOutExpo");
  });
  $('#loginForm a').bind("click",function(){
    $('#recPassSubmit').removeAttr('disabled');
    $('#loginForm, #sucessRecPass').hide();
    $('#recPassForm').show();
    $('#loginMsg').text('').css({'display':'none'});
    $('#loginForm').each(function(){this.reset();});
    $('#nickInput, #passInput').removeClass('error');
    return false;
  });  
  $('#recPassForm a, #sucessRecPass a').bind("click",function(){
    $('#loginSubmit').removeAttr('disabled');
    $('#recPassForm, #sucessRecPass').hide();
    $('#loginForm, .login .btn2, .login p:first').show();
    $('#loginMsg').text('').css({'display':'none'});
    $('#recPassForm').each(function(){this.reset();});
    $('#emailEEInput').removeClass('error');
    return false;
  });  
}
// form login
initLoginForm = function() {
  $('#loginForm').validate({
    errorPlacement: function(error, element) {
      error.hide();
    },
    invalidHandler: function(form, validator) {    
      var errors = validator.numberOfInvalids();
      if (errors==2) {
        $('#loginMsg').text(resources["Login_RequiredNickAndPass"]).show();
      } else if($('body').validate().element("#nickInput")) {
         $('#loginMsg').text(resources["Login_RequiredPass"]).show();
      } else {
         $('#loginMsg').text(resources["Login_RequiredNick"]).show();
      }
    },    
    rules: {
      nickInput: {required:true},  
      passInput: {required:true}
    },
    submitHandler: function() {
      $('#loginSubmit').attr('disabled', 'disabled');
      $('#loginMsg').text('').hide();
      LoginMaster();             
      return false;
    }
   });
}
// form recover password
initRecPassForm = function() {         
  $('#recPassForm').validate({
    errorPlacement: function(error, element) {
      error.hide();
    },               
    invalidHandler: function(form, validator) {
      var errors = validator.numberOfInvalids();
      $('#loginMsg').text(resources["Login_InvalidEmail"]).show();
    },
    rules: {
      emailEEInput: {email:true,required:true}      
    },
    submitHandler: function() {
      $('#recPassSubmit').attr('disabled', 'disabled');
      $('#loginMsg').text('').hide();
      PwdRecover(0);
      return false;
    }
   });
}  
/* loginPais */
function loginPais(x) {
    if (x) {
        $('.loginPais').hide();
        $('.loggedPais').show();
        if (existe('#parabensLogged')) {
      // se n tiver educandos mostra o step0c
          if(hasChildren){
            $('#step0a, .voltar').show();
            $('.contFormulario h3, #step0b, #step0c, #parabensLogged, #step1, #step2, #step3').hide();
          }else{
             $('#step0c, .voltar').show();
            $('.contFormulario h3, #step0b, #step0a, #parabensLogged, #step1, #step2, #step3').hide();
          }
        }
        if (existe('#amigosRegForm')) {
          $('#start').show();
          $('#notLoggedh5').hide()
          $('#loggedp').show();
        }
    } else {
        $('.loginPais').show();
        $('.loggedPais').hide();
       if (existe('#parabensLogged')) {
            $('#step0b, .voltar').show();
            $('.contFormulario h3, #step0a, #step0c, #parabensLogged, #step1, #step2, #step3').hide();
        }
        if (existe('#amigosRegForm')) {
          $('#start').hide();
          $('#notLoggedh5').show();
          $('#loggedp').hide();
        }
    }
}
function bindRecPassPaisSubmit(){
  $('#recPassPaisSubmit').bind("click", function(){
    if ($("#recPassPaisForm").valid()){
      $('#recPassPaisMsg').text('').hide();
      $('#recPassPaisSubmit').unbind('click');
      PwdRecover(1);
      return false;
    }
  });  
}
function logPaisEvents() {
    $('#loginPaisSubmit').bind("click", function(){
    if ($("#loginPaisForm").valid()){
      $('#loginPaisMsg').text('').hide();
      LoginPaisEduc();             
      return false;
    }    
  });
  bindRecPassPaisSubmit();

    $('#btnLoggedPais').bind("click", function () {
        if (existe('#registo2Form')) {
            window.location = '/pais-e-educadores/artigos';
            LogOutPaisEduc();
        } else {
            LogOutPaisEduc();
        }
        return false;
    });
    $('#loginPaisForm a').bind("click", function () {
        $('#loginPaisForm').hide();
        $('#recPassPaisForm').show();
    $('#loginPaisMsg').text('').hide();
    $('#loginPaisForm').each(function(){this.reset();});
    $('#emailPaisInput, #passPaisInput').removeClass('error');  
        return false;
    });
    $('#recPassPaisForm a, #sucessRecPassPais a').bind("click", function () {
        $('#recPassPaisForm, #sucessRecPassPais').hide();
        $('#loginPaisForm').show();
    $('#recPassPaisMsg').text('').hide();
    $('#recPassPaisForm').each(function(){this.reset();});
    $('#email2PaisInput').removeClass('error');    
        return false;
    });
}
// form login pais
initLoginPaisForm = function() {
  $('#loginPaisForm').validate({
    errorPlacement: function(error, element) {
      error.hide();
    },
    invalidHandler: function(form, validator) {    
      var errors = validator.numberOfInvalids();
      if (errors==2) {
        $('#loginPaisMsg').text(resources["Login_RequiredEmailAndPass"]).show();
      } else if($('body').validate().element("#emailPaisInput")) {
         $('#loginPaisMsg').text(resources["Login_RequiredPass"]).show();
      } else {
         $('#loginPaisMsg').text(resources["Login_RequiredEmail"]).show();
      }
    },    
    rules: {
      emailPaisInput: {required:true},
      passPaisInput: {required:true}
    },
    onsubmit: false
   });
}    
// form recover password pais
initRecPassPaisForm = function() {         
  $('#recPassPaisForm').validate({
    errorPlacement: function(error, element) {
      error.hide();
    },                       
    invalidHandler: function(form, validator) {
      var errors = validator.numberOfInvalids();
      $('#recPassPaisMsg').text(resources["Login_InvalidEmail"]).show();
    },
    rules: {
      email2PaisInput: {email:true,required:true}      
    },
    onsubmit: false
   });
}
/* falaCEvents */
function falaCEvents() {
  $('#falaCTelInput').keypress(function (event) {
    return permite(event,numbersTel);
  });
  dropDown('#dd6', 'dD2Wrapper', '#falaCAssuntoInput', 24, 173);
  $('#btnFala').bind("click",function(){
    $('#falaCSubmit').removeAttr('disabled');
    $('.subHeader').stop().animate({top: '-60px'}, 500, "easeInOutExpo");
    $('.falaC').stop().delay(50).animate({top: '60px'}, 900, "easeInOutExpo");
  });
  $('#closeFala').bind("click",function(){
    $('.falaC').stop().animate({top: '-450px'}, 900, "easeInOutExpo", function(){
      $('#falaMsg, #sucessFalaC').hide();
      $('#falaMsg').text('');  
      $('#falaCForm input, #falaCMsgTextarea').removeClass('error');
      $('#falaCForm').each(function(){this.reset();});    
      $('#falaCForm').show();
    });
    $('.subHeader').stop().delay(400).animate({top: '60px'}, 500, "easeInOutExpo");
  });
}
// form FalaC
initFalaCForm = function () {
    $('#falaCForm').validate({
        errorPlacement: function (error, element) {
            error.hide();
        },
        invalidHandler: function (form, validator) {
            var errors = validator.numberOfInvalids();
            $('#falaMsg').text(resources["FalaC_RequiredFields"]).css({ 'display': 'block' });
        },
        rules: {
            falaCNomeInput: { required: true },
            falaCApelidoInput: { required: true },
            falaCTelInput: { required: true },
            falaCEmailInput: { email: true, required: true },
            falaCMsgTextarea: { required: true }
        },
        submitHandler: function () {
      $('#falaCSubmit').attr('disabled', 'disabled');
            SubmitContactForm(function(){
                $('#falaMsg, #falaCForm').hide();
                $('#falaMsg').text('');
                $('#falaCForm').each(function () { this.reset(); });
                $('#sucessFalaC').show();
        $('#falaCSubmit').removeAttr('disabled');
            });
            return false;
        }
    });
}  
/* newsEvents */
function newsEvents() {
    $('#btnNewsletter').bind("click", function () {
        
            $('#newsSubmit').removeAttr('disabled');
            $('.subHeader').stop().animate({ top: '-60px' }, 500, "easeInOutExpo");
            $('.newsletter').stop().delay(50).animate({ top: '60px' }, 900, "easeInOutExpo");
        
    });
   $('#closeNews').bind("click",function(){
    $('#newsSubmit').removeAttr('disabled');
    $('.newsletter').stop().animate({top: '-220px'}, 900, "easeInOutExpo", function(){
      $('#sucessNews p').text('')
      $('#newsForm').each(function(){this.reset();});
      $('#newsEmailInput').removeClass('error');
      $('#newsForm, .newsletter p').show();
      $('#newsMsg, #sucessNews').hide();      
    });    
    $('.subHeader').stop().delay(400).animate({top: '60px'}, 500, "easeInOutExpo");  
  });
}
// form News
initNewsForm = function () {
    $('#newsForm').validate({
        errorPlacement: function (error, element) {
            error.hide();
        },
        invalidHandler: function (form, validator) {
            var errors = validator.numberOfInvalids();
            //$('#falaMsg').text(resources["Newsletter_RequiredFields"]).css({'display':'block'});
            $('#newsMsg').text(resources["Newsletter_Error"]).css({ 'display': 'block' });
        },
        rules: {
            newsEmailInput: { email: true, required: true }
        },
        submitHandler: function () {
            SubmitNewsletter(function () {
                $('#newsSubmit').attr('disabled', 'disabled');
                $('#newsMsg, #newsForm, .newsletter p').hide();
                $('#newsMsg').text('');
                $('#newsForm').each(function () { this.reset(); });
                $('#sucessNews p').text(resources["Newsletter_OK"]);
                $('#sucessNews, #sucessNews p').show();
            });
            return false;
        }
    });
}  
// form registo 
initRegFormS1 = function() {
  $('#opcao1, #opcao2').click(function () {
    $('#step1 .custom-radio').removeClass('errorRadioBtn');
  });
  $('#regTelInput').keypress(function (event) {
    return permite(event,numbersTel);
  });
  $('#regCPostalInput').keypress(function (event) {
    return permite(event,numbersCP);
  });
  var form = $('#registoForm').get(0); 
  $.removeData(form,'validator');
  $('#registoForm').validate({
    errorPlacement: function(error, element) {
      error.hide();
    },
    invalidHandler: function(form, validator) {    
      var errors = validator.numberOfInvalids();
      if(!($("#opcao1").is(':checked')||$("#opcao2").is(':checked'))){
        $('#step1 .custom-radio').addClass('errorRadioBtn');
      } else {
        $('#step1 .custom-radio').removeClass('errorRadioBtn');
      }
      $('#errorMsg').text(resources["Registration_RequiredFields"]).show();
    },    
    rules: {
      regNomeInput: {required:true},  
      regApelidoInput: {required:true},
      opcao: {required:true},
      regBiInput: {required:true},
      regTelInput: {required:true},
      regEmailInput: {required:true,email:true},
      regLocalidadeInput: {required:true},
      regNickInput: {required:true},
      regPassInput: {required:true},
      regPassConfInput: {required:true}
    },
    onsubmit: false
   });
}
initRegFormS2 = function() {
  $('#regDiaNascEd1, #regDiaNascEd1, #regAnoNascEd1').keypress(function (event) {
    return permite(event,numbers);
  });    
  var form = $('#registoForm').get(0); 
  $.removeData(form,'validator');  
  $('#registoForm').validate({
    onsubmit: false
   });
}
initRegFormS3 = function() {
  var form = $('#registoForm').get(0); 
  $.removeData(form,'validator');
  $('#registoForm').validate({
    errorPlacement: function(error, element) {
      error.hide();
    },
    invalidHandler: function(form, validator) {    
      var errors = validator.numberOfInvalids();
      if(!($("#check1").is(':checked'))){
        $('#step3 .termos .custom-checkbox').addClass('errorCheckBox');
      } else {
        $('#step3 .termos .custom-checkbox').removeClass('errorCheckBox');
      }
      $('#errorMsg').text(resources["Registration_RequiredLegalNotice"]).show();
    },    
    rules: {
      check1: {required:true}
    },
    onsubmit: false
   });
}
function bindConcluirForm(){
  $('#step3 .btn2:eq(1)').click(function () {
    if ($("#registoForm").valid()){
      $('#step3 .btn2:eq(1)').unbind('click');
      ValidateStep3SS(function (data) {
        if (data.Status) {
          $('#errorMsg').hide();
          $('#step3, .contFormulario h3').hide();
          $('#step4').show();
          reinitShadowIE();
          $('#formSteps li').removeClass();
          // registo - envia form
        }
      });
    return false;
    }          
  });  
}
// form envia Desenho
initDesEnviaForm = function() {
  $('#desEnviaForm').validate({
    errorPlacement: function(error, element) {
      error.hide();
    },
    invalidHandler: function(form, validator) {    
      var errors = validator.numberOfInvalids();
      if(!($('body').validate().element("#desenhoInput"))){
        $('#desenho').addClass('error');
      } else {
        $('#desenho').val($('#desenhoInput').val());
        $('#desenho').removeClass('error');
      }
      $('#desEnviaForm .errorMsg').text(resources["Espaco_RequiredFields"]).show();
    },    
    rules: {
      desenhoInput: {required:true},  
      nomeDesEnviaInput: {required:true},
      titDesEnviaInput: {required:true},
      idadeDesEnviaInput: {required:true}
    },
    onsubmit: false
   });
}
// form faz Desenho
initDesFazForm = function() {
  $('#desFazForm').validate({
    errorPlacement: function(error, element) {
      error.hide();
    },
    invalidHandler: function(form, validator) {    
      $('#desFazForm .errorMsg').text(resources["Espaco_RequiredFields"]).show();
    },    
    rules: {
      nomeDesFazInput: {required:true},
      titDesFazInput: {required:true},
      idadeDesFazInput: {required:true}
    },
    onsubmit: false
   });
}
// form Pbns
initPbnsForm = function() {
  $('#pbnsDiaNasc,#pbnsMesNasc,#pbnsAnoNasc').keypress(function (event) {
    return permite(event,numbers);
  });
}  
/* adicionar educandos */
function educandos(x) {
    var nEd = x;
  
    function addEducando(nEd) {

        $('.add').before(
['<div id="educando' + nEd + '" class="educando"><div class="step2a"><h4><span>' + nEd + '</span>.</h4>',
'<div class="form1"><label>Nome</label><input type="text" value="" id="regNomeInputEd' + nEd + '" name="regNomeInputEd' + nEd + '" /></div>',
'<div class="form1"><label>Apelido</label><input type="text" value="" id="regApelidoInputEd' + nEd + '" name="regApelidoInputEd' + nEd + '" /></div>',
'<div class="form5"><label>Data de nascimento</label><div class="dataNasc"><input type="text" value="" id="regDiaNascEd' + nEd + '" name="regDiaNascEd' + nEd + '" maxlength="2" /><input type="text" value="" id="regMesNascEd' + nEd + '" name="regMesNascEd' + nEd + '" maxlength="2" /><input type="text" value="" id="regAnoNascEd' + nEd + '" name="regAnoNascEd' + nEd + '" maxlength="4" /></div></div>',
'<div class="form5"><label>Sexo</label><fieldset><input type="radio" name="opcaoEd' + nEd + '" id="opcao1Ed' + nEd + '" value="M" /><label for="opcao1Ed' + nEd + '">Masculino</label><input type="radio" name="opcaoEd' + nEd + '" id="opcao2Ed' + nEd + '" value="F" /><label for="opcao2Ed' + nEd + '">Feminino</label></fieldset></div>',
'<div class="form5"><label>Grau de Parentesco</label><div id="dd3Ed' + nEd + '" class="dDown3"><div class="dD3Wrapper"><div class="opened"></div><input type="text" readonly="readonly" id="regParentInputEd' + nEd + '" name="regParentInputEd' + nEd + '" value="Escolha uma resposta"><input type="hidden" value="" name="dropRelashtionInputValue' + nEd + '" id="dropRelashtionInputValue' + nEd + '"><ul>' + dropRelashtion(nEd) + '</ul></div><div class="close"></div></div></div></div>',
'<div class="step2b"><div class="form1"><label>Nickname</label><input type="text" value="" id="regNickInputEd' + nEd + '" name="regNickInputEd' + nEd + '" /></div>',
'<div class="form1"><label>Password</label><input type="password" value="" id="regPassInputEd' + nEd + '" name="regPassInputEd' + nEd + '" /></div>',
'<div class="form2"><label>Preferência: (opcional)</label><div id="dd4Ed' + nEd + '" class="dDown4"><div class="dD2Wrapper"><div class="opened"></div><input type="text" readonly="readonly" id="regPrefInputEd' + nEd + '" name="regPrefInputEd' + nEd + '" value="Assinale os programas"><ul>' + dropFavorits(nEd) + '</ul></div><div class="close"></div></div></div>',
'<div class="form1"><label>Confirmar Password</label><input type="password" value="" id="regPassConfInputEd' + nEd + '" name="regPassConfInputEd' + nEd + '" /></div>',
'<div class="btn1 btn1Cor0"><a id="remove' + nEd + '" href="#">Remover</a></div><div class="certeza"><div class="btn1 btn1Cor0"><a id="removeNo' + nEd + '" href="void(0);">Cancelar</a></div><div class="btn1 btn1Cor0"><a id="removeYes' + nEd + '" href="void(0);">Remover</a></div><p>Tem a certeza que quer remover?</p></div></div>'].join('')
);
    $('#regDiaNascEd'+nEd+', #regMesNascEd'+nEd+', #regAnoNascEd'+nEd+'').keypress(function (event) {
      return permite(event,numbers);
    });  
        cInputsEd('#opcao', 1, 2, nEd);
        $('#regAnoNascEd' + nEd + '').css('margin-right', '0');
        if (!$.browser.msie) cInputsEd('#check', 1, Number($('#dd4Ed1 li').length), nEd);
        dropDown('#dd3Ed' + nEd, 'dD3Wrapper', '#regParentInputEd' + nEd, 24, 173);
        dropDown('#dd4Ed' + nEd, 'dD2Wrapper', '#regPrefInputEd' + nEd, 24, 173);
    $(".dDown3 *, .dDown4 *").attr("tabindex", "-1");
        $('#remove' + nEd).click(function () {
            $('#removeNo' + nEd).parent().parent().show();
            $(this).parent().hide();
            return false;
        });
        $('#removeNo' + nEd).click(function () {
            $('#remove' + nEd).parent().show();
            $(this).parent().parent().hide();
            return false;
        });
        $('#removeYes' + nEd).click(function () {
            if ($("#alterRegisto").size() > 0) {
                var username = $($(this).parent().parent().parent().find(".form1")[0]).find("input").val();
                DeleteChild(username, function (data) {
                    $('#educando' + nEd).remove();
                    renomeia();
                });
            }
            else {
                $('#educando' + nEd).remove();
                renomeia();
            }
            return false;
        });
    }
    $('#registoForm #add').click(function () {
        CanAddChild(function (data) {
                nEd += 1;
                addEducando(nEd);
                renomeia();
                addHandlerDrop(nEd);
        });
        return false;
    });

    $('#registo2Form #add').click(function () {
      CanAddChildUpdate(function (data) {
            nEd += 1;
            addEducando(nEd);
            renomeia();
            addHandlerDrop(nEd);
      });
        return false;
    });
   
}
function renomeia() {

    if ($("#registo2Form").size() == 0) {
        $('.educando .step2a h4').each(function (intIndex) {
            $('span', this).text(intIndex + 2);
        });
    }
    else {
        $('.educando .step2a h4').each(function (intIndex) {
            $('span', this).text(intIndex + 1);
        });
    }
    reinitShadowIE();
}
/* bindPBensSubmit */
function bindPBensSubmit(){
  $('#step2 .btn2:eq(1)').bind("click", function(){
    if ($('#check1:checked').length == 1) {
      $('#step2 .btn2:eq(1)').unbind('click');
      $('.termos > div').removeClass('errorCheckBtn');
      $('#error2').html("");
      SubmitParabens();
      /* $('#step2, .contFormulario h3').hide();
      $('#step3, .voltar').show();
      reinitShadowIE();
      $('#formSteps li').removeClass();*/
    } else {
      $('.termos > div').addClass('errorCheckBtn');
      $('#error2').html(resources["Parabens_Legal"]);
    }
    // registo - envia form
    
  });
}
/* sliders */
function sliderNH() { // slider Nav Home
  if (typeof(ahomeSlider) != "undefined") { // preload Banners
    var sliderNHCount = $('#homeSliderNav li').size();
    var bannersDaHome = '', bannersDummy = '';
    for (i=sliderNHCount;i>0;i--){
      bannersDaHome += '<div class="destqBg" id="dBg'+i+'" style="background:url(\''+ahomeSlider[i-1]['image']+'\') no-repeat center top;"></div>';
      bannersDummy += '<img src="'+ahomeSlider[i-1]['image']+'" />';
    }
    $('#homeSlider').prepend(bannersDaHome);
    var bannersPreload = $(bannersDummy); //create a new jquery element out of the dynamic html
    bannersPreload.onImagesLoad({ //attach onImagesLoad to the new content 
      itemCallback: sliderNoGo, 
      selectorCallback: sliderNHGo,
      callbackIfNoImagesExist: sliderNoGo       
    });
  }
  function sliderNoGo(domObject){}   
  function sliderNHGo(domObject) { // banners Preloaded
    $('#homeSLoad').hide();
    var sliderNHActivo = 0;
    var initTimer = setTimeout(autoSlide,6000)
    var destq = 1;
    var bgIndex = 1;
    $('#dBg1').fadeIn(400);
    $('.homeLink').bind("click",function(){location.href= ahomeSlider[0]['link']});
    $('#homeSliderNav li:first').addClass('on');
    $('#homeSliderNav li').each(function(intIndex){  
    $(this).bind("click",function(){
      resetTimer();
      if(intIndex!=sliderNHActivo) {
      sliderNHActivo = intIndex;
      if (destq) {
        $('#dBg'+bgIndex).fadeOut(400,0);
        bgIndex = intIndex+1;
        $('#dBg'+bgIndex).fadeIn(400,function(){
        $('.homeLink').bind("click",function(){location.href= ahomeSlider[intIndex]['link']});
        });        
      }
      $('#homeSliderNav li').removeClass();
      $(this).addClass('on');
      }
      return false;
    });
    });  
    function autoSlide(){
    sliderNHActivo == sliderNHCount-1 ? sliderNHActivo=0 : sliderNHActivo++;
    if (destq) {
      $('#dBg'+bgIndex).fadeOut(400,0);
      bgIndex = sliderNHActivo+1;
      $('#dBg'+bgIndex).fadeIn(400,function(){
      $('.homeLink').bind("click",function(){location.href= ahomeSlider[bgIndex]['link']});
      });
    }
    $('#homeSliderNav li').removeClass();
    $('#homeSliderNav li:nth-child('+Number(sliderNHActivo+1)+')').addClass('on');
  
    resetTimer();
    }
    function resetTimer(){
    clearTimeout(initTimer);
    initTimer = setTimeout(autoSlide,6500);
    }  
  }
  return false;
}
                               
function sliderLH() {// slider Links Home
  
  var sliderLHIndex = 0;
  var sliderLHCount = $('#homeLinksSlider li').size();
  var sliderLHWidth = 67*seriesFitaCout;
  var sliderLHul = $("#homeLinksSlider ul");
  sliderLHul.css({'width':sliderLHWidth});
  
  $('.left').css({'cursor':'default'});
  $('.left').bind("mouseenter",function(){
    if (sliderLHIndex>0) $(this).css({'backgroundPosition':'-528px -414px','cursor':'pointer'});
  });
  
  $('.right').bind("mouseenter",function(){
    if (sliderLHIndex<sliderLHCount-9) $(this).css({'backgroundPosition':'-590px -414px','cursor':'pointer'});
  });
  
  $('.left').bind("mouseleave",function(){
    $(this).css({'backgroundPosition':'-528px -354px','cursor':'default'});
  });  
  
  $('.right').bind("mouseleave",function(){
    $(this).css({'backgroundPosition':'-590px -354px','cursor':'default'});
  });
  
  $('.left').bind("click",function(){  
    if (sliderLHIndex>0) {
      sliderLHIndex -= 1;
      sliderLHul.stop().animate({left: '-'+(sliderLHIndex*67)+'px'}, 200, "easeInOutExpo");
      if (sliderLHIndex==0) $(this).css({'backgroundPosition':'-528px -354px','cursor':'default'});
      return false;
    } else {return false}  
  });  
            
  $('.right').bind("click",function(){
    var sliderLHCount = $(".slide li").size();
    $('.right').bind("mouseenter",function(){
      if (sliderLHIndex<sliderLHCount-9) $(this).css({'backgroundPosition':'-590px -414px','cursor':'pointer'});
    });
    $('.right').bind("mouseleave",function(){
      $(this).css({'backgroundPosition':'-590px -354px','cursor':'default'});
    });
    $('li',sliderLHul).each(function(intIndex){
    $(this).bind("mouseenter",function(){
      var esteLeft = Number(((intIndex - sliderLHIndex)*67)+63);
      $('#enterBorder').css({'left':esteLeft+'px','display':'block'});
    });
    $(this).bind("mouseleave",function(){
      $('#enterBorder').hide();
    })    
    });
      
    LoadfitaHomePageAsync(); 
    if (sliderLHIndex<sliderLHCount-9){
      sliderLHIndex += 1;
      sliderLHul.stop().animate({left: '-'+(sliderLHIndex*67)+'px'}, 200, "easeInOutExpo");
      if (sliderLHIndex==sliderLHCount-5) $(this).css({'backgroundPosition':'-590px -354px','cursor':'default'});
      return false;
    } else {return false}  
    
  });
            
  $('li',sliderLHul).each(function(intIndex){
    $(this).bind("mouseenter",function(){
      var esteLeft = Number(((intIndex - sliderLHIndex)*67)+63);
      $('#enterBorder').css({'left':esteLeft+'px','display':'block'});
    });
    $(this).bind("mouseleave",function(){
      $('#enterBorder').hide();
    })    
  });
}    
                          
                          
function sliderDias() {
  var sliderDiasIndex = 0;
  var sliderDiasCount = $('#pageHeaderContent li').size();
  var sliderDiasWidth = 128*sliderDiasCount;
  $("#pageHeaderContent").css({'width':sliderDiasWidth});
  $('.left').css({'cursor':'default'});
  $('.left').bind("mouseenter",function(){
    if (sliderDiasIndex>0) $(this).css({'backgroundPosition':'-438px -662px','cursor':'pointer'});
  });
  $('.right').bind("mouseenter",function(){
    if (sliderDiasIndex<sliderDiasCount-5) $(this).css({'backgroundPosition':'-471px -662px','cursor':'pointer'});
  });
  $('.left').bind("mouseleave",function(){
    $(this).css({'backgroundPosition':'-513px -662px','cursor':'default'});
  });  
  $('.right').bind("mouseleave",function(){
    $(this).css({'backgroundPosition':'-546px -662px','cursor':'default'});
  });
  $('.left').bind("click",function(){  
    if (sliderDiasIndex>0) {
      sliderDiasIndex -= 1;
      $('#pageHeaderContent').stop().animate({left: '-'+(sliderDiasIndex*128)+'px'}, 200, "easeInOutExpo");
      if (sliderDiasIndex==0) $(this).css({'backgroundPosition':'-513px -662px','cursor':'default'});
      return false;
    } else {return false}  
  });  
  $('.right').bind("click",function(){
    if (sliderDiasIndex<sliderDiasCount-5){
      sliderDiasIndex += 1;
      $('#pageHeaderContent').stop().animate({left: '-'+(sliderDiasIndex*128)+'px'}, 200, "easeInOutExpo");
      if (sliderDiasIndex==sliderDiasCount-5) $(this).css({'backgroundPosition':'-546px -662px','cursor':'default'});
      return false;
    } else {return false}  
  });  
  $('#pageHeaderContent li a').each(function(intIndex){  
    $(this).bind("click",function(){
      $('#pageHeaderContent li').removeClass();
      $(this).parent().addClass('on');
    });
  });  
}
/* salaDePintura */
function salaDePintura(){
  $('.col18:eq(1)').css('padding-right','0');
  $('.contSala > .clearfix').each(function(){
    $(this).append('<div class="contDesLoad">&nbsp;</div>');
  });
  $('.espaco').onImagesLoad({ //attach onImagesLoad
    itemCallback: imgsNoGo, 
    selectorCallback: imgsGo,
    callbackIfNoImagesExist: imgsNoGo       
  });
  function imgsNoGo(domObject){}   
  function imgsGo(domObject) { // banners Preloaded
    $('.contSala').each(function(intIndex){
      var altD = $('img', this).outerHeight();
      if (altD>350){
      $(this).addClass('csVert');
      $('.fita6', this).removeClass().addClass('fita5');
      $('.contDes, .contDes img', this).css('height',$('img', this).outerHeight());
      } else {
      $('.contDes, .contDes img', this).css('height',altD);
      }
      $('.contDesLoad', this).remove();
    });
    reinitShadowIE();
    $('.contDes').addClass('posTop');
    $('.desDescr').show();
  }
}
    

/* vota Desenhos */
function votaDraw() {
     
    $(".votaDraw").each(function (intIndex) {
      
      var elem= $('.votaDraw').eq(intIndex);  
      var userRate = elem.attr("userrate");
      
      elem.append('<ul><li style="cursor:default;"></li><li style="cursor:default;"></li><li style="cursor: default;"></li><li style="cursor: default;"></li><li style="cursor: default;"></li></ul>');
      var votaList = elem.find("li");
     
      for (var i = 0; i < userRate; i++) {
          $(votaList[i]).css('backgroundPosition', '-333px -82px');
      }
      if (userRate == 0) {
        elem.find("li").css("cursor","pointer");
        votaList.each(function (intIndex) {
            $(this).bind("mouseenter", function () {
                for (g = 0; g < intIndex + 1; g++) {
                    elem.find('li:eq(' + g + ')').css('backgroundPosition', '-418px -83px');
                }
            });
            $(this).bind("mouseleave", function () {
                votaList.css('backgroundPosition', '-473px -83px');
            });
            $(this).bind("click", function () {

                var rate = $(this).prevAll("li").size() + 1;
                var drawid= elem.attr("drawid");
                
                DoVoteDraw(drawid, rate, function (data) {
                    if (data.Status) {
                        elem.find(".starsBig").html(data.Rate); //+ " estrelas"
                        elem.find(".starsBig").attr("class", "starsBig sB" + data.RateCssClass);
                        votaList.unbind();
                        votaList.css('cursor', 'default');
                        for (g = 0; g < intIndex + 1; g++) {
                           elem.find('li:eq(' + g + ')').css('backgroundPosition', '-333px -82px');
                        }
                        for (h = intIndex + 1; h < 6; h++) {
                            elem.find('li:eq(' + h + ')').css('backgroundPosition', '-389px -82px');
                        }
                    }
                    else {
                        //alert(data.Message);
                    }

                });
            });
        });
        
          
      }
      
    });
}       
    
    
/* vota */
function vota() {

    var userRate = $('#vota').attr("userrate");
    $('#vota').append('<ul><li></li><li></li><li></li><li></li><li></li></ul>');
    var votaList = $('#vota li');

    for (var i = 0; i < userRate; i++) {
        $(votaList[i]).css('backgroundPosition', '-333px -82px');
    }

    // So ainda não tiver votado
    if (userRate == 0) {
        votaList.each(function (intIndex) {
            $(this).bind("mouseenter", function () {
                for (g = 0; g < intIndex + 1; g++) {
                    $('#vota li:eq(' + g + ')').css('backgroundPosition', '-418px -83px');
                }
            });
            $(this).bind("mouseleave", function () {
                votaList.css('backgroundPosition', '-473px -83px');
            });
            $(this).bind("click", function () {

                var rate = $(this).prevAll("li").size() + 1;
                var nodeid = $('#vota').attr("nodeid");
                DoVote(nodeid, rate, function (data) {
                    if (data.Status) {
                        $(".starsBig").html(data.Rate); //+ " estrelas"
                        $(".starsBig").attr("class", "starsBig sB" + data.RateCssClass);
                        votaList.unbind();
                        votaList.css('cursor', 'default');
                        for (g = 0; g < intIndex + 1; g++) {
                            $('#vota li:eq(' + g + ')').css('backgroundPosition', '-333px -82px');
                        }
                        for (h = intIndex + 1; h < 6; h++) {
                            $('#vota li:eq(' + h + ')').css('backgroundPosition', '-389px -82px');
                        }
                    }
                    else {
                        alert(data.Message);
                    }

                });
            });
        });
    }
}
/* isiPadIphone*/           
function isiPadIphone() {
      if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i))) {
          return true
      } else {
      return false;
      }
}
function isiPadIphoneIe() {
      if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i)) (navigator.userAgent.match(/MSIE/i)) ) {
          return true
      } else {
      return false;
      }
}
/* sondagens */
var poll = {cont:0, poll:0, pollIn:0, h:0, loader:0, qts:0, nodeId:0,
      alt: function(){
            poll.h = Number(poll.pollIn.outerHeight()+4);
            poll.cont.css({height:poll.h});
          }
};
function sondagens(){
  poll.cont = $('.contPoll');
  poll.pollIn =  $('.pollIn');
  setTimeout(poll.alt,200);
  setTimeout(poll.alt,1000);  
  setTimeout(poll.alt,4000);
  poll.poll = $('#poll');
  poll.loader = poll.cont.find('.loader');
  poll.qts = poll.poll.find('input').length;
  if(poll.qts>0) cInputs('#pollChoice', 1, poll.qts);
}

/* vota */
function tvPlayerF(oVideoId, oFlashId) {
    
    var tvPlay = 1;
    var tvSound = 0;
    var tvVideo = document.getElementById(oVideoId);
    var canPlayHtml5 = false;
    var flashMovie = null;
    
  
  function detectVideoSupport(){
    var detect = document.createElement('video') || false;
    this.html5 = detect && typeof detect.canPlayType !== "undefined";
    this.mp4 = this.html5 && (detect.canPlayType("video/mp4") === "maybe" || detect.canPlayType("video/mp4") === "probably");
    this.ogg = this.html5 && (detect.canPlayType("video/ogg") === "maybe" || detect.canPlayType("video/ogg") === "probably");
    return this;
  }

  function replaceVideoWithObject(video_id){    
    if(!video_id){ return false; }
    var video = document.getElementById(video_id);
    if(video){
      var obj = video.getElementsByTagName("object")[0];
      if(obj){
        var obj_copy = obj.cloneNode(true);
        video.parentNode.insertBefore(obj_copy, video);
        video.parentNode.removeChild(video);
      }
    }
  };

  /*var video = detectVideoSupport();
  //Both Opera and Firefox support OGG but lack MP4 support
  if(video.ogg && !video.mp4){
    replaceVideoWithObject(oVideoId);
    canPlayHtml5 = false;
    flashMovie = getFlashMovieObject(oFlashId);
    $('#' + oFlashId).show();
    $('#' + oFlashId).css('visibility','visible');
  }else{
    canPlayHtml5 = true;
  }*/


  if (isiPadIphone()) {
      canPlayHtml5 = true;
    
  }else{
      replaceVideoWithObject(oVideoId);
      canPlayHtml5 = false;
      flashMovie = getFlashMovieObject(oFlashId);
      
      //$('#' + oFlashId).show();
      //$('#' + oFlashId).css('visibility', 'visible');
  }


    function checkVideo() {
    return canPlayHtml5;
        //if (!!document.createElement('video').canPlayType) { return true; } else { return false; }
    }
    function startVideo() {
        if (checkVideo()) { tvVideo.play() } else { flashMovie.videoPlay() }
        $('#controls li:eq(2)').css('backgroundPosition', '-546px -532px');
        tvPlay = 1;
    }
    function pauseVideo() {
        if (checkVideo()) { tvVideo.pause() } else { flashMovie.videoPause() }
        $('#controls li:eq(1)').css('backgroundPosition', '-546px -468px');
        tvPlay = 0;
    }


    function sound() {

        if (checkVideo()) { tvVideo.muted = !tvVideo.muted; } else { flashMovie.videoSound(); }
        if (tvSound) {
            tvSound = 0;
            $(this).css('backgroundPosition', '-546px -410px');
        } else {
            tvSound = 1;
            $(this).css('backgroundPosition', '-686px -410px');
        }
    }
    function stopSound() {
    //acho que não está fazendo nada!!!
        tvSound = 0;
    }
    var theNameOfTheFlashObject = "";
    function getFlashMovieObjectChrome(movieName) {
        flashMovie = document.getElementById(theNameOfTheFlashObject);
        
    }
    function getFlashMovieObject(movieName) {


        if (navigator.appName.indexOf("Microsoft") != -1) {
            return window[movieName];
        }
        else {
            try {
                if (document[movieName].length != undefined) {
                    return document[movieName][1];
                }
                return document[movieName];
            } catch (e) {



                return document.getElementById(movieName);

            }


        }
       
        

    }
    $('#controls li:eq(0)').css({ 'backgroundPosition': '-546px -410px', 'margin-bottom': '13px' });
    $('#controls li:eq(1)').css({ 'backgroundPosition': '-546px -468px', 'margin-bottom': '19px' });
    $('#controls li:eq(2)').css({ 'backgroundPosition': '-546px -532px' });
    //Auto play 
          $('#controls li:eq(1)').css('backgroundPosition', '-686px -468px');

      
      
    $('#controls li:eq(0)').bind("mouseenter", function () {
        $(this).css('backgroundPosition', '-616px -410px');
    });
    $('#controls li:eq(0)').bind("mouseleave", function () {
        if (tvSound) { $(this).css('backgroundPosition', '-686px -410px') }
        else { $(this).css('backgroundPosition', '-546px -410px') }
    });
    $('#controls li:eq(0)').bind("click", function () { sound() });

    $('#controls li:eq(1)').bind("mouseenter", function () {
        if (!tvPlay) $(this).css('backgroundPosition', '-616px -468px');
    });
    $('#controls li:eq(1)').bind("mouseleave", function () {
        if (!tvPlay) $(this).css('backgroundPosition', '-546px -468px');
    });
    $('#controls li:eq(1)').bind("click", function () {
        if (!tvPlay) { startVideo(); $(this).css('backgroundPosition', '-686px -468px'); }
    });

    $('#controls li:eq(2)').bind("mouseenter", function () {
        if (tvPlay) $(this).css('backgroundPosition', '-616px -532px');
    });

    $('#controls li:eq(2)').bind("mouseleave", function () {
        if (tvPlay) $(this).css('backgroundPosition', '-546px -532px');
    });
    $('#controls li:eq(2)').bind("click", function () {
        if (tvPlay) { pauseVideo(); $(this).css('backgroundPosition', '-686px -532px'); }
    });
}
var swfTeste = "";
/* alinhaArtigos */
function alinhaArtigos() {
    var esq = Number($('.col6').outerHeight() - 136);
    var dir = Number($('.col7:first').outerHeight() - 136);
    if (esq > dir) {
        if (existe('.artDetalhe')) {
            $('.contArtigosList').css('height', Number(esq + 2));
            if ($.browser.msie) $('.contArtigosList').css('height', Number(esq));
        } else {
            $('.contArtigosList').css('height', Number(esq - 42));
        }
    } else {
        var nContArtigos = $('.contArtigo');
        var esqNum = nContArtigos.length;
        var esq2 = 0;
        for (i = 1; i < esqNum; i++) {
            esq2 += Number($('.contArtigo:eq(' + Number(i - 1) + ')').outerHeight() + 2);
        }
        if (existe('.artDetalhe')) {
            $('.contArtigo:last').css('height', Number(dir - esq2 - 262));
        } else {
            $('.contArtigo:last').css('height', Number(dir - esq2 - 70));
        }
    }
}
/* alinhaFun */
function alinhaFun() {
    var col12h = Number($('.col12').outerHeight());
    $('.contFunFilter').css('height', Number(col12h - 60));
}
/* alinhaWpSs */
function alinhaWpSs() {
    $('.contWpSs').each(function () {
        var rightP = 9;
        if ($('.btn4', this).length > 0) { var oBot = '.btn4' } else { var oBot = '.btn2' }
        for (i = 0; i < 3; i++) {
            $(oBot + ':eq(' + i + ')', this).css('right', rightP + 'px');
            rightP += Number($(oBot + ':eq(' + i + ')', this).outerWidth() + 9);
        }
    });
}
/* dropDown */
function dropDown(elemento, classe, input, altura1, altura2) {
    var elemDiv = $('.' + classe, elemento);
    var closeBtn = $('.close', elemento);
    $(elemDiv).click(function () {
        $(this).removeClass().addClass(classe + 'Active').css({ height: altura2 });
        $(closeBtn).show();
    });
/*  $(elemento + ',' + elemento + ' ul').mouseleave(function () {*/
    $(elemento).mouseleave(function () {
        fecha();
    });
    $(closeBtn).click(function () {
        fecha();
    });
    $(elemento + ' li a').each(function () {
        $(this).click(function () {
            fecha();
            mudaInput($(this).text());
            return false;
        });
    });
    function fecha() {
        $(elemDiv).css({ height: altura1 }).removeClass().addClass(classe);
        $(closeBtn).hide();
    }
    function mudaInput(valor) {
        $(input).val(valor);
    }
}
// permite
function permite(e,allow) {
  var k;
  k=e.keyCode?parseInt(e.keyCode): parseInt(e.charCode);
  if (!((k > 36 && k < 47)||(k > 7 && k < 10))){ // para alem do allow, permite delete, tab, arrows, etc
    return (allow.indexOf(String.fromCharCode(k))!=-1);
  }
}
/* cInputs */
function cInputs(x, y, z) {
    for (i = y; i < z + 1; i++) { $(x + i).customInput(); }
}
/* cInputsEd */
function cInputsEd(x, y, z, nEd) {
    for (i = y; i < z + 1; i++) { $(x + i + 'Ed' + nEd).customInput(); }
}
/* existe */
function existe(x) {
    if ($(x).length > 0) return true;
}
/* shadowIE */
function shadowIE() {
    if ($.browser.msie) {
        $('.shadow').boxShadow(2, 2, 3, "#969696"); // sombras em ie
    }
}
/* reinitShadowIE */
function reinitShadowIE() {
    if ($.browser.msie) {
        $('.shadow').removeBoxShadow();
    }
}
/* getParameterByName */
function getParameterByName(name){
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return decodeURIComponent(results[1].replace(/\+/g, " "));
}

/* init */
function init(fonte) {
    /*if (loginEstado==undefined) loginEstado = 0;
    if (loginPaisEstado==undefined) loginPaisEstado = 0;
    login(loginEstado);
    logEvents();  
    loginPais(loginEstado);
    logPaisEvents();*/
    if (!fonte) {
        $('#nav a,#paisNav a,#pstNav a,.contWpSs .btn2f,.btn4f').css('font-family', 'Lucida Grande,Lucida Sans Unicode,sans-serif');
        $('#nav a,#paisNav a,#pstNav a,.contWpSs .btn2f,.btn4f').css('font-weight', 'bold');
        $('.contWpSs .btn2f, .btn4f').css('font-size', '13px');
    }
    lapis();
    aleatorio();  
  initLoginForm();
  initRecPassForm();
  falaCEvents();
  initFalaCForm();
  newsEvents();
  initNewsForm();
  if(existe('#loginPaisForm')){
    initLoginPaisForm();
    initRecPassPaisForm();
  }
  if(existe('.cHome')) {
    sliderLH(); // slider Links Home
    sliderNH(); // slider Nav Home
  }
    if (existe('#vota'))vota();      
    
  if (existe('#pollVote')) sondagens();

    if (existe('.jogos')) {  // jogos
        $('.wrapper').css({ 'backgroundImage': 'url("/Images/fundoJogos.jpg")', 'backgroundRepeat': 'no-repeat', 'backgroundPosition': 'center 60px' });
        $('.content').prepend('<div class="quad"></div>');
        if (existe('.contJogos')) {
            $('.jogosNav .prim').bind("click", function () {
                $('.jogosNav a').removeClass();
                $('a', this).addClass('on');
                JogosClickChanGePage();
                return false;
            });
            $('.jogosNav .seg').bind("click", function () {
                $('.jogosNav a').removeClass();
                $('a', this).addClass('on');
                JogosClickChanGePage();
                return false;
            });
        }
        if (existe('#part1Form')) {
            $('#part1Form fieldset:first input').css('width', '196px');
            $('.contPartilha1').prepend('<div class="seta"></div>');
        }
    }
    if (existe('.pr') || existe('.contPesq')) {  // programacao ou pesquisa
        $('.wrapper').css({ 'backgroundImage': 'url(/Images/fundoProgramacao.jpg)', 'backgroundRepeat': 'no-repeat', 'backgroundPosition': 'center 60px' });
        $('.content').prepend('<div class="quad"></div>');
        if (existe('.contDetalhe')) {
            if (existe('#pandaTV')) tvPlayerF('pandaTV', 'pandaTVswf');
            if ($('.detalheNav .prim a').hasClass('on')) $('#contDetalheSlider').css('backgroundImage', 'url(/Images/bg3.gif)');
            $('.detalheNav .prim').bind("click", function () {
                $('.detalheNav a').removeClass();
                $('a', this).addClass('on');
                $('#contDetalheSlider').css('backgroundImage', 'url(/Images/bg3.gif)');
                return false;
            });
            $('.detalheNav .seg').bind("click", function () {
                $('.detalheNav a').removeClass();
                $('a', this).addClass('on');
                $('#contDetalheSlider').css('backgroundImage', 'url(/Images/bg4.gif)');
                return false;
            });
        }
    if(existe('#contProg2DiasSlider')) setTimeout(sliderDias, 400);
    }
    if (existe('.pst')) {  // passatempos
        $('.wrapper').css({ 'backgroundImage': 'url(/Images/fundoPassatempos.jpg)', 'backgroundRepeat': 'no-repeat', 'backgroundPosition': 'center 60px' });
        $('.content').prepend('<div class="quad"></div>');
        setTimeout(smallMenu, 600);
        $('.detalheNav .prim').bind("click", function () {
            $('.detalheNav a').removeClass();
            $('a', this).addClass('on');
            PastChangeTab(1);
            return false;
        });
        $('.detalheNav .seg').bind("click", function () {
            $('.detalheNav a').removeClass();
            $('a', this).addClass('on');
            PastChangeTab(0);
            return false;
        });
        $('#pstNav li').each(function (intIndex) {
            if ($(this).hasClass('on')) {
                $('#pstArea' + Number(intIndex + 1)).show();
            }
            $('a', this).click(function () {
                $('#pstNav li').removeClass();
                $(this).parent().addClass('on');
                $('.pst .contDetalhe > div').hide(); // muda conteudo
                $('#pstArea' + Number(intIndex + 1)).show();
                reinitShadowIE();
                $('.nuvem2').css('top', '-660px'); // muda nuvem fundo
                $('#nuvem2' + Number(intIndex + 1)).css('top', '10px');
                $('#pstNav a').css('color', '#009ee1'); // muda cor do link
                $(this).css('color', '#fff');
                pstNavEvents(); // muda rollovers  
                return false;
            });
        });
        function pstNavEvents() {
            $('#pstNav a').unbind('mouseenter');
            $('#pstNav a').unbind('mouseleave');
            $('#pstNav a').each(function (intIndex) {
                if (!$(this).parent().hasClass('on')) {
                    $(this).bind('mouseenter', function () {
                        $(this).css('color', '#fff');
                        $('#nuvem2' + Number(intIndex + 1)).css('top', '10px');
                    });
                    $(this).bind('mouseleave', function () {
                        $(this).css('color', '#009ee1');
                        $('#nuvem2' + Number(intIndex + 1)).css('top', '-600px');
                    });
                }
            });
        }
    }
    if (existe('.tv')) {  // pandatv
        $("#tvFilterForm input:checked").attr("checked", "");
        $($("#tvFilterForm input:radio")[1]).attr("checked", "checked");
        $('.wrapper').css({ 'backgroundImage': 'url(/Images/fundoPandaTV.jpg)', 'backgroundRepeat': 'no-repeat', 'backgroundPosition': 'center 60px' });
        $('.content').prepend('<div class="quad"></div>');
        if (existe('#tvFilterForm')) cInputs('#opcao', 1, 5);
        if (existe('#pandaTV')) tvPlayerF('pandaTV', 'pandaTVswf');
    }
    if (existe('.fun')) {  // fun
        $('.wrapper').css({ 'backgroundImage': 'url(/Images/fundoPandaFun.jpg)', 'backgroundRepeat': 'no-repeat', 'backgroundPosition': 'center 60px' });
        $('.content').prepend('<div class="quad"></div>');
        if (existe('.contDetalhe')) $('.col12 .clearfix').css('margin-bottom', '60px');
        if (existe('.contFunSlider')) $('.contFunFilter').css('height', '600px');
        if (existe('.contDetalhe')) setTimeout(alinhaFun, 50);
        if (existe('#pandaTV')) tvPlayerF('pandaTV', 'pandaTVswf');
        if (existe('.contWpSs')) setTimeout(alinhaWpSs, 50);
        if (existe('#funFilterForm')) cInputs('#opcao', 1, 5);
    }
    if (existe('.espaco')) {  // oteuespaco
        $('.wrapper').css({ 'backgroundImage': 'url(/Images/fundoTeuEspaco.jpg)', 'backgroundRepeat': 'no-repeat', 'backgroundPosition': 'center 60px' });
        $('.content').prepend('<div class="quad"></div>');
        if (existe('.contSala')) salaDePintura();
        if (existe('#pandaTV')) tvPlayerF('pandaTV', 'pandaTVswf');
        if (existe('#tvFilterForm')) cInputs('#opcao', 1, 5);
        if (existe('#espacoDrawsFiltersWrap')) $('.espacoNav').css('height', '76px');
        $('.espacoNav .btn3:last').show();
        if (!isiPadIphone())  $('.espacoNav .btn3:first, .espacoNav span').show();
        if (existe('#desFaz1')) {
            $('#idadeDesFazInput').keypress(function (event) {
              return permite(event,numbers);
            });
            $('.espacoNav .btn3:last').show();   
            $('.espacoNav .btn3:first, .espacoNav span').hide();
            $('#desFazForm fieldset:last').css('width', '80px');
            $('#part2Form fieldset:first').css('width', '278px');
            $('.contPartilha2').prepend('<div class="seta"></div>');
      initDesFazForm();
            $('#desFaz1').show();
//            $('.desFazFlash > img').click(function () {
//                $('#desFaz1').hide();
//                $('#desFaz2, #desFaz3').show();
//                reinitShadowIE();
//            });
            $('.desFaz2in .voltar2').click(function () {
                $('#desFazForm .errorMsg, #desFaz2, #desFaz3').hide();
                $('#desFaz1').show();
                reinitShadowIE();
            });
            $('#desFazForm .btn3').click(function () {
        if ($("#desFazForm").valid()){
            SubmitCreatedDraw(function () {
            $('#desFazForm .errorMsg, #desFazForm, .desFaz2in .voltar2').hide();
            $('#desFazOk').show();
            $('.espacoNav .btn3:last').show();
            if (!isiPadIphone())  $('.espacoNav .btn3:first, .espacoNav span').show();              
          });
        }
            });
        }
        if (existe('#desEnvia1')) {
      $('#idadeDesEnviaInput').keypress(function (event) {
        return permite(event,numbers);
      });
      $('#desEnviaForm fieldset:last').css('width','80px');
            $('.espacoNav .btn3:last, .espacoNav span').hide();
            if (isiPadIphone())  $('.espacoNav .btn3:first').hide();
      initDesEnviaForm();
            $('#desEnviaForm .btn3').click(function () {
        if ($("#desEnviaForm").valid()){
          UploadDraw(function(){
            $('#desEnviaForm .errorMsg, #desEnviaForm').hide();
            $('#desEnviaOk, .espacoNav .btn3:last').show();
            if (!isiPadIphone())  $('.espacoNav .btn3:first, .espacoNav span').show();
          });
        }
            });

        }
    }
    if (existe('.postalNatal')) {  // postalNatal
/*      $('.wrapper').css({ 'backgroundImage': 'url(/Images/fundoPostalNatal.jpg)', 'backgroundRepeat': 'no-repeat', 'backgroundPosition': 'center 60px' });  */
    $('.wrapper').css({ 'backgroundImage': 'url(/Images/fundoPostalNatal.jpg)', 'backgroundRepeat': 'no-repeat', 'backgroundPosition': 'center 60px' });
    $('.content').prepend('<div class="quad"></div>');
    }  
    if (existe('.txt')) $('.wrapper').css('backgroundImage', 'url(Images/bg5.gif)');
    if (existe('.pais')) {  // pais e educadores
        $('.wrapper').css('backgroundImage', 'url(/Images/bg5.gif)');
        $('.content').prepend('<div class="fundoPais"></div>');
        $('.content h2').css('right', '20px');
        $('.col7:last').css('margin-left', '10px');
        setTimeout(smallMenu, 600);
        if (existe('.contArtigo')) alinhaArtigos();
        if (existe('.pagCom')) $('.pagCom:last').css('margin', '28px 0 16px 0');
        if (existe('#comentarForm')) $('#comentarForm .btn2:first').css('right', '150px');

        if (existe('#artigosInput')) dropDown('#dd1', 'dD1Wrapper', '#artigosInput', 24, 173);
        if (existe('#registoForm') || existe('#registo2Form')) {
            cInputs('#opcao', 1, 2);
            cInputs('#check', 1, 3);
            dropDown('#dd2', 'dD2Wrapper', '#regConheceuInput', 24, 173);
        }
        if (existe('#registoForm')) {  // registo pais
            $('#step2 .btn2:eq(0), #step3 .btn2:eq(0)').css('left', '90px');
            $('#step2 .btn2:eq(1), #step3 .btn2:eq(1)').css('right', '90px');
            // educandos
            $('#regAnoNascEd1').css('margin-right', '0');
            cInputsEd('#opcao', 1, 2, 1);
            dropDown('#dd3Ed1', 'dD3Wrapper', '#regParentInputEd1', 24, 173);
            dropDown('#dd4Ed1', 'dD2Wrapper', '#regPrefInputEd1', 24, 173);
            if (!$.browser.msie) cInputsEd('#check', 1, Number($('#dd4Ed1 li').length), 1);
          $("#dd2 *, .dDown3 *, .dDown4 *").attr("tabindex", "-1");
            educandos(1);
         initRegFormS1();
            $('#step1 .btn2').click(function () {
        if ($("#registoForm").valid()){
          ValidateStep1SS(function (data) {
            if (data.Status) {
              $('#errorMsg').hide();
              $('#step1').hide();
              $('#step2').show();
              initRegFormS2();
              reinitShadowIE();
              $('#formSteps li').removeClass();
              $('#formSteps li:eq(1)').addClass('on');
            }
          });  
          return false;
        }      
            });
            $('#step2 .btn2:eq(0)').click(function () {
                $('#step1').show();
             initRegFormS1();
                $('#step2').hide();
             $('#errorMsg').hide();
                reinitShadowIE();
                $('#formSteps li').removeClass();
                $('#formSteps li:eq(0)').addClass('on');
            });
            $('#step2 .btn2:eq(1)').click(function () {
        if ($("#registoForm").valid()){
          ValidateStep2SS(function (data) {
            if (data.Status) {
              $('#errorMsg').hide();
              $('#step2').hide();
              $('#step3').show();
              initRegFormS3();
              reinitShadowIE();
              $('#formSteps li').removeClass();
              $('#formSteps li:eq(2)').addClass('on');
            }
          });
        return false;
        }            
            });
            $('#step3 .btn2:eq(0)').click(function () {
                $('#step2').show();
        initRegFormS2();
                $('#step3').hide();
        $('#errorMsg').hide();
                reinitShadowIE();
                $('#formSteps li').removeClass();
                $('#formSteps li:eq(1)').addClass('on');
            });
            $('#step3 .btn2:eq(1)').click(function () {
        if ($("#registoForm").valid()){
          ValidateStep3SS(function (data) {
            if (data.Status) {
              $('#errorMsg').hide();
              $('#step3, .contFormulario h3').hide();
              $('#step4').show();
              reinitShadowIE();
              $('#formSteps li').removeClass();
              // registo - envia form
            }
          });
        return false;
        }          
            });
        }
    bindConcluirForm();
  if (existe('#registo2Form')) {  // registo pais - alterar dados
    $('.loggedPais').show();
    $('#btnLoggedPais').css('float', 'left');  
      $('#regTelInput').keypress(function (event) {
      return permite(event,numbersTel);
      });
      $('#regCPostalInput').keypress(function (event) {
      return permite(event,numbersCP);
      });
      $('#regdateEd1').keypress(function (event) {
      return permite(event,numbersCP);
      });
    // educandos  
    var qtsEducandos = $('.educando').length;
    $('#nEducandos').text(qtsEducandos);
      for (j = 1; j < qtsEducandos + 1; j++) {
        cInputsEd('#opcao', 1, 2, j);
        $('#regAnoNascEd' + j + '').css('margin-right', '0');
        if (!$.browser.msie) cInputsEd('#check', 1, Number($('#dd4Ed1 li').length), j);
        dropDown('#dd3Ed' + j, 'dD3Wrapper', '#regParentInputEd' + j, 24, 173);
        dropDown('#dd4Ed' + j, 'dD2Wrapper', '#regPrefInputEd' + j, 24, 173);
      }
      $('.step2b .certeza').each(function (intIndex) {
  
        $('#remove' + Number(intIndex + 1)).click(function () {
          $('#removeNo' + Number(intIndex + 1)).parent().parent().show();
          $(this).parent().hide();
          return false;
        });
  
        $('#removeNo' + Number(intIndex + 1)).click(function () {
          $('#remove' + Number(intIndex + 1)).parent().show();
          $(this).parent().parent().hide();
          return false;
        });
  
        $('#removeYes' + Number(intIndex + 1)).click(function () {
  
          if ($("#alterRegisto").size() > 0) {
            var username = $($(this).parent().parent().parent().find(".form1")[0]).find("input").val();
            DeleteChild(username, function (data) {
              $('#educando' + Number(intIndex + 1)).remove();
              renomeia();
            });
            return false;
          }
          else {
            $('#educando' + Number(intIndex + 1)).remove();
            renomeia();
            return false;
          }
        });
      });
      educandos(qtsEducandos);
      $('#formSteps li a:eq(0)').click(function () {
        $('#step2, #step3').hide();
        $('#step1').show();
        reinitShadowIE();
        $('#formSteps li').removeClass().addClass('alterar');
        $('#formSteps li:eq(0)').removeClass().addClass('alterarOn');
        return false;
      });
      $('#formSteps li a:eq(1)').click(function () {
        $('#step1, #step3').hide();
        $('#step2').show();
        reinitShadowIE();
        $('#formSteps li').removeClass().addClass('alterar');
        $('#formSteps li:eq(1)').removeClass().addClass('alterarOn');
        return false;
      });
      $('#formSteps li a:eq(2)').click(function () {
        $('#step1, #step2').hide();
        $('#step3').show();
        reinitShadowIE();
        $('#formSteps li').removeClass().addClass('alterar');
        $('#formSteps li:eq(2)').removeClass().addClass('alterarOn');
        return false;
      });
      $('#step1 .btn2').click(function () {
        UpdateStep1SS(function (data) {
          $('#step1 .confirmMsg').show();
          $('#step1 .errorMsg').hide();
          $('#step1 .confirmMsg').delay(2500).fadeOut();
          return false;
        });        
      });
      $('#step2 .btn2').click(function () {
        UpdateStep2SS(function () {
          $('#step2 .confirmMsg').show();
      $('#step2 .errorMsg').hide();
          $('#step2 .confirmMsg').delay(2500).fadeOut();
        });
        return false;
      });
      $('#step3 .btn2').click(function () {
        UpdateStep3Registo(function () {
          $('#step3 .confirmMsg').show();
           $('#step3 .errorMsg').hide();
          $('#step3 .confirmMsg').delay(2500).fadeOut();
        });
        return false;
      });
      // if step=2
      if(getParameterByName('step')==2) $('#formSteps li a:eq(1)').click();
        }
    }
    if (existe('.pbns')) {  // parabens
        $('.wrapper').css('backgroundImage', 'url(/Images/bg6.gif)');
        $('.col7:last').css('margin-left', '10px');
    initPbnsForm();
        if (existe('#parabensForm')) { // formulario
            $('#pbnsAnoNasc').css('margin-right', '0');
            $('.contFormulario').css({ 'backgroundImage': 'url(/Images/bg7.gif)', 'backgroundPosition': 'left bottom', 'backgroundRepeat': 'no-repeat' });
            $('.contFormulario h3').hide();
            $('#step2 .btn2:eq(0)').css('left', '90px');
            $('#step1 .btn2, #step2 .btn2:eq(1)').css('right', '90px');
            dropDown('#dd5', 'dD5Wrapper', '#pbnsAnivInput', 30, 173);
            cInputs('#check', 1, 1);
            $('#step0c .btn3, #step1 .btn5').click(function () {
                window.location = '/alterar-registo?step=2';
            });
            $('#step0a .btn3').click(function () {
                $('#step0, .voltar').hide();
                $('#step1, #parabensLogged, .contFormulario h3').show();
                reinitShadowIE();
                $('#formSteps li').removeClass();
                $('#formSteps li:eq(0)').addClass('on');
            });
            $('#step1 > .btn2').click(function () {
                /*if (checkParabens()) {
                    $('#step1').hide();
                    $('#step2').show();
                    reinitShadowIE();
                    $('#formSteps li').removeClass();
                    $('#formSteps li:eq(1)').addClass('on');
                }*/
              checkParabens(stepFwd);
            });
          
            $('#step2 .btn2:eq(0)').click(function () {
                $('#step1').show();
                $('#step2').hide();
                reinitShadowIE();
                $('#formSteps li').removeClass();
                $('#formSteps li:eq(0)').addClass('on');
            });
      bindPBensSubmit();
      $('#check1').click(function () {
        $('.termos > div').removeClass('errorCheckBtn');
      });
        }
    }
}
function stepFwd(){
            $('#step1').hide();
            $('#step2').show();
            reinitShadowIE();
            $('#formSteps li').removeClass();
            $('#formSteps li:eq(1)').addClass('on');
          }
function search() {
    if ($('#searchInput').val() != '') {
            window.location = '/pesquisa?query=' + $('#searchInput').val();
    }
}



/************* onload ****************/
$(document).ready(function () {
  
    $.fn.removeBoxShadow = function () {
        if (!$.browser.msie) return;
        return this.each(function () {
            $(this).next().remove();
            $(this).boxShadow(2, 2, 3, "#969696");
        });
    };
    /* Created by Martin Hintzmann 2008 martin [a] hintzmann.dk
    * MIT (http://www.opensource.org/licenses/mit-license.php) licensed.
    * Version: 0.1
    */
    $.fn.boxShadow = function (xOffset, yOffset, blurRadius, shadowColor) {
        if (!$.browser.msie) return;
        return this.each(function () {
            $(this).css({
                position: "relative",
                zoom: 1,
                zIndex: "2"
            });
            $(this).parent().css({
                position: "relative"
            });

            var div = document.createElement("div");
            $(this).parent().append(div);

            var _top, _left, _width, _height;
            if (blurRadius != 0) {
                $(div).css("filter", "progid:DXImageTransform.Microsoft.Blur(pixelRadius=" + (blurRadius) + ", enabled='true')");
                _top = yOffset - blurRadius - 1;
                _left = xOffset - blurRadius - 1;
                _width = $(this).outerWidth() + 1;
                _height = $(this).outerHeight() + 1;
            } else {
                _top = yOffset;
                _left = xOffset;
                _width = $(this).outerWidth();
                _height = $(this).outerHeight();
            }
            $(div).css({
                top: _top,
                left: _left,
                width: _width,
                height: _height,
                background: shadowColor,
                position: "absolute",
                zIndex: 1
            });

        });
    };
    try {
        Typekit.load({
            active: function () {
                init(1);
            },
            inactive: function () {
                init(0);
            }
        })
    } catch (e) { init(0); }  
});
