/*
Supersized - Fullscreen Slideshow jQuery Plugin
By Sam Dunn (www.buildinternet.com // www.onemightyroar.com)
Version: supersized.2.0.js // Relase Date: 5/7/09
Website: www.buildinternet.com/project/supersized
Thanks to Aen for preloading, fade effect, & vertical centering
*/

(function($){

	//Resize image on ready or resize
	$.fn.supersized = function() {
		$.inAnimation = false;
		$.paused = false;
		var options = $.extend($.fn.supersized.defaults, $.fn.supersized.options);
		var ncol="#000000";
		$(window).bind("load", function(){
			$('#loading').hide();
			$('#diaporama').fadeIn('fast');
			$('#diaporama img').each(function(){
				$(this).hide()
			});
			$('#diaporama img:first').show();
			$('#content').show();
			
			if ($('#slideshow .activeslide').length == 0) $('#diaporama img:first').addClass('activeslide');
			
			if (options.slide_captions == 1) $('#slidecaption').html($('#diaporama .activeslide').attr('title'));
			if (options.navigation == 0) $('#navigation').hide();
			//Slideshow
			if (options.slideshow == 1){
				if (options.slide_counter == 1){ //Initiate slide counter if active
					$('#slidecounter .slidenumber').html(1);
	    			$('#slidecounter .totalslides').html($("#diaporama > *").size());
	    		}
				slideshow_interval = setInterval("nextslide()", options.slide_interval);
				if (options.navigation == 1){ //Skip if no navigation
					$('#navigation a').click(function(){  
   						$(this).blur();  
   						return false;  
   					}); 	
					//Slide Navigation
				    $('#nextslide').click(function() {
				    	if($.paused) return false; if($.inAnimation) return false;
					    clearInterval(slideshow_interval);
					    nextslide();
					    slideshow_interval = setInterval(nextslide, options.slide_interval);
					    return false;
				    });
				    $('#prevslide').click(function() {
				    	if($.paused) return false; if($.inAnimation) return false;
				        clearInterval(slideshow_interval);
				        prevslide();
				        slideshow_interval = setInterval(nextslide, options.slide_interval);
				        return false;
				    });
					$('#nextslide img').hover(function() {
						if($.paused == true) return false;
					   //	$(this).attr("src", "images/forward-dull.png");
					}, function(){
						if($.paused == true) return false;
					   // $(this).attr("src", "images/forward_dull.png");
					});
					$('#prevslide img').hover(function() {
						if($.paused == true) return false; 
					   // $(this).attr("src", "images/back-dull.png");
					}, function(){
						if($.paused == true) return false;
					   // $(this).attr("src", "images/back_dull.png");
					});
					
				    //Play/Pause Button
				    $('#pauseplay').click(function() {
				    	if($.inAnimation) return false;
				    	var src = ($(this).find('img').attr("src") === "images/play.gif") ? "images/pause.gif" : "images/play.gif";
      					if (src == "images/pause.gif"){
      						$(this).find('img').attr("src", "images/play.gif");
      						$.paused = false;
					        slideshow_interval = setInterval(nextslide, options.slide_interval);  
				        }else{
				        	$(this).find('img').attr("src", "images/pause.gif");
				        	clearInterval(slideshow_interval);
				        	$.paused = true;
				        }
      					$(this).find('img').attr("src", src);
					    return false;
				    });
				    $('#pauseplay').mouseover(function() {
				    	var imagecheck = ($(this).find('img').attr("src") === "images/play_dull.gif");
				    	if (imagecheck){
      						$(this).find('img').attr("src", "images/play.gif"); 
				        }else{
				        	$(this).find('img').attr("src", "images/pause.gif");
				        }
				    });
				    
				    $('#pauseplay').mouseout(function() {
				    	var imagecheck = ($(this).find('img').attr("src") === "images/play.gif");
				    	if (imagecheck){
      						$(this).find('img').attr("src", "images/play_dull.gif"); 
				        }else{
				        	$(this).find('img').attr("src", "images/pause_dull.gif");
				        }
				        return false;
				    });
				}
			}
		});
				
		$(document).ready(function() {
			$('#diaporama').resizenow(); 
		});
		
		//Pause when hover on image
		$('#diaporama > *').hover(function() {
	   		if (options.slideshow == 1 && options.pause_hover == 1){
	   			if(!($.paused) && options.navigation == 1){
	   				$('#pauseplay > img').attr("src", "images/pause.gif"); 
	   				clearInterval(slideshow_interval);
	   			}
	   		}
	   		original_title = $(this).find('img').attr("title");
	   		if($.inAnimation) return false; else $(this).find('img').attr("title","");
	   	}, function() {
			if (options.slideshow == 1 && options.pause_hover == 1){
				if(!($.paused) && options.navigation == 1){
					$('#pauseplay > img').attr("src", "images/pause_dull.gif");
					slideshow_interval = setInterval(nextslide, options.slide_interval);
				} 
			}
			$(this).find('img').attr("title", original_title);	
	   	});
		
		$(window).bind("resize", function(){
    		$('#diaporama').resizenow(); 
		});
		
		$('#diaporama').hide();
		$('#content').hide();
	};
	
	//Adjust image size
	$.fn.resizenow = function() {
		
	};
	
	$.fn.supersized.defaults = { 
			startwidth: 4,  
			startheight: 3,
			vertical_center: 1,
			slideshow: 1,
			navigation:1,
			transition: 1, //0-None, 1-Fade, 2-slide top, 3-slide right, 4-slide bottom, 5-slide left
			pause_hover: 0,
			slide_counter: 1,
			slide_captions: 1,
			slide_interval: 5000
	};
	
})(jQuery);

	//Slideshow Next Slide
	function nextslide() {
		
		if($.inAnimation) return false;
		else $.inAnimation = true;
	    var options = $.extend($.fn.supersized.defaults, $.fn.supersized.options);
	    var currentslide = $('#diaporama .activeslide');
	    currentslide.removeClass('activeslide');
		
	    if ( currentslide.length == 0 ) currentslide = $('#diaporama img:last');
			
	    var nextslide =  currentslide.next().length ? currentslide.next() : $('#diaporama img:first');
	    var prevslide =  nextslide.prev().length ? nextslide.prev() : $('#diaporama img:last');
		
		
		//Display slide counter
		if (options.slide_counter == 1){
			var slidecount = $('#slidecounter .slidenumber').html();
			currentslide.next().length ? slidecount++ : slidecount = 1;
		    $('#slidecounter .slidenumber').html(slidecount);
		}
		
		$('.prevslide').removeClass('prevslide');
		prevslide.addClass('prevslide');
		
		//Captions require img in <a>
	    if (options.slide_captions == 1) $('#slidecaption').html($(nextslide).find('img').attr('title'));
		
	    //modif maison
	    var lacolor=$(nextslide).attr('rel')
	  
	    ncol={backgroundColor : "'"+lacolor+"'"}
	    $("#container, #transbox, #barrepp, #echec ul li, #echec2 ul li, #echec3 ul li, #resa, #cont3").animate(ncol, 850);
	    prevslide.fadeOut(750);
	   
	    nextslide.hide().addClass('activeslide')
	    	if (options.transition == 0){
	    		nextslide.show(); $.inAnimation = false;
	    	}
	    	if (options.transition == 1){
	    		nextslide.fadeIn(850, function(){
	    			
	    			$.inAnimation = false;
	    			// $("#container, #transbox").animate(ncol, 400); 
		    		 //$("#transbox").animate(ncol, 400); 
		    		/* $("#barrepp").animate(ncol, 400); 
		    		 $("#echec ul li").animate(ncol, 400);
		    		 $("#echec2 ul li ").animate(ncol, 400);
		    		 $("#echec3 ul li").animate(ncol, 400);
		    		 $("#resa").animate(ncol, 400);*/
	    		});
	    		  
	    		// $("#transbox").animate(ncol, 400); 
	    		 /*$("#barrepp").animate(ncol, 400); 
	    		$("#echec ul li").animate(ncol, 400);
	    		$("#echec2 ul li").animate(ncol, 400);
	    		$("#echec3 ul li").animate(ncol, 400);
	    		 $("#resa").animate(ncol, 400);*/
	    		 
	    	}
	    	if (options.transition == 2){
	    		nextslide.show("slide", { direction: "up" }, 'slow', function(){$.inAnimation = false;});
	    	}
	    	if (options.transition == 3){
	    		nextslide.show("slide", { direction: "right" }, 'slow', function(){$.inAnimation = false;});
	    	}
	    	if (options.transition == 4){
	    		nextslide.show("slide", { direction: "down" }, 'slow', function(){$.inAnimation = false;});
	    	}
	    	if (options.transition == 5){
	    		nextslide.show("slide", { direction: "left" }, 'slow', function(){$.inAnimation = false;});
	    	}
	    	
	    $('#diaporama').resizenow();//Fix for resize mid-transition
	    
	}
	
	//Slideshow Previous Slide
	function prevslide() {
		if($.inAnimation) return false;
		else $.inAnimation = true;
	    var options = $.extend($.fn.supersized.defaults, $.fn.supersized.options);
	    var currentslide = $('#diaporama .activeslide');
	    currentslide.removeClass('activeslide');
		
	    if ( currentslide.length == 0 ) currentslide = $('#diaporama a:first');
			
	    var nextslide =  currentslide.prev().length ? currentslide.prev() : $('#diaporama img:last');
	    var prevslide =  nextslide.next().length ? nextslide.next() : $('#diaporama img:first');
		
	
		//Display slide counter
		if (options.slide_counter == 1){
			var slidecount = $('#slidecounter .slidenumber').html();
			currentslide.prev().length ? slidecount-- : slidecount = $("#diaporama > *").size();
		    $('#slidecounter .slidenumber').html(slidecount);
		}
		
		$('.prevslide').removeClass('prevslide');
		prevslide.addClass('prevslide');
		
		//Captions require img in <a>
	    if (options.slide_captions == 1) $('#slidecaption').html($(nextslide).find('img').attr('title'));
		
	    //modif maison
	    var lacolor=$(nextslide).attr('rel')
	  
	    ncol={backgroundColor : "'"+lacolor+"'"}
	    $("#container, #transbox, #barrepp, #echec ul li, #echec2 ul li, #echec3 ul li, #resa").animate(ncol, 850);
	    
	    prevslide.fadeOut(750);
	   
	    nextslide.hide().addClass('activeslide')
	    	if (options.transition == 0){
	    		nextslide.show(); $.inAnimation = false;
	    	}
	    	if (options.transition == 1){
	    	//alert($(nextslide).attr('title'))
nextslide.fadeIn(750, function(){
	    			
	    			$.inAnimation = false;
	    			
	    		});
	    		
	    	}
	    	if (options.transition == 2){
	    		nextslide.show("slide", { direction: "down" }, 'slow', function(){$.inAnimation = false;});
	    	}
	    	if (options.transition == 3){
	    		nextslide.show("slide", { direction: "left" }, 'slow', function(){$.inAnimation = false;});
	    	}
	    	if (options.transition == 4){
	    		nextslide.show("slide", { direction: "up" }, 'slow', function(){$.inAnimation = false;});
	    	}
	    	if (options.transition == 5){
	    		nextslide.show("slide", { direction: "right" }, 'slow', function(){$.inAnimation = false;});
	    	}
	    	
	    	$('#diaporama').resizenow();//Fix for resize mid-transition
	}
