//////////////////////////////////////////////////////
//
//	The purpose of this file is to
//	apply a hover class on mouseover
//	on the <li> elements in the nav.
//	This is because IE doesn't put
//	the pseudo class :hover on <li> elements
//
//	This is code that uses the
//	jquery javascript library (http://jquery.com/)
//
//////////////////////////////////////////////////////
$(document).ready(function() {
	if (document.all&&document.getElementById) {
		// this is needed for the IE 6 pseudo hover class bug
		$(".navtop > li").hover(function() {
			$(this).addClass("hover");
		},
		function () {
			$(this).removeClass("hover");
		});

		// this adds flyout support for IE 6
		$(".navtop > li li ").hover(function () {
			$(this).addClass("hover");
		},
		function () {
			$(this).removeClass("hover");
		});
	} else {
		// this is need for safari when nav covers flash
		$(".navtop li ul").hover(function () {
			$(this).addClass("redraw");
		},
		function () {
			$(this).removeClass("redraw");
		});
	}

	// selector for pretty photo lightbox used with videos

	$("a[rel^='lightbox']").prettyPhoto({ theme: 'light_square', default_width: 641, default_height: 385,modal: true });

	// prevent link action on top links
	$("#headernav ul.navtop > li > a").each(function(){
		var $this = $(this);
		$this.replaceWith("<span>" + $this.text() + "</span>");
	});
});

/* News Navigation Stuff */
$(function(){
	/*Collapse/expand navigation*/
	$('#newsNav ul li .title').click(function(){
		isSelected = $(this).parent().hasClass('selected');
		$('#newsNav > ul > li.selected').removeClass('selected');
		if(!isSelected){
			$(this).parent().addClass('selected');
		}
	});
	
	/*show only 3 items and append read more link to description*/
	var newsListItems = $('#newsList .item');
	var itemsToShow = 3;
	if(newsListItems.length < itemsToShow){
		itemsToShow = newsListItems.length;
	}
	for(var i = 0; i < itemsToShow; i++){
		var item = $($('#newsList .item')[i]);
		item.css({display: 'block'});
		linkHref = item.find('a:first').attr('href');
		item.find('.description').append(' ').append($('<a>[read more]</a>').attr('href',linkHref));
		if(i == itemsToShow -1)
			item.addClass('last');
	}
});

