
var forms = ['connection_form', 'forminsc1', 'forminsc2', 'lost_password', 'form1'];
    	
function getHash() {
  var hash = window.location.hash;
  return hash.substring(1); // remove #
}

function popup(elt,url,name,width,height) {
 url = elt.getParent('li').getElement('a.blog_url').href + url;
 url = url.replace(/\/\/i/g,'/i');
 window.open(url,name,'scrollbars=yes,width='+width+',height='+height+'');
 return true;
} 

window.addEvent('domready', function() {
  
  // homepage :articles
  if($$('.article_content').length > 0) {
    disp_w = $$('.column_left')[0].getWidth() - $$('.column_left')[0].getStyle('padding-right').toInt();
  }
  
  // block : choose your country
  if($('country_form') != null) {
    $('country_form').addEvent('change', function() {
      window.location.href = $('country_form').value;
    });
  }

  // formulaire d'inscription
  forms.each(function(form) {  
    if($(form) != null && (!Browser.Engine.trident && Browser.Engine.version != '4')) {
      if(form == 'forminsc2') {
        $(form).getElements('select').each(function(elt) {
          elt.addClass('validate[\'required\'] cf_correct');
        });
        if($(form).getElement('input[name=partenaires]') != null) {
          $(form).getElement('input[name=partenaires]').addClass('cf_correct');
        }
      }
      new FormCheck(form);
    }  
  });
  
  
  // faq
  if($$('.highlight_faq').length > 0) {
  
      var params = {'display':-1};
      
      $$('.highlight_faq').each(function(elt,i) {
          elt.addEvent('click', function() {                    
            $$('.highlight_faq').each(function(el) {
              if(el.hasClass('highlight_faq_clicked')) {
                el.removeClass('highlight_faq_clicked');
              }
            });
            elt.addClass('highlight_faq_clicked');
          });
        
          var href = elt.href.split('#')[1];
          
          if(getHash()!='' && href == getHash()) {
            params.show = i;
            elt.addClass('highlight_faq_clicked');
          }
      });
      
      var myAccordion = new Fx.Accordion($$('.highlight_faq'), $$('.faq-answer'), params);
      
  }

  // pagination
  if($$('.pagination-block').length > 0) {
    var pagpos = Math.round(($$('.pagination-block')[0].getWidth() - $$('.pagination')[0].getWidth()) / 2);
    $$('.pagination')[0].setStyles({'padding-left':pagpos + 'px','width':$$('.pagination')[0].getWidth()+'px','position':'relative'});
  }
  

});
