

var they={

  relatedTagsLimit:3,

  relatedPostsLimit:18,

	loadRelated:function() {
	var idlist=[];
	var ids = new Array();
    idlist.push($("body").attr("class").replace(/post/,""));
		$('#tags a').each(function() {
			var tagName=$(this).attr('rel');
			var b=0;
			//$.get('/tagged/'+tagName,function(data) {
	$.getJSON("http://designersgotoheaven.com/api/read/json?callback=?&tagged=" + tagName, function (data) {
    $.each(data.posts, function (i, posts) {
     	var id = this.id;
        var type = this.type;
        var date = this.date;
        var url = this.url;
        var photo = this['photo-url-100'];
		if(idlist != id) { 
		if (jQuery.inArray(id, ids) === -1) {
			$('#related').append('<a href="http://designersgotoheaven.com/post/' + id + '"><img src =' + photo + '></a>');
			ids.push(id);
		}
		}else{}
    });


});


			/*	$(data).find('.post').each(function() {

					var pid=$(this).attr('id').replace(/post/,"");

					var e=0;

					if (e<=5 && b<=they.relatedPostsLimit && idlist.indexOf(pid)==-1) {

						idlist.push(pid);

						e++;

						b++;

						$(this).appendTo($('#related'));

					}

				});



			});
*/


		});



		$('#related').show();
		$('#descriere').show();




	},



	trimTags:function() {

		$a=$('#tags a:last');

		$a.html($a.html().replace(', ',''));

	}

};



$(document).ready(function() {

	$('body#perm').each(function() {

		they.loadRelated();

		they.trimTags();

	});

});
