$.fn.extend({
    image : function(src, f){
        return this.each(function(){
            var i = new Image();
            i.src = src;
            i.onload = f;
            this.appendChild(i);
        });
    },

    imageFadein: function(image, f){
        return this.each(function(){
            this.appendChild(image);
    })
    },

      openImageDetail : function() {
      
        return this.each(function() {

            $(this).click(function(e) {

                $('#detail').css('background-image','none');      
                var src=$(this).attr('href');
                var title=$(this).attr('title');
                var content=$(this).html();

                if(content.length>0 && title.length>0)
                {
                    $('#detail').html('<h2 style="position:absolute;width:328px;">' + content + '</h2>');
                }
                else
                {
                $('#detail').html('');
                }
                
                
                var img = new Image();
                
                // wrap our new image in jQuery, then:
                $(img)
                // once the image has loaded, execute this code
                .load(function () {
                    // set the image hidden by default    
                    $(this).hide();
            
                    // fade our image in to create a nice effect
                    $(this).fadeIn("normal",function() { 
                        $('#detail h2').show();
                    });

                })
            
                // if there was an error loading the image, react accordingly
                .error(function () {
                    // notify the user that the image could not be loaded
                })
            
                // *finally*, set the src attribute of the new image to our image
                .attr('src', src);
                
        
                $('#detail').imageFadein(img);
                $('#detail').css('background-color','white');

                e.preventDefault();
            });
        
        });
    },

    slideMenu: function() {
        return this.each(function() {

          $(this).click(function(e) {
        
            link = $(this);
            menus = link.parent().find('>ul');

            if(menus.length > 0)
            {
            e.preventDefault();
            menus.each(function(){
              $(this).slideToggleWidth();
              });
            }

            });

          });

    },
    slideRight: function() {
        return this.each(function() {
            jQuery(this).animate({
                width: 'show'
            });
        });
    },
    slideLeft: function() {
        return this.each(function() {
            jQuery(this).animate({
                width: 'hide'
            });
        });
    },
    slideToggleWidth: function() {
        return this.each(function() {
            var el = jQuery(this);
            if (el.css('display') == 'none') {
                el.slideRight();
            } else {
                el.slideLeft();
            }
        });
    }
});

$(document).ready(function(){
    $('#detail .slide').cycle({
      fx: 'fade',
      timeout: 6000,
      speed: 2000,
      cleartype:  true,
      cleartypeNoBg:  true
    });

    $('#text-content .cadre').jScrollPane({});

    var $scrollmap = $('#scroll-annuaire').jScrollPane({
        animateScroll: false
    });
    //$('#text-content .jspDrag').addClass('back-color');

    $('.open-image-detail').openImageDetail();

    $('.nyro').nyroModal({
        zIndexStart: '9000',
        closeButton: '<a href="#" class="nyroModalClose" id="closeBut" title="close">Close</a>'
    });

    $('#ok-entreprises').click(function() {
       $('#link-annu').trigger('click'); 
    });
});


  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-26321416-1']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();
