﻿
jQuery.fn.reverse = function()
{
	return this.pushStack(this.get().reverse(), arguments);
};

$(function() {
        // Array
        var tmp=[];
        // Get xml 
        $.ajax({
            url: "http://www.longleyacademy.com/xml/blog_headlines.xml",
            dataType: "xml",
            success: function(data){
                $(data).find("article").each(function() {
                     //alert($(this).find("title").text());
                     var id = $(this).attr('id')
                     //var id = $(this).find('ID').text()
                     var date = $(this).find('date').text()
                     var title = $(this).find('title').text()
                     var description = $(this).find('description').text()
                     var content = $(this).find('content').text()
					 var link = $(this).find('link').text()
                    
                    // Create the list of articles 
//                     $('<span></span>')
//                         .html(date + "<br/>" + title + "<br/>" + description + "<br/><a href=javascript:showWindow('viewArticle" + id + "')>Read More</a><br/><br/>")
//                         .appendTo('#home_panel_news_content div');
//                         
                     var articleItem = "<li><h4><span class='date'>" + date + "</span>" + " <a href='" + link + "')>" + title + "</a> &#187;</h4><p>" + description + "</p></li>";    
                     tmp.push(articleItem); 
                         
                     // Display the full article in a modal    
                     $('<div></div>')
                        .html("<div  class='news_article' id='viewArticle" + id + "' style='display:none; background:#FFFFFF; border: 4px solid #B1000A; width:60%; padding:20px; height: 450px;'>" + 
                                "<h2>" + title + "</h2>" +
                                "<div style='background:#FFFFFF;padding:20px;height:360px;overflow:auto;margin-bottom:10px'>" + content + "</div>" + 
                                "<p style='text-align:center'><a href='javascript:hideWindow()' class='close' title='Action: Close window'>X Close</a></p></div>")
                        .appendTo('#articleContainter');

                });
				
                for(i=(tmp.length-1); i>=0; i--){ 
                   $("#blog_container").append(tmp[i]); 
                } 
				
				var t = $("#blog_container").html();
				$("#blog_container").html("<h3>Latest Blog Postings</h3><ul>" + t + "</ul>");
            }
         });
         
    });