jQuery(document).ready(function(){
	idtgv.init();
	/*checkFaqQuestionForm();*/
});

jQuery(window).bind("resize", function(){
	idtgv.cssFixedIE6();
});


var idtgv = {
	init: function(){
		idtgv.cssFixedIE6();
		idtgv.sizeFooter(".footer", "#flashTrainClosed");
		idtgv.nav();
		idtgv.flashs();
		idtgv.lng();
		idtgv.reservation.init();
		idtgv.myiDTGV.init();
		idtgv.schedules.init();
		idtgv.faq.init();
		idtgv.register.init();
		idtgv.coloring.init();
		idtgv.labels.init();
		idtgv.activities.init();
		idtgv.partners.init();
		idtgv.common();
		idtgv.popin();
		idtgv.addComment();
	},
	cssFixedIE6: function(){
		if( jQuery.browser.msie && jQuery.browser.version.substr(0,1) == "6" && jQuery("#fixed").size() == 0 ){ // only IE6
			if(jQuery("#fakeBody").size() == 0){
				var fakeBody = document.createElement("div");
				jQuery(fakeBody).attr({ id: "fakeBody" });
				jQuery("#containerMain").wrap(fakeBody);
			}
			
			setTimeout(function(){
				jQuery("#fakeBody").css({ height: jQuery(window).height() + "px" });
				jQuery("#footerContainer").css({ width: (jQuery("#containerMain").width()) + "px" });
			}, 100);
		}
	},
	nav: function(){
		if( jQuery(".mainHome").size() > 0 ){ // only homepage
			var logged = jQuery(".logged").size() > 0 ? true : false;
			
			if(logged){
				jQuery(".nav a").hover(function(){
					// Hide default visible
					jQuery(".nav1 a, .nav2 a").removeClass("on");
					if(!jQuery(this).next("img").is(":visible")) jQuery(".bulle1:visible, .bulle2:visible").fadeOut(200);
					
					active = jQuery(this).attr("rel");
					if( jQuery("." + active).is(":hidden") ) jQuery("." + active).fadeIn(200);
				},
				function(){
					jQuery(".bulle1, .bulle2").fadeOut(200);
				});
				
				jQuery(".pictureUser").hover(function(){
					jQuery(".bulle3").show();
				},
				function(){
					jQuery(".bulle3").fadeOut(200);
				});
			} else {
				jQuery(".nav a").hover(function(){
					// Hide default visible
					jQuery(".nav a").removeClass("on");
					if(!jQuery(this).next("img").is(":visible")) jQuery(".nav img:visible").fadeOut(200);
					
					active = jQuery(this).attr("rel");
					if( jQuery("." + active).is(":hidden") ) jQuery("." + active).fadeIn(200);
				},
				function(){
					if( jQuery("." + active).is(":visible") ) jQuery("." + active).fadeOut(200);
				});
			}
		}
	},
	sizeFooter: function(el1, el2){
		var height1 = jQuery(el1).height();
		var height2 = jQuery(el2).height();
		
		jQuery("#footerContainer").css({ height: (height1+height2) + "px" });
        /* add Yanlep pour le Toy */
        var toyBot = 64;
        if(height2 >= 70)
            toyBot = 99;
		jQuery("#fixed #flashToy").css({ bottom: toyBot + "px" });
	},
	flashs: function(){
        // open on homepage
		if(jQuery(".mainHome").size() > 0) idtgv.actionFlashTrain("open");
		// #22440
		if(jQuery("#hiddenReserver").size() == 0) idtgv.actionFlashTrain("open");
		
		jQuery("#flashTrainClosed a").click(function(){
			idtgv.actionFlashTrain("open");
			return false;
		});
	},
	actionFlashTrain: function(action){
		switch(action){
			case "open":
				jQuery("#flashTrainContainer").css({ left: 0 });
				idtgv.sizeFooter(".footer", "#flashTrainContainer");
				break;
			case "close":
				jQuery("#flashTrainContainer").css({ left: "-9999px" });
				idtgv.sizeFooter(".footer", "#flashTrainClosed");
				break;
		}
	},
	lng: function(){
		jQuery(".lng p a").click(function(){
			( jQuery(".lng ul").is(":hidden") ) ? jQuery(".lng ul").show() : jQuery(".lng ul").hide();
			return false;
		});
	},
	reservation: {
		init: function(){
			if(jQuery(".events, .destinations").size() < 2) return false;
			
			jQuery(".events ul, .destinations ul").prepend( document.createElement("li") );
			jQuery(".events ul, .destinations ul").append( jQuery( document.createElement("li") ).addClass("last") );
			
			jQuery(".events ul, .destinations ul").jcarousel({
				vertical: true,
				scroll: 1,
				start: 1,
				initCallback: idtgv.reservation.callback,
				itemFirstInCallback: idtgv.reservation.update
			});
		},
		callback: function(carousel) {
			jQuery("li a", carousel.clip).css({ display: "block" });
			
			var old = 0;
			
			if( jQuery(carousel.container).parent().get(0).className == "events" ){
				jQuery("li a", carousel.clip).bind("click", function(){
					href = jQuery(this).attr("href");
					
					carousel.scroll(jQuery.jcarousel.intval( href.split("#")[1] ));
					
					jQuery(".popupContainer .close").click(function(){
						jQuery(".popupContainer .jScrollPaneContainer:visible, .popupContainer").fadeOut();
						
						jQuery("#flashResa").show();
						old = 0;
						return false;
					});
					
					if( jQuery(this).parent().hasClass("current") ){
						current = href.split("#")[1];
						
						if(old != current){
							if( jQuery(".popupContainer .jScrollPaneContainer").is(":visible") ){
								jQuery(".popupContainer .jScrollPaneContainer:visible").fadeOut(function(){
									jQuery(".popupContainer").fadeIn(500);
									jQuery("#popup" + current).parent(".jScrollPaneContainer").fadeIn(500);
									jQuery("#popup" + current).fadeIn(500, function(){ idtgv.reservation.bindScrollPane(this); });
								});
							} else {
								jQuery(".popupContainer").fadeIn(500);
								jQuery("#popup" + current).parent(".jScrollPaneContainer").fadeIn(500);
								jQuery("#popup" + current).fadeIn(500, function(){ idtgv.reservation.bindScrollPane(this); });
							}
						}
						
						jQuery("#flashResa").hide();
						
						old = current;
					}
									
					return false;
				});
			}
		},
		update: function(carousel, item, idx, state) {
			// Bad height on init
			setTimeout(function(){
				jQuery("ul", carousel.clip).css({ height: "auto" });
				jQuery("ul", carousel.clip).css({ height: jQuery("ul", carousel.clip).height() + "px" });
				
				carousel.reload();
			}, 50);
			
			jQuery("li", carousel.clip).removeClass("current");
			jQuery("li .picture", carousel.clip).hide();
			jQuery("li .imgTitle", carousel.clip).css({ display: "inline" });
			jQuery("li .imgTitleOn", carousel.clip).hide();
			
			jQuery(item).next("li").addClass("current");
			jQuery(item).next("li").find(".picture").show();
			jQuery(item).next("li").find(".imgTitle").hide();
			jQuery(item).next("li").find(".imgTitleOn").show().css({ display: "inline" });
			
			idtgv.reservation.handlePNGIE6(item);
		},
		handlePNGIE6: function(item){
			if( jQuery.browser.msie && jQuery.browser.version.substr(0,1) == "6" ){ // only IE6 - handle PNG
				var elt = jQuery(item).next("li").find(".imgTitleOn").get(0);
				
				if(elt.pngsrc){
					var pngsrc = elt.pngsrc;
					pngsrc = pngsrc.replace("_off","_on");
					
					var nextImage = new Image();
					nextImage.src = pngsrc;
					
					elt.style.width = nextImage.width;
					elt.style.height = nextImage.height;
					elt.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+pngsrc+"',sizingMethod='crop')";
				}
			}
		},
		bindScrollPane: function(elt){
			jQuery(elt).jScrollPane({ scrollbarWidth: 9, dragMinHeight: 43, dragMaxHeight: 43 });
		}
	},
	myiDTGV: {
		init: function(){
			idtgv.myiDTGV.pictureUser();
			
			jQuery(".account .carousel ul").jcarousel({
				scroll: 1,
				initCallback: idtgv.myiDTGV.callback
			});
			
			idtgv.myiDTGV.ideas();
			
			jQuery("#colLeft .navLeft, #colRight .block1 .block, #colRight .blockIdeas .ideaText, .ideas .item .text, .register .form .wrap, .account .blockPostID .wrap, .faq-v2 #colCenter .list, .faq-v2 #colCenter .details").roundCorners({ classTop: "blockTop", classBottom: "blockBottom" });
			jQuery("#colLeft .navLeft li").roundCorners({ classTop: "top", classBottom: "bottom" });
			
			jQuery("#colLeft .loginBox iframe").attr({ allowTransparency: true });
			
			jQuery("#colRight textarea").prettyComments({ animate: true });
		},
		pictureUser: function(){
			if( jQuery(".nav .nav3 .pictureUser").size < 1 ) return false;
			
			currentLink = jQuery(".nav .nav3 a:eq(0)").attr("href");
			jQuery(".nav .nav3 .pictureUser").append('<a href="' + currentLink + '"></a><span></span>').css({ visibility: "visible" });
		},
		callback: function(carousel){
			jQuery("ul", carousel.clip).css({ visibility: "visible" });
			jQuery("li", carousel.clip).each(function(){
				currentLink = jQuery("a:eq(0)", this).attr("href");
				jQuery(this).append('<a href="' + currentLink + '" class="link"></a><span></span>')
			});
		},
		ideas: function(){
			jQuery("#colRight .blockIdeas .listNum a").click(function(){
  				numToShow = jQuery(this).text();
				
				jQuery("#colRight .blockIdeas .listNum a").removeClass("on");
				jQuery("#colRight .blockIdeas .listNum .idea" + numToShow + " a").addClass("on");
				
				jQuery("#colRight .blockIdeas .item").hide();
				jQuery("#colRight .blockIdeas #item" + numToShow).show();
				
				return false;
			});
		}
	},
	schedules: {
		init: function(){
			if( jQuery(".schedules").size() > 0 ){
				var maxWidth = 0;
				
				jQuery(".schedules h3").each(function(){
					if( jQuery("span:eq(0)", this).width() > maxWidth )
						maxWidth = jQuery("span:eq(0)", this).width();
				});
				
				jQuery(".schedules h3").css({ backgroundPosition: (maxWidth+34) + "px 6px" });
				jQuery(".schedules h3 span:eq(0)").css({ width: maxWidth + "px" });
			}
		}
	},
	faq: {
		init: function(){
			idtgv.faq.menu();
			setTimeout("idtgv.faq.stars()", 1000);
			//idtgv.faq.stars();
			
			jQuery(".faq #colCenter li, .faq #colCenter .others").roundCorners({ classTop: "top", classBottom: "bottom" });
			
			var valDefault = "";
			
			jQuery(".search input:eq(0)")
				.bind("click", function(){
					if(valDefault == "") valDefault = jQuery(this).val();
					if( jQuery(this).val() == valDefault ) jQuery(this).val('').removeClass("inputTextIcon");
				})
				.bind("blur", function(){
					if( jQuery(this).val() == "" ){
						jQuery(this).val(valDefault);
						
						if( !jQuery(this).hasClass("currentSearch") )
							jQuery(this).addClass("inputTextIcon");
					}
				});
			
			jQuery(".faq #colLeft .navLeft .content ul").not(".noCarousel").jcarousel({
				scroll: 1,
				vertical: true
			});
		},
		tools: function(details){
			if( jQuery(".tools", details).size() > 0 ){
				jQuery(".tools a:eq(0)", details).click(function(){
					window.print();
					return false;
				});
				
				jQuery(".tools a:eq(1)", details).click(function(){
					details.animate({ height: "toggle" }, 500);
					return false;
				});
			}
		},
		menu: function(){
			jQuery("#containerMain .faq-v2 #colLeft ul.noCarousel > li > a").not( jQuery("#containerMain .faq-v2 #colLeft ul.noCarousel > li.first > a") ).click(function(){

				if( jQuery(this).parent("li").hasClass("current") ){
					jQuery(this).parent("li").removeClass("current");
				}else{
					jQuery(this).parent("li").addClass("current");
				}
/*
				jQuery("#containerMain .faq-v2 #colLeft ul.noCarousel > li").removeClass("current");
				jQuery(this).parent("li").addClass("current");
*/
				return false;
			});
		},
		stars: function(){
			if (jQuery(".starsHover a img").size() > 0) { initRatingStars = idtgv_tools.ratingStars(".starsHover"); }
		}
	},
	register: {
		init: function(){
			if( jQuery("#colCenter .form form").size() > 0 ){
				if(typeof idtgv_validate == "function")
					idtgv_validate("#colCenter .form form");
			}
		}
	},
	coloring: {
		init: function(){
			if( jQuery(".coloring").size() > 0 ){
				idtgv.coloring.resetOpacity(":eq(0)");
				/*jQuery(".coloring .print").show();*/
				
				jQuery(".coloring #colCenter ul a").click(function(){
					idtgv.coloring.resetOpacity("");
					jQuery("img", this).css({ opacity: 1 });
					jQuery("#pictureBig").attr({ src: jQuery(this).attr("href") });
					return false;
				});
			}
		},
		resetOpacity: function(except){
			jQuery(".coloring #colCenter ul img").not(except).css({ opacity: 0.5 });
		}
	},
	labels: {
		init: function(){
			if( jQuery(".labels").size() > 0 ){
				/*jQuery(".labels .print").show();*/
				
				jQuery(".form input:text").bind("blur", function(){
					idtgv.labels.writeLabel(this);
				});
				jQuery(".form input:radio").bind("click", function(){
					idtgv.labels.writeLabel(this);
				});
				
				jQuery(".labelsList input").click(function(){
					jQuery(".labelPictureBig").attr({ src: jQuery(this).val() });
					idtgv.hackPNGIE6( jQuery(".labelPictureBig") );
				});
			}
		},
		writeLabel: function(elt){
			switch( jQuery(elt).attr("name") ){
				case "civility":
					jQuery(".labelBig span:eq(0)").html( jQuery(elt).val() );
					break;
				case "lastname":
					jQuery(".labelBig span:eq(1)").html( jQuery(elt).val() );
					break;
				case "firstname":
					jQuery(".labelBig span:eq(2)").html( jQuery(elt).val() );
					break;
				case "address":
					jQuery(".labelBig span:eq(3)").html( jQuery(elt).val() );
					break;
				case "city":
					jQuery(".labelBig span:eq(4)").html( jQuery(elt).val() );
					break;
				case "country":
					jQuery(".labelBig span:eq(5)").html( jQuery(elt).val() );
					break;
			}
		}
	},
	activities: {
		init: function(){
			if( jQuery("#mapActivities").size() > 0 ){
				imgOriginal = jQuery("#pictureActivities").attr("src");
				idtgv.activities.preload(imgOriginal);
				idtgv.activities.bind(imgOriginal);
			}
		},
		preload: function(img){
			for(i=2; i<7; i++){
				preload = new Image();
				preload.src = img.replace("_1", "_" + i);
			}
		},
		bind: function(img){
			jQuery("#mapContes,#mapSudoku,#mapAudioguides,#mapEtiquettes,#mapColoriages").each(function(i){
				jQuery(this).mouseover(function(){
					jQuery("#pictureActivities").attr({ src: img.replace("_1", "_" + (i+2)) });
				},
				function(){
					jQuery("#pictureActivities").attr({ src: img });
				});
			});
		}
	},
	partners: {
		init: function(){
			if( jQuery(".partners").size() > 0 ){
				jQuery(".partners .cols .block .content").sameHeight();
			}
		}
	},
	altFlashs: function(obj){
		// Flash "reservation"
		if(jQuery("#flashResa").size() > 0){
		
            jQuery("#resaBack").show(); 
		
			jQuery("#resa_date_depart, #resa_date_retour").datePicker();
			jQuery("#resa_date_depart").dpSetRenderCallback(function($td, thisDate, month, year)
			{
				var d = thisDate.getDate();	
				d = d < 10 ? "0" + d : d;							
				var m = (Number(month)+1) < 10 ? "0" + (Number(month)+1) : (Number(month)+1);
				$td.unbind("click").bind("click", function(){									
					jQuery("#resa_date_depart").val(d + "/" + m + "/" + year);
					jQuery("#resa_date_depart_day_hidden").val(d);
					jQuery("#flashResa input[name='AvailabilitySearchInputSearchView$DropDownListMarketDay1']").val(d);
					jQuery("#resa_date_depart_month_year_hidden").val(year + "-" + m);
					jQuery("#flashResa input[name='AvailabilitySearchInputSearchView$DropDownListMarketMonth1']").val(year + "-" + m);
					jQuery("#resa_date_depart").dpClose();
				});
			});
			
			jQuery("#resa_date_retour").dpSetRenderCallback(function($td, thisDate, month, year)
			{
				var d = thisDate.getDate();
				d = d < 10 ? "0" + d : d;
				
				var m = (Number(month)+1) < 10 ? "0" + (Number(month)+1) : (Number(month)+1);
				$td.unbind("click").bind("click", function(){
					jQuery("#resa_date_retour").val(d + "/" + m + "/" + year);
					jQuery("#resa_date_retour_day_hidden").val(d);
					jQuery("#resa_date_retour_month_year_hidden").val(year + "-" + m);
					
					jQuery("#flashResa input[name='AvailabilitySearchInputSearchView$DropDownListMarketDay2']").val(d);	
					jQuery("#flashResa input[name='AvailabilitySearchInputSearchView$DropDownListMarketMonth2']").val(year + "-" + m);
					
					jQuery("#resa_date_retour").dpClose();
				});
			});
			
			jQuery(".choice input:eq(1)").click(function(){
				jQuery("#resaBack").hide();
				jQuery("#flashResa input[name='AvailabilitySearchInputSearchView$RadioButtonMarketStructure']").val('OneWay');
			});
			
			jQuery(".choice input:eq(0)").click(function(){
				jQuery("#resaBack").show();
				jQuery("#flashResa input[name='AvailabilitySearchInputSearchView$RadioButtonMarketStructure']").val('RoundTrip');
			});
			
			if(typeof(obj) == "object" && obj.resaConfigXML != ""){
				jQuery.ajax({
					type: "POST",
					url: obj.resaConfigXML,
					dataType: "xml",
					data: "",
					success: function(xml){
						var link = jQuery.trim( jQuery("link", xml).text() );
						var label_titre = jQuery.trim( jQuery("label_titre", xml).text() );
						var label_resa = jQuery.trim( jQuery("label_resa", xml).text() );
						var label_as = jQuery.trim( jQuery("label_as", xml).text() );
						var label_ar = jQuery.trim( jQuery("label_ar", xml).text() );
						var ville_depart = jQuery.trim( jQuery("ville_depart", xml).text() );
						var ville_destination = jQuery.trim( jQuery("ville_destination", xml).text() );
						var promp = jQuery.trim( jQuery("promp", xml).text() );
						var label_depart = jQuery.trim( jQuery("label_depart", xml).text() );
						var label_retour = jQuery.trim( jQuery("label_retour", xml).text() );
						var label_pass = jQuery.trim( jQuery("label_pass", xml).text() );
						var pass = jQuery.trim( jQuery("pass", xml).text() );
						var flex = jQuery.trim( jQuery("flex", xml).text() );
						var option = "";
						
						jQuery("#flashResa form").attr({ action: link });
						jQuery("#flashResa form label[for='resa_from']").html(ville_depart);
						jQuery("#flashResa form label[for='resa_to']").html(ville_destination);
						jQuery("#flashResa form label[for='resa_date_depart']").html(label_depart);
						jQuery("#flashResa form label[for='resa_date_retour']").html(label_retour);
						jQuery("#flashResa form label[for='resa_passengers']").html(label_pass);
						jQuery("#flashResa .radio label:eq(1)").html(label_as);
						jQuery("#flashResa .radio label:eq(0)").html(label_ar);
						for(i=1; i<(parseInt(pass)+1); i++){ option += "<option value=\"" + i + "\">" + i + "</option>" }
						jQuery("#flashResa form #resa_passengers").html(option);
					}
				});
			}
			
			if(typeof(obj) == "object" && obj.resaVillesXML != ""){
				jQuery.ajax({
					type: "POST",
					url: obj.resaVillesXML,
					dataType: "xml",
					data: "",
					success: function(xml){
						var option = "<option value=\"0\"></option>";
						var destination = [];
						
						jQuery("ville", xml).each(function(i){
							city = jQuery.trim( jQuery(this).attr("nom") );
							city = jQuery.ucFirst(city);
							cityCode = jQuery.trim( jQuery(this).attr("code") );
							option += "<option value=\"" + cityCode + "\">" + city + "</option>";
							
							destination[i] = [];
							
							jQuery("destination", this).each(function(j){
								destination[i][j] = [jQuery(this).attr("nom"), jQuery(this).attr("code")];
							});
						});
						
						jQuery("#flashResa form #resa_from").html(option);
						
						jQuery("#flashResa form #resa_from").change(function(){
							jQuery("#flashResa input[name='AvailabilitySearchInputSearchView$TextBoxMarketOrigin1'], #flashResa input[name='AvailabilitySearchInputSearchView$TextBoxMarketDestination2']").val( jQuery(this).val() );
							
							currentIndex = jQuery(this)[0].selectedIndex;
							
							if(currentIndex > 0){
								currentIndex = currentIndex - 1;
								
								var option = "<option value=\"0\"></option>";
								
								for(i=0; i<destination[currentIndex].length; i++)
									option += "<option value=\"" + destination[currentIndex][i][1] + "\">" + destination[currentIndex][i][0] + "</option>";
								
								jQuery("#flashResa form #resa_to").html(option);
							}
						});
						
						jQuery("#flashResa form #resa_to").change(function(){
							jQuery("#flashResa input[name='AvailabilitySearchInputSearchView$TextBoxMarketDestination1'], #flashResa input[name='AvailabilitySearchInputSearchView$TextBoxMarketOrigin2']").val( jQuery(this).val() );
						});
						
						jQuery("#flashResa form #resa_passengers").change(function(){
							jQuery("#flashResa input[name='AvailabilitySearchInputSearchView$DropDownListPassengerType_ADT']").val( jQuery(this).val() );
						});
						
						var handleError = function(elt){
							jQuery(elt).prev("label").addClass("msgError");
							jQuery(elt).addClass("msgError");
							return true;
						};
						
						jQuery("#flashResa form").submit(function(){
							var error = false;
							
							jQuery("#flashResa form input, #flashResa form select, #flashResa form label").removeClass("msgError");
							
							if( jQuery("#flashResa form #resa_from").val() == 0 ) error = handleError("#flashResa form #resa_from");
							if( jQuery("#flashResa form #resa_to").val() == 0 ) error = handleError("#flashResa form #resa_to");
							
							var regDate = new RegExp("^[0-9]{2}\/[0-9]{2}\/[0-9]{4}$");
							var start = jQuery("#flashResa form #resa_date_depart").val();
							
							if( start == "" ) error = handleError("#flashResa form #resa_date_depart");
							else if( !regDate.test(start) ) error = handleError("#flashResa form #resa_date_depart");
							
							if( jQuery("#resaBack").is(":visible") ){
								var end = jQuery("#flashResa form #resa_date_retour").val();
								
								if( end == "" ) error = handleError("#flashResa form #resa_date_retour");
								else if( !regDate.test(end) ) error = handleError("#flashResa form #resa_date_retour");
							}
							
							return error ? false : true;
						});
						
						jQuery("#flashResa .altFlash").show();
						jQuery(".altFlashPlayer").show();
					}
				});
			}
		}
		
		// Flash "train de l'info"
		if(jQuery("#flashTrainContainer").size() > 0){
			jQuery("#flashTrainContainer .altFlash .close").click(function(){
				idtgv.actionFlashTrain("close");
				return false;
			});
			
			if(typeof(obj) == "object" && obj.trainImgPath != "" && obj.trainXML != ""){
				jQuery.ajax({
					type: "POST",
					url: obj.trainXML,
					dataType: "xml",
					data: "",
					success: function(xml){
						var str = "<ul>";
						
						jQuery("bloc", xml).each(function(){
							img = jQuery.trim( jQuery("url", this).text() );
							url = jQuery.trim( jQuery("link", this).text() );
							str += '<li><a href="' + url + '" target="_blank"><img src="' + img + '" alt="" class="hack-png" /></a></li>';
						});
						
						str += "</ul>";
						
						if(jQuery("#flashTrainContainer .altFlash ul").size() > 0) jQuery("#flashTrainContainer .altFlash ul").remove();
						
						jQuery("#flashTrainContainer .altFlash").prepend(str);
						
						heightVal = jQuery("#flashTrainContainer .altFlash").css("height");
						
						jQuery("#flashTrainContainer .altFlash").css({ height: "0" }).show(function(){
							jQuery("#flashTrainContainer .altFlash img[src*='.png']").each(function(){
								idtgv.hackPNGIE6(this);
							});
							
							jQuery(this).css({ height: heightVal });
						});
					}
				});
			}
		}
		
		// Flash "toy aide"
		if(jQuery("#flashToy").size() > 0){
			jQuery("#flashToy .altFlash a").hover(function(){
				current = jQuery(this)[0].className.split("help")[1];
				
				jQuery(".txt" + current).show();
			},
			function(){
				jQuery("#flashToy .altFlash div").hide();
			});
			
			if(typeof(obj) == "object" && obj.toyXML != ""){
				jQuery.ajax({
					type: "POST",
					url: obj.toyXML,
					dataType: "xml",
					data: "",
					success: function(xml){
						jQuery("#flashToy .altFlash a").each(function(i){
							url = jQuery("picto" + (i+1) + " > lien", xml).text();
							jQuery(this).attr({ href: url });
						});
						
						jQuery("#flashToy .altFlash").show();
					}
				});
			}
		}
	},
	hackPNGIE6: function(item){
		if( jQuery.browser.msie && jQuery.browser.version.substr(0,1) == "6" ){ // only IE6 - handle PNG
			var elt = jQuery(item).get(0);
			var pngsrc = elt.src;
			
			elt.style.width = elt.clientWidth;
			elt.style.height = elt.clientHeight;
			elt.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+pngsrc+"',sizingMethod='crop')";
			
			elt.setAttribute("src", pathImgPix);
		}
	},
	popin: function(){
		// opens the popin
		jQuery(".popin a").click(function(){
			href = jQuery(this).attr("href");
			var current = href.split("#")[1];
						
			if(current){
				jQuery("#popin" + current).show();
				jQuery("#popin" + current).parent(".popupContainer").fadeIn(500);
			}
									
			return false;
		});
		
		// closes the popin
		jQuery(".popupContainer .close").click(function(){
			jQuery(".popupContainer").fadeOut();
			jQuery(".popupContainer .content").hide();
			return false;
		});	
	},
	popupClose: function(elt){
		jQuery(".close", elt).click(function(){
			jQuery(elt).fadeOut();
			return false;
		});
	},
	common: function(){
		correctpng = PNGHack(pathImgPix);
		correctpng.hackClass();
		
		jQuery("#colCenter .block").roundCorners({ classTop: "blockTop", classBottom: "blockBottom" });
		
		// Avoid background flickering
		try { document.execCommand('BackgroundImageCache', false, true); } catch(e) {}
		
		jQuery(".swapValue").toggleVal();
		
		if( jQuery(".popupContainerSmall").size() > 0 && jQuery(".popupContainerSmall").is(":visible") && jQuery("#popupAddTrainConfirm").size() < 1 ){
			idtgv.popupClose(".popupContainerSmall");
			jQuery(".popupContainerSmall form").jScrollPane({ scrollbarWidth: 9, dragMinHeight: 43, dragMaxHeight: 43 });
		}
		
		if( jQuery(".popupContainerBig").size() > 0 && jQuery(".popupContainerBig").is(":visible") ){
			idtgv.popupClose(".popupContainerBig");
			jQuery(".popupContainerBig form").jScrollPane({ scrollbarWidth: 9, dragMinHeight: 43, dragMaxHeight: 43 });
		}
		
		if( jQuery(".popupContainerError").size() > 0 && jQuery(".popupContainerError").is(":visible") ){
			idtgv.popupClose(".popupContainerError");
			jQuery(".popupContainerError .msg").jScrollPane({ scrollbarWidth: 9, dragMinHeight: 43, dragMaxHeight: 43 });
		}
	},
	print_r: function(theObj){
		if(theObj.constructor == Array || theObj.constructor == Object){
			document.write("<ul>")
			for(var p in theObj){
				if(theObj[p].constructor == Array||
					theObj[p].constructor == Object){
					document.write("<li>["+p+"] => "+typeof(theObj)+"</li>");
					document.write("<ul>")
					idtgv.print_r(theObj[p]);
					document.write("</ul>")
				} else {
					document.write("<li>["+p+"] => "+theObj[p]+"</li>");
				}
			}
			document.write("</ul>")
		}
	},
	addComment : function(){
	    var elm  = jQuery('.post-comment-bt');
	    var zone = jQuery('#post-comment');
	    if (elm[0] && zone[0]) {
	        elm.bind('click',function(e){
	            zone.toggle();
	            zone.scrollTo();
	            e.preventDefault();
	        });
	    }
	}
};

