$(window).load(function() {
	$('#dialog').hide();
	$("img[name^='dessin']").each(function(){
		$(this).addClass($(this).attr('name').substr(7, 6));
		$(this).css("width",$('#accordion').width()*0.5);
	});
	if ($('#illustration img').attr('src')=='img/budget.suivre-mon-budget.png') {
		$('#suivre-mon-budget').liquidCanvas("[border{color:rgba(34, 148, 165, 0.95); width:1} gradient{from:rgba(34, 148, 165, 0.95); to:rgba(77, 45, 91, 0.95);}] => roundedRect{radius:10}");
	} else {
		$('#suivre-mon-budget').liquidCanvas("[gradient{from:rgba(34, 148, 165, 0.95); to:rgba(77, 45, 91, 0.95);}] => roundedRect{radius:10}");
	}
	if ($('#illustration img').attr('src')=='img/budget.maitriser-mon-budget.png') {
		$('#maitriser-mon-budget').liquidCanvas("[border{color:rgba(170, 202, 43, 1.0); width:1} gradient{from:rgba(170, 202, 43, 1.0); to:rgba(77, 45, 91, 0.95);}] => roundedRect{radius:10}");
	} else {
		$('#maitriser-mon-budget').liquidCanvas("[gradient{from:rgba(170, 202, 43, 1.0); to:rgba(77, 45, 91, 0.95);}] => roundedRect{radius:10}");
	}
	if ($('#illustration img').attr('src')=='img/budget.corriger-mon-budget.png') {
		$('#corriger-mon-budget').liquidCanvas("[border{color:rgba(186, 70, 240, 1.0); width:1} gradient{from:rgba(186, 70, 240, 1.0); to:rgba(77, 45, 91, 0.95);}] => roundedRect{radius:10}");
	} else {
		$('#corriger-mon-budget').liquidCanvas("[gradient{from:rgba(186, 70, 240, 1.0); to:rgba(77, 45, 91, 0.95);}] => roundedRect{radius:10}");
	}
	if (!$.browser.safari) $('#suivre-mon-budget').children('ul').fadeOut(0);
	if (!$.browser.safari) $('#maitriser-mon-budget').children('ul').fadeOut(0);
	if (!$.browser.safari) $('#corriger-mon-budget').children('ul').fadeOut(0);
	$('#suggestion').liquidCanvas("[border{color:rgba(255, 255, 255, 0.5); width:1} fill{color:rgba(255, 255, 255, 0.1)}] => roundedRect{radius:10}");
	$('#liens').liquidCanvas("[border{color:rgba(255, 255, 255, 0.5); width:1} fill{color:rgba(255, 255, 255, 0.1)}] => roundedRect{radius:10}");
	$('#nav-gauche').liquidCanvas("[border{color:rgba(255, 255, 255, 0.5); width:1} fill{color:rgba(255, 255, 255, 0.1)}] => ecken{tl:10; bl:10; br:0; tr:0}");
	$('#nav-droite').liquidCanvas("[border{color:rgba(255, 255, 255, 0.5); width:1} fill{color:rgba(255, 255, 255, 0.1)}] => ecken{tl:0; bl:0; br:10; tr:10}");
	$('#cigale-ou-fourmi').liquidCanvas("[border{color:rgba(255, 255, 255, 0.5); width:1} fill{color:rgba(255, 255, 255, 1.0)}] => roundedRect{radius:10}");
	$('#cadre').liquidCanvas("[border{color:rgba(255, 255, 255, 0.3); width:2} fill{color:rgba(255, 255, 255, 0.5)}] => roundedRect{radius:10}");
	$('.intro').liquidCanvas("[border{color:rgba(255, 204, 102, 0.8); width:1} fill{color:rgba(255, 204, 102, 0.1)}] => roundedRect{radius:5}");
	$('#nav-gauche').hover(
	   function(){
	   		$(this).stop().animate({right: '10px'},{queue: false, duration: 350});
	}, function(){
	   		$(this).stop().animate({right: '0px'},{queue: false, duration: 0});
	});
	$('#nav-droite').hover(
	   function(){
	   		$(this).stop().animate({left: '10px'},{queue: false, duration: 350});
	}, function(){
	   		$(this).stop().animate({left: '0px'},{queue: false, duration: 0});
	});
	$('#suivre-mon-budget').hover(
    	function(){
    	//$('.dummy').hide();
    	$(this).css('cursor','pointer');
        $(this).stop().animate(
            {height: '192px'},
            {queue: false,
            duration: 300,
            easing: 'easeOutBounce'});
        if (!$.browser.safari) $(this).children('ul').fadeIn(1500);
	}, function(){
    	//$('.dummy').hide();
        $(this).stop().animate(
            {height: '12px'},
            {queue: false,
            duration: 600,
            easing: 'easeOutBounce'});
        if (!$.browser.safari) $(this).children('ul').fadeOut(25);
	});

	$('#maitriser-mon-budget').hover(
    	function(){
    	//$('.dummy').hide();
    	$(this).css('cursor','pointer');
        $(this).stop().animate(
            {height: '329px'},
            {queue: false,
            duration: 300,
            easing: 'easeOutBounce'});
        //$(this).children('ul')
        if (!$.browser.safari) $(this).children('ul').fadeIn(1500);
	}, function(){
    	//$('.dummy').hide();
        $(this).stop().animate(
            {height: '12px'},
            {queue: false,
            duration: 600,
            easing: 'easeOutBounce'});
        if (!$.browser.safari) $(this).children('ul').fadeOut(25);
	});
	
	$('#corriger-mon-budget').hover(
    	function(){
    	//$('.dummy').hide();
    	$(this).css('cursor','pointer');
        $(this).stop().animate(
            {height: '382px'},
            {queue: false,
            duration: 300,
            easing: 'easeOutBounce'});
        if (!$.browser.safari) $(this).children('ul').fadeIn(1500);
	}, function(){
    	//$('.dummy').hide();
        $(this).stop().animate(
            {height: '12px'},
            {queue: false,
            duration: 600,
            easing: 'easeOutBounce'});
        //$(this).children('ul').hide(0)
        if (!$.browser.safari) $(this).children('ul').fadeOut(25);
	});
});
   
