$(document).ready(function(){
	
	/* -----------------------------------------------------------------------------
	 * NAVIGATION
	 */
	
	// Recuperation de la couleur de la page
	var pageColor = $('body').attr('class');
	
	// Activation du lien par defaut
	var pageName = $('body').attr('id');
	
	if (pageName) {
		$('#mainNav a[name="' + pageName + '"] img').attr('src', '../images/nav_' + pageName + '_' + pageColor + '.png');
	}
	
	// Gestion des rollovers
	$('#mainNav a')
		.hover(function() {
			var navImageName = '../images/nav_' + $(this).attr('name') + '_' + pageColor + '.png';
			
			$(this)
				.find('img')
				.attr('src', navImageName);
		}, function() {
			if ($(this).attr('name') != pageName) {
				var navImageName = '../images/nav_' + $(this).attr('name') + '_up.png';
				
				$(this)
					.find('img')
					.attr('src', navImageName);
			}
		});
	
	
	
	
	/* -----------------------------------------------------------------------------
	 * SUBNAVIGATION
	 */
	
	$('#leftContent li a')
		.hover(function() {
			$(this)
				.stop()
				.animate({ lineHeight: '3em' }, 400);
		}, function() {
			$(this)
				.stop()
				.animate({ lineHeight: '2em' }, 400);
		});
	
	
	
	
	/* -----------------------------------------------------------------------------
	 * INFOZONE > HOME
	 */
	
	var infoZoneHover = false;
	
	function getScrollPosition() {
		if (infoZoneHover) {
			if($('#infoZoneContentLimit').scrollLeft() > 1) {
				$('#infoZoneLeftExtend').show();
				$('#infoZoneRightExtend').hide();
			} else {
				$('#infoZoneLeftExtend').hide();
				$('#infoZoneRightExtend').show();
			}
		} else {
			$('#infoZoneLeftExtend, #infoZoneRightExtend').hide();
		}
	}
	
	getScrollPosition();
	
	$('#home #infoZone').mouseover(function() {
		infoZoneHover = true;
		getScrollPosition();
	});
	
	$('#home #infoZone').mouseout(function() {
		infoZoneHover = false;
		$('#infoZoneLeftExtend, #infoZoneRightExtend').hide();
	});
	
	$('#infoZoneLeftExtend').click(function() {
		$('#infoZoneContentLimit')
			.stop()
			.scrollTo(
				'div:first',
				700,
				{ onAfter:function() { getScrollPosition(); }}
			);
	});
	
	$('#infoZoneRightExtend').click(function() {
		$('#infoZoneContentLimit')
			.stop()
			.scrollTo(
				'div:last',
				1200,
				{ onAfter:function() { getScrollPosition(); }}
			);
	});
	
	/* -----------------------------------------------------------------------------
	 * INFOZONE
	 */
	
	$('body:not(#home) #infoZoneContent div > *')
		.css('margin-top', '131px');
	
	$('body:not(#home) #infoZoneContent div')
		.hover(function() {
			$(this)
				.find('*')
				.stop()
				.animate({ marginTop: 0 }, 400);
		}, function() {
			$(this)
				.find('*')
				.stop()
				.animate({ marginTop: 131 }, 400);
		});
	
	
	$('#nav_investor table tr td').hover(
	function()
	{
		if(!$(this).hasClass('hoverDisabled')){
			$(this).parent().toggleClass('trHover');
		}
	},
	function()
	{
		if(!$(this).hasClass('hoverDisabled')){
			$(this).parent().toggleClass('trHover');
		}
	});
	
	
	
	/* -----------------------------------------------------------------------------
	 * HOMEPAGE
	 */
	
	$('#home .section a').parent().parent().parent().css('cursor', 'pointer');
	
	$('#home .section a').parent().parent().parent().click(function() {
		var url = $(this).find('a').attr('href');
		document.location.href = url;
	});
	

	
	
	/* -----------------------------------------------------------------------------
	 * CONTENT > DEFINITION LIST
	 */
	
	$('#rightContent dl.itemList dd').hide();
	
	$('#rightContent dl.itemList dt').click(function() {
		$('#rightContent dl.itemList dd div.iframePlaceholder').empty();
		$('#rightContent dl.itemList dd').hide();
		$('#rightContent dl.itemList dt').removeClass('openedDLParent');
		
		$(this).parent().find('dd').show();
		$(this).addClass('openedDLParent');
		
		if ($(this).find('div.iframePlaceholder:empty')) {
				
				var JScatID = $(this).parent().attr('name');
				var JSitemID = $(this).parent().find('dt').attr('name');
				
				var placeholder = $(this).parent().find('div.iframePlaceholder');
				
				$.get("../../inc/googlemap_iframe.inc.php", { catID: JScatID, itemID: JSitemID }, function(data){
					$(placeholder).append(data);
				}, "html");
			}
	})
	
	
	
	/* -----------------------------------------------------------------------------
	 * CONTENT > JOBS LIST
	 */
	
	$('#rightContent dl.jobsList dd:not(.opened)').find('p:not(:first)').hide();
	$('#rightContent dl.jobsList dd:not(.opened)').find('li').hide();
	$('#rightContent dl.jobsList dd:not(.opened)').find('table').hide();
	$('#rightContent dl.jobsList dd:not(.opened)').find('hr').hide();
	
	$('.opened').parent().find('dt').addClass('openedDLParent');
	
	$('#rightContent dl.jobsList dt').click(function() {
		$(this).toggleClass('openedDLParent');
		$(this).parent().find('dd p:not(:first)').toggle('normal');
		$(this).parent().find('dd li').toggle('normal');
		$(this).parent().find('dd table').toggle('normal');
		$(this).parent().find('dd hr').toggle('normal');
	})
	
	
	
	/* -----------------------------------------------------------------------------
	 * CONTENT > NEWS LIST
	 */
	
	$('#rightContent dl.newsList dd:not(.opened)').find('p:not(:first)').hide();
	
	$('.opened').parent().find('dt').addClass('openedDLParent');
	
	$('#rightContent dl.newsList dt').click(function() {
		$(this).toggleClass('openedDLParent');
		$(this).parent().find('dd p:not(:first)').toggle('normal');
	})
	
	
	
	/* -----------------------------------------------------------------------------
	 * CONTENT > FIRM GOVERNMENT
	 */
	
	$("dl.peopleList").tooltip({
		track: true, 
		delay: 100,
		fade: 250,
		showBody: " - ",
		showURL: false,
		extraClass: "gallery",
		bodyHandler: function() {
			return $($(this).find('.dialogBox')).html();
		}
	});

	
	
	
	
	/* -----------------------------------------------------------------------------
	 * EMAIL ADDRESS
	 */
	
	$('address').append('E. <a href="#" class="mail">Veuillez utiliser le formulaire</a>');
	
	var m_a_i_l_A_r_r_a_y=[118,105,108,108,97,114,115,104,111,108,100,105,110,103,64,118,105,108,108,97,114,115,104,111,108,100,105,110,103,46,99,104]
	var m_a_i_l='' //variable to contain encrypted email 
	for (var i=0; i<m_a_i_l_A_r_r_a_y.length; i++){
 		m_a_i_l+=String.fromCharCode(m_a_i_l_A_r_r_a_y[i]);
 		m_a_i_l_h_r_e_f = 'm'+'a'+'i'+'l'+'t'+'o'+':'+m_a_i_l;
 	}
	
	$('a.mail').attr({'href':m_a_i_l_h_r_e_f}).html(m_a_i_l);
		
	/* -----------------------------------------------------------------------------
	 * CONTACT FORM
	 */
	
	$("#contactForm").validate({
		rules: {
			firstname_field: "required",
			lastname_field: "required",
			email_field: {
				required: true,
				email: true
			},
			message_field: "required"
		}, messages: {
			firstname_field: "saisissez votre prénom",
			lastname_field: "saisissez votre nom",
			email_field: "saisissez votre e-mail",
			message_field: "saisissez votre date de naissance"
		}
	});
	
	/* -----------------------------------------------------------------------------
	 * SUBSCRIBE FORM
	 */
	
	$('#subscribeForm').validate({
			rules: {
				
				email_subscr_field: {
					required: true,
					email: true
				}
			}, messages: {
				email_subscr_field: "saisissez votre e-mail"
			}	
		
	});
	
	$('#subscr_submit').click(function(){
		
		if($('#subscribeForm').valid()==true){
		
			$.post('../inc/newsletter_form.inc.php',{
						
				user_mail: $("#email_subscr_field").val(),
				user_step: $("#user_step").val()
				
				},function(data){	
					
					$('#rightContent').html(data);
					
					$('#subscr_submit').click(function(){
						
						$.post('../inc/newsletter_form.inc.php',{
									
							user_mail: $("#email_subscr_field").val(),
							user_step: $("#user_step").val(),
							user_choice: $("input:checked").val()
							
						},function(data){
							
							$('#rightContent').html(data);
							
						});
						
						return false;
					
					});
					//ajouter enregistrement, désenregistrement
						
				});	
				//end callback post newsletter.
			
		}else {
		
		
		
		}
		
		return false;
	});	

	
	/* -----------------------------------------------------------------------------
	 * POSTULATE FORM
	 */
	
	$("#jobForm").validate({
		rules: {
			firstname_field: "required",
			lastname_field: "required",
			email_field: {
				required: true,
				email: true
			},
			address_field: "required",
			zip_field: "required",
			city_field: "required",
			phone_field: "required",
			birthdate_field: "required",
			cv_field: "required",
			letter_field: "required"
		}
	});
	
});



/* -----------------------------------------------------------------------------
 * Void Function - abstract - annulation des liens vides
 */
function voidFunction() {}