var idtgv_tools = {
	ratingStars: function(elt) {
		jQuery(elt).each(function(){
			var currentIndexStar = 0;
			var currentElt = this;
			jQuery("img", currentElt).each(function(i){
				this.i = i;
				/* hover sur les stars */
				jQuery(this).hover(
					function(){
						jQuery("img", currentElt).slice(0,this.i+1).each(function(){
							jQuery(this).attr("src", jQuery(this).attr("src").replace("_empty","_full"));
						});
					},
					function(){
						jQuery("img", currentElt).each(function(){
							jQuery(this).attr("src", jQuery(this).attr("src").replace("_full","_empty"));
						});
						jQuery("img", currentElt).slice(0,currentIndexStar).each(function(){
							jQuery(this).attr("src", jQuery(this).attr("src").replace("_empty","_full"));
						});
					}
				);
				jQuery(this).click( function(){
                    currentIndexStar = this.i+1;
                    jQuery("img", currentElt).each(function(){
                        jQuery(this).attr("src", jQuery(this).attr("src").replace("_full","_empty"));
                    });
                    jQuery("img", currentElt).slice(0,currentIndexStar).each(function(){
                        jQuery(this).attr("src", jQuery(this).attr("src").replace("_empty","_full"));
                    });
                });
				
				/*
				jQuery(this).click( function(){
					currentIndexStar = this.i+1;
					
					var currentTD = jQuery(this).parents("td");
					if(jQuery(currentTD).size() > 0){
						var votes = parseInt( jQuery(this).parents("td").next("td").children(".votes").html() );
						jQuery(this).parents("td").next("td").children(".votes").html(votes+1);
						
						jQuery("img", currentTD).each(function(){
							jQuery(this).unbind("mouseover");
							jQuery(this).unbind("mouseout");
							jQuery(this).unbind("click");
						});
					} else {
						var votes = parseInt( jQuery(this).parents(".starsHover").nextAll(".votes").html() );
						jQuery(this).parents(".starsHover").nextAll(".votes").html(votes+1);
						
						var current = jQuery(this).parents(".starsHover");
						jQuery("img", current).each(function(){
							jQuery(this).unbind("mouseover");
							jQuery(this).unbind("mouseout");
							jQuery(this).unbind("click");
						});
					}
					
					return false;
				});
				*/
			});
		});
	}
};

