function DoAccueil()

{

	SetupDrawers();

	SetupNews();

	SetupMenu();

	$(".KLevel1 > div[style]").removeAttr("style");

}

var baseSrcPath = "/templates/E6ED7704-72A9-4309-8260-FBBD42925627/images/{1}";

var basePath = "url('"+baseSrcPath+"')";



var cooldown = null;

var globalTimer = 8000;

var widthNws=570;

function SetupNews()

{

	$("#ac-white").empty().append('<div id="w-wrap"><div id="n-wrap"></div><span id="n-sel-l"></span><span id="n-sel-r"></span></div>');

	$("#rawNews .KTitle a").clone().addClass("nouv").appendTo("#n-wrap");

	

	if($("#n-wrap > a").length<=1)

		return;

		

	UpdateArrowState();

	

	$("#n-wrap").css("width",$("#n-wrap > a").length * widthNws);

	

	$("#n-wrap").data("active",0);

	

	cooldown = setTimeout(function(){SwitchNews(true);},globalTimer);

	

	$("#n-sel-l").hover(

		function()

		{

			$(this).css("background-image",basePath.replace("{1}","ac_arr_a2.gif"));

		},

		function()

		{

			$(this).css("background-image",basePath.replace("{1}","ac_arr_a.gif"));

		}

	);

	$("#n-sel-r").hover(

		function()

		{

			$(this).css("background-image",basePath.replace("{1}","ac_arr_b2.gif"));

		},

		function()

		{

			$(this).css("background-image",basePath.replace("{1}","ac_arr_b.gif"));

		}

	);

	$("#n-sel-l").click(function(){SwitchNews(false)});

	$("#n-sel-r").click(function(){SwitchNews(true)});

}



function SwitchNews(foward)

{

	clearTimeout(cooldown);

	var index = $("#n-wrap").data("active");

	var len = $("#n-wrap > a").length-1;

	

	

	if(foward)

	{

		index++;

	}

	else

	{

		index--;

	}



	

	$("#n-wrap").data("active",index);

	

	$("#n-wrap").stop().animate({left:index*-widthNws},"slow","swing",

		function()

		{

			if(index<0)

			{

				index=len;

				$("#n-wrap").css("left",((index + 1)*-widthNws)+"px");
				
				$("#n-wrap").animate({left:index*-widthNws},"slow","swing");

				$("#n-wrap").data("active",index);

			}
			if(index>len)

			{

				index=0;

				$("#n-wrap").css("left",((index - 1)*-widthNws)+"px");
				
				$("#n-wrap").animate({left:index*-widthNws},"slow","swing");

				$("#n-wrap").data("active",index);

			}
		
			

			UpdateArrowState();

			cooldown=setTimeout(function(){SwitchNews(true);},globalTimer);

		}

	);	

}



function UpdateArrowState()

{

	if($("#n-wrap > a").length ==1)

	{

		$("#n-sel-r").css("background-image",basePath.replace("{1}","ac_arr_b3.gif"));

		$("#n-sel-l").css("background-image",basePath.replace("{1}","ac_arr_a3.gif"));

	}

	

}



function addLoadEvent(param)

{

	$(document).ready(

		function()

		{

			param();

		}

	);

}



var fadeTmr = null;

var fadeSpd=1000;

function SetupMenu()

{

	var baseImgRotation = "ac_rota_";

	$("#acc-rota-sel > li").hover(

		function()

		{

			var submenu = parseInt($(this).attr("rel")) - 2;

			

			$(this).siblings().children("a").addClass("shadowed");

			$("#ac-rota"+$(this).attr("rel")).stop().css({"z-index":"260",opacity:0}).animate({opacity:1});

			

			

			if($(".KMenu_Anim > .KLevel0 > .KMenuItem:eq("+submenu+")").length===1)

			{

				if($(this).children("table").length===0)

				{

					$(this).append("<table id='tblRel"+submenu+"' cellspacing='0' cellpadding='0' border='0' style='display:none;'><tbody><tr><td valign='center' id='tdRel"+submenu +"'></td></tr></tbody></table>");

					//console.log($(".KMenu_Anim > .KLevel0 > .KMenuItem:eq("+submenu+")").siblings("div").find("a"));

					$("#tdRel"+submenu).append($(".KMenu_Anim > .KLevel0 > .KMenuItem:eq("+submenu+")").siblings("div").find("a"));

				}

				$(this).children("table").show();

			}

		},

		function()

		{

			$(this).siblings().children("a").removeClass("shadowed");

			$(".ac-fade").css("z-index","200");

			$("#ac-rota"+$(this).attr("rel")).stop().css("z-index","240");

			$(this).children("table").hide();

		}

	);

	$("#acc-rota-sel").hover(

		function()

		{

			

		},

		function()

		{

			$(".ac-fade").stop().animate({opacity:0});

		}

	);

}



