$(document).ready(function () {
	var livepreviewSufix = "-livepreview";
	var livepreviewClass = "livepreviewBox";
	var isIE = ($('body').first().attr('id') == 'ie9');
	$("#menu li a[livepreview='true']").hover(function () {
		if ($(this).parent().html().indexOf(livepreviewClass) < 0) {
			var livepreviewHref = $(this).attr("href");
			var livepreviewPrefix = livepreviewHref.substring(0, livepreviewHref.lastIndexOf("."));
			var livepreviewFileType = livepreviewHref.substring(livepreviewHref.lastIndexOf(".") + 1);
			var livepreviewUrl = livepreviewPrefix + livepreviewSufix + "." + livepreviewFileType;
			var livepreviewCaller = $(this);
			$.ajax({
				url: livepreviewUrl,
				context: livepreviewCaller,
				cache: true,
				dataType: 'html',
				type: 'post',
				beforeSend: function () {
					$(this).parent().append('<div class="' + livepreviewClass + ' loading">Načítám...</div>');
				},
				success: function (data) {
					$(this).parent().find('.' + livepreviewClass).removeClass('loading').addClass('loaded').html(data);
				},
				complete: function (data) {
					if (data.status != '200') {
						$(this).parent().find('.' + livepreviewClass).removeClass('loading').addClass('error').html('No data');
					}
				}
			});
		};
		if (isIE) {
			$(this).parent().hover(function () {
				var $box = $('.' + livepreviewClass, this);
				$box.height('0px').css({
					'opacity': 0
				});
				$box.animate({
					'height': '276px',
					'opacity': 1
				}, 1000)
			}, function () {
				var $box = $('.' + livepreviewClass, this);
				$box.height('276px').css({
					'opacity': 1
				}, 500);
				$box.animate({
					'height': '0px',
					'opacity': 0
				}, 500)
			})
		}
	})
});
