﻿$(document).ready(function()
{
	$('.sectionContent').hide();
	$('.sectionContent').first().show();
	$('.sectionFooter').hide();
	$('.sectionFooter').first().show();
	
		
	$('h3').hover(
		function()
		{$(this).css('cursor','pointer');},
		function()
		{$(this).css('cursor','auto');}
	);
	
	
	
	$('h3').click(function()
	{
		//Footer
		$(this).next().animate({'height':'toggle'},'fast','swing');
		//sectionFooter
		$(this).next().next().animate({'height':'toggle'},'fast','swing');

						
		if ($(this).text().substring(0,1) == '+')
		{
			$(this).html($(this).html().replace('+','-'));
		}
		else
		{
		 	$(this).html($(this).html().replace('-','+'));
		}
	});
	
	$.ajax({
		type: "GET",
		url: "getfeed.php",
		dataType: "xml",
		success: parseXML,
		error: errorXML
	});	
	
	function parseXML(xml)
	{

		$('#blogContent').html('');
		var LineCount = 0;
		$(xml).find('item').each(function()
		{
			
			LineCount++;
			var title = $(this).find('title').text();
			var desr = $(this).find('description').text();
			var link = $(this).find('link').text();
			var pubdate = $(this).find('pubDate').text();
			var titlelink = '<a href="'+link+'">'+title+'</a>'
			
			var cutpos = pubdate.indexOf(':') -2;
			var formattedDate = pubdate.substring(0,cutpos);
			
			if (LineCount % 2 == 0) //Even Number
			{

				$('<div class="blog_title even"></div>').html(titlelink).appendTo('#blogContent');
				$('<div class="blog_descr even"></div>').html(desr).appendTo('#blogContent');
				$('<div class="blog_pubdate even"></div>').html(formattedDate).appendTo('#blogContent');
			}
			else
			{
				$('<div class="blog_title"></div>').html(titlelink).appendTo('#blogContent');
				$('<div class="blog_descr"></div>').html(desr).appendTo('#blogContent');
				$('<div class="blog_pubdate"></div>').html(formattedDate).appendTo('#blogContent');

			}
																								
		});
		if (LineCount == 0)
		{
			$('<div class="blog_descr"></div>').html("<em>No Blog Posts Found</em>").appendTo('#blogContent');
		}
				
	}
	
	function errorXML(object,ts,et)
	{
		$('#blogContent').html('');
		$('<div class="blog_descr"></div>').html("<em>No Blog Posts Available</em>").appendTo('#blogContent');
	}
	
	
	//var MAX_ITEMS = 0;
			//$(xml).find('item').each(function()
			//{
				//MAX_ITEMS++;
				//var title = $(this).find('title').text();
				//$('<div class="blog_title"></div>').html(title).appendTo('.blogContent');
			//});	
		
	$('#LinkTable tbody tr:odd').css('background-color','#dddddd');
	
	
	
	
	


	
	
});

