/*ref sliding pas utilisé */

$(document).ready(function(){
	/* This code is executed after the DOM has been completely loaded */
	
	var totWidth=0;
	var positions = new Array();
	
	$('.slides .slide').each(function(i){
		
		/* Traverse through all the slides and store their accumulative widths in totWidth */
		
		positions[i]= totWidth;
		totWidth += $(this).width();
		
		/* The positions array contains each slide's commulutative offset from the left part of the container */
		
		if(!$(this).width())
		{
			alert("Please, fill in width & height for all your images!");
			return false;
		}
		
	});
	
	$('.slides').width(totWidth);

	/* Change the cotnainer div's width to the exact width of all the slides combined */

	$('.menuRef ul li a').click(function(e){

			/* On a thumbnail click */

			$('li.menuItem').removeClass('act').addClass('inact');
			$(this).parent().addClass('act');
			
			var pos = $(this).parent().prevAll('.menuItem').length;
			
			$('.slides').stop().animate({marginLeft:-positions[pos]+'px'},450);
			/* Start the sliding animation */
			
			e.preventDefault();
			/* Prevent the default action of the link */
	});
	
	$('.menuRef ul li.menuItem:first').addClass('act').siblings().addClass('inact');
	/* On page load, mark the first thumbnail as active */
	
});




/*ref thumbs pas utilisé */

$(document).ready(function() {
			   //Coulissement horizontal    
			    $('.boxgrid.peek').hover(function() {
			        $(".cover", this).stop().animate({top:'-45px'},{queue:false,duration:160});
			    }, function() {
			        $(".cover", this).stop().animate({top:'0px'},{queue:false,duration:160});
			    });
			});
			
			
			
			

			
/*Accordeon*/
	
	
		jQuery().ready(function(){
		// simple accordion
				jQuery('#list1b').accordion({
			autoheight: false
		});
		
			});





$(document).ready(function() {	
	var selectedFeatIdx = 0;
			var isTransitioning = false;
			
			var features = $('.selectedFeat, .feat');
			features.each(function() {
				$('.navigation').append('<li><a href="#"></a></li>');
			});
			$('.navigation a:first').addClass('selected');
			
			function updateSelectedFeature() {
				isTransitioning = true;
				$('.navigation .selected').removeClass('selected');
				$('.navigation a:eq(' + selectedFeatIdx + ')').addClass('selected');
				
				$('.selectedFeat').fadeOut(500, function() {
					
					
					
					

					$(this).removeClass('selectedFeat');
					$(this).css('display','');
					$(this).addClass('feat');
					
					$(features[selectedFeatIdx]).fadeIn(500, function() {
					 


						$(this).removeClass('feat');
						$(this).addClass('selectedFeat');
						isTransitioning = false;
					});
				});
				
			}
			
			$('.navigation a').click(function() {
			
     

				for(var i = 0; i < $('.navigation a').length ; i++) {
					if(this == $('.navigation a')[i]) {
						selectedFeatIdx = i;
						updateSelectedFeature();
						break;
					}
				}
			});
			
			$('#rightArrow').click(function() {
				if(selectedFeatIdx < features.length-1 && !isTransitioning) {
					selectedFeatIdx++;
					updateSelectedFeature();
				}
			});
			
			$('#leftArrow').click(function() {
				if(selectedFeatIdx != 0 && !isTransitioning) {
					selectedFeatIdx--;
					updateSelectedFeature();
				}
			});
		});

		


 $(function () {
        if ($.browser.msie && $.browser.version < 7) return;
        
        $('#navigation li')
            .removeClass('highlight')
            .find('a')
            .append('<span class="hover" />').each(function () {
                    var $span = $('> span.hover', this).css('opacity', 0);
                    $(this).hover(function () {
                        // on hover
                        $span.stop().fadeTo(350, 1);
                    }, function () {
                        // off hover
                        $span.stop().fadeTo(350, 0);
                    });
                });
                
    });
    
    
/* TWITTER */

(function($) {
	

	$.fn.getTwitter = function(options) {
		var o = $.extend({}, $.fn.getTwitter.defaults, options);
	
		// hide container element
		$(this).hide();
	
		// add heading to container element
		if (o.showHeading) {
			$(this).append('<h2>'+o.headingText+'</h2>');
		}

		// add twitter list to container element
		$(this).append('<ul id="twitter_update_list"><li></li></ul>');

		// hide twitter list
		$("ul#twitter_update_list").hide();

		// add preLoader to container element
		var pl = $('<p id="'+o.preloaderId+'">'+o.loaderText+'</p>');
		$(this).append(pl);

		// add Twitter profile link to container element
		if (o.showProfileLink) {
			$(this).append('<a id="profileLink" href="http://twitter.com/'+o.userName+'">http://twitter.com/'+o.userName+'</a>');
		}

		// show container element
		$(this).show();
	
		$.getScript("http://twitter.com/javascripts/blogger.js");
		$.getScript("http://twitter.com/statuses/user_timeline/"+o.userName+".json?callback=twitterCallback2&count="+o.numTweets, function() {
			// remove preLoader from container element
			$(pl).remove();

			// show twitter list
			if (o.slideIn) {
				$("ul#twitter_update_list").slideDown(1000);
			}
			else {
				$("ul#twitter_update_list").show();
			}

			// give first list item a special class
			$("ul#twitter_update_list li:first").addClass("firstTweet");

			// give last list item a special class
			$("ul#twitter_update_list li:last").addClass("lastTweet");
		});
	};

	
})(jQuery);
			$(document).ready(function() {
				$("#twitter").getTwitter({
					userName: "benjaminpirson",
					numTweets: 1,
					loaderText: "Chargement du dernier tweet...",
					slideIn: false,
					showHeading: false,
					headingText: "Derniers Tweets",
					showProfileLink: false
				});
			});
	
	
	
/* Form contact*/


$(document).ready(function(){
	

	$("button").click(function(){

		$(".formError").hide();

	});

	var use_ajax=true;
	
	$("#contact-form").submit(function(e){

			if(!$('#subject').val().length)
			{
				$.validationEngine.buildPrompt(".jqTransformSelectWrapper","* This field is required","error")
				return false;
			}
			
			if(use_ajax)
			{
				$('#loading').css('visibility','visible');
				$.post('submit.php',$(this).serialize()+'&ajax=1',
				
					function(data){
						if(parseInt(data)==-1)
							$.validationEngine.buildPrompt("#captcha","* Wrong verification number!","error");
							
						else
						{
							$("#contact-form").hide('slow').after('<h1>Thank you!</h1>');
						}
						
						$('#loading').css('visibility','hidden');
					}
				
				);
			}
			e.preventDefault();
	})

}); 



/* Hover sur elements*/

$(document).ready(function() {
	$('.fadeElement').append('<span class="hover"></span>').each(function () {
	  var $span = $('> span.hover', this).css('opacity', 0);
	  $(this).hover(function () {
	    $span.stop().fadeTo(300, 1);
	  }, function () {
	    $span.stop().fadeTo(300, 0);
	  });
	});
});



/* Loader img*/

    $(function () {
      $(".loading").removeClass("loading");
      $(".fadein").fadeIn(); 
    });     	



/* devis contact*/

$(document).ready(function(){


	$("#subject").change(function(){
		
		if($(this).val() == "devis"){
			$("#devisLabel").slideDown("slow");
	   		
	  	} else {
	  		$("#devisLabel").slideUp("slow");
	  	}
	});

});





