(function($) {

	/*  ------------------------------------------------------------------
    	Load Function ---------------------------------------------------- */ 
		
    	$.fn.loadFct = function() {
			
			// Lazyload			
			//$('#slider a > img').lazyload({
			//	effect: "fadeIn"
			//});
						
			// Roll-over bloc réalisation
			$('#lst_realisations li div div div, #featured_img').hover(
				function(){
					var $this = $(this);
					if($.browser.msie) {
						$this.find('.over').show();
						$this.children('.details').show();
					}
					else {
						$this.find('.over').stop(false, true).fadeIn(400);
						$this.children('.details').stop(false, true).fadeIn(100);
					}
					return false;
				},
				function(){
					var $this = $(this);
					if($.browser.msie) {
						$this.find('.over').hide();
						$this.children('.details').hide();
					}
					else {
						$this.find('.over').stop(false, true).fadeOut(300);
						$this.children('.details').stop(false, true).fadeOut(300)
					}
					return false;
				}
			);
			
			// Roll-over quick links
			$('#quick_links li').hover(
				function() {
					var $this = $(this);
					if($.browser.msie) {
						$this.find('span').show();
					}
					else {
						$this.find('span').stop(false, true).animate({
							opacity: 'toggle',
							top: '-24px'
						}, 300);
					}
					return false;
				},
				function() {
					var $this = $(this);
					if($.browser.msie) {
						$this.find('span').hide();
					}
					else {
						$this.find('span').stop(false, true).animate({
							opacity: 'toggle',
							top: '-21px'
						}, 200);
					}
					return false;
				}
			);
			
			// Clic quick links
			$('#ico_email_light, #ico_cv_light').click(function() {
				window.location.href = $(this).find('a').attr('href');
				return false;
			});
			
			// Colorbox
			$('#lst_realisations .bloc').colorbox({
				href: function(){ var href = $(this).attr('href') + ' #wrapper_popin'; return href; },
				initialWidth: '16px',
				initialHeight: '16px',
				innerWidth: '852px',
				opacity: 0.95,
				rel: 'realisations',
				transition: function(){if($.browser.msie) { return 'none'; } else { return 'fade'; } }				
			});
			
			$('#lst_realisations .details').colorbox({
				href: function(){ var href = $(this).attr('href') + ' #wrapper_popin'; return href; },
				initialWidth: '16px',
				initialHeight: '16px',
				innerWidth: '852px',
				opacity: 0.95,
				rel: 'realisations2',
				transition: function(){if($.browser.msie) { return 'none'; } else { return 'fade'; } }
			});
			$('#featured a').colorbox({
				href: function(){ var href = $(this).attr('href') + ' #wrapper_popin'; return href; },
				initialWidth: '16px',
				initialHeight: '16px',
				innerWidth: '852px',
				opacity: 0.95,
				transition: function(){if($.browser.msie) { return 'none'; } else { return 'fade'; } },
				onComplete: function(){$('#popin_nav_prev, #popin_nav_next, .popin_nav_sep').hide();}
			});
			
			$(document).bind('cbox_complete', function(){
				$('#popin_btn_fermer').click($.fn.colorbox.close);
				$('#popin_nav_prev').click($.fn.colorbox.prev);
				$('#popin_nav_next').click($.fn.colorbox.next);
				
				// Slider réalisations
				$('#popin_inner_slider').nivoSlider({
					directionNav: false,
					effect: 'fade',
					slices: 1
				});
				
				// Calcul Marge gauche bullets
				var nbBullets = $('.nivo-controlNav a').size();
				var marge = Math.round(( 478 - ( nbBullets * 11 + (nbBullets-1) * 4 + 4 ) ) / 2) + 'px';
				$('.nivo-controlNav').css('left', marge);
			});			
		}	
})(jQuery);