function SetupDrawers()

{

		//remplir les menus a partir de luka

	$(".KMenu_LiensRap a").each(

			function(i,e)

			{

				var li = document.createElement("LI");

				li.appendChild(e);

				$("#ac-m-rap-db > ul").append(li);

			}

	);



	$(".KMenu_Joindre a").each(

			function(i,e)

			{

				var li = document.createElement("LI");

				li.appendChild(e);

				$("#ac-m-joi-db > ul").append(li);

			}

	);	

	

	//slide liens rapides

	$("#ac-m-rap-db").data("fh",$("#ac-m-rap-db").height());

	$("#ac-m-rap").hover(

		function()

		{

			$("#ac-m-rap-db").stop().css({"display":"block","height":"0px"}).animate({height:$("#ac-m-rap-db").data("fh")});

		},

		function()

		{	

			$("#ac-m-rap-db").stop().animate({height:0});

		}

	);

	

	//slide joindre

	$("#ac-m-joi-db").data("fh",$("#ac-m-joi-db").height());

	$("#ac-m-joi").hover(

		function()

		{

			$("#ac-m-joi-db").stop().css({"display":"block","height":"0px"}).animate({height:$("#ac-m-joi-db").data("fh")});

		},

		function()

		{	

			$("#ac-m-joi-db").stop().animate({height:0});

		}

	);

	

	

}





function DoGeneral()

{

	$(".KPagePath").prepend('<span id="k-init">Vous êtes :</span>');

	$(".KPagePath").append('<div id="clear"></div>');

	$(".KPagePath > .KPathDivider").html("&nbsp;");

	SetupDrawers();

	SetupMenuPrinc();

	SetupTabs();

	RemoveBreadCrumbInteraction();

}



function RemoveBreadCrumbInteraction()

{

	if($(".KPagePath > a[href]:eq(0)").text().toLowerCase() === $.trim($(".KMenu_Principal .KMenuItemSelected:has(a[href='javascript:;'])").text().toLowerCase()))

	{

		$(".KPagePath > a[href]:eq(0)").attr("href","javascript:;").addClass("noLink");

	}

}



function DoProg()

{

	DoGeneral();

	SetupTabs();

	SetupPastilles();

}



function SetupMenuPrinc()

{

	$(".KLevel0").each(

		function(i,e)

		{

			$(".KMenuItem",e).attr("onmouseout","dn();");

			$(".KMenuItem",e).attr("onmouseover","dn();");

			$(".KMenuItem",e).hover(

					function()

					{

						$(this).toggleClass("KMenuItemOver");

					},

					function()

					{

						$(this).toggleClass("KMenuItemOver");

					}

				);

			

			if(parseInt($(e).find(".KChildGroup > div").length) != 0)

			{

				$("> .KMenuItemSelected > a",e).attr("href","javascript:;");

				$("> .KMenuItem > a",e).attr("href","javascript:;");

				$("> .KMenuItem > a",e).click(

						function()

						{

							//if($(e).next(".KChildGroup").is(":hidden"))

							//	return false;

							$(this).blur();

							$(".openBlock").removeClass("openBlock");

							$(e).addClass("openBlock");

							$(".KMenuItemSelected2").removeClass("KMenuItemSelected2");

							$(e).find("div:eq(0)").addClass("KMenuItemSelected2");

//							$(".KLevel0 > .KChildGroup:visible").css("overflow","hidden").slideUp("slow");

							slideToggle($(".KLevel0 > .KChildGroup:visible").css("overflow","hidden"),false);

							if(!$(e).find("> .KChildGroup").is(":visible"))

							{

								//$(e).find("> .KChildGroup").css("overflow","hidden").slideToggle("slow");

								slideToggle($(e).find("> .KChildGroup").css("overflow","hidden"));

							}

						}

					);

				$("> .KMenuItemSelected > a",e).click(

						function()

						{

							$(this).blur();

							$(".openBlock").removeClass("openBlock");

							$(e).addClass("openBlock");

							$(".KMenuItemSelected2").removeClass("KMenuItemSelected2");

							$(e).find("div:eq(0)").addClass("KMenuItemSelected2");

							//$(".KLevel0 > .KChildGroup:visible").css("overflow","hidden").slideUp("slow");

							slideToggle($(".KLevel0 > .KChildGroup:visible").css("overflow","hidden"),false);

							if(!$(e).find("> .KChildGroup").is(":visible"))

							{

								//$(e).find("> .KChildGroup").css("overflow","hidden").slideToggle("slow");

								slideToggle($(e).find("> .KChildGroup").css("overflow","hidden"));

							}

						}

					);

				

			}

			

			if($(".KMenuItemSelected",e).length!==0)

			{

				$(e).addClass("openBlock");

				$("> .KChildGroup",e).show();

			}

		}

	);

}



