var Width = "630";
var Height = "21";

$(document).ready(function()
{
	windowLocation = absolutePath();
	
	listeOffres(windowLocation);
	
	$(".contenuOnglet").each(function()
	{
		$(this).css("display", "none");
	});
	
	$(".ongletTitle").click(function(e)
	{
	    e.preventDefault();
	    if($(this).next(".contenuOnglet").text().length > 5 )
	    {
	    	
	    	if($(this).next(".contenuOnglet:visible").length != 0)
			{
				$(this).next(".contenuOnglet").slideUp("normal");
				$(this).css("font-weight", "normal");
			}
			else
			{
				$(".contenuOnglet").slideUp("normal");
				$(".ongletTitle").css("font-weight", "normal");
				$(this).next(".contenuOnglet").slideDown("normal");
				$(this).css("font-weight", "bold");
				
			}
		}
	});
	
});

function listeOffres(pWindowLocation)
{
	$("div .offre_cache").css("display", "none");
	/*$(".UL li.toggleArticle span").each( function ()
	{
		// on stocke le contenu du span :
		var texteSpan = $(this).text();
		
		// les valeurs Width et Height prennent les valeurs width et height de la balise parent.
		$(this).parent(".onglet").attr("style", "display:block; position:relative; margin:0px; padding: 0px; ");
		var PaddingTop = Math.round(Height/4.5);
		var HeightA = Height-PaddingTop; 
		
		// on remplace l'élément span par une balise a pour permettre le clic de l'onglet.
		$(this).replaceWith("<a href='' title='Afficher fiche' style='position:relative;display:block; margin:0px; padding: 0px; padding-top:"+PaddingTop+"px;padding-left:20px;'>"+texteSpan+"</a>");
	
	});*/
	
	$("li.toggleArticle div.onglet span").each(function()
	{
		if($(this).parent().next().text() != "")
		{
			$(this).hover(function(e)
			{
				$("li.toggleArticle span").removeClass("current");
				$(this).addClass("current");
			},function()
			{
				$(this).removeClass("current");
			});
			$(this).click(function(e)
			{
				e.preventDefault();
				$("li.toggleArticle span").removeClass("current");
				$(this).removeClass("current");
				getOffreInfos(this,pWindowLocation, "metier");
			});
		}else{
			$(this).click(function(e)
			{
				e.preventDefault();
			});
		}
	});
}

function getOffreInfos(pEl,pWindowLocation, pType)
{
	var offreInfos = new Object();
	var winLocation = pWindowLocation;
	
	var infosTitle = $(pEl).text();
	offreInfos["nom"] = infosTitle.substr(2, (infosTitle.length));
	offreInfos["fiche"] = $(pEl).parent().next().html();
	var n = "";
	
	n += "<div id='message'>";
	n += "<a id='btPrint' href=''>imprimer</a>";
	n += "<a id='btPostule' href=''>postuler</a>";
	n += "<h1>"+offreInfos["nom"]+"</h1>";
	n += "<div class='bloc_text'>"+offreInfos["fiche"]+"</div>";
	n += "</div>";
	var lightBox = new classLightBox("#dialog","#ffffff","#ffffff","all",n,500);
	lightBox.init();
	var round1 = new classRound("#btPrint","#a80e3a",winLocation+"javascripts/classes/fdRound_img/lit_de_vin.png",5);
	var round2 = new classRound("#btPostule","#eb6e1d",winLocation+"javascripts/classes/fdRound_img/orange.png",5);
	$("#dialog").find("td").not(".colgauche").find("p").attr("style","");
	/*var $abc ="";
	$("#dialog").find("td").not(".colgauche").each(function()
	{
	    $this = $(this);
	    if(! $this.children().length)
	    {
	    	$this.wrapInner("<p></p>");
	    }
	    
	});*/
	$("#btPrint").click(function(){
		window.print();
		return false;
	});
	
	$("#btPostule").click(function(){
		$("#btPrint").css("display", "none");
		$(this).css("display", "none");
		formuPostule(offreInfos["nom"], pType);
		lightBox.ferme("#dialog");
		return false;
	});
}
