﻿function get_news_feed() {
    var feedURL = "/includes/newsFeeds.aspx";
    var showCount = 5;
    var i = 0;
    $("#feedContent").html("<BR><P><IMG src=\"/images/ajax-loader.gif\" align=\"left\">&nbsp;&nbsp;Loading News Feeds");
    $.get(feedURL, function(d) {
        $("#feedContent").empty();
        $(d).find('NewsRelease').each(function() {
            if (i < showCount) {
                var $item = $(this);
                var releaseID = $item.attr("ReleaseID");
                var title = $item.find('Title').text();
                var link = $item.find('ExternalURL').text();
                if (link.length == 0) {
                    link = "http://ir.net1.com/phoenix.zhtml?c=73876&p=irol-newsArticle&ID=" + releaseID + "&highlight=";
                }
                var pubDate = $item.find('Date').text();
                var html = "<div class=\"entry\"><h4>" + title + "<\/h4>";
                html += "<em class=\"date\">" + pubDate + "</em>";
                html += " &nbsp;<a href=\"" + link + "\" target=\"_blank\">Read More >><\/a><\/div>";
                $('#feedContent').append($(html));
                i++;
            }
        });
    });
};

function get_stock_quote() {
    var feedURL = "/includes/stockQuotes.aspx";
    var i = 0;
    $("#iRandDollar").hide();
    $(".stockQuotes").html("...");
	$.get(feedURL, function(d) {
	    $(".stockQuotes").empty();
		$(d).find("data").each(function() {
		    var $item = $(this);
		    $("#Quote" + i).html((i == 0 ? "$" : "R") + $item.find('Quote').text());
		    $("#Change" + i).html(indicator(parseFloat($item.find('Change').text())) + $item.find('Change').text());
		    $("#PctChange" + i).html(indicator(parseFloat($item.find('PctChange').text())) + $item.find('PctChange').text());
		    $("#Volume" + i).html($item.find('Volume').text());
		    $("#DataTime" + i).html($item.find('DateExt').text().split(" ")[1].substr(0,5) + (i == 0 ? " EST" : " CAT"));
		    $("#DataDate" + i).html($item.find('DateExt').text().split(" ")[0]);
		    i++;
		});
		 $("#irefresh a").css("background-image", "url(images/refresh.gif)");
	});
};

function indicator(val)
{
    var pic = "images/arrow_equal.gif";;
    if(val < 0)
        pic = "images/arrow_down.gif";
    if(val > 0)
        pic = "images/arrow_up.gif";
    return "<img alt=\"\" src=\"" + pic + "\" />";
}

$(document).ready(function(){
    get_stock_quote();
    get_news_feed();
    $("#irefresh a").click(function(){
        $(this).css("background-image", "url(images/refresh_animated.gif)");
        get_stock_quote();    
    }).css("cursor","pointer");
});