(function($) {
	$(document).ready(function(){
		$(".entriesThumbnailList").isEntriesImages();
	});

	$.fn.isEntriesImages = function () {
		return this.each(function () {
			var thumbBox = $(this);
			$(".entriesImages").click(function () {
				var thumbImg = $(this);
				var thisOffset = thumbImg.offset();
				thumbBox.css({
					top : thisOffset.top + (thumbImg.height()/2), left : thisOffset.left + 20// + B.width()// + B.width()
				});
				thumbBox.html('');
				thumbBox.toggle().isEntriesImagessss(thumbImg);
				return false;
			});
			$(".calendar_year .calDay .GrayDate a.calClick").click(function () {
				var thumbImg = $(this);
				var thisOffset = thumbImg.offset();
				thumbBox.css({
					top : thisOffset.top + (thumbImg.height()/2), left : thisOffset.left + 20// + B.width()// + B.width()
				});
				thumbBox.html('');
				thumbBox.toggle().isEntriesImagessss(thumbImg);
				return false;
			});
			thumbBox.mouseup(function () {
				return false;
			});
			$(document).mouseup(function (thumbImg) {
				if ($(thumbImg.target).parent(".entriesImages").length == 0) {
					thumbBox.hide()
				}
			});
		});
	};

	$.fn.isEntriesImagessss = function (thumbImg) {
		thumbBox = $(this);
		var loading = $(".loading");
		var requestURL = blogURL + "/plugin/archiveCalendarEntries/";
		var requestData =  {period : thumbImg.attr("rel")};
		$.ajax({
			type : "POST", url : requestURL, dataType : "xml", data : requestData,
			beforeSend : function () {
				thumbBox.html(loading.html());
			},
			success : function (resultXML) {
				thumbBox.html($(resultXML).find("archiveCalendarBody").text());
				$(".AC_PreviewImage").isPreviewImage();
			},
			error : function () {
				return false;
			}
		});
	};

	$.fn.isPreviewImage = function () {
		var permalink = '';
		$(this).click(function () {
			permalink = $(this).find(".previewImage").attr("rel");
		location.href = permalink;
		}).mouseover(function () {
			$(this).addClass("AC_PreviewImageHover");
		}).mouseout(function () {
			$(this).removeClass("AC_PreviewImageHover");
		});
	};
})(jQuery);