$(function() {

  $("#przyciski li").mouseover(function() {
    var nr = $(this).index() + 1;
    with ($(".submenu[data-menu=" + nr + "]")) {
      css("left", $("#przyciski li").eq(nr-1).offset().left);
      css("top", $("#przyciski li").eq(nr-1).offset().top + 35);
      fadeIn(300);
    }
  });
  
  $("#przyciski li").mouseleave(function(ev) {
    var submenu = $(".submenu[data-menu=" + ($(this).index() + 1) + "]")[0];
    if (submenu && ev.relatedTarget != submenu)
      $(submenu).fadeOut(300);
  });
  
  $(".submenu").mouseleave(function(ev) {
    if (ev.relatedTarget != $("#przyciski a")[$(this).index() - 1])
      $(this).fadeOut(300);
  });

	$(".konsult").attr("href", function(i, href) {
		return href + "&ajax=1";
	});

	$(".dialog").fancybox({"autoDimensions": false, "width": 550, "height": 400, "overlayOpacity": 0.4});
	
	$(".eml").each(function() {
		$(this).replaceWith('<strong>e-mail:</strong> <a href="mailto:' + $(this).text() + '@cmwum.pl">'
												+ $(this).text() + '@cmwum.pl</a>');
	});

	$("#praca").fancybox({"overlayOpacity": 0.4, "autoDimensions": false, "width": 600, "height": 370});
	
	if (window.location.search.substring(1) == '') $("#praca").click();
});
	

