//////////////////////////////////////////////////////
//
//	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");
		});
	}
	
	// Remove default search text on focus
	$(".emptytext").focus( function(){
		if ( $(this).val() == $(this)[0].defaultValue ) {
			$(this).val("");
		}
	});

	// Replace default search text on blur if input is empty
	$(".emptytext").blur( function(){
		if ( $(this).val() == "" ) {
			$(this).val( $(this)[0].defaultValue );
		}
	});
	
	
	$('.readMore').click(function() {
		$(this).toggleClass('open');
		$(this).prev('.extraInfo').slideToggle();
	});


	// get blog RSS for footer
	get_blog_feed("#footernav li.blog", "/pressroom/feed/rss/");

});

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name, "", -1);
}

function areCookiesEnabled() {
	var r = false;
	createCookie("testing", "Hello", 1);
	if (readCookie("testing") != null) {
		r = true;
		eraseCookie("testing");
	}
	return r;
}

function get_blog_feed(container, rss_url) {
	var container = jQuery(container);

	if (container.length > 0) {
		jQuery.get(rss_url, function(data) {
			if (typeof data == "string") { // help IE
				xml = new ActiveXObject("Microsoft.XMLDOM");
				xml.async = false;
				xml.loadXML(data);
			} else {
				xml = data;
			}

			var feed = jQuery(xml);
			var length = 105;
			var max = 4;
			var list = "";

			feed.find('channel item').each(function(count){
				var item = jQuery(this);
				var title = jQuery.trim(item.find('title').text());
				var description = jQuery.trim(item.find('description').text().substring(0, length)) + '...';

				if (count < max) {
					list += '<li><a href="' + item.find('link').text() + '">' + title + '</a></li>';
				} else {
					return false;
				}
			});

			container.append("<ul>" + list + "</ul>");
		});
	}
}	

