  jQuery(document).ready(function($) {
            
            $('.confirmDeletion').click(function(e) {
					
					e.preventDefault();
					thisHref	= $(this).attr('href');
					
					if(confirm('Etes-vous certain? Cette action est irréversible')) {
						window.location = thisHref;
					}
					
				});
	$('#dialog >  #loginBox #submit').live('click',function(e) {
		e.preventDefault();
		$.ajax({
			url: $('#loginBox > form').attr('action')  + '?format=json',
			type: 'POST',
			data: $('#loginBox > form').serialize(),
			dataType: 'json',
			success: function(json) {
				if(json.login == false) {
					display_captcha();
					$('#token').val(json.token);

					// @todo : Afficher les erreurs
					jQuery.each(json.messages, function(key, value) {
						alert(key);
						jQuery.each(value, function(k, msg) {
							alert(msg);
						});
					});
				}  else { window.location.reload();}
                                                    
			}
		});
	});
        $('.ajaxloader').click(function (e){
                      //   replace =  $(this).parent().parent().find('.respond');
                            e.preventDefault();
                            iscaptcha = $(this).hasClass('docaptcha'); //true/false
                                                        $.ajax({
                                                                url: $(this).attr('href') + '?format=html',
                                                                type: 'GET',
                                                                dataType: 'html',
                                                                success: function(html) {
                                                                    $('body').append('<div id="dialog"></div>');
				$('#dialog').html(html);
                                
                                                                        if(iscaptcha) {display_captcha();}
                                                                        
				jQuery('#dialog').dialog({
					modal: true
				});
                                                                }
                                                        });
                    });
        $('.ajaxloadMP').click(function (e){
           input_subject        = $(this).attr('data-subject');
           input_nameuser   = $(this).attr('data-to');
           input_content        = $(this).attr('data-content');
           
           rep  = $(this).hasClass('rep');
           fwd  = $(this).hasClass('fwd');
           simpleMp  = $(this).hasClass('smp');
           
                            e.preventDefault();
                                                        $.ajax({
                                                                url: $(this).attr('href') + '?format=html',
                                                                type: 'GET',
                                                                dataType: 'html',
                                                                success: function(html) {
                                                                    $('body').append('<div id="dialog"></div>');
				$('#dialog').html(html);                                                                                                        
				jQuery('#dialog').dialog({
					modal: true
				});
                                                                       if(simpleMp) populateZend(false,input_nameuser,false);
                                                                       if(rep) populateZend(input_subject,input_nameuser,false);
                                                                       if(fwd) populateZend(input_subject,false,input_content);
                                                                }
                                                        });
                    });
        $(".new_acv").click(function() {
                      $(this).fadeOut('slow');
                    });  
                    
          $('#scrolling').topLink({
            min: 400,
            fadeSpeed: 500
          });
          //smoothscroll
          $('#scrolling').click(function(e) {
            e.preventDefault();
            $.scrollTo(0,300);
          });      
          
    $("ul.subnav").parent().append("<span></span>"); //Only shows drop down trigger when js is enabled (Adds empty span tag after ul.subnav*)  
  
    $("ul.onlineuserlist li span").click(function() { //When trigger is clicked...  
  
        //Following events are applied to the subnav itself (moving subnav up and down)  
        $(this).parent().find("ul.subnav").slideDown('fast').show(); //Drop down the subnav on click  
  
        $(this).parent().hover(function() {  
        }, function(){  
            $(this).parent().find("ul.subnav").slideUp('slow'); //When the mouse hovers out of the subnav, move it back up  
        });  
  
        //Following events are applied to the trigger (Hover events for the trigger)  
        }).hover(function() {  
            $(this).addClass("subhover"); //On hover over, add class "subhover"  
        }, function(){  //On Hover Out  
            $(this).removeClass("subhover"); //On hover out, remove class "subhover"  
    }); 
    
            //blink TEXT
            makeMeblink();
            
   });
setInterval("makeMeblink();",400);
 function makeMeblink(){ 
     classblink = $('.blink');
     //trigger la classe blink
     $(classblink).animate({ color: "#FF5C00" }, 200);
     $(classblink).animate({ color: "#CCCCCC" }, 200);
 }

    /*
     *  By Xspirist pop BBcode
     */
    
 function WrapCode(balise,smiley){ 
                    var textarea = $('textarea');

                    var len = textarea.val().length; 

                    var start = textarea[0].selectionStart;
                    var end = textarea[0].selectionEnd; 

                    var sel = textarea.val().substring(start, end); 

             if(!smiley){
                    var replace = '['+balise+']' + sel + '[/'+balise+']'  
                   newtext =  textarea.val().substring(0,start) + replace +  textarea.val().substring(end,len); 

             }
             else{                    
                   newtext =  textarea.val().substring(0,start) + balise +  textarea.val().substring(end,len); 
             }
                    $('#Postform textarea').val(newtext);
} 
// Populate Zend Form in order to send a MP's response
function populateZend(input_title,input_nameuser,input_content){
    if(input_nameuser) $('#recipient').val(input_nameuser);
    if(input_title) $('#subject').val(input_title);
    if(input_content) $('#message').val(input_content);
    
   if(input_nameuser) $('#message').focus();
   if(input_content) $('#recipient').focus();
}