$(document).ready(function(){
	$("#accordion").accordion({ autoHeight: false, active: false, clearStyle: true, collapsible: true, fillSpace: true });
	if ($("#accordion > h3").length==1) {
		$("#accordion").accordion("activate", 0);
	}
	$("a[href^='http://']").not("a[href*='fastt.org']").click(function(){ 
		window.open(this.href,'external'); 
		return false; 
	});
	$("a[href^='https://']").click(function(){ 
		window.open(this.href,'external'); 
		return false; 
	});

	$(".sheet").each(function() {
		var id=$(this).attr("name");
		$.ajax
		({
		type: "GET",
		url: "sheet.php",
		data: "id="+id,
		cache: false,
		success: function(result)
		{
			$(".sheet[name="+id+"]").html(result);
		}
		});
	});
	
	$("a.bulle").each(function() {
		var id=$(this).attr("rel");
		$.ajax
		({
		type: "POST",
		url: "lexique.php",
		data: "id="+id,
		cache: false,
		success: function(result)
		{
			$("a.bulle[rel="+id+"]").qtip({
				content: {
					text: result
				},
				show: 'mouseover',
				hide: 'mouseout', 
				style: { 
					name: 'cream', 
					tip: true 
				}
			});
		}
		});
	});
	
	$('#rubrique a[rel=lightbox]').lightBox();
	$('#rubrique a[rel=lightbox2]').lightBox();
	
	$('#valider').click( function(){ if (typeof($('input[type=radio][name=q1]:checked').attr('value'))=='undefined') { dialogue('Avertissement','Veuillez s\'il vous plaît répondre à la question 1'); return; } if (typeof($('input[type=radio][name=q2]:checked').attr('value'))=='undefined') { dialogue('Avertissement','Veuillez s\'il vous plaît répondre à la question 2'); return; } if (typeof($('input[type=radio][name=q3]:checked').attr('value'))=='undefined') { dialogue('Avertissement','Veuillez s\'il vous plaît répondre à la question 3'); return; } if (typeof($('input[type=radio][name=q4]:checked').attr('value'))=='undefined') { dialogue('Avertissement','Veuillez s\'il vous plaît répondre à la question 4'); return; } if (typeof($('input[type=radio][name=q5]:checked').attr('value'))=='undefined') { dialogue('Avertissement','Veuillez s\'il vous plaît répondre à la question 5'); return; } if (typeof($('input[type=radio][name=q6]:checked').attr('value'))=='undefined') { dialogue('Avertissement','Veuillez s\'il vous plaît répondre à la question 6'); return; } if (typeof($('input[type=radio][name=q7]:checked').attr('value'))=='undefined') { dialogue('Avertissement','Veuillez s\'il vous plaît répondre à la question 7'); return; } if (typeof($('input[type=radio][name=q8]:checked').attr('value'))=='undefined') { dialogue('Avertissement','Veuillez s\'il vous plaît répondre à la question 8'); return; } var total = parseInt($('input[type=radio][name=q1]:checked').attr('value')) + parseInt($('input[type=radio][name=q2]:checked').attr('value')) + parseInt($('input[type=radio][name=q3]:checked').attr('value')) + parseInt($('input[type=radio][name=q4]:checked').attr('value')) + parseInt($('input[type=radio][name=q5]:checked').attr('value')) + parseInt($('input[type=radio][name=q6]:checked').attr('value')) + parseInt($('input[type=radio][name=q7]:checked').attr('value')) + parseInt($('input[type=radio][name=q8]:checked').attr('value')) ; if (total<6) { dialogue("Résultat du test : dépensier", "Vous dégainez votre carte bleue facilement. Vous dépensez selon vos envies sans vous soucier des fins de mois difficiles. Etre dans le rouge ne vous inquiète pas, même si cela peut vous coûter cher. "); } else if (total>11) { dialogue("Résultat du test: très économe", "Il n'y a pas de petites économies pour vous. Vous épluchez vos comptes au centime près et tenez les cordons de la bourse d'une main de fer. Vous faites la chasse aux gaspis et êtes à l'affût des bons plans pour économiser. Vous épargnez autant que possible pour protéger vos arrières et réaliser vos projets. "); } else { dialogue("Résultat du test : bon gestionnaire", "Vous surveillez votre compte en banque régulièrement pour éviter les découverts. Vous êtes plutôt prévoyant, en cas de coup dur vous avez un peu d'épargne pour faire face. Vous savez aussi vous faire plaisir une fois que les dépenses obligatoires sont assurées. "); }  } );
	
});

function dialogue(titre, message, largeur, hauteur) {
	if (!largeur) largeur = 320;
	if (!hauteur) hauteur = 150;
	$('#dialog').dialog({
		bgiframe: true,
		width: largeur, 
		height: hauteur,
		modal: true,
		title: titre, 
		close: function() {$(this).dialog('destroy');}
	});	
	if (message.length>0) $("#dialog").text(message);
	$("#dialog").dialog('open');
}

