$(document).ready(function(){
//	$('#prestation ul li a').next().hide();
	$('#prestation ul li ul').each(function(){
		var width = $(this).width();
		$('#prestation ul li a').click(function(){
			$('#prestation ul li a').next().hide();
				$(this).next().show();
				$(this).parent().siblings().removeClass('choosen');
				$(this).parent().addClass('choosen');
				$('#prestation>ul').css('background', 'url(/extension/luxcontrol/design/standard/images/layout/prestationArrow.gif) 0 42px no-repeat');
		});
	});
	$('#prestation').mouseleave(function(){
		$('#prestation ul li').removeClass('choosen');
		$('#prestation ul ul').hide();
	});
	
	/*centering subnav*/
	$("#nav>li").each( function(){
		var thiner = $('#nav>li').width();
		var largest = $('#nav>li>ul').width() - 20;
		var diff = (largest - thiner)/2;
		$('#nav>li>ul').css( 'margin-left', -(diff) );	
		$('#nav>li:first-child>ul').css( 'margin-left', 0 );	
		$('#nav>li:last-child>ul').css( 'margin-left', -(diff*2 + 30) );
	}).mouseenter(function()
	{
		$(this).find('>ul').css( 'visibility', 'visible' );
	}).mouseleave(function()
	{
		$(this).find('>ul').css( 'visibility', 'hidden' );
	});
	
	
	$("#closeIE8Warning").click(function() {
		$(this).parent().fadeOut();
	});
	
	// tabs to manage languages
	$("#availableLanguage").tabs();
	
	// nyro
	$('.gmap a').nyroModal({
		type: 'iframe'
		});
	// form
	$('#newsletter_subscription').nyroModal({
		type: 'iframe',
		closeButton: false,
		windowResize: true,
		minHeight: 70,
		minWidth: 0
		});
	$('#contact_us').nyroModal({
		type: 'iframe',
		closeButton: false,
		minHeight: 70,
		minWidth: 0
		});
	$('#apply_job').nyroModal({
		type: 'iframeForm',
		closeButton: false,
        windowResize: true,
        width: 500,
        height: 400
		});
	
	// multi form
	$('.jserialform').serialform();
	
	// accordion. Used in the formations pages
	$('#formations').accordion({
		header: 'h3',
		autoheight: false, 
		alwaysOpen: false,
		active: false,
		collapsible: true
	});
	
	jQuery.extend(jQuery.validator.messages, {
		required: ""
	});
	
	$('#search').validate();
	
	// only for xhtml strict validation
	//replace rel attribute by target attribute
	$('a').each(function()
	{
		if( $(this).attr('rel') && $(this).attr('rel') == '_blank' 
			|| $(this).attr('rel') == '_self' 
			|| $(this).attr('rel') == '_parent'
			|| $(this).attr('rel') == '_top')
		{
			var relValue = $(this).attr('rel'); 
			$(this).removeAttr('rel');
			$(this).attr('target', relValue );
		}
	});
	
});

// Flash map: display Google Map on click 
function displayGMap(id)
{
	$( '#company_' + id ).click();
}