jQuery.fn.showCaseSlide = function(pos) {
    $('.showCase ul').animate({
        right: (pos) * $('.showCase .wrapper').width()+'px'
        }, 200, function() {
        $('.showCase li').removeClass('active');
        $('.showCase li').eq(pos).addClass('active');
    });
}
function display_captcha() {
    Recaptcha.create('6LcXuQoAAAAAABPnIctU_lL3IB3-hDQ7kpim9g2c', 'captcha', {
        theme: 'custom',
        tabindex: 0,
        custom_theme_widget: 'captcha'
    });
}

function slideSwitch(vitesse) {
   var $active = $('.fadein IMG.active');

    if ( $active.length == 0 ) $active = $('.fadein IMG:last');

    var $next =  $active.next().length ? $active.next()
        : $('.fadein IMG:first');

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, vitesse, function() {
            $active.removeClass('active last-active');
        });
}
      
    
// plugins
jQuery.fn.topLink = function(settings) {
  settings = jQuery.extend({
    min: 1,
    fadeSpeed: 200
  }, settings);
  return this.each(function() {
    //listen for scroll
    var el = $(this);
    el.hide(); //in case the user forgot
    $(window).scroll(function() {
      if($(window).scrollTop() >= settings.min)
      {
        el.fadeIn(settings.fadeSpeed);
      }
      else
      {
        el.fadeOut(settings.fadeSpeed);
      }
    });
  });
};
jQuery.fn.center = function () {
  this.css("position","absolute");
  this.css("top", ( $(window).height() - this.height() ) / 2+$(window).scrollTop() + "px");
  this.css("left", ( $(window).width() - this.width() ) / 2+$(window).scrollLeft() + "px");
  return this;
}

/**
 * jQuery.ScrollTo - Easy element scrolling using jQuery.
 * Copyright (c) 2007-2009 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com
 * Dual licensed under MIT and GPL.
 * @author Ariel Flesler
 * @version 1.4.2
 *
 */
;(function(d){var k=d.scrollTo=function(a,i,e){d(window).scrollTo(a,i,e)};k.defaults={axis:'xy',duration:parseFloat(d.fn.jquery)>=1.3?0:1};k.window=function(a){return d(window)._scrollable()};d.fn._scrollable=function(){return this.map(function(){var a=this,i=!a.nodeName||d.inArray(a.nodeName.toLowerCase(),['iframe','#document','html','body'])!=-1;if(!i)return a;var e=(a.contentWindow||a).document||a.ownerDocument||a;return d.browser.safari||e.compatMode=='BackCompat'?e.body:e.documentElement})};d.fn.scrollTo=function(n,j,b){if(typeof j=='object'){b=j;j=0}if(typeof b=='function')b={onAfter:b};if(n=='max')n=9e9;b=d.extend({},k.defaults,b);j=j||b.speed||b.duration;b.queue=b.queue&&b.axis.length>1;if(b.queue)j/=2;b.offset=p(b.offset);b.over=p(b.over);return this._scrollable().each(function(){var q=this,r=d(q),f=n,s,g={},u=r.is('html,body');switch(typeof f){case'number':case'string':if(/^([+-]=)?\d+(\.\d+)?(px|%)?$/.test(f)){f=p(f);break}f=d(f,this);case'object':if(f.is||f.style)s=(f=d(f)).offset()}d.each(b.axis.split(''),function(a,i){var e=i=='x'?'Left':'Top',h=e.toLowerCase(),c='scroll'+e,l=q[c],m=k.max(q,i);if(s){g[c]=s[h]+(u?0:l-r.offset()[h]);if(b.margin){g[c]-=parseInt(f.css('margin'+e))||0;g[c]-=parseInt(f.css('border'+e+'Width'))||0}g[c]+=b.offset[h]||0;if(b.over[h])g[c]+=f[i=='x'?'width':'height']()*b.over[h]}else{var o=f[h];g[c]=o.slice&&o.slice(-1)=='%'?parseFloat(o)/100*m:o}if(/^\d+$/.test(g[c]))g[c]=g[c]<=0?0:Math.min(g[c],m);if(!a&&b.queue){if(l!=g[c])t(b.onAfterFirst);delete g[c]}});t(b.onAfter);function t(a){r.animate(g,j,b.easing,a&&function(){a.call(this,n,b)})}}).end()};k.max=function(a,i){var e=i=='x'?'Width':'Height',h='scroll'+e;if(!d(a).is('html,body'))return a[h]-d(a)[e.toLowerCase()]();var c='client'+e,l=a.ownerDocument.documentElement,m=a.ownerDocument.body;return Math.max(l[h],m[h])-Math.min(l[c],m[c])};function p(a){return typeof a=='object'?a:{top:a,left:a}}})(jQuery);