jQuery.fn.roundCorners = function(s) {
	this.each(function(){
		cornerTop = '<span class="' + s.classTop + '"></span>';
		cornerBottom = '<span class="' + s.classBottom + '"></span>';
		
		jQuery(this).prepend(cornerTop);
		jQuery(this).append(cornerBottom);
		
		jQuery(this).css({ visibility: "visible" });
	});
};

jQuery.ucFirst = function(str) {
	if(str != null) return str.slice(0, 1).toUpperCase() + str.slice(1).toLowerCase();
};

jQuery.fn.toggleVal = function(focusClass) {
	return this.each(function() {
		jQuery(this).focus(function() {
			if(jQuery(this).val() == this.defaultValue) { jQuery(this).val(""); }
			if(focusClass) { jQuery(this).addClass(focusClass); }
		}).blur(function() {
			if(jQuery(this).val() == "") { jQuery(this).val(this.defaultValue); }
			if(focusClass) { jQuery(this).removeClass(focusClass); }
		});
	});
};

jQuery.fn.sameHeight = function() {
	var maxHeight = 0;
	
	this.each(function(){
		currentHeight = jQuery(this).height();
		if(currentHeight > maxHeight) maxHeight = currentHeight;
	});
	
	return this.each(function(){
		jQuery(this).css({ height: maxHeight + "px" });
	});
};

