$(function() {

// Main navigation drop-down menus

	$('.head ul').hide();
	$('.head li:last-child').addClass('last');

	$('.head > a').bind('mouseenter', function(){
		$(this).next('ul').slideDown('fast');
		$(this).addClass('open');
		$(this).css('cursor','pointer');
		$(this).blur();return false;
	});

	$('.head').bind('mouseleave', function(){
    	$('.head > ul').slideUp('fast');
    	$('.head > a').css('cursor','auto').removeClass('open');
    });

    $('.subHead > a').bind('mouseenter', function(){
		$(this).next('ul').show();
		$(this).addClass('open');
		$(this).css('cursor','pointer');
		$(this).blur();return false;
	});

	$('.subHead').bind('mouseleave', function(){
    	$('.subHead > ul').hide();
    	$('.subHead > a').css('cursor','auto').removeClass('open');
    });



// Side Navigation sub-list menus

	$('.sideNav li > ul').hide();
	$('.sideNav li:has(ul) > a').bind('mouseenter', function() {
		$(this).css('cursor','pointer');
		$(this).css('text-decoration','underline');
	});
	$('.sideNav li:has(ul) > a').bind('mouseleave', function() {
		$(this).css('cursor','auto');
		$(this).css('text-decoration','none');
	});
	$('.sideNav li:has(ul) > a').click(function() {

		var $nextItem = $(this).next('ul');
		var $visibleSiblings = $nextItem.parent('li').siblings('li').find('ul:visible');

		if ($visibleSiblings.length) {
			$visibleSiblings.slideUp('fast', function() {
				$nextItem.slideToggle('fast');
			});
		} else {
			$nextItem.slideToggle('fast');
		}

		$(this).blur();

		return (typeof($(this).attr('href')) != 'undefined');
	});

	$('.sideNav li > ul.open').show();


// Popup links parsing

	$('a[rel^=popup]').click(function() {
		var url = $(this).attr('href');
		var popup = $(this).attr('rel');

		$(this).attr('target', '_blank');

		return eval(popup + "('" + url + "')");
	});

// Set target blank for external/pdf/txt URLs

	$("a[href$='pdf'], a[href$='txt'], a[href^='http']:not(a[href^='http://www.bostonoptions.com/'], a[href^='http://staging10.mcex.ca/'])").attr('target', '_blank');

// Set last class of last childs to remove extra padding/margin

	//$('td p:last-child, ul li:last-child, ol li:last-child').addClass('last');
	$('td p:last-child').addClass('last');
	$('div.latestNews dd:last-child').addClass('last');
	$('div.publications div.publication:last-child').addClass('last');
});

