/* IE6 DISPLAY MESSAGE */
$(document).ready(function(){
	if(navigator.userAgent.indexOf("MSIE 6") != -1) {
		document.location.href="browser-update.html"
	}
});

/* MAIN NAVIGATION SLIDE UP/DOWN */
$(document).ready(function(){
    // 1. On cache les sous-menus
    $("ul.subNavigation").hide();
    // 2. On affiche ou masque le sous-menu
	$(".toggleSubNavigation").hover(
		function(){
			$(this).find("ul.subNavigation").show();
		},
		function(){
			$(this).find("ul.subNavigation").hide();
		}
	);   
});

/* SORTING SLIDE UP/DOWN */
$(document).ready(function(){
    // 1. On cache les sous-menus
    $("ul.sorting_criteria").hide();
    // 2. On affiche ou masque le sous-menu
	$(".toggleSorting").hover(
		function(){
			$(this).find("ul.sorting_criteria").slideDown();
		},
		function(){
			$(this).find("ul.sorting_criteria").slideUp();
		}
	);   
});

/* POP-IN DETAILS PAGE */
$(document).ready(function(){
	$(".link_to_detail a").nyroModal({
		padding:0,
		autoSizable: true,
		closeSelector: '.close-button'
	});
});

/* GIVER TABS */
$(document).ready(function(){
	$(".detailed_explanation").tabs();
});

/* GIFT CALCUTOR PRIVATE */
$(document).ready(function(){	
	$("#gift_calculator_private #calcutor_button").click(function(){
		var amount = $("#gift_calculator_private #gift_amount").val();
		var deduction = Math.floor((amount*2)/3);
		$("#gift_calculator_private #tax_deduction").val(deduction);
		$("#gift_calculator_private #real_costs").val(amount-deduction);
	});
});

/* GIFT CALCUTOR COMPANIES */
$(document).ready(function(){	
	$("#gift_calculator_companies #calcutor_button").click(function(){
		var amount = $("#gift_calculator_companies #gift_amount").val();
		var deduction = Math.floor((amount*6)/10);
		$("#gift_calculator_companies #tax_deduction").val(deduction);
		$("#gift_calculator_companies #real_costs").val(amount-deduction);
	});
});

/* KIDS TESTIMONIES TABS */
$(document).ready(function(){
	$(".kids_testimonies_list .toggle_link").click(
		function(){
			var that = this;
			if($(this).next("#kids_testimonies").css("display")=="none"){
				$(this).next("#kids_testimonies").slideDown("slow", function(){
					$(".kids_testimonies_list .toggle_link").text("Masquer tous les témoignages");
				});
			}
			else{
				$(this).next("#kids_testimonies").slideUp("slow", function(){
					$(".kids_testimonies_list .toggle_link").text("Voir tous les témoignages");
				});
			}
		}
	);
	$(".kids_testimonies_list .toggle_link").hover(
		function(){
			$(this).css({textDecoration:"none"});
		},
		function(){
			$(this).css({textDecoration:"underline"});
		}
	);
});

/* POP-IN CAROUSEL */
$(document).ready(function(){
	$("#carousel a").nyroModal({
		padding:0,
		autoSizable: true,
		closeSelector: '.close-button'
	});
});

/* POP-IN TESTIMONY PAGE */
$(document).ready(function(){
	$(".link_to_details a").nyroModal({
		padding:0,
		autoSizable: true,
		closeSelector: '.close-button'
	});
});

/* POP-IN CALENDAR */
$(document).ready(function(){
	$("a.calendar_event").nyroModal({
		padding:0,
		autoSizable: true,
		closeSelector: '.close-button'
	});
});

/* TESTIMONY SLIDER */
function testimonyDiaporama(){
	$(".testimony_box").stopTime();
	$(".testimony_box").everyTime(7500,function(){		
		testimonyNumber=((testimonyNumber+1) % 5);
		$(".testimony_box .content:visible").fadeOut("slow",function(){
			$("#testimony_"+(testimonyNumber+1)).fadeIn("slow");														 
		});			 
	});
}
testimonyNumber=0;
$(document).ready(function(){
	$(".testimony_box .content").hide();
	$(".testimony_box .content:first").show();	
	testimonyDiaporama();
	$(".testimony_box .navigation a").click( function(){
		$(".testimony_box").stopTime();
		$(".testimony_box").everyTime(30000,function(){
			testimonyDiaporama();
		});													
		var href = $(this).attr("href");
		var testimonyId = href.substring(1,href.length);
		testimonyNumber = href.charAt(href.length-1);
		$(".testimony_box .content:visible").fadeOut("slow",function(){
			$("#"+testimonyId).fadeIn("slow");														 
		});		
	});
});

/* POP-IN LEGAL MENTIONS PAGE */
$(document).ready(function(){
	$("#footer p a.popin").nyroModal({
		padding:0,
		autoSizable: true,
		closeSelector: '.close-button'
	});
});
