
jQuery(document).ready(function(){

//	$(".tab-content div").hide(); //Hide all content
//	$(".tab-menu li:first").addClass("active"); //Show first tab content
//	$(".tab-content div:first").show(); //Show first tab content
	
	//On Click Event
//	$(".tab-menu li").click(function() {
//		$(".tab-menu li").removeClass("active"); //Remove any "active" class
//		$(this).addClass("active"); //Add "active" class to selected tab
//		$(".tab-content div").hide(); //Hide all tab content
//		var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
//		$(activeTab).fadeIn(); //Fade in the active ID content
//		return false;
//	});
	
	
  var oldt = 0;
   var sudoSlider = $("#products-tabs-content").sudoSlider({ 
      beforeAniFunc: function(t){ 
         var substract = $('#products-tabs-menu ul').offset();
         var posi = $('#products-tabs-menu ul li').eq(t-1).offset();
         var top =  posi.top - substract.top;
         var diff = Math.sqrt(Math.abs(oldt-t));
         var speed = parseInt(diff*400);
         var text = $('#products-tabs-menu ul li').eq(t-1).text();
         var height = $('#products-tabs-menu ul li').eq(t-1).height();
         $('#products-tabs-menu ul li.currentone').animate({
            top: top
            }, speed).children().animate({
            height: height
            }, speed);
         oldt = t;
      },
      customLink: '.custom',
	  fade: true,

	  fadespeed:'1',
	  prevNext:false,
      autoheight: true
   });
   

  	$("#page-support .manual-request a").click(function(){
		var requestManual = $(this).html();
		$("#request-manual h4 span").html(requestManual);
		$("#inputhiddenmanual").val(requestManual);
				
	}, function(){}
	);
   
		
		

	var sudoSlider = $("#home-slider > div").sudoSlider({
				prevNext:true,
				auto: true,
				speed: 500,
				pause: 5000,
				afterAniFunc: function(t){
					var slide = $(this).attr("class");
				
					if (slide == "slideb" || slide == "slidec") {
						$(this).find("h2:eq(0)").show().animate({left:'0px'}, 200, function(){
							$(this).parent().find("h2:eq(1)").show().animate({left:'0px'}, 200, function(){
								$(this).parent().find("h2:eq(2)").show().animate({left:'0px'}, 200, function(){
									$(this).parent().find("h2:eq(3)").show().animate({left:'0px'}, 200, function(){});
								});
							});
						});
					}
					
			   	},
				beforeAniFunc: function(t){
					
					$(this).find("h2").animate({left:'-600px'}, 0);	
				}
		});
		
	var sudoSlider = $(".sliders-applis > div").sudoSlider({
				prevNext:true,
				speed: 300
		});
		
	var sudoSlider = $("#home-products-slider > div").sudoSlider({
				prevNext:false,
				auto: true,
				speed: 500,
				pause: 3000,
				vertical: true
		});
			
	var sudoSlider = $("#techno-slider > div").sudoSlider({
				prevNext:true,
				auto: true,
				pause: 6000
		});
	var sudoSlider = $("#home-applis > div").sudoSlider({
				prevNext:true,
				auto: true,
				speed: 300,
				pause: 6000
		});

$('.manual-request a').fancybox({
	
//			href: "#shop-form",
		hideOnOverlayClick: false,
		enableEscapeButton: false,
		height: "80%"
	});
	

$('.fancybox').fancybox();

$('.btn-video').click(function() {
	$.fancybox({
        'type' : 'iframe',
        // hide the related video suggestions and autoplay the video
        'href' : this.href.replace(new RegExp('watch\\?v=', 'i'), 'embed/') + '?rel=0&autoplay=1',
        'overlayShow' : true,
        'centerOnScroll' : true,
        'speedIn' : 100,
        'speedOut' : 50,
        'width' : 640,
        'height' : 480

		});

	return false;
});


	$('.partner p').css("opacity", 0);
	$('.partner').hover(function(){
		$(this).find('img').stop().animate({left:'-150px'},{queue:false,duration:100});
		$(this).find('p').stop().animate({opacity:1},{queue:false,duration:200});
		
	}, function() {
		$(this).find('p').stop().animate({opacity:0},{queue:false,duration:200});
		$(this).find('img').stop().animate({left:'5px'},{queue:false,duration:300});
	});
	
	
	
	(function($)
	{
		$.fn.defaultValue = function( options )
		{
			var options = $.extend(
				{
					defVal: 'Search'
				},
				options
			);
			return this.each( function()
				{
					$( this ).blur( function()
						{
							if ( $( this ).val() === '' )
								$( this ).val( options.defVal );
						}
					).focus( function()
						{
							if ( $( this ).val() === options.defVal )
								$( this ).val( '' );
						}
					);
				}
			);
		}
	}
)(jQuery);

	 
$( '#name' ).defaultValue( { defVal: 'Name' } )
$( '#name2' ).defaultValue( { defVal: 'Nom' } )
$( '#company' ).defaultValue( { defVal: 'Company' } )
$( '#company2' ).defaultValue( { defVal: 'Société' } )
$( '#phone' ).defaultValue( { defVal: 'Phone' } )
$( '#phone2' ).defaultValue( { defVal: 'Téléphone' } )
$( '#mail, #mail2' ).defaultValue( { defVal: 'e-Mail' } )
$( '#message, #message2' ).defaultValue( { defVal: 'Message...' } )
$( '#captcha' ).defaultValue( { defVal: 'Security code' } )
$( '#captcha2' ).defaultValue( { defVal: 'Code de sécurité' } )




 
jQuery.validator.addMethod("notEqualTo",
 function(value, element, param) {return this.optional(element) || value != param; },
 "This has to be different...");

jQuery.validator.addMethod("egalA",
 function(value, element, param) {return this.optional(element) || value == param; },
 "This has to be different...");


$('#ajax_form').validate({
		debug: false,
		errorClass: "error",
		rules: {
			name:  {
				required:true,
				notEqualTo:"Name"
			},
			name2:  {
				required:true,
				notEqualTo:"Nom"
			},
			company:  {
				required:true,
				notEqualTo:"Company"
			},
			company2:  {
				required:true,
				notEqualTo:"Société"
			},
			phone:  {
//				required:true,
//				notEqualTo:"Phone"
			},
			mail: {
				required: true,
				email: true
			},
			mail2: {
				required: true,
				email: true
			},
			message:  {
				required: true,
				notEqualTo:"Message..."
			},
			message2:  {
				required: true,
				notEqualTo:"Message..."
			}
//			captcha_code: {
//				required: true,
//				remote: "/testcaptcha.php"
//			}
//			captcha2: {
//				required: true,
//				egalA: 4
//			}
		},
		messages: {
			name: "Please, enter your Name",
			name2: "Merci de saisir votre Nom",
			company: "Please, enter your Company name",
			company2: "Merci de saisir le nom de votre société",
//			phone: "Please, enter your Phone number",
			mail: "Please, enter a valid eMail address",
			mail2: "Merci de saisir une adresse email valide",
			message:"Don't miss your message !",
			message2:"N'oubliez pas votre message !"
//			captcha_code:{
//				required:"Security code is required",
 //       		remote:"Security code is incorrect!"//

//				}
//			captcha2:"Merci de saisir le bon code de sécurité"
		},
		submitHandler: function(form) {
			// do other stuff for a valid form
			$.post('/message.php', $("#ajax_form").serialize(), function(data) {
				json = typeof JSON !='undefined' ?  JSON.parse(data) : eval('('+data+')');
				if("error" in json) {
						alert("Security code is incorrect!");
					} else {
					$('#results').show();
					$('.button').hide();	
					}
				
			});
		}
});



//	$("#language a").hover(
//			function(){
//				$(this).animate({ right:'0' },{queue:false,duration:100});
//			},
//			function(){
//				$(this).animate({right:'-100px'},{queue:false,duration:100});
//			}
//	);
//	

	
	// On cache le span
	$("#lang-text").hide();
	// On cherche quel est le langage actif
	if ($("#lang-en").hasClass("active")) {
		var langdef= $("#lang-en > span").html();
		}
	if ($("#lang-fr").hasClass("active")) {
		var langdef= $("#lang-fr > span").html();
		}
	// On attribut au span le langage actif
	$("#lang-text").html(langdef);
	
	// On attribut au span le langage survolé
	$("#lang-fr, #lang-en").hover(function(){
		var langhover = $(this).find("span").html();
		$("#lang-text").html(langhover);	
	}, function(){
		$("#lang-text").html(langdef);	
	});
	
	//on anime la box langage au survol
	$("#language").hover(function(){
		$("#language").animate({ width:'130px' },{queue:false,duration:100});
		$("#lang-text").show();
				
	}, function(){
		$("#lang-text").hide();
		$("#language").animate({width:'60px'},{queue:false,duration:100});

	}
	);


























// Custom sorting plugin
(function($) {
  $.fn.sorted = function(customOptions) {
    var options = {
      reversed: false,
      by: function(a) { return a.text(); }
    };
    $.extend(options, customOptions);
    $data = $(this);
    arr = $data.get();
    arr.sort(function(a, b) {
      var valA = options.by($(a));
      var valB = options.by($(b));
      if (options.reversed) {
        return (valA < valB) ? 1 : (valA > valB) ? -1 : 0;				
      } else {		
        return (valA < valB) ? -1 : (valA > valB) ? 1 : 0;	
      }
    });
    return $(arr);
  };
})(jQuery);

// DOMContentLoaded
$(function() {

  // bind radiobuttons in the form
  var $filterType = $('#filter li');
	$filterType.addClass("active");	

  // get the first collection
  var $applications = $('#applications');

  // clone applications to get a second collection
  var $data = $applications.clone();

  // attempt to call Quicksand on every form change
  $filterType.bind('click', function(e) {
	  $filterType.removeClass("active");
	  $(this).addClass("active");
		if ($(this).attr("id") == 'all') {
			$filterType.addClass("active");	
		  var $filteredData = $data.find('li');
		} else {
		  var $filteredData = $data.find('li[data-type=' + $(this).attr("id") + ']');
		}


	  	// if sorted by name
	  	var $sortedData = $filteredData.sorted({
			by: function(v) {
		  		return $(v).find('strong').text().toLowerCase();
			}
	  	});
 

    	// finally, call quicksand
    	$applications.quicksand($sortedData, {
      		duration: 800
    	});

  });

});


	
});


