$(document).ready(function(){
	try {
		var ie6 = !window.XMLHttpRequest;
		
		function hideFlash(){
			$("object").add(ie6 ? "select" : "embed").each(function(index, el) {
				el.style.visibility = "hidden";
			});
		}
		
		function showFlash(){
			$("object").add(ie6 ? "select" : "embed").each(function(index, el) {
				el.style.visibility = "visible";
			});
		}
		
		$('#menu').addClass('menu_cufon');
		$('#menu > li').each(function(){
			var li = $(this);
			var anchor = li.find('> a');
			var anchor_clone = anchor.clone();
			li.append(anchor_clone);
			
			anchor.addClass('original');
			anchor_clone.addClass('clone');
			anchor.hide();
			
			li.bind('mouseenter', function(){
				anchor_clone.hide();
				anchor.show();
				li.addClass('hover');
				
			}).bind('mouseleave', function(){
				anchor_clone.show();
				anchor.hide();
				li.removeClass('hover');
			});
		});
		
		Cufon.replace('#menu > li > a.li', { });
		Cufon.replace('h1, h2, h3, #right legend, button.submit', { });
	
		var opt = {
			callbackOnStart: hideFlash,
			callbackOnClose: showFlash
		};
		
		$('a[rel=lightbox-cats]').fancybox(opt);
		
		$('a[rel=lightbox]').each(function(){
			$(this).fancybox(opt);
		});
		
		$('a.popup').fancybox({
			frameWidth: 1200,
			frameHeight: 650,
			callbackOnStart: hideFlash,
			callbackOnClose: showFlash
		});
		
		window.useCufon = true;
		
		function menuOver(self) {
			if(!window.useCufon) self.id = 'hover'
		}
		
		function menuBlur(self) {
			if(!window.useCufon) self.id = null;
		}
	
		/**
		 * prida vsem <li> na nejvyssi urovni onmouseover a onmouseout
		 * prida poslednimu <a> na kazde druhe urovni tridu last
		 **/
		if (document.getElementById('menu')) {
			elems = document.getElementById('menu').childNodes;
			for (i = 0; i < elems.length; i++) {
				elems[i].onmouseover = function() {
					menuOver(this);	
				};
				elems[i].onmouseout = function() {
					menuBlur(this);
				};
				if (elems[i].tagName && elems[i].tagName == 'LI') {
					children = elems[i].getElementsByTagName('a');
					if (children.length) {
						children[(children.length-1)].className += ' last';
					}
				}
			}
		}
		
		// $('#harmonyPopup').click();
	} catch (e) {
		if (typeof window.console != 'undefined') {
			window.console.log(getException(e));
		} else {
			throw new Error(getException(e));
		}
	}
});
