
jQuery.fn.resizeImage = function (boxSize) {
	boxSize = boxSize || 100;
	return this.each(function () {
		var max, width, height;
		if (this.width && this.height) {
			max = this.height > this.width  ? { dim: 'h', val: this.height } : { dim: 'w', val: this.width };
			if (max.val <= boxSize) {
				height = max.dim == 'h' ? max.val : this.height;
				width  = max.dim == 'w' ? max.val : this.width;
			} else {
				height = max.dim == 'h' ? boxSize : Math.floor(this.height * boxSize / max.val);
				width  = max.dim == 'w' ? boxSize : Math.floor(this.width * boxSize / max.val);
			}
			$(this).css({
				height: height,
				width: width
			});
		}
	});
}

$(function () {
	$('#datepicker').datepicker({
		autosize: true,
		onSelect: function (dateText, inst) {
			var dateObject = $(this).datepicker("getDate");
			// dateText - текстовое предстваление даты
			// dateObject - JS объект выбранной даты
		}
	});

	$('#content .post').each(function (index) {
		var images = $('.images img', this);
		images
			//.not(':first')
			//.resizeImage(63)
			//.error(function () { })
			//.load(function () {
			//	$(this).resizeImage(63);
			//})
			//.end()
			//.eq(0)
			//.parents('a:first')
			//.wrap('<div class="first img-first-wrapper"><div class="img-second-wrapper"></div></div>');
		$('.images a', this)
			.attr('rel', 'photo-gallery-'+index)
			.colorbox({
				photo: true,
				scalePhotos: true,
				//maxWidth: $(window).width(),
				maxWidth: function () {
					return $(window).width() - 20;
				},
				maxHeight: function () {
					return $(window).height() - 20;
				},
				rel: 'photo-gallery-'+index,
				slideshowStart: "Начать показ слайдов",
				slideshowStop: "Остановить показ слайдов",
				current: "{current} из {total}",
				previous: "предыдущее",
				next: "следующее",
				close: "закрыть"
			});
	});
});

