$(document).ready(function() {

if (document.getElementsByTagName && document.createElement && document.createTextNode && document.documentElement && document.getElementById) {
	$(document.documentElement).addClass('js');
}

var el = $('div.hovered'),
	hide = el.find('div.hide'),
	overlay = $('#overlay'),
	popup = $('#popup'),
	animate = true,
	w = $('#w'),
	wi = $('#wi'),
	w2 = $('#w2');
	
function animateTab(start) {
	start = typeof(start) != 'undefined' ? start : true;
	if (start) {
		if (!animate) return;
		el.doTimeout( 'loop', 1000, function(){
			el.toggleClass('hovered-zebra');
			return true;
		});
	}
	else {
		el.doTimeout('loop');
	}
}

function popupShow() {
	overlay.show();
	popup.show();
	el.attr('class', 'hovered');
	animateTab(false);
	animate = false;
	return false;
}

function popupHide() {
	animate = true;
	animateTab(true);
	overlay.hide();
	popup.hide();
	return false;
}

function resizeWindow() {
	var height = w.height();
	if (height < 1440) {
		var top = Math.round(height / 2);
		w2.css('top', top+20+'px');
		wi.css('min-height', 620+top+'px');
	} else {
		w2.css('top', '50%');
		wi.css('min-height', '1062px');
	}
}

el.hover(
	function() {
		animateTab(false);
		hide.fadeIn(200);
	},
	function() {
		animateTab();
		hide.fadeOut(400);
	}
);

animateTab(true);

hide.find('a').click(popupShow);
overlay.click(popupHide);
popup.find('a.bt-close').click(popupHide);

popup.find('a.bt-print').click(function(){
	window.print();
	return false;
});

resizeWindow();
$(window).resize(function() {
	resizeWindow();
});


});
