
$(document).ready(function() {

	$('#datepicker').datepicker({
		maxDate: '+1D',
		beforeShowDay: function(date) {
			var now = new Date(date);
			var m = now.getMonth()+1, d = now.getDate();
			var f = now.getFullYear() + '' + (m<10?'0'+m:m) + '' + (d<10?'0'+d:d);
			for (var i=-1, iCount=dp.length; ++i<iCount;) {
				if (dp[i] == f) {
					return [true, 'dayOn', ''];
				}
			}
			return [false, '', ''];
		},
		onSelect: function(dateText, inst) {
			location.replace('/news/short/date/' + dateText.replace(/(\.)/g, '-'));
			return true;
		}
	});

	$('a[class="gallery"], a[rel="group"]').fancybox();


	$("#feedBack").dialog({
		autoOpen: false,
		height: 420,
		width:500,
		modal: true,
		buttons: {
			'Отправить': function() {

				if ('' == $('#fbName').val() || '' == $('#fbQuestion').val()) {
					$('#fbStatus').html('Поля "Имя" и "Сообщение" обязательны к заполнению.');
					return false;
				}
				$('#fbStatus').html('Пожалуйста подождите...');

				$.post('/?js=feedback', {
						name:	$('#fbName').val(),
						email:	$('#fbEmail').val(),
						city:	$('#fbCity').val(),
						text:	$('#fbQuestion').val()
					},
					function(reply) {
						if (1 == reply) {
							$('#fbStatus').html('<b>Ваше сообщение успешно отправлено.</b>');
							$('.row input, textarea', '#feedBack').val('');
						} else {
							$('#fbStatus').html('<u>По техническим причинам не удалось отправить, попробуйте позже.</u>');
						}
					});

			},
			'Отмена': function() {
				$(this).dialog('close');
			}
		},
		close: function() {

		}
	});

	$('#footer a[href="#feedback"]')
		.click(function() {
			$('#feedBack').dialog('open');
			return false;
		});


});

var cssFix = function() {
	var u = navigator.userAgent.toLowerCase(),
	is = function(t) {
		return (u.indexOf(t) != -1);
	};
	$("html").addClass([(!(/opera|webtv/i.test(u)) && /msie (\d)/.test(u)) ? ('ie ie' + RegExp.$1)
		: is('firefox/2') ? 'gecko ff2'	: is('firefox/3') ? 'gecko ff3'	: is('gecko/') ? 'gecko'
		: is('chrome/') ? 'chrome'
		: is('opera/9') ? 'opera opera9'	: /opera (\d)/.test(u) ? 'opera opera' + RegExp.$1
		: is('konqueror') ? 'konqueror'
		: is('applewebkit/') ? 'webkit safari'
		: is('mozilla/') ? 'gecko'
		: '',
		(is('x11') || is('linux')) ? ' linux' : is('mac') ? ' mac' : is('win') ? ' win'
	: ''].join(''));
}();

