$(document).ready(function(){
	$(document).pngFix();
	
	/*
	$('#self_video_show').click(
			function() {
				$('#self_video').html($('#self_embed').html());
				$('#video').empty();
			  }
		);
		$('#hide_all_video').click(
			function() {
				$('#self_video').empty();
				$('#video').empty();
			  }
		);
		$('#self_video_hide').click(
			function() {
				$('#self_video').empty();
				$('#video').html($('#v1').html());
			  }
		);
*/
	//affichage des videos
	var loadVideo = (function () {
		$('#vid1').click( function() {
	    	if($(".decouvrirVideo li a.selected_link")) { $(".decouvrirVideo li a.selected_link").removeClass("selected_link"); }
			$(this).addClass("selected_link");	    	
			$('#video').html($('#v1').html());
	      }
		);
		$('#vid2').click( function() {
		    	if($(".decouvrirVideo li a.selected_link")) { $(".decouvrirVideo li a.selected_link").removeClass("selected_link"); }
				$(this).addClass("selected_link");
				$('#video').html($('#v2').html());
		      }
		);
		$('#vid3').click( function() {
			    if($(".decouvrirVideo li a.selected_link")) { $(".decouvrirVideo li a.selected_link").removeClass("selected_link"); }
				$(this).addClass("selected_link");
				$('#video').html($('#v3').html());
		      }
		);	
	});	

/*
	$("#jouer").click(function(){
		
		$("#contentZone1").empty();
		$("#contentZone1").css("background","none");
		$("#contentZone1").append('<iframe id="commentiframe" />');
		$("#commentiframe").attr('width', $("#contentZone1").width());
		$("#commentiframe").attr('height', $("#contentZone1").height());
		$("#commentiframe").attr('src',gameURL );
		$("#commentiframe").attr('scrolling', 'no');
		$("#commentiframe").attr('frameborder', '0');
		});
*/

		// Clique Bouton jouer
		var downloadclicked=false;
		$("#jouer").click(function(){
		var gameURL= document.getElementById('gameURL').value;
		$("#contentZone1").empty();
		$("#contentZone1").css("background","none");
		$("#contentZone1").append('<iframe id="commentiframe"width="479px" scrolling="no" frameborder="0" src=""></iframe>');
		$("#commentiframe").attr('src', gameURL );
		$("#commentiframe").animate({height:"535px"},400);
		$('#petitsplaisirs_sidebar').animate({'height': "535px"}, 400);
		if(downloadclicked==true){
		//$('.download').animate({'top': $('#parttwo').height()-40}, 400);
		$(".download").css( "top", $('#parttwo').height()-40 );
		}else{
		//$('.download').animate({'top': $('#partone').height()-43}, 400);
		$(".download").css( "top", $('#partone').height()-43 );
		}
		
		$("#download").addClass("play_was_clicked");
		});
		// Clique Bouton Telecharger
		$("#download").click(function(){
		downloadclicked=true;
		if(this.className=='download play_was_clicked'){
		$("#partone").fadeOut('normal', function(){ $("#parttwo").fadeIn(); });
		$('#petitsplaisirs_sidebar').animate({'height': "535px"}, 400);
		$(".download").css( "top", $('#parttwo').height()-40 );
		//$('.download').animate({'top': $('#parttwo').height()-40}, 400);
		$("#download").toggleClass('play_was_clicked');
		}
		else{
		$('#petitsplaisirs_sidebar').animate({'height': $('#parttwo').height()},400);
		$(".contentZone").animate({'height': $('#parttwo').height()}, 400);
		$("#partone").fadeOut('normal', function(){ $("#parttwo").fadeIn(); });
		$(".download").css( "top", $('#parttwo').height()-40 );
		//$('.download').animate({'top': $('#parttwo').height()-40}, 400);
		}
		});
	
	
	// Valid Formulaire diagnostic
	$('#valid_boutton').click( function() {					   
		if($('form#preoccumations')) {
			
			if ($("input[@name='prioritaire']:checked").length==0) 
			{	
				$("#prioritaires").addClass('BorderRed');
				$("span.erreur").fadeIn('normal');
				return false;
			}
			else {
				if ($("input[@name='prioritaire']:checked").attr('value')==$("input[@name='secondaire']:checked").attr('value'))
					{$('.erreur').html('Veuillez choisir deux pr&eacute;occupations diff&eacute;rentes.');
					$("span.erreur").fadeIn('normal');
					return false;}
				else {
					loadReponses($(this).attr('href'));
					return false;}
				}
			}					   
	});	
	
	var loadReponses = (function (href) {
	    var choix = $("input[@name='prioritaire']:checked").attr('value') ;
	    var secondaire =  "";
	    var principal  =  document.getElementById("p" + $("input[@name='prioritaire']:checked").attr('value')).innerHTML;
	    
	    if( ! $("input[@name='secondaire']:checked").length == 0){
	    	choix += $("input[@name='secondaire']:checked").attr('value');
	    }
	    choix += "/" + principal;
	    
	    if( ! $("input[@name='secondaire']:checked").length == 0){	
	    secondaire =  document.getElementById("p" + $("input[@name='secondaire']:checked").attr('value')).innerHTML;
	    choix += "/" + secondaire ;
	    }	
		
		$("#diag_results").load(href,{choice : choix  },retourQuestion() );
		$("#diag_questions").hide();
		
		document.getElementById("choice").value = choix;
		$("#diag_results").fadeIn(1000, function() {$(document).pngFix();});
		$(document).pngFix();
		return false;
	});
	
	var retourQuestion = (function () {
		$('.recommencer').click( function() {							  
			$("#diag_questions").load(function(){  $("#diag_questions").pngFix();loadReponses(lien)} );
				$("#diag_results").hide();
				$("#diag_questions").show();
				$("input[@name='prioritaire']:checked").attr('checked',false);
				$("input[@name='secondaires']:checked").attr('checked',false);
				$("#prioritaires").removeClass('BorderRed');
				$("span.erreur").hide();
				$(document).pngFix()
				return false;
		});
	});
						   
	$(".contmenu li span").each(function() {
		$(this).css('margin-top','-' + Math.round($(this).height() / 2) + 'px');								
	});
	
	if($('input#subsection_pos:hidden').val()) {
	var i = $('input#subsection_pos:hidden').val();
			if($(".contmenu li a.selected")) { $(".contmenu li a.selected").removeClass("selected"); }
			$(".contmenu li:nth-child(" + i + ") a").addClass("selected");
			$('div.contentZone').hide();
			$('div.ColonneRight').hide();
			$('#main .contentZone').fadeOut('slow');
			$("#contentZone" + i).fadeIn('slow');		
	}
	
	$(".contmenu li a").click(loadContent = function() {			   
			if($(".contmenu li a.selected")) { 
				$(".contmenu li a.selected").removeClass("selected"); 
			}
			$(this).addClass("selected");
			var href = $(this).attr('href');
			$("#contentBlock").load(href,function (){loadVideo();});
			$(".contentZone").show();
			return false;
		});	
		
	$("javascript:void(0)one").click(function(){
		$(".bottomOne").hide();
		$('javascript:void(0)concours').animate({'height': $('.partTwo').height()}, 'normal');
		$(".partOne").fadeOut('normal', function(){ $(".partTwo").fadeIn('normal'); });                    
	});             
	$("javascript:void(0)two").click(function(){
		$(".bottomTwo").hide();
		$('javascript:void(0)concours').animate({'height': $('.partThree').height()}, 'normal');
		$(".partTwo").fadeOut('normal', function(){ $(".partThree").fadeIn('normal'); });                    
	});
});