function SetupTabs()

{

	$(".KModCollegePrograms > hr:eq(0)").remove();

	$(".KModCollegePrograms > .Navigation a").appendTo("#m-c-b-tabs");

	if($(".KModCollegePrograms").length===1)

	{

		$("#m-c-b-tabs").removeAttr("style");

	}

}



function SetupPastilles()

{

	if(!(typePast3==="###") && !(descPast3==="###"))

		BuildPastille(typePast3,descPast3,linkPast3);

	

	if(!(typePast2==="###") && !(descPast2==="###"))

		BuildPastille(typePast2,descPast2,linkPast2);

	

	if(!(typePast1==="###") && !(descPast1==="###"))

		BuildPastille(typePast1,descPast1,linkPast1);

	

	

}



function BuildPastille(type,desc,lnk)

{

	if(!(lnk==="###"))

	{

		if(lnk.indexOf("#")===0)

		{

			lnk="javascript:SwitchTabToAnchor('"+lnk.replace("#","")+"');";

		}

		desc = '<a href="'+lnk+'" target="_self">'+desc+'</a>';

		

	}

	$('<div class="pastille" id="past_'+type+'"><div class="innerPastille"><div class="basePastille">'+desc+'</div></div></div>').appendTo("#m-c-b-tabs");

}



function SwitchTabToAnchor(anchor)

{

	var div = $(".KModCollegePrograms > div[id]:has(a[name="+anchor+"])");

	//legacy code

	__kmodCP_currentPanel = $(div)[0];

	$(div).css("display","block").siblings("div[id]").hide();

	$("#m-c-b-tabs > a[onclick*="+$(div).attr("id")+"]").addClass("Selected").siblings("a[onclick]").removeClass("Selected");

	//legacy code

	__kmodCP_currentLnk = $("#m-c-b-tabs > a[onclick*="+$(div).attr("id")+"]")[0];

	

	var href= window.location.href.toString();

	if(href.indexOf("#")>-1)

		href = href.substring(0,href.indexOf("#"));

	window.location.href = href + "#" + anchor;

}



var defDuration = 550;

function slideToggle(el, bShow){

  var $el = $(el), height = $el.data("originalHeight"), visible = $el.is(":visible");

  

  // if the bShow isn't present, get the current visibility and reverse it

  if( arguments.length == 1 ) bShow = !visible;

  

  // if the current visiblilty is the same as the requested state, cancel

  if( bShow == visible ) return false;

  

  // get the original height

  if( !height ){

    // get original height

    height = $el.show().height();

    // update the height

    $el.data("originalHeight", height);

    // if the element was hidden, hide it again

    if( !visible ) $el.hide().css({height: 0});

  }



  // expand the knowledge (instead of slideDown/Up, use custom animation which applies fix)

  if( bShow ){

    $el.show().animate({height: height}, {duration: defDuration});

  } else {

    $el.animate({height: 0}, {duration: defDuration, complete:function (){

        $el.hide();

      }

    });

  }

}



function dn()

{

	return true;

}

function log(obj)

{

	try

	{

		console.log(obj);

	}

	catch(e)

	{

	

	}

}
