$(function() {

	// Find all ampersands and wrap with a span
	$('#main_nav, #breadcrumbs, h3, h4, h5, h6, #sectionMenuElementID_0').html(function(i,html) {
		return html.replace(/&amp;/gi,'<span class="amp">&amp;</span>');
	});
	
	// Create a:hover canvas arrow for main nav
	$('#main_nav ul li a').hover(function() {
		$(this).addClass('shadow');
		$(this).parent().append('<canvas id="arrow" width="150" height="40"></canvas>');
		var canvas = document.getElementById('arrow');
		if (canvas.getContext){
			var ctx = canvas.getContext('2d');
			ctx.beginPath();
			ctx.moveTo(50,0);
			ctx.lineTo(100,0);
			ctx.lineTo(75,20);
			ctx.shadowOffsetX = 0;
			ctx.shadowOffsetY = 0;
			ctx.shadowBlur = 30;
			ctx.shadowColor = 'rgba(0, 0, 0, 0.5)';
			ctx.fillStyle = '#5b1f69';
			ctx.fill();
		} else {
			return false;
		};
	}, function() {
		$(this).removeClass('shadow');
		$('canvas#arrow').remove();
	});
	
	// Grabs the current page's page title (generated by an Active CMS template tag)
	var currentPage = $('#page_title').text();
	
	// Traverses side_nav looking for link text that match currentPage.
	// If the there is a match with no extra text around it, add a class to the link.
	$('#sub_nav a:contains(' + "'" + currentPage + "'" + ')' ).filter(function() {
		if ($.trim($(this).text()) == currentPage ) {
			$(this).addClass('active');
		}
	});
	
	// Initialize plugins
	$('#slides').cycle({timeout: 10000, prev: '#prev', next: '#next'});

});
  
