$(document).ready(
	function() {
		
		// gestion du carroussel
		$('#pause').click(function() { $('#slides').cycle('pause'); return false; });
	    $('#play').click(function() { $('#slides').cycle('resume'); return false; });
	    
	    $('#slideshow').hover(
	        function() { $('#controls').fadeIn(); },
	        function() { $('#controls').fadeOut(); }
	    );
	    
	    $('#slides').cycle({
	        fx:     'cover',
	        speed:   600,
	        timeout: 3000,
	        next:   '#next',
	        prev:   '#prev'
	    });
		
	    
	    //gestion du formulaire de contact
		$('img#load').hide();
		$("form#form-contact").submit(
			function() {
				$('div#retour').html('');
				$('img#load').show();
				
				$.post('typo3conf/ext/arobaweb/lib/form.php', $(this).serialize(),
							function(retour){
									if (retour.OK) {
										$('div#retour').html('<span class="retour-true">'+retour.OK+'</span>');
									}else if(retour.KO) {
										$('div#retour').html('<span class="retour-false">'+retour.KO+'</span>');
									}else{
										$('div#retour').html('Une erreur est survenue lors du transfert du formulaire en Ajax.');
									}
									$('img#load').hide();
							}
						,"json");
				return false;
			}
		);
		
		//gestion des infobulles sur les liens
		$('#footer div.int div a').hover(
			function (){
				if(!$(this).attr('name')) {
					$(this).attr('name',$(this).attr('title'));
				}
				$(this).before('<div class="infobulle" style="display:none;"><h6></h6><p>'+$(this).attr('name')+'</p></div>');
				$(this).attr('title','');
				$(this).siblings('div.infobulle').slideDown('normal');
				//$(this).siblings('div.infobulle').show();				
			},
			function(){
//				$(this).siblings('div.infobulle').siblings('a').attr('title',$(this).siblings('div.infobulle').text());
				$(this).siblings('div.infobulle').slideUp('normal',
					function(){
						$(this).siblings('a').attr('title',$(this).siblings('a').attr('name'));
						$(this).remove();
					}
				);
				
			}
		);
		$('#footer div.int div a').click(function(){return false;});

	}
);

function debugJS() {
	
	/**
	 *	tabulation
	 */
	this.tabul			= '    ';
	
	/**
	 * fonctions
	 */
	this.dumpJS			= dumpJS;
	
	
	/**
	 *	@desc	decompose rÃ©cursivement un element
	 *	@param	mixed	elt		element a decomposer
	 *	@param	int		max		nombre maxi de recurances
	 *	@param	string	S_tab	suivi des tabulations
	 *	@param	int		rec		suivi de reccuression
	 */
	function dumpJS(elt, max, S_tab, rec) {
		if (max == undefined) {
			max = 2;	
			
		}
		rec++;
		var S_result	= '';
		if (elt == 'undefined') {
			return "undefined";
			
		}
		switch (typeof elt) {
			case 'object' : 
				S_result	+= "object {\n";
				if (rec < max) {
					for (myI in elt) {
						try {
							S_result += S_tab + this.tabul + '[' + myI + '] => ' 
							S_result += this.dumpJS(elt[myI], max, S_tab + this.tabul, rec);
							
						} catch (e) {
							S_result += S_tab + this.tabul + '[' + myI + '] => ' + "** ERROR **\n";
							
						}
						
					}
					
				} else {
					S_result += S_tab + this.tabul + "** MAX RECURSION **\n";	
					
				}
				S_result	+= S_tab + "}\n";
				break;
				
			case 'string' :
				S_result	+= typeof elt + ' "' + elt + "\"\n";
				break;
 
			default :
				S_result	+= typeof elt + '(' + elt + ")\n";
				break;
				
		}
		return S_result;
		
	}
	
}
 
___O_debugJS	= new debugJS();
/**
 *	@desc	decompose rÃ©cursivement un element et affiche une alerte
 *	@param	mixed	elt		element a decomposer
 *	@param	int		max		nombre maxi de recurances
 */
function alert_r(elt, max) {
	alert(___O_debugJS.dumpJS(elt, max, "", 0));	
	
}
 
/**
 *	@desc	decompose rÃ©cursivement un element et affiche dans le body
 *	@param	mixed	elt		element a decomposer
 *	@param	int		max		nombre maxi de recurances
 */
function document_r(elt, max) {
	document.write('<pre>');	
	document.write(___O_debugJS.dumpJS(elt, max, "", 0));	
	document.write('</pre>');	
	
}
 
 
/**
 *	@desc	decompose rÃ©cursivement un element et affiche une nouvelle fenetre
 *	@param	mixed	elt		element a decomposer
 *	@param	int		max		nombre maxi de recurances
 */
function window_r(elt, max) {
	win = window.open('', 'format','width=400,height=300,left=50,top=50,status,menubar,scrollbars,resizable');
	win.document.write('<pre>' + ___O_debugJS.dumpJS(elt, max, "", 0) + '</pre>');
	win.focus();	
	
}

