var YCM = YAHOO.util.Connect;

function asyncBlogFeed() {

	var div;
	var anchor;

	this.init = function(cat_id, format, post_id, anc)
	{
		anchor = anc;
		div = document.getElementById('dic_'+cat_id);
		div.innerHTML = "<div style=\"padding:30px; text-align: center\"><img src=\"content/home/ajax-loader.gif\"style=\"padding-bottom: 6px; display: block; margin-left: auto; margin-right: auto;\"> Loading...</div>";
		this.getContent(cat_id, format, post_id);
	};

	this.successHandler = function(o)
	{
		var html = "";
		html = o.responseText;

		// Format and display results in the response container.
		div.innerHTML = html;

		// target a specific part of the page (anchor)
		if (anchor)
		{
			var tmp = new String(window.location)
			tmp = tmp.split("#");
			window.location = tmp[0]+"#"+anchor;
		}
	};

	this.failureHandler = function(o)
	{
		div.innerHTML = o.status + " " + o.statusText;
	};

	this.getContent = function(cat_id, format, post_id)
	{
		var boxType = 1;

		var sUrl = "";
		var url_comments = "";
		if (boxType == 1)
		{
			var baseURL = "http://www.5pointsrecords.com/blog/?feed=rss2";

			var params = "";
			if (post_id > 0)
			{
				//feedType = "rss";
				params = "&post="+post_id;
				url_comments = baseURL+"&p="+post_id;
			}
			var url = baseURL+"&cat="+cat_id;

			var entryPoint = './async/magpie.php';
			var queryString = "?cat="+cat_id+"&format="+format+params;
			    queryString += encodeURI('&url=') + encodeURIComponent(url);
			    queryString += encodeURI('&urlc=') + encodeURIComponent(url_comments);
			sUrl = entryPoint + queryString;
		}
		// Initiate the HTTP GET request.
		var request = YCM.asyncRequest('GET', sUrl, { success:this.successHandler, failure:this.failureHandler });
	};
};

function asyncHtmlFeed() {

	var div;

	this.init = function(div_id, url)
	{
		div = document.getElementById(div_id);
                div.innerHTML = "<div style=\"padding:30px; text-align: center\"><img src=\"content/home/ajax-loader.gif\"style=\"padding-bottom: 6px; display: block; margin-left: auto; margin-right: auto;\"> Loading...</div>";
                this.getContent(url);
	}

	this.successHandler = function(o)
	{
		var html = "";
		html = o.responseText;

		// Format and display results in the response container.
		div.innerHTML = html;
	};

	this.failureHandler = function(o)
	{
		div.innerHTML = o.status + " " + o.statusText;
	};
	
	this.getContent = function(url)
	{
		var entryPoint = './async/html.php';
		var queryString = "";
		queryString += encodeURI('?p=') + encodeURIComponent(url);
		sUrl = entryPoint + queryString;
		var request = YCM.asyncRequest('GET', sUrl, { success:this.successHandler, failure:this.failureHandler });
	}
}

