$(function(){
	// Dropdown navigation
    $("ul.nav li").hoverIntent(function() {
        $(this).addClass("hover");
        $('ul:first',this).css('visibility', 'visible');
    }, function() {
        $(this).removeClass("hover");
        $('ul:first',this).css('visibility', 'hidden');
    });
    
    // $("ul.nav li ul li:has(ul)").find("a:first").append(" &raquo; ");

	// Featured slideshow for home page
	$("#slide-nav").tabs("#slides > .slide", {
        // effect: 'fade', 
        // fadeOutSpeed: 'slow',
        rotate: true
	}).slideshow({
		autoplay: true,
		interval: 5000
	});
	
	// Truncation
	var newWidth = 300;
	$("#dashboard .ec3_events h6 a").textTruncate(newWidth);
	$("#dashboard .blog h6 a").textTruncate(newWidth);
	$("#dashboard .blog p").textTruncate(newWidth*2.733);
	$("#dashboard .exhibit h6 a").textTruncate(newWidth / 1.4);
	$("#dashboard .exhibit p").textTruncate(newWidth*1.9);
	
	// Hide extra things list elements
	var eventNumber = $('#upcoming li').size();
	
	if (eventNumber > 3) {
		$('#upcoming li:gt(2)').hide();
		// Add the view button
		$('#upcoming ul').append('<a class="more-less">view all</a>');
		// Setup the click action and toggle the elements
		$('#upcoming .more-less').click(function() {
			$('#upcoming li:gt(2)').toggle();
			$('#upcoming .more-less').toggleClass('active');
			if ($(this).is(".active")) {
				$(".more-less").text("view less");
			} else {
				$(".more-less").text("view all");
			}
		});	
	}
	

	// STYLE THE LINKS ACCORDING TO MEDIA - word doc
	$("a[href$=doc]").addClass("download_doc");
	
	// STYLE THE LINKS ACCORDING TO MEDIA - pdf
	$("a[href$=pdf]").addClass("download_pdf");	
});
