$(function(){
	/**/
	Cufon.replace('h1.orange-title, .cufon');
	Cufon.replace('#index-offre-technologique #button-toutes-les-offres');
	Cufon.replace('#index-bottom h2, #index-navigation-secondaire h2, #right h2, #index-carousel h2');
	Cufon.replace('#menu a');
	/**/
	
	// Ajout des corners sur les headers
	$('.orange-title').prepend('<img src="' + template_url + '/images/headers-corner.png" class="headers-corner">');
	$('.blue-title').prepend('<img src="' + template_url + '/images/corner-blue.png" class="headers-corner-blue">');
	if ( $.browser.msie && $.browser.version > 7 ) {
		$('#index-bottom h2:not(:last)').prepend('<img src="' + template_url + '/images/headers-corner-gris.png" class="headers-corner-gris">');
		$('#index-bottom h2:last, #right h2, #index-navigation-secondaire h2').prepend('<img src="' + template_url + '/images/headers-corner-gris-right.png" class="headers-corner-gris-right">');
	}
	
	$('.external-link').attr('target','_blank');
	
/************************************************
						MENU
************************************************/
	$('#menu li:has(ul)').hover(function(){
		$(this).children('ul').slideDown('fast', function(){
		});
	}, function(){
		$(this).children('ul').stop(true, true).slideUp('fast');
	});
	
	$('#menu > li:eq(0)').hover(function(){
		$('.catch-phrase-1').fadeIn('fast');
	}, function(){
		$('.catch-phrase-1').stop(true, true).fadeOut('fast');
	});
	
	$('#menu > li:gt(0):not(:last-child)').hover(function(){
		$('.catch-phrase-2').fadeIn('fast');
	}, function(){
		$('.catch-phrase-2').stop(true, true).fadeOut('fast');
	});
	
	$('#menu-social li').hover(function(){
		$(this).fadeTo('fast', 0.7);
	}, function(){
		$(this).fadeTo('fast', 1);
	});
/************************************************
						FIN MENU
************************************************/
	
/************************************************
						CAROUSEL
************************************************/
	var initCarouselItemLeftMargin = $('span:first', '#index-carousel-content').css('margin-left');
	
	if($('#index-carousel-content span').length > 4){
		$('#index-carousel-next').click(function(){
			$('span:first', '#index-carousel-content').animate({'margin-left': '-=208'}, 1000, function(){
				$(this).appendTo($('div', '#index-carousel-content')).css('margin-left', initCarouselItemLeftMargin);
			});
		}).hover(function(){
			$(this).attr('src', template_url + '/images/index-carousel-arrow-right-hover.png');
		}, function(){
			$(this).attr('src', template_url + '/images/index-carousel-arrow-right.png');
		});
		$('#index-carousel-previous').click(function(){
			$('span:last', '#index-carousel-content').css('margin-left', '-208px').prependTo('#index-carousel-content div').animate({'margin-left': initCarouselItemLeftMargin}, 1000);
		}).hover(function(){
			$(this).attr('src', template_url + '/images/index-carousel-arrow-left-hover.png');
		}, function(){
			$(this).attr('src', template_url + '/images/index-carousel-arrow-left.png');
		});
	}else{
		$('#index-carousel-previous, #index-carousel-next').css('visibility','hidden');
	}
	
/************************************************
					FIN CAROUSEL
************************************************/
	
/************************************************
				INDEX SCROLLERS
************************************************/
	var scrollers = $('#index-infos-porteurs, #index-infos-agenda, #index-infos-actualites');
	if($('#index-infos-porteurs li').length < 3)	$('#index-infos-porteurs').next().hide();
	if($('#index-infos-agenda li').length < 3)		$('#index-infos-agenda').next().hide();
	if($('#index-infos-actualites li').length < 3)	$('#index-infos-actualites').next().hide();
	if($('#right-news li').length < 2)					$('#right-news').next().hide();
	
	scrollers.children('li:nth-child(1n+3)').hide();
	$('#right-news li:not(:first)').hide();
	
	$('.scroller-command-down').click(function(){
		var ulControler = $(this).parent().prev();
		if(ulControler.children(':animated').length == 0){
			ulControler.children('li:first').slideUp(1000);
			ulControler.children('li:hidden:first').slideDown(1000, function(){
				ulControler.children('li:first').appendTo(ulControler);
			});
		}
	});
	
	$('.scroller-command-up').click(function(){
		var ulControler = $(this).parent().prev();
		if(ulControler.children(':animated').length == 0){
			ulControler.children('li:visible:last').slideUp(1000);
			ulControler.children('li:last').prependTo(ulControler).slideDown(1000);
		}
	});
	
	$('#index-infos-partenaires li:gt(2)').hide();
	
	function autoScroll(){
		var firstChild = $('#index-infos-partenaires li:first');
		firstChild.delay(5000).slideUp(1000);
		$('#index-infos-partenaires li:hidden:first').delay(5000).slideDown(1000, function(){
			firstChild.appendTo($('#index-infos-partenaires'));
			autoScroll();
		});
	}
	
	autoScroll();
/************************************************
			FIN INDEX SCROLLERS
************************************************/
	
/************************************************
				FAQ
************************************************/
	$('#faq h2:eq(0)').next().show();
	$('#faq h2').click(function(){
		$(this).next().slideToggle();
	});
/************************************************
				FIN FAQ
************************************************/
	
/************************************************
				BUSINESS CONTACT
************************************************/
	$('#business-contact form').submit(function(){
		if ( $('[name="nom-societe"]').val() == '') {
			alert(errorNomSociete);
			return false;
		}
		if ( $('[name="domaine-activite"]').val() == '') {
			alert(errorDomaine);
			return false;
		}
		if ( $('[name="nom"]').val() == '') {
			alert(errorNom);
			return false;
		}
		if ( $('[name="prenom"]').val() == '') {
			alert(errorPrenom);
			return false;
		}
		if ( $('[name="email"]').val() == '') {
			alert(errorEmail);
			return false;
		}
		 var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
		 if (reg.test($('[name="email"]').val()) == false) {
			alert(errorEmail2);
			return false;
		 }
	});
/************************************************
				FIN BUSINESS CONTACT
************************************************/
	
/************************************************
				PARTAGER PROJET
************************************************/
	$('.button-share').click(function(){
		$('span', '.button-share-content').slideUp('fast', function(){
			$(this).remove();
		});
		$('form', '.button-share-content').toggle('fast');
	}).hover(function(){
		if ( isEn ) {
			$(this).attr('src', templateUrl + '/images/btn-share-on.png');
		} else {
			$(this).attr('src', templateUrl + '/images/btn-partager-on.png');
		}
	}, function(){
		if ( isEn ) {
			$(this).attr('src', templateUrl + '/images/btn-share-off.png');
		} else {
			$(this).attr('src', templateUrl + '/images/btn-partager-off.png');
		}
	});
	
	$('.button-test').hover(function(){
		if ( isEn ) {
			$(this).attr('src', templateUrl + '/images/btn-test-off.png');
		} else {
			$(this).attr('src', templateUrl + '/images/btn-tester-off.png');
		}
	}, function(){
		if ( isEn ) {
			$(this).attr('src', templateUrl + '/images/btn-test-on.png');
		} else {
			$(this).attr('src', templateUrl + '/images/btn-tester-on.png');
		}
	});
	
	$('#email-share').focus(function(){
		if ( $(this).val() == emailDefaultValue ) {
			$(this).val('');
		}
	}).blur(function(){
		if ( $(this).val() == '' ) {
			$(this).val(emailDefaultValue);
		}
	});
	
	$('form', '.button-share-content').submit(function(){
		 var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
		 if (reg.test($('#email-share').val()) == false) {
			alert(emailAlert);
			return false;
		 }
	});
/************************************************
				FIN PARTAGER PROJET
************************************************/
	
/************************************************
				NEWSLETTER
************************************************/
	
	$('#newsletter-email').focus(function(){
		if ( $(this).val() == nsDefaultValue ) {
			$(this).val('');
		}
	}).blur(function(){
		if ( $(this).val() == '' ) {
			$(this).val(nsDefaultValue);
		}
	});
	
	$('#newsletter-form').submit(function(){
		 var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
		 if (reg.test($('#newsletter-email').val()) == false) {
			alert(nsAlert);
			return false;
		 }
	});
/************************************************
				FIN NEWSLETTER
************************************************/

/************************************************
				CATALOGUE
************************************************/
	$('.catalogue-container .full-width .attachment-miniature-a-la-une, .catalogue-container .thumb .attachment-miniature-a-la-une').before('<img src="' + templateUrl + '/images/zoom_image.png" class="overlay" alt="" />');
	$('.catalogue-container .full-width .external-link').prepend('<img src="' + templateUrl + '/images/zoom_play.png" class="overlay" alt="" />');
	
	$('.catalogue-container .full-width a, .catalogue-container .thumb a').hover(function(){
		$(this).children('.overlay').fadeOut('fast');
	}, function()  {
		$(this).children('.overlay').fadeIn('fast');
	});
/************************************************
				FIN CATALOGUE
************************************************/
});
