function getnews(id, target, displayCount, displayLink) {
	$.get('/FeedService.php?Action=' + target, function(rss) {	 		
		var counter = 0;
		
		$(rss).find('item').each(function() {
			if (counter == displayCount) return;
		
			var $item = $(this);
			var title = $item.find('title').text();
			var link = $item.find('link').text();
			var description = $item.find('description').text();
			var date = $item.find('pubDate').text();
 
			var html = '<h2 class="news">' + title + '</h2>';
			//html += '<em>' + date + '</em>';
			html += '<p>' + description + '</p>';
 			
			if (displayLink) {
				html += '<a href="' + link + '">read more</a>';	
			}
			
			if (counter > 3) {
				//html += '';
				$('#' + id).append($(html));
			}
			counter++;
		});
	});
}

$(function() {
	$("#trigger").tooltip();
			
	$('.banner-fade').innerfade({
		speed: 1000,
		timeout: 6000,
		type: 'random_start'
	});
	 
	$("#dropmenu ul").css({display: "none"});
	$("#dropmenu li").hover(function(){
		$(this).find('ul:first').css({visibility: "visible",display: "none"}).show(268);
	}, function(){
		$(this).find('ul:first').css({visibility: "hidden"});
	});
	
	getnews('newsone', 'tp', 8, false);
	getnews('newstwo', 'health', 6, false);
	getnews('newsthree', 'health', 7, false);
	
	
	//To switch directions up/down and left/right just place a "-" in front of the top/left attribute
	//Vertical Sliding
	//$('.boxgrid.slidedown').hover(function(){
	//	$(".cover", this).stop().animate({top:'-260px'},{queue:false,duration:300});
	//}, function() {
	//	$(".cover", this).stop().animate({top:'0px'},{queue:false,duration:300});
	//});
	
	//Horizontal Sliding
	$('.boxgrid.slideright').hover(function(){
		$(".cover", this).stop().animate({left:'260px'},{queue:false,duration:300});
	}, function() {
		$(".cover", this).stop().animate({left:'0px'},{queue:false,duration:300});
	});
	
	/** EMAIL SECTION */
	$("#email-form").submit(function () {
		var email = $("#email").val();
		if (email == "") {
		    $("#error").show();
			$("#email").focus();
			return false;
		} else {
			$("#error").hide();		
		}
		var payload = 'email=' + email + '&domain=www.healthconducive.com';
		$.ajax({
		    type: "GET",
			url: "/email/EmailService.php?Action=capture",
			data: payload,
			success: function() {
		        $("#email-confirmation").show("slow");
                $("#email-box").hide("slow");
            }
        });
		return false;
    });
});