function cuisineFacebook(configuation)
{
	this.init(configuation);
}

cuisineFacebook.prototype.basePath = "";
cuisineFacebook.prototype.siteName = "";
cuisineFacebook.prototype.debug = false;
cuisineFacebook.prototype.locale = "de";
cuisineFacebook.prototype.teaserLength = 50;

cuisineFacebook.prototype.init = function(configuation)
{
	if(typeof(configuation) == "object")
	{
		if(typeof(configuation.basePath) != "undefined")
			this.basePath = configuation.basePath;
			
	   	if(typeof(configuation.debug) != "undefined")
	   		this.debug = configuation.debug;
	
		if(typeof(configuation.locale) != "undefined")
	   		this.locale = configuation.locale;
	
		if(typeof(configuation.teaserLength) != "undefined")
			 	this.teaserLength = configuation.teaserLength;
			
		if(typeof(configuation.siteName) != "undefined")
			 	this.siteName = configuation.siteName;
	}
}

cuisineFacebook.prototype.displayNewsTeaser = function(data, container)
{
	if(container.length)
	{
		var html = '<ul class="facebook_stream">';
		
		for(i in data.data)
		{
			if(data.data[i].message)
			{
				var time = this.parseDate(data.data[i].created_time, this.locale);

				if(!data.data[i].name)
				{
					if(data.data[i].type == "status")
						data.data[i].name = this.siteName;
					else
						data.data[i].name = data.data[i].message.substr(0,25)+"…";
				}

				if(!data.data[i].icon)
				{
					data.data[i].icon = "http://graph.facebook.com/"+data.data[i].from.id+"/picture";
				}


				html += '\
				<li>\
					<h2><a href="'+this.basePath+'/facebook/news/'+data.data[i].id+'/"><img width="16" src="'+data.data[i].icon+'" />'+data.data[i].name+'</a></h2>\
					<div class="timestamp">'+time.toLocaleString()+'</div>\
					<div class="text">\
				';

				if(data.data[i].message.length > this.teaserLength)
					html += data.data[i].message.substr(0,this.teaserLength)+"…";
				else
					html += data.data[i].message;

				html += '\
					</div>\
				</li>';
			}
			
		}
		
		html += '</ul>';
		
		container.removeClass("loading");
		container.html(html);
	}
}

cuisineFacebook.prototype.parseDate = function(string, locale)
{
	string = string.split("T");
	
	var date = string[0].split("-");
	var time = string[1].split("+")[0].split(":");
	
	if(!locale)
	{	
		var my_date = new Date(date[0], date[1]-1, date[2], time[0], time[1], time[2]);
		return my_date;
	}
	else
	{
		if(locale == "de")
		{
			return date[2]+"."+date[1]+"."+date[0]+" "+time[0]+":"+time[1];
		}
		else
		{
			return date[0]+"/"+date[1]+"/"+date[2]+"."+" "+time[0]+":"+time[1];
		}
	}
}

cuisineFacebook.prototype.log = function(string)
{
	if(this.debug && typeof(console.log) == "function")
		console.log(string);
}

cuisineFacebook.prototype.getNewsTeaser = function(container, limit)
{
	var count = (count) ? count : 1;
	var facebook = this;
	
	$.getJSON(this.basePath+"/facebook/get_page_stream/"+limit+"/", function(data)
	{
		facebook.displayNewsTeaser(data, container);
	});
	
	
}
