// Start jQuery

$(document).ready(function() {
						   
	// Add "NEW" to new menu items
	$('#header .page-item-1266').append('<span class="new">new</span>');
	
	// Wrap each list item. 
	$('.toggle ul li, .toggle ol li').wrap('<li><ul class="toggle-item"></ul></li>');
	
	// Prepend title to parent list item
	$('.toggle-item li h3').each(function() {
		$(this).prependTo(this.parentNode.parentNode.parentNode);
	});
	
	// Append +/– symbols to toggle titles
	$('.toggle h3, .slider-title').append('<span class="plus">+</span><span class="minus">–</span>');
	
	// Hide all toggle items
	$('.toggle-item, .toggle h3 .minus, .slider .minus, .slider-content').hide();
	
	// Toggle list items
	$('.toggle h3').click(function () {
		$(this).siblings('ul').slideToggle();
		$(this).children('.plus, .minus').toggle();
		$(this).toggleClass('active');
	});
	
	// Toggle Active Title State
	$(".slider-title").click(function () {
		$(this).siblings('.slider-content').slideToggle('slow');
		$(this).children('.plus, .minus').toggle();
		$(this).toggleClass('active');
	});
	
	
	// Programs: Slider Content without Children Bkd is White
	$('.page-id-8 .slider-content').each( function() {
		if ( $(this).children('.slider').length == 0 ) {
			$(this).addClass('noChildren');
		}
	});
	
	
	$('.page-item-1266 a').click(function() {
        _gaq.push(['_trackEvent', 'Outbound Links', 'Click', 'Online Community']);
    });
	
	$('a:not([href*="' + document.domain + '"])').click(function() {
        _gaq.push(['_trackEvent', 'Outbound Links', 'Click', $(this).attr('href')]);
    });
	
	if (window.location.pathname.lastIndexOf("fr/") == -1)
	{
		// Full Ballon Tips
		$(".tableSort").each(function() {
			$(this).find("tr").each(function() {
				if (($(this).children(".register").html() == "FULL")
						|| ($(this).children(".register").html() == "COMPLET"))
				{	
					$(this).hover(function() {
						$(this).addClass("fullProgramOnBallon");
					},
					function(e) {
						if (e.relatedTarget == null)
						{
							$(this).removeClass("fullProgramOnBallon");
							$(".waiting-list-msg").hide();
						}					
						else if ((e.relatedTarget.className != "waiting-list-msg") && (e.relatedTarget.className != "msg-bottom"))
						{
							$(this).removeClass("fullProgramOnBallon");
							$(".waiting-list-msg").hide();						
						}
						else
						{
							var currentTr = $(this)[0]; 
							$(".waiting-list-msg").hover(function() {							
								$(this).show();							
							},
							function(e) {				
								$(currentTr).removeClass("fullProgramOnBallon");
								$(this).hide();							
							});
						}
					});
					
					$(this).children("td").hover(function() {
						var ballonContent = $(this).parent().children(".fullMessage").html();
						$(".waiting-list-msg").html(ballonContent);
						$(".waiting-list-msg").show();
					
						//Adde 10 pixels because of the padding
						var xPosition = $(this).offset().left + $(window).scrollLeft() + ($(this).width()/2) - ($(".waiting-list-msg").width()/2) + 10;
						var yPosition = $(this).offset().top - $(window).scrollTop() - $(".waiting-list-msg").height();					
						
						$(".waiting-list-msg").css({left: xPosition, top: yPosition});															
					},
					function() {
						
					});				
				}
			});
		});
	}
	
}); // End jQuery

function sort(field, dir, anchor)
{
	location.href='?sort=' + field + '&dir=' + dir + '#' + anchor;

	return false;
}
