document.write(unescape("%3Clink rel='stylesheet' type='text/css'  href='gfx/style_js.css'%3E%3C/script%3E"));
var windowWidth;

function showMenu() {

  if (windowWidth == jQuery(window).width()) return false;

  jQuery("#menu").show().find("li").show();
  var m = document.getElementById("menu");
  var mt =  jQuery(m).parent().height()/2 - jQuery(m).height()/2;
  jQuery(m).css({"margin-top":mt+"px"});
  
  var cw = jQuery(m).parent().width();
  var iw = 0;
  
  jQuery(m).children("li").each (function() {iw += jQuery(this).outerWidth(true); } );
  if (iw < cw) {
      
      var pl = cw/2 - iw/2;
      jQuery(m).css({"padding-left":pl+"px", "width":cw-pl+"px"});
  }
  
  function displayItems(start_item, total_time) {
  
      var l = $(start_item).siblings().length + 1;
      jQuery(start_item).fadeIn(total_time/l, function() {
            var sibl = jQuery(start_item).next(); 
            if (sibl.length) displayItems(sibl,total_time);
      });
  }
  jQuery("#menu li").hide();
  displayItems(jQuery("#menu li:first")[0], 500);

  windowWidth = jQuery(window).width();
  jQuery(window).resize(showMenu);
}

jQuery(document).ready(function() {

    jQuery("#window").hide();
});


jQuery(window).ready(function() {

  jQuery("#window").show();               
  jQuery("#menu").hide();
  
  if (jQuery(".article").length) {
    
    // ----- article ------ //

    function wrapText(el) {

        var ch = el.childNodes;
        var nodes = [];
        for (var ii in ch) {
            nodes[nodes.length] = ch[ii];
        }

        for (var ii in nodes) {

            var n = nodes[ii];            

            if (n.nodeType == 3) {
                var txt = n.nodeValue.split(" ");
                var space = txt.length>1 ? " ":"";                

                for (var xx in txt) {
                    
                    var span = document.createElement('span');
                        span.className = 'tsh';
                        jQuery(span).html(txt[xx]+space);
                    n.parentNode.insertBefore(span,n);                    
                }
                n.parentNode.removeChild(n);
            }
            if (n.nodeType == 1) {
                wrapText(n);
            } 
        }
        
    }

 
    jQuery("#content").hide();
    var elements = jQuery("#content").find("h1,h2,h3,p,li,label,a");
    elements.each (function() {
        wrapText(this);
    });
    var words = jQuery("#content span.tsh");
    words.hide();
    jQuery("#content").show();
    jQuery("div.article").show();
    var nr = 0;
    function showWord() {
        nr%2 ? jQuery(words[nr]).fadeIn(200) : jQuery(words[nr]).show();
        if (words[nr+1]) {
          nr++;
          setTimeout(showWord, 50);
        }
    }
    showWord();
    
    var shakeStop = false;    
    function shake(obj) {
        if (shakeStop || !obj) return false;
        var rand = Math.floor(Math.random()*4);
        var oldw = jQuery(obj).width();
        var oldh = jQuery(obj).height();
        jQuery(obj).animate({width:(oldw+rand)+"px", margin:rand+"px", height:(oldh+rand)+"px"}, 200).animate({width:oldw+"px",height:oldh+"px"}, 200, function() { shake(obj) } );
    }
    shake(jQuery("#email")[0]);
    jQuery("#email").focus( function() { shakeStop = true; } );

    // ----- !article ------ //   

  } else {            
  
    // ----- main frame ------ // 
    function startPage() {
    jQuery("div#window").css({width:"100px"}).show().animate({width:"100%"}, showMenu);
    jQuery("#menu li img").css("opacity","0.7").hover(
                                                function() {
                                                    $(this).css({"opacity":1}).animate({width:"65px",height:"63px"},200);
                                                    $("#selectedItem").html($(this).attr("alt"));
                                                }, 
                                                function(){
                                                    $(this).stop();
                                                    $(this).css({"opacity":0.7,width:"60px",height:"58px"});
                                                    $("#selectedItem").html("");
                                                }).attr({title:""});
    }
    jQuery("div#window").hide();
    setTimeout(startPage,600);  
    // ----- !main frame ------ //
  } 
  
  jQuery("a").focus(function(){ this.hideFocus=true; });
  jQuery("#send_form").submit( function() {

      var em = jQuery("#email").val();
      var ms = jQuery("#msg").val();
      
      if (!em.match(/^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/)) {
        alert("Proszę wpisać adres e-mail.");
        return false;
      }
      if (ms.length < 10) {
        alert("Proszę wpisać wiadomość.");
        return false;
      }
  
      jQuery(this).html("<div id='thx' style='font-size:4px;'>Dziękuję za wysłanie zgłoszenia. Odpowiem tak szybko, jak to możliwe.</div>");
      
      jQuery.post("send.php", {email:em,msg:ms}, function() {
          jQuery("#fkon").hide();
          jQuery("#thx").animate({fontSize:'20px',marginTop:'60px'}, 1000);
      });    
      return false;
  
  });
                                           
});