
Request = {
	QueryString: function(item) {
		var svalue = location.search.match(new RegExp("[\?\&]" + item + "=([^\&]*)(\&?)", "i"));
		return svalue ? svalue[1] : svalue;
	}
}


function get_rss_feed() {
	//clear the content in the div for the next feed.
    
 
	//use the JQuery get to grab the URL from the selected item, put the results in to an argument for parsing in the inline function called when the feed retrieval is complete
    $.get("/proxy.aspx?u=http://blog.yourshare.com.au/?feed=rss2", function (d) {
        $("h4.blogs").show();
        var count = 0;
        //find each 'item' in the file and parse it
        $(d).find('item').each(function () {
    
            count++;
            if (count > 3) {
                return true;
            }
            //name the current found item this for this particular loop run
            var $item = $(this);
            // grab the post title
            var title = $item.find('title').text();
            // grab the post's URL
            var link = $item.find('link').text();
            // next, the description
            var description = truncate($item.find('description').text(), 200, '...');
            //don't forget the pubdate
            var pubDate = $item.find('pubDate').text();
            var baddate = pubDate.split(" ");
            var newdate = baddate[0] + " " + baddate[1] + " " + baddate[2] + " " + baddate[3];


            newdate = newdate.replace(/\,/g, '');
            //newdate = relative_time(newdate);
            // now create a var 'html' to store the markup we're using to output the feed to the browser window
            var html = " <blockquote class=\"cfix\"><a href=\"" + link + "\" target=\"_blank\"><h4 class=\"postTitle\">" + title + "<\/h4></a>";
//            html += "<h5 class=\"date\">" + newdate + "</h5>";
//            html += "<p class=\"description\">" + description + "</p>";
            html += "<\/blockquote>";
            
            //put that feed content on the screen!
            $('#testimonials').append($(html));
        });
        $('#testimonials blockquote p a').attr("target", "_blank");
    });
 
};
truncate = function(text, length, ellipsis) {    

    // Set length and ellipsis to defaults if not defined
    if (typeof length == 'undefined') var length = 100;
    if (typeof ellipsis == 'undefined') var ellipsis = '...';

    // Return if the text is already lower than the cutoff
    if (text.length < length) return text;

    // Otherwise, check if the last character is a space.
    // If not, keep counting down from the last character
    // until we find a character that is a space
    for (var i = length-1; text.charAt(i) != ' '; i--) {
        length--;
    }

    // The for() loop ends when it finds a space, and the length var
    // has been updated so it doesn't cut in the middle of a word.
    return text.substr(0, length) + ellipsis;
}
// pubDate delta function
function get_delta(time_value) {
console.log(time_value);
	var values = time_value.split(" ");
	time_value = values[2] + " " + values[1] + ", " + values[3] + " " + values[4];
	var parsed_date = Date.parse(time_value);
	var relative_to = (arguments.length > 1) ? arguments[1] : new Date();
	var delta = parseInt((relative_to.getTime() - parsed_date) / 1000);
	if (values[5] == "+0000") {
		delta = delta + (relative_to.getTimezoneOffset() * 60);
	} else {
		delta = delta + relative_to.getTimezoneOffset();
	}


	return delta;
}
function relative_time(time_value) {

	var delta = get_delta(time_value);

	if (delta < 60) {
		return 'less than a minute ago';
	} else if(delta < 120) {
		return 'about a minute ago';
	} else if(delta < (60*60)) {
		return (parseInt(delta / 60)).toString() + ' minutes ago';
	} else if(delta < (120*60)) {
		return 'about an hour ago';
	} else if(delta < (24*60*60)) {
		return 'about ' + (parseInt(delta / 3600)).toString() + ' hours ago';
	} else if(delta < (48*60*60)) {
		return '1 day ago';
	} else {
		return (parseInt(delta / 86400)).toString() + ' days ago';
	}
}
