var visibleMenu={element:null, subElementName:null, timeout:null};
var menuToShow ={element:null, subElementName:null, timeout:null};

function hideMenu() {
	clearTimeout(visibleMenu.timeout);
	visibleMenu.timeout = null;
	if (visibleMenu.element && (visibleMenu.element != menuToShow.element)) {
		$(visibleMenu.element).find(visibleMenu.subElementName).fadeOut('fast');
		visibleMenu.element = null;
	}
}

function showMenu(){
if(menuToShow.element != visibleMenu.element){
	hideMenu();
	if(menuToShow.element){  //show menu to show if any
		$(menuToShow.element).find(menuToShow.subElementName).fadeIn('fast');
		visibleMenu.element = menuToShow.element;
		menuToShow.element = null;
		}
	}
}

function showSearch(){
	$("#extrasearch").fadeIn('fast');
}
function hideSearch(){
	$("#extrasearch").fadeOut('slow');
}
function showSubSearch(){
	$("#extrasubsearch").fadeIn('fast');
}
function hideSubSearch(){
	$("#extrasubsearch").fadeOut('slow');
}

$(document).ready(function() {
//activate menu
 $('#menu > li').hover(function() {
		menuToShow.element = this;
		menuToShow.subElementName = 'div';
		menuToShow.timeout = setTimeout("showMenu()",100);
	}, function() {
	  clearTimeout(menuToShow.timeout);
	  menuToShow.element = null;
	  visibleMenu.subElementName = 'div';
		visibleMenu.timeout = setTimeout("hideMenu()",400);
	});
//activate search
	$('#searchtext').click(function(){
		showSearch();
		$('#searchtext').select();
	});

	$('#searchtext').blur(function(){
		setTimeout("hideSearch()",1000);
	});
//activate subsearch
	$('#subsearchtext').click(function(){
		showSubSearch();
		$('#subsearchtext').select();
	});

	$('#subsearchtext').blur(function(){
		setTimeout("hideSubSearch()",1000);
	});


});


/**
 * odkaz na otevirani odkazu do novych oken
 * k odkazu se prida atribut rel="external"
 */
function externalLinks()
{
 if (!document.getElementsByTagName) {
   return;
   }
 var anchors = document.getElementsByTagName("a");
 for (var i = 0; i < anchors.length; i++) {
   var anchor = anchors[i];
   if (anchor.getAttribute("href") &&
   anchor.getAttribute("rel") == "external") {
     anchor.target = "_blank";
     }
 }
}
$(document).ready(function(){
 externalLinks();
});

function thisMovie(movieName) {
    if (navigator.appName.indexOf("Microsoft") != -1) {
        return window[movieName];
    } else {
        return document[movieName];
    }
}
//because of buggy IE6 not to flicerk background images
try {document.execCommand("BackgroundImageCache", false, true);} catch(err) {}

