Event.observe(window, 'load', function() {
    $$('.products-grid .item').each(function(el) {
        var $el = jQuery(el);
        if($el.find('img.secondImg').length) {
            el.observe('mouseover', function() {
                $el.find('img.firstImg').addClass('imgProductBack');
                $el.find('img.secondImg').removeClass('imgProductBack');
            });
            el.observe('mouseout', function() {
                $el.find('img.firstImg').removeClass('imgProductBack');
                $el.find('.secondImg').addClass('imgProductBack');
            });
        }
    });

   if($('divBreadcrumbs') && $('ulBreadcrumbs'))
   {
       var liTab = $('ulBreadcrumbs').childElements();
       var lastLi = liTab[liTab.length-1];
       var search = lastLi.readAttribute('class').indexOf('category',0);
       var params = getUrlVars();

       if( (search != -1) && (params.p > 1))
       {
          var urlWithoutParam = window.location.href.split('?');
          var a = document.createElement('a');
          a.setAttribute('href',urlWithoutParam[0]);
          a.update(lastLi.innerHTML);
          a.setStyle({color:'#FB5F62'});
          lastLi.update(a);

       }
   }

   // Masque la valeur du champ pour écrire
   var champsmagicclic = new Array();
   $$('.input-text').each(function(el){
       champsmagicclic[el.id] = el.value;
   });
    for(idch in champsmagicclic) {
        if($(idch) && $(idch).className != 'bypass'){
            $(idch).value = champsmagicclic[idch];
            $(idch).onfocus = function(){
                if(this.value == champsmagicclic[this.id])
                this.value = '';
            };
            $(idch).onblur = function(){
                if(this.value == '')
                this.value = champsmagicclic[this.id];
            };
        }
    }

    onHover('emoi_soucat');
    onHover('list-item');
});

function onHover(classname) {
    $$('li.'+classname).each(function(el,i){
        el.observe('mouseover',function(){
            el.addClassName('hover');
            Cufon.refresh();
        });

        el.observe('mouseout',function(){
            el.removeClassName('hover');
            Cufon.refresh();
        });
    });
}

function getUrlVars()
{
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    return vars;
}

jQuery().ready(function () {
    jQuery(".langandcontact .contact").hover(function () {
        jQuery(this).find('.contact-infos').addClass('contact-infos-hover').show();
    }, function () {
        jQuery(this).find('.contact-infos').removeClass('contact-infos-hover').hide();
    });
});
