$(document).ready(function() {
	$(".featured.equipes").click(function(e) { // Redirect click on equipes logo
		e.preventDefault();
		$("#equipes").click();
	});
	
	$(".event div.extras").filterIE6out()
	.each(function(i) { // style event extra infos
		$("<div></div>").css({
			backgroundColor: "white",
			float: "right",
			height: "16px",
			width: "16px",
			position: "relative",
			top: "-6px",
			left: "6px",
			backgroundImage: "url(/images/public/topright_corner.gif)",
			backgroundPosition: "left bottom"
		}).prependTo($(this));
	})
		 
	_bindHoraireTOC();
	$(".attachments").filter(function() { return ($(this).find("div.items-inner ul li").length == 0); }).hide()
	$(".attachments.toggle")
	.find("div.items").hide().end()
	.find("h3")
		.find("em").hide().end()
		.append("<em><a href=\"#\" class=\"show_toggled\"><span>Montrer:</span> </a></em>")
		.find("a.show_toggled").each(function(index) { 
			$("<cite></cite>").text($(this).parent().siblings("em").text())
			.appendTo($(this));
		})
			.click(function(e) {
				e.preventDefault();
				$(this).parent().hide().siblings("em").show().parent().siblings(".items").animate({height: "show", opacity: "show"}, 300);
			})
	$('.attachments ul.photos, div.diapo ul#photos').each(function(index) { $(this).find("li a").lightBox(); })
	
	$("li.lien a.url, div.righted a.coms, li.commanditaire a.url")
	.filterIE6out()
	.hover(function() {
		$(this).animate({paddingRight: "16px"}, 120)
		.queue(function() { $(this).css({backgroundImage: "url(/images/shared/simple_arrow.gif)"}).dequeue(); });
	}, function() {
		$(this).stop().stop().css({backgroundImage: "none"}).animate({paddingRight: "0"}, 70);
	});

	$.preloadImages("/images/icons/loading.gif");
	$.preloadImages([ 
		"/images/public/email.gif", 
		"/images/shared/horaire/checked_as.gif", 
		"/images/shared/calendar.gif", 
		"/images/shared/print.gif",
		"/images/shared/pencil.gif",
		"/images/shared/simple_arrow.gif",
		"/images/shared/pencil.gif",
		"/images/shared/print.gif",
		"/images/icons/tiny_arrow.gif",
		"/images/calendar/summary_bottom.jpg",
		"/images/calendar/summary_top.jpg",
		"/images/icons/big/download.gif",
		"/images/shared/arrow_down.gif",
		"/images/public/rss_s.png"
	]);	
	
	//
	$("a#rss").filterIE6only().hide();
});

$(window).load(function() { 
	$("li.wavatar .description, li.wavatar .attachments").each(function(index) {
		$(this).css({marginLeft: ($(this).siblings("img").innerWidth() + 10)+"px"});
	});
	
	$("li.diapo .description").each(function(index) {
		$(this).css({marginLeft: ($(this).siblings("img").outerWidth() + 10)+"px"});
	});
	$("li.photo .comment").each(function(index) {
		$(this).css({marginLeft: ($(this).siblings("a").find("img").outerWidth() + 10)+"px"});
	}) 
})

function _bindHoraireTOC() {
	
	$(".horaire-toc a")
	.filterIE6out()
	.click(function(e) {
		e.preventDefault();
		$(this).css({backgroundImage: "url(/images/icons/loading.gif)"});
		$(".horaire-toc a").unbind("click").click(function(e){e.preventDefault()});
		$.ajax({
			url: $(this).attr("href"),
			dataType: "html",
			data: {format: "xml"},
			success: function(data, sts) {
				$('div#main')
				.find("#horaireset").fadeOut(200)
				.queue(function() {
					$(this).parent().remove();
					$('<div id="main"></div>').html( $(data).html() ).insertAfter("#sidebar")
					.find("#horaireset").hide().fadeIn(300);
					$(this).dequeue();
					
					_bindHoraireTOC();
				});
			}
		});
	})
}
