var jq = jQuery.noConflict();


/* 
 * email mangling : com example name2 name1 wil be converted to:
 * name1.name2@example.com
 * sarch all a tags where the href contains ' ' (single blanks)
 */

function eMailMangling()
{
    jq("a[href*=' '], a[href*='%20']").click(function() {
        var realemail = '';
        var email = jq(this).attr("href");

        if ( ! email || ! email.length ) return

        if ((email.indexOf("mailto:") == -1) && (email.indexOf("http:") == -1))
        {
            if (email.indexOf(" ") != -1)
            {
                var emailArray = email.split(" ");
            }
            else
            {
                var emailArray = email.split("%20");
            }
            for (var i=emailArray.length; i>=0; i=i-1)
            {
                if (typeof emailArray[i] != 'undefined')
                {
                    if (i==2)
                    {
                    realemail = realemail + emailArray[i] + '@';
                    }
                    else
                    {
                    realemail = realemail + emailArray[i] + '.';
                    }
                }
            }
            realemail = realemail.substring(0, realemail.length -1);
            realemail = 'mailto:' + realemail;
            jq(this).attr("href", realemail);
        //alert (realemail);
        }
    });
}

jq(document).ready(function(){
    eMailMangling();
    Cufon.set('fontFamily', 'Taz');
    Cufon.replace('ul#nav a', { hover: true });
    Cufon.replace('ul#portal-siteactions a', { hover: true });
    Cufon.replace('.location');
    Cufon.replace('h3');
    Cufon.replace('.portletHeader');

    // startpage, ver_overview
    var jqbody = jq('body');
    if (jqbody.hasClass('template-atct_startpage_view') || jqbody.hasClass('template-atct_events_view')){
      Cufon.replace('h4', { hover:true });
      Cufon.set('fontFamily', 'Esta');
      Cufon.replace('h2');
    }
    else {
      Cufon.set('fontFamily', 'Esta');
      Cufon.replace('h1');
    }

    // fixing section tabs first line bold
    jq(function(){
      jq('#nav li').each(function(i) {
        if(i<4)
          jq(this).css('font-weight', 'bold');
      });
    });

   jq('#sujet_width ul').imagefit( { fillMethode : 'fitOuter' },
                                   function(){
                                       jq('#sujet_width ul').innerfade( {speed: 2000, timeout:8000} );
                                   }
                               );

});

