$(document).ready(function(){
	/* general menu */
	$('#nav01').superfish();
													 
	/*Toolbox*/
	$("#toolbox").hover(function(){
		$(this).addClass('active');
		var content = $('.content', this);
		if(!content.is(':animated')) content.slideDown('slow');
	}, function(){
		$(this).removeClass('active');
		var content = $('.content', this);
		if(!content.is(':animated')) content.slideUp('slow');
	});
	
	/*centering subnav*/
	$("#nav li").each( function(){
		var thiner = $(this).width();
		var largest = $('ul',this).width();
		var diff = (largest - thiner)/2;
		$('ul', this).css( 'margin-left', -(diff) );		
	});
	
	/*Same height*/
	var higher = $('#contentTxt .oh #seminar-date #contentSeminar');
	var highest = $('#contentTxt .oh #testimonial .txt');
	var ref = 0
	if ( higher.height() && highest.height() ){
		if ( highest.height() > ref ) ref = highest.height();
		if ( higher.height() > ref ) ref = higher.height();
		highest.css('height', (ref) ) && higher.css('height', (ref));
	};
	
	/*New Same height*/
	var higher = $('#contentTxt .oh #seminar-date #contentSeminar');
	var highest = $('#toCalendar-visu');
	var ref = 0
	if ( higher.height() && highest.height() ){
		if ( highest.height() > ref ) ref = highest.height();
		if ( higher.height() > ref ) ref = higher.height();
		highest.css('height', (ref)) && higher.css('height', (ref - 6));
	};

	
	
	/*hotnews*/
	$('#theHotNews').cycle({ 
	    fx:     'scrollHorz', 
	    speed:  'slow', 
	    timeout: 5000, 
	    next:   '#next', 
	    prev:   '#prev' 
	});
	
	/*lightbox*/
	$(function() {
		$('a.lightbox').lightBox();
	});
	
	/*png fix*/
	$('.promoGray td').pngFix();
	$('.promoSlimGray td').pngFix();
	$('.promoBlue').pngFix();
	$('.promoSlimBlue td').pngFix();
	$('.promoOrange td').pngFix();
	$('.promoSlimOrange td').pngFix();
	
	/*Discover agenda*/
	$('#discovery').click(function(){		
		$('#agenda').slideToggle( 'slow' );
	});
	
	$('#participants').children().next().hide();
	$('#participants').children().click(function(){
		if($(this).next().css('display') == 'block'){
			$(this).children().css("background", "url(/extension/mach/design/mach/images/downArrowWhite.png) left center no-repeat")
		}else{
			$(this).children().css("background", "url(/extension/mach/design/mach/images/leftArrowWhite.png) left center no-repeat")
		}
		$(this).next().slideToggle();
	});
	
	$('.setupAppointment').next().hide();
	$('.setupAppointment').click(function(){	
		displayElement( $(this).next() );
	});
	
	/*Registration Form*/
	$('#inscription').click(function()
	{
//		$("#form-btn").hide( 'slow' );
		$("#form_events_register").slideToggle( 'slow' );
	});
	
	// Display courses if training seminar is selected
	if( $("select[name='seminarID']").val() != 0 )
	{
		changeSeminar ();
	}
	
	// second case : on change
	$("select[name='seminarID']" ).change( function()
	{
		changeSeminar ();
	});
	

	$("#tabs").tabs({selected:0});

		
	$('a.tooltip').simpletooltip({ hideDelay: 0.5 });

	
});

function displayElement( element )
{
	element.slideToggle( 'slow' );
}

/*Close flash overlayer*/
function closeOverlayer(){
	$('#closeOverlayer').click();
}

// Display Visa Datas in register form
function displayVisaDatas( show ){
	var div = document.getElementById( 'visa_datas' );
	if ( show && div.style.display == 'none' ) $( '#visa_datas' ).slideToggle( 'slow' );
	else if ( !show && div.style.display == 'block' ) $( '#visa_datas' ).slideToggle( 'slow' );
}

// Display background in home flash
function displayBackgroundHomeFlash(){
	var homeFlash = document.getElementById( 'homeFlash' );
	if( homeFlash ) homeFlash.style.background = "url('extension/mach/design/mach/images/mosaique_984.jpg') no-repeat";
}

// Add to favorite
function favoris() {
	u=location.href;
	t=document.title;
	if ( navigator.appName != 'Microsoft Internet Explorer' ) window.sidebar.addPanel( t , u,"");
	else window.external.AddFavorite( u, t );
}

// Add to Facebook
function fbs_click() {
	var u = location.href;
	var t = document.getElementsByName( 'title' );
		t = t[0].content;
	var targetUrl = 'http://www.facebook.com/sharer.php?u=' + encodeURIComponent( u ) + '&t=' + encodeURIComponent( t );
	window.open( targetUrl, 'sharer', 'toolbar=0,status=0,width=626,height=436' );
	return false;
}

// Add to MySpace
function mspace_click() {
	var u = location.href;
	var t = document.getElementsByName( 'title' );
		t = t[0].content;
	var c = document.getElementsByName( 'description' );
		c = c[0].content;
	var targetUrl = 'http://www.myspace.com/index.cfm?fuseaction=postto&' + 't=' + encodeURIComponent( t ) + '&c=' + encodeURIComponent( c ) + '&u=' + encodeURIComponent( u );
	window.open( targetUrl, 'sharer', 'toolbar=0,status=0,width=626,height=436' );
	return false;
}

// Add to Twitter
function twitter_click() {
	var u = location.href;
	var targetUrl = 'http://twitter.com/home?status=' + encodeURIComponent( u );
	window.open( targetUrl, 'sharer', 'toolbar=0,status=0,width=626,height=436' );
	return false;
}

function $$( id ){
	return document.getElementById( id );
}

//Trim
function trim ( myString ){
	return myString.replace(/^\s+/g,'').replace(/\s+$/g,'');
}

//Formatage de la saisie de recherche
function formatSearch( id ){
	// Vérifie que l'on a saisi quelque chose
	if ( trim( $$( id ).value ) == "" ){
		$$( id ).value = "";
		return;
	}
	// Nouvelle instance d'objet String
	// Valeur de la recherche saisie entourrée de quote
	var search = new String( '"' + trim( $$( id ).value ) + '"' );
	// Suppression des doublons en début et fin de chaine
	search = search.replace( '""', '"' ).replace( '""', '"' );
	// Nouvelle valeure pour le submit
	$$( id ).value =  search;
}