var flashMoveUp = function(){
	jQuery(".events").css("z-index", "15");
};

var flashMoveDown = function(){
	jQuery(".events").css("z-index", "5");
};

/* jeangu 2009/10/02 */
function checkFaqQuestionForm() {

    if (jQuery("#email").val() == "") {
	    jQuery("#notify_publish").attr("disabled", true);
	    jQuery("#notify_publish_label").css("color","#999999");
	            
	    jQuery("#notify_new_comment").attr("disabled", true);
	    jQuery("#notify_new_comment_label").css("color","#999999");
    }

	jQuery(".emailHideNotify").blur(function() {
		if (jQuery(this).attr("value") == "") {
			jQuery("#notify_publish").attr("disabled", true);
			jQuery("#notify_publish").attr("checked", false);
			jQuery("#notify_publish_label").css("color","#999999");
			
			jQuery("#notify_new_comment").attr("disabled", true);
			jQuery("#notify_new_comment").attr("checked", false);
			jQuery("#notify_new_comment_label").css("color","#999999");
		} else {
			jQuery("#notify_publish").attr("disabled", false);
			jQuery("#notify_publish_label").css("color","#E40780");
			
			jQuery("#notify_new_comment").attr("disabled", false);
			jQuery("#notify_new_comment_label").css("color","#E40780");
		}
	});
}

function regAjax(url, data, callback) {
    $.post(url, data, callback);
}
