$(function onlikecookies() {
	var COOKIE_NAME = 'onlikes';
	var date = new Date();
	date.setTime(date.getTime() + (30 * 24 * 60 * 60 * 1000));
	var options = { path: '/', expires: date };

	$('a.like').click(function() {
		var postid = $(this).attr("id");
		var newvalue = ($.cookie(COOKIE_NAME) == null ) ? "|" + postid + "|" : $.cookie(COOKIE_NAME) + postid + "|";
		$.cookie(COOKIE_NAME, newvalue, options);
		return false;
	});

var displayedPostsId = new Array();

$('.like').each(function(){
	displayedPostsId[displayedPostsId.length] = $(this).attr("id");
});

if ($.cookie(COOKIE_NAME)) {
for(i in displayedPostsId){
		if ($.cookie(COOKIE_NAME).indexOf("|" + displayedPostsId[i] + "|") >= 0) {
			$("#" + displayedPostsId[i]).replaceWith('<div class="heart-active"></div>');
			$("#postlikes-msg").fadeOut(1000);
		}
}

} else {
//	$("#messaging").replaceWith('<div class="sub-head"><div class="bannheader-728"><img src="/wp-content/themes/kilone/img/messaging-welcome.png" alt="" /></div></div>');
}

});

$(document).ready(function() {
							 
	$(".like").click( function() {
	var likeid = $(this).attr("rel");
	$(this).fadeOut(1000);
	$("#postlikes-msg").fadeOut(1000);
	var count = $("#numlike"+likeid).text();
	count++;
	$("#numlike"+likeid).text(count);
	$.ajax({
		   type:		'POST',
		   cache:		false,
		   url:			'../../../../script_likes.php',
		   data:		'postid='+likeid,
		   'success': 	function(data, textStatus){
			   $('#like'+likeid).replaceWith("<div class=\"heart-active\"></div>");
			}
	});	
	onlikecookies();
});	

	$("div[id^='post-']").each(function (i) {
		var linkId = $(this).attr("id").substr(5);
		var bgimg = $("#post-" + linkId + " .postpicture img").attr("src");			
		$("#teasering" + linkId).html("<div class='teasbging' style='background: url(" + bgimg + ") 50% 50% repeat;'></div>");				
	});
	
});