// JavaScript Document

/* "Media-Box"
* Ignition-Groupe-Interactive
* K. Schaefer
* 02/2010
* Version 2010-02-11, 14:04
*************/

function bloggerBox()
{
	this.htmlElement;
	this.blogSource;
	this.blogItemDate;
	this.blogItemDateObject;	
	var to = this;
	
	this.init = function () {
		var copyCommentElement;
		var commentElement;		
		jQuery(to.htmlElement).parent("div").css("minHeight","60px");
		jQuery(to.htmlElement).parent("div").addClass("activity_status_loading");
		jQuery.ajax({
			url: this.blogSource,
			type: "GET",
			dataType: "json",
			success: function(result) {
				commentElement = jQuery(to.htmlElement).find("li");
				jQuery(to.htmlElement).find("li").remove();				
				jQuery.each(result.blogs, function (i, item) {
						copyCommentElement = jQuery(commentElement).clone();
						//to.blogItemDateObject = new Date(item.date);
						//to.blogItemDate = to.blogItemDateObject.getDate() + "." + to.blogItemDateObject.getMonth() + "." + to.blogItemDateObject.getFullYear();						
						jQuery(copyCommentElement).find("a:first").attr({href:item.url,target:"_blank"}).append(item.urlTitle);
						jQuery(copyCommentElement).find(".date").append(item.date);
						jQuery(copyCommentElement).find(".headline").append(item.headline);
						jQuery(copyCommentElement).find(".content").append(item.content);
						if(i==0){jQuery(copyCommentElement).addClass("first")};
						if((i+1)==jQuery(result.blogs).length){jQuery(copyCommentElement).addClass("last")};							
						jQuery(to.htmlElement).append(copyCommentElement);
					});
					jQuery(to.htmlElement).parent("div").removeClass("activity_status_loading");
					jQuery(to.htmlElement).parent("div").css("minHeight","inherit");
				
				},
			error: function(msg) {jQuery(to.htmlElement).append("<div class='error'>An error occoured. Please try later! <br/>(Couldn't load data)</div>");}
			});
	}
}