$(document).ready(function()
{	
	if ($(".default").length)
	{
		var heightCadreMenu = $(".cadre_menu").height() + parseInt($(".cadre_menu").css("margin-top"));
		var topCadreButtons = $(".line_buttons").height() + parseInt($(".default").parent().css("margin-top"));
		var paddinTopDefault = parseInt($(".default").css("padding-top"));
		var paddinBottomDefault = parseInt($(".default").css("padding-bottom"));		
		$(".default").css("min-height", (heightCadreMenu - topCadreButtons - paddinTopDefault - paddinBottomDefault)+"px");
	}
	
	function checkIt(string) // safari, msie, opera
	{
		var detect = navigator.userAgent.toLowerCase();
		place = detect.indexOf(string) + 1;
		thestring = string;
		return place;
	}
	
	function isIE()
	{
		return (checkIt('msie'));
	}
	
	if (typeof(espace_journaliste) != "undefined")
	{
		espace_journ_height = $(".membre_cadre_global").height();
	}
	else
	{
		espace_journ_height = 0;
	}
	
	heightGeneral = $(".main_container").height() + espace_journ_height;
	$(".bottom").css("top", heightGeneral+"px");
	
	
	if (!isIE())
	{
		$(".line_buttons").children("a").each(function(eq)
		{
			$(this).mouseover(function()
			{
				$(this).children("img:last").fadeTo(300, 1);
			});
			$(this).mouseout(function()
			{
				$(this).children("img:last").stop(true, true).fadeTo(300, 0);
			});
		});
	}
	else
	{alert("ok");
		$(".line_buttons").children("a").each(function(eq)
		{
			$(this).mouseover(function()
			{
				$(this).children("img:first").hide();
				$(this).children("img:last").show();
			});
			$(this).mouseout(function()
			{
				$(this).children("img:last").hide();
				$(this).children("img:first").show();
			});
		});
	}
	
	$("#journ_connect_login").focus(function()
	{
		if ($(this).val() == "Identifiant")
		{
			$(this).removeClass("style2").addClass("style1");
			$(this).val("");
		}
	});
	$("#journ_connect_login").blur(function()
	{
		if ($(this).val() == "")
		{
			$(this).removeClass("style1").addClass("style2");
			$(this).val("Identifiant");
		}
	});
	
	$("#journ_connect_mdp_text").focus(function()
	{
		if ($(this).val() == "Mot de passe")
		{
			$(this).hide();
			$("#journ_connect_mdp").show().focus();
		}
	});
	$("#journ_connect_mdp").blur(function()
	{
		if ($(this).val() == "")
		{
			$(this).hide();
			$("#journ_connect_mdp_text").show();
		}
	});
	
	if ($("#journ_connect_btn").length)
	{
		var etat_form_journ = 0;
		$("form[name='form_journ_connect']").submit(function() { return false; });
		function redirect_connect()
		{
			$(location).attr("href", redirectPage);
		}
		
		function submitFormJourn()
		{
			if (etat_form_journ == 0)
			{
				var login_journ = $("#journ_connect_login").val();
				var mdp_journ = $("#journ_connect_mdp").val();
				
				if (verif_noempty(login_journ) && (login_journ != "Identifiant") && verif_noempty(mdp_journ))
				{
					$.ajax({
					type: "POST",
					url: "./../includes/ajax/result_journ_connect.php",
					data: $("form[name='form_journ_connect']").serialize(),
					dataType: "html",
					success: function(msg)
					{
						if (msg == "ok")
						{
							etat_form_journ = 1;
							$(location).attr("href", "./journaliste_home.php");
						}
						else
						{
							var nextURL = "";
							if (verif_noempty(login_journ) && (login_journ != "Identifiant")) { nextURL += "&id_journ_connect="+login_journ; }
							$(location).attr("href", "./journaliste_connect.php?error_connect=1"+nextURL);
						}
					}
					});
				}
				else
				{
					var nextURL = "";
					if (verif_noempty(login_journ) && (login_journ != "Identifiant")) { nextURL += "&id_journ_connect="+login_journ; }
					$(location).attr("href", "./journaliste_connect.php?error_champs=1"+nextURL);
				}
			}
		}
		
		$("#journ_connect_btn").click(function()
		{
			submitFormJourn();
		});
		$("#journ_connect_login, #journ_connect_mdp").keypress(function(e)
		{
			if (e.which == 13) submitFormJourn();
		});
	}
	
	if ($(".img_vdm_contain").length)
	{
		$(".img_vdm_contain:last").css("border-bottom", "none");
	}
	
	if ($("#list_parten_menu").length)
	{
		$(".list_type_parten a").hover(function()
		{
			$(this).parent().children("div").children("img").show();
		}, function()
		{
			$(this).parent().children("div").children("img").hide();
		});
		
		$(".list_type_parten a").click(function()
		{
			var idTypeParten = $(this).attr("id");
			$("html, body").animate({scrollTop: $(".titre_type_parten#bloc_"+idTypeParten).offset().top}, 1000);
		});
		
		$(".cadre_parten_img img").hover(function()
		{
			if ($(this).parent().parent().children(".cadre_parten_infos").children(".cadre_parten_more").length)
			{
				$(this).addClass("cadre_parten_img_hover");
				$(this).parent().parent().children(".cadre_parten_infos").children(".cadre_parten_more").children("a").addClass("cadre_parten_link_hover");
			}
			else
			{
				$(this).css("cursor", "auto");
			}
		}, function() {
			if ($(this).parent().parent().children(".cadre_parten_infos").children(".cadre_parten_more").length)
			{
				$(this).removeClass("cadre_parten_img_hover");
				$(this).parent().parent().children(".cadre_parten_infos").children(".cadre_parten_more").children("a").removeClass("cadre_parten_link_hover");
			}
		});
		
		$(".cadre_parten_img img").click(function()
		{
			if ($(this).parent().parent().children(".cadre_parten_infos").children(".cadre_parten_more").length)
			{
				var hrefPart = $(this).parent().parent().children(".cadre_parten_infos").children(".cadre_parten_more").children("a").attr("href");
				$(location).attr("href", hrefPart);
			}
		});
		
		$(".cadre_parten_more a").hover(function()
		{
			$(this).parent().parent().parent().children(".cadre_parten_img").children("img").addClass("cadre_parten_img_hover");
		}, function()
		{
			$(this).parent().parent().parent().children(".cadre_parten_img").children("img").removeClass("cadre_parten_img_hover");
		});
		
		$(".cadre_parten_container").each(function()
		{
			$(this).children(".cadre_parten:last").css({"border-bottom": "none"});
		});
	}
	
	if ($(".list_files_blog_container").length)
	{
		var paddingHeightDdlContainer = 30; // Regarder dans le CSS : padding en hauteur de ".list_files_blog_container"
		var heightDdlContainer = $(".list_files_blog_container").height() + paddingHeightDdlContainer;
		var heightSheetCoin = $(".list_file_blog_sheet_coin_top").height();
		$(".list_file_blog_sheet_bottom").css("height", (heightDdlContainer - heightSheetCoin)+"px");	
	}
	
	if ($(".notre_equipe_img_container").length)
	{
		$(".notre_equipe_img_container a").mouseenter(function()
		{
			$(this).fadeTo("fast", 1);
		});
		$(".notre_equipe_img_container a").mouseleave(function()
		{
			$(this).fadeTo("fast", 0);
		});
		
		$(".notre_equipe_img_container a").colorbox({minWidth: 100, minHeight: 100, maxWidth:"90%", maxHeight:"90%"});
	}
});
