


function makeXMLHTTP()
{
  try {
    xmlHTTP = new XMLHttpRequest();
  }
  catch (e) {
    var xmlhttp_verze =
        new Array('MSXML2.XMLHTTP.5.0',
        'MSXML2.XMLHTTP.4.0',
        'MSXML2.XMLHTTP.3.0',
        'MSXML2.XMLHTTP',
        'Microsoft.XMLHTTP')
    var success = false;
    for (var i = 0; i < xmlhttp_verze.length && !success; i++) {
      try {
        xmlHTTP  = new ActiveXObject(xmlhttp_verze[i]);
          success = true;
      } catch (e) {}
    }
    if (!success) {
      throw new Error('Nebylo možné vytvořit objekt XMLHttpRequest.');
    }
  }
  return  xmlHTTP;
}

function start(url,statefunc)
{
  xmlHTTP=makeXMLHTTP();
  xmlHTTP.open("GET",url,true);
  xmlHTTP.onreadystatechange=statefunc;
  xmlHTTP.send(null);
}

$(document).ready(function(){
  window.setTimeout(check_logged,300000);
  progress_im=new Image();
  progress_im.src=baseHref+'img/progress.gif';	
});
 
function check_logged()
{
  //start("/check_logged.php",check_logged_response);
  window.setTimeout(check_logged,300000);

  $.ajax({dataType:"text",
	      type:"GET",
	      url: baseHref+"check_logged.php",
	      success:function(text,status)
  {
 
	if(text=="0")
	  $("#check-logged").slideDown("slow");	  

  }});      
}



////////////////////////////////////////////////////////////////////////////////
function del_msg(id,impl_text)
{
  if(document.getElementById(id).value==impl_text)
  {
    document.getElementById(id).value="";
  }
}

////////////////////////////////////////////////////////////////////////////////
/**
 *Zobrazi listbox s nabidkou kategorii nadkategorii bez aktualni ulozene
 */
function get_listbox()
{
  list_menu=1;
  selected="";
  if(document.getElementById("potvrzeni").value)
    selected="&selected="+document.getElementById("potvrzeni").value;



  selobj=document.getElementById("lang");
  lng=selobj.options[selobj.selectedIndex].value;
  elem=document.getElementById("nadkategorie");
  elem.innerHTML="";
  elem.appendChild(progress_im);

  var xmlHTTP=makeXMLHTTP();
  if(xmlHTTP.readyState==4 || xmlHTTP.readyState==0)
  {
      makeXMLHTTP();
      xmlHTTP.open("GET",baseHref+"ajax.php?list-menu="+list_menu+"&lng="+lng+selected,true);
      xmlHTTP.onreadystatechange=function()
      {
        if(xmlHTTP.readyState==4)
        {
          if(xmlHTTP.status==200)
          {

            elem=document.getElementById("nadkategorie");
            elem.innerHTML=xmlHTTP.responseText;


          }
        }
      };
      xmlHTTP.send(null);


  }
  else
  {
    window.setTimeout(get_listbox,100);
  }
}



////////////////////////////////////////////////////////////////////////////////
/**
 *Zobrazi listbox s nabidkou kategorii (vsech k danemu jazyku)
 */
function get_listbox_kategorie()
{
  list_menu=1;
  selected="";
  if(document.getElementById("potvrzeni_kategorie").value)
    selected="&selected="+document.getElementById("potvrzeni_kategorie").value;



  selobj=document.getElementById("lang");
  lng=selobj.options[selobj.selectedIndex].value;
  elem=document.getElementById("nadkategorie");
  elem.innerHTML="";
  elem.appendChild(progress_im);

  var xmlHTTP=makeXMLHTTP();
  if(xmlHTTP.readyState==4 || xmlHTTP.readyState==0)
  {
      makeXMLHTTP();
      xmlHTTP.open("GET",baseHref+"ajax.php?list-menu-all="+list_menu+"&lng="+lng+selected,true);
      xmlHTTP.onreadystatechange=function()
      {
        if(xmlHTTP.readyState==4)
        {
          if(xmlHTTP.status==200)
          {

            elem=document.getElementById("nadkategorie");
            elem.innerHTML=xmlHTTP.responseText;


          }
        }
      };
      xmlHTTP.send(null);


  }
  else
  {
    window.setTimeout(get_listbox_kategorie,100);
  }
}


////////////////////////////////////////////////////////////////////////////////
/**
 *Zobrazi listbox s nabidkou galerii
 */
function get_list_gallery()
{
  list_menu=1;
  selected="";
  if(document.getElementById("potvrzeni_galerie").value)
    selected="&selected="+document.getElementById("potvrzeni_galerie").value;



  selobj=document.getElementById("lang");
  lng=selobj.options[selobj.selectedIndex].value;
  elem=document.getElementById("id_galerie");
  elem.innerHTML="";
  elem.appendChild(progress_im);

  var xmlHTTP=makeXMLHTTP();
  if(xmlHTTP.readyState==4 || xmlHTTP.readyState==0)
  {
      makeXMLHTTP();
      xmlHTTP.open("GET",baseHref+"ajax.php?list-gallery-all="+list_menu+"&lng="+lng+selected,true);
      xmlHTTP.onreadystatechange=function()
      {
        if(xmlHTTP.readyState==4)
        {
          if(xmlHTTP.status==200)
          {

            elem=document.getElementById("id_galerie");
            elem.innerHTML=xmlHTTP.responseText;


          }
        }
      };
      xmlHTTP.send(null);


  }
  else
  {
    window.setTimeout(get_listbox_kategorie,100);
  }
}


////////////////////////////////////////////////////////////////////////////////
/**
 *Zobrazi listbox s nabidkou kategorii nadkategorii PRODUKTU bez aktualni ulozene
 */
function get_listbox_produkty()
{
  list_menu=1;
  selected="";
  if(document.getElementById("potvrzeni").value)
    selected="&selected="+document.getElementById("potvrzeni").value;



  selobj=document.getElementById("lang");
  lng=selobj.options[selobj.selectedIndex].value;
  elem=document.getElementById("nadkategorie");
  elem.innerHTML="";
  elem.appendChild(progress_im);


  var xmlHTTP=makeXMLHTTP();
  if(xmlHTTP.readyState==4 || xmlHTTP.readyState==0)
  {
      makeXMLHTTP();
      xmlHTTP.open("GET",baseHref+"ajax.php?list-katalog="+list_menu+"&lng="+lng+selected,true);
      xmlHTTP.onreadystatechange=function()
      {
        if(xmlHTTP.readyState==4)
        {
          if(xmlHTTP.status==200)
          {

            elem=document.getElementById("nadkategorie");
            elem.innerHTML=xmlHTTP.responseText;


          }
        }
      };
      xmlHTTP.send(null);


  }
  else
  {
    window.setTimeout(get_listbox,100);
  }
}



////////////////////////////////////////////////////////////////////////////////
/**
 *Zobrazi listbox s nabidkou kategorii produktu (vsech k danemu jazyku)
 */
function get_listbox_kategorie_produkty()
{
  list_menu=1;
  selected="";
  if(document.getElementById("potvrzeni_kategorie").value)
    selected="&selected="+document.getElementById("potvrzeni_kategorie").value;



  selobj=document.getElementById("lang");
  lng=selobj.options[selobj.selectedIndex].value;
  elem=document.getElementById("nadkategorie");
  elem.innerHTML="";
  elem.appendChild(progress_im);


  var xmlHTTP=makeXMLHTTP();
  if(xmlHTTP.readyState==4 || xmlHTTP.readyState==0)
  {
      makeXMLHTTP();
      xmlHTTP.open("GET",baseHref+"ajax.php?list-katalog-all="+list_menu+"&lng="+lng+selected,true);
      xmlHTTP.onreadystatechange=function()
      {
        if(xmlHTTP.readyState==4)
        {
          if(xmlHTTP.status==200)
          {

            elem=document.getElementById("nadkategorie");
            elem.innerHTML=xmlHTTP.responseText;


          }
        }
      };
      xmlHTTP.send(null);


  }
  else
  {
    window.setTimeout(get_listbox_kategorie,100);
  }
}

////////////////////////////////////////////////////////////////////////////////
/**
 *Zobrazi parametry dynamicky k danemu typu lementu na strance
 */
function get_element_params()
{


  selobj=document.getElementById("typ");
  typ=selobj.options[selobj.selectedIndex].value;
  elem=document.getElementById("sekce_parametru");
  elem.innerHTML="";
  elem.appendChild(progress_im);


  if(document.getElementById("potvrzeni").value)
    selected="&prvek="+document.getElementById("potvrzeni").value;
  else
    selected="";

  var xmlHTTP=makeXMLHTTP();
  if(xmlHTTP.readyState==4 || xmlHTTP.readyState==0)
  {
      makeXMLHTTP();

      xmlHTTP.open("GET",baseHref+"ajax.php?element-params="+typ+selected,true);
      xmlHTTP.onreadystatechange=function()
      {
        if(xmlHTTP.readyState==4)
        {
          if(xmlHTTP.status==200)
          {

            elem=document.getElementById("sekce_parametru");
            elem.innerHTML=xmlHTTP.responseText;


          }
        }
      };
      xmlHTTP.send(null);


  }
  else
  {
    window.setTimeout(get_listbox_kategorie,100);
  }
}



















function simple_ajax(url,target)
{
  //$(target).html("");
  $.get(url,function(text){
     if(target.length>0)
     {
       $(target).html(text).hide();
       $(target).fadeIn(300);
     }
  });
  return false;
  
}

////////////////////////////////////////////////////////////////////////////////
/**
 *Vysouvaci menu pro elementy UL, LI
 */
(function($)
{
  $.fn.rollmenu = function(params)
  {

    //Funkci je predan element(y) UL, koren seznamu
    this.each(function()
    {
      var timer;
      var timerrunning=false;
      var $parent=$(this);
      $(this).find("ul > li:not(.active)").parent().hide();
      $(this).find("ul > li.active").parent().show();
      $(this).find("li.active >ul").show();

      $(this).find("li:has( ul ) > a, li:has( ul ) > span").addClass("menu-unrolled");
      $(this).find("li.active > a, li.active > span").addClass("menu-rolled");
      $(this).find("li:has( ul ) > a, li:has( ul ) > span").hover(function()
      {
        var $t=$(this);
        var $ul=$(this).next() ;
        if(!timerrunning && $(this).next().css("display") == "none")
        {
          timerrunning=true;
          window.clearTimeout(timer);
          timer=window.setTimeout(function()
          {
            if(timerrunning)
            {
              $parent.find(".active-item").removeClass("active-item");
              $t.addClass("active-item");
              $parent.find("ul:not(ul:has(.active-item))").slideUp().prev().removeClass("menu-rolled").addClass("menu-unrolled");
              //$parent.find("a:jasul:not(ul:has(.active-item)).menu-rolled").removeClass("menu-rolled").addClass("menu-unrolled");
              $ul.slideDown('fast');
              $t.removeClass("menu-unrolled");
              $t.addClass("menu-rolled");

              timerrunning=false;
            }
          },300);

        }
        else
        {
          window.clearTimeout(timer);
          timer=window.setTimeout(function()
          {
            if(timerrunning)
            {
              $parent.find(".active-item").removeClass("active-item");
              $ul.slideUp('fast');
              $t.removeClass("menu-rolled");
              $t.addClass("menu-unrolled");
              timerrunning=false;
            }
          },300);
          timerrunning=true;
        }

      },function()
      {
        window.clearTimeout(timer);
        timerrunning=false;
      });
    });
  }
})(jQuery);

////////////////////////////////////////////////////////////////////////////////
/**
 *Vyskakovaci menu pro elementy UL, LI
 */
(function($)
{
  $.fn.popupmenu = function(params)
  {

    //Funkci je predan element(y) UL, koren seznamu
    /*this.each(function()
    {
      var timer;
      var timerrunning=false;
      $(this).find("ul li:not(.active)").parent().hide();
      $(this).find("li:has( ul ) a,li:has( ul ) span").hover(function()
      {
        var $ul=$(this).next()
        if(!timerrunning && $(this).next().css("display") == "none")
          $ul.slideDown('fast');
        else
        {
          window.clearTimeout(timer);
          timer=window.setTimeout(function()
          {
            if(timerrunning)
            {
              $ul.slideUp('fast');
              timerrunning=false;
            }
          },500);
          timerrunning=true;
        }

      },function()
      {
        window.clearTimeout(timer);
        timerrunning=false;
      });
    }); */
  }
})(jQuery);


////////////////////////////////////////////////////////////////////////////////
/**
 *Dropdown menu s dynamickym vyberem autora
 */
(function($)
{
  $.fn.authorDropDown = function(params)
  {
    params = $.extend( {url: ""}, params);
    var serverUrl=params.url;

    //Funkci je predan element(y) input
    this.each(function()
    {

      var $t=$(this);
      //$t.css("display","block");
      var zadaniUzivatele={};
      var vybrany;
      var zobrazeniZakazano=false;

      $t.attr("autocomplete","off");
      //Ke kazdemu inputu se pripoji list menu
      var target=$("<ul></ul>");
      target.disableTextSelect();
      $t.parent().append($("<div class=\"author-suggestions\"></div>").append(target) );

      target.hide();

      //Reakce na zmacknuti tlacitka
      $t.keypress(function(e)
      {
        var li=target.find("li");
        if(e.keyCode==9||e.keyCode==13)
        {
          nacitaniDokonceno();
          if(!zadaniUzivatele[vybrany.id])
            pridejUzivatele(vybrany);

          e.preventDefault();
          return false;
        }
        else if(e.keyCode==38) //dolu
          return upravPozici($(vybrany).prev().size() < 1 ? li[li.length-1] : $(vybrany).prev());
        else if (e.keyCode==40)//nahoru
        {
          return upravPozici($(vybrany).next().size() < 1 ? li[0] : $(vybrany).next());
        }

      });


      //Zpozdeni vstupu
      zpozdenyVstup(
      {
        elem: $t,
        znaku:1,
        zamereni:true,
        otevreni:function(q,otevreni)
        {
          var posledniSlovo=trim(q.substr(q.lastIndexOf(",")+1,q.length));
          if(posledniSlovo && !zobrazeniZakazano)
          {
            vybrany=null;
            var vysledky=target.lastChild;
            $(target).html("");
            $(target).width($t.width());
            $.post(serverUrl,{data:posledniSlovo},function(html)
            {
              $(target).html(html);
              //alert(html);
              nacitaniDokonceno();
              var li=target.find("li");
              for(var i=0;i<li.length;i++)
              {
                var $li=$(li[i]);
                if(zadaniUzivatele[$li.attr("id")])
                {
                  $li.remove();
                  //i--;
                }
                else
                {
                  $li.mouseover(function()
                  {
                    upravPozici(this);
                  });
                  $li.bind("click mousedown",function()
                  {

                    pridejUzivatele(this);
                    zobrazeniZakazano=true;
                    setTimeout(function(){zobrazeniZakazano=false;},2000);

                    $t.focus();
                  });
                }
              }

              li=target.find("li");
              if(li.length==0)
                target.hide();
              else
              {
                target.find("li:odd").addClass("lichy");
                upravPozici(li[0]);
                target.show();

              }
            });
          }
        },
        //Menu ma byt zavreno
        zavreni:function()
        {
          target.hide();
        }
      });

      function zpozdenyVstup(opt)
      {
        opt.prodleva=opt.prodleva || 400;
        opt.znaku = opt.znaku!=null ? opt.znaku : 3;
        opt.otevreni=opt.otevreni || function(){};
        opt.zavreni=opt.zavreni || function(){};
        opt.zamereni=opt.zamereni!==null ? opt.zamereni : false;
        var staraHodnota=$(opt.elem).val();
        var stav=false;

        setInterval(function()
        {

          var novaHodnota=$(opt.elem).val();
          ///var delka=s.length;
          if(staraHodnota!=novaHodnota)
          {

            if(novaHodnota<opt.znaku && stav)
            {
              opt.zavreni();
              stav=false;
            }
            else if(novaHodnota.length >=opt.znaku && novaHodnota.length>0 )
            {
              opt.otevreni(novaHodnota,stav);
              stav=true;
            }
            staraHodnota=novaHodnota;
          }
        },opt.prodleva);

        $(opt.elem).keyup(function()
        {
          if(this.value.length==0)
          {
            opt.zavreni();
            stav=false;
          }
        });
        if(opt.zamereni)
        {
          $(opt.elem).blur(function()
          {
            if(stav)
            {
              opt.zavreni();
              stav=false;
            }
          });
          opt.elem.zamereni=function(){
            if(this.value.length!=0 && !stav)
            {
              //opt.otevreni('',stav);
              //stav=true;
            }
          };
        }

      }

      function trim(s)
      {
        return s.replace(/^\s/,"").replace(/\s+$/,"");
      }

      function upravPozici(elem)
      {

        vybrany=elem;
        var li=target.find("li").removeClass("selected");
        $(vybrany).addClass("selected");
        return false;
      }

      function nacitaniDokonceno()
      {
        zadaniUzivatele={};
        var uzivatele=$t.val().split(",");
        for(var i=0;i<uzivatele.length;i++)
        {
          zadaniUzivatele[trim(uzivatele[i].toLowerCase())]=true;
        }
      }

      function pridejUzivatele(elem)
      {
        var v=$t.val();
        $t.val((v.indexOf(",")>=0 ? v.substr(0,v.lastIndexOf(",")+2) : "")+$(elem).attr("id"));//+", ");
        //staraHodnota=$t.val();
        zadaniUzivatele[trim($(elem).attr("id").toLowerCase())]=true;

        $(elem).remove();
        target.hide();
      }


    });
    return this;
  };
})(jQuery);



////////////////////////////////////////////////////////////////////////////////
/**
 *Zabraneni oznacovani textu
 */
(function($){
	$.extend($.fn.disableTextSelect = function() {
		return this.each(function(){
			if($.browser.mozilla){//Firefox
				$(this).css('MozUserSelect','none');
			}else if($.browser.msie){//IE
				$(this).bind('selectstart',function(){return false;});
			}else{//Opera, etc.
				$(this).mousedown(function(){return false;});
			}
		});
	});
	$('.noSelect').disableTextSelect();//No text selection on elements with a class of 'noSelect'
})(jQuery);


////////////////////////////////////////////////////////////////////////////////

/**
*Image expander
*/
function jqslide(link)
{
  var image=$(link).find("img");
  if(!image) return false;
  var fullWidth;
  var fullHeight;
  jqslide.helpText="Press left or right arrow to navigate, \nescape to hide, p or P to display slideshow, f or F to display full size";
  $("a.jqslide-selected").removeClass("jqslide-selected");


  //alert(image.width()+" "+image.height()+" "+image.offset().top);

  //Vytvori strukturu pro obrazek
  if($("#jqslide-window").length<1)
  {
    $("body").append("<div id=\"jqslide-window\" class=\"jqslide-window\" style=\"\">"+

    "</div>");


  }
  else
  {
    $("#jqslide-window").removeClass("jqslide-image-loaded")
      .stop()
      .hide()
      .draggable("destroy")
      .unbind("mousemove mouseup mousedown")
      .css("padding",0);
  }
  var w=$("#jqslide-window");
  //
  w.css("top",image.offset().top);
  w.css("left",image.offset().left);
  w.css("width",image.width());
  w.css("height",image.height());
  w.addClass("jqslide-image");
  w.css("opacity",0.5);
  w.html("");

  w.show();

  var newImage=new Image;
  $(newImage).bind("mousemove mouseup mousedown",animateBack);
  $(document).keydown(jqbuttonPressed);


  //Pridani obrazku a zvetseni
  $(newImage).load(function()
  {
    //window.setTimeout(function()
    //{
      var newWidth=newImage.width;
      fullWidth=newImage.width;
      var newHeight=newImage.height;
      fullHeight=newImage.height;
      //Maximalni vyske - zohledneni bileho okraje a velikost popisku
      var maxHeight= $(window).height()-50;
      if(newHeight > maxHeight)
      {
        newWidth=newWidth/newHeight*maxHeight;
        newHeight=maxHeight;
      }
      var newLeft = ($(window).width()-newWidth)/2;
      var newTop=$(window).scrollTop()+($(window).height()-newHeight)/2-30;

      var title=$("<div class=\"jqslide-title\"><div class=\"jqslide-inner-title\">"+image.attr("title")+"</div></div>");
      title.css("width",newWidth);

      /**
       *Tlacitka navigace
       */
      var navigation=$("<div id=\"jqslide-navigation\" style=\"\"> </div>");
      var close=$("<a href=\"#\" id=\"jqslide-close\"> </a>").css("opacity",0.75).click(function()
      {
        //Zanimuje zpet
        window.clearInterval(jqslide.jqpresentation);
        jqhide();
        return false;
      });
      var next=$("<a href=\"#\" id=\"jqslide-next\"> </a>").css("opacity",0.75).click(function()
      {
        jqnext();
        return false;
      });
      var prev=$("<a href=\"#\" id=\"jqslide-prev\"> </a>").css("opacity",0.75).click(function()
      {
        jqprevious();
        return false;
      });
      var full=$("<a href=\"#\" id=\"jqslide-full\"> </a>").css("opacity",0.75).click(function()
      {
        jqfullSize();
        return false;
      });

      var play=$("<a href=\"#\" id=\"jqslide-play\"> </a>").css("opacity",0.75).click(function()
      {
        jqplay();
        return false;
      });


      navigation.append(close).append(play).append(next).append(prev).append(full);
      navigation.css("width",newWidth);


      $(newImage).css("width",image.width());
      $(newImage).css("height",image.height());
      $(newImage).attr("title",jqslide.helpText);
      //$(newImage).css("margin","0 10px 0 10px");

      w.css("opacity",1.0);
      w.addClass("jqslide-image-loaded");
      w.html(newImage);
      $(newImage).animate({width:newWidth, height:newHeight},500);
      w.animate({padding:10,width:newWidth, height:newHeight, top: newTop, left:newLeft},500,function()
      {
        //dalsi animace
        //Tlacitka navigace
        w.prepend(navigation);
        top.width=newWidth;

        $(link).addClass("jqslide-selected");
        navigation.hide().slideDown(500);
        //Titulek
        if(image.attr("title"))
        {
          w.append(title);
          w.prepend(navigation);

          title.hide().fadeIn(500);
          navigation.hide().fadeIn(500);
          w.animate({ height:newHeight+title.height()},500 );

        }
        w.draggable();


      });
    //timeout
    //},500);

  });

  newImage.src=link.href;
  return false;

  /**************************************************************************/
  function jqprevious()
  {
    var elems = $(".highslide:has(img) , .jqslide:has(img)") ;
    var show;
    for(i=0;i<elems.size();i++)
    {
      if($(elems.get(i)).hasClass("jqslide-selected"))
      {
        //alert($(".jqslide-selected").get());
        if(i==0)
        { show=elems.size()-1;}
        else
        { show=i-1;}

        //Zanimuje zpet
        jqhide();
        //Nastavi novou animaci
        window.setTimeout(function()
        {
          jqslide(elems.get(show));
        },500);
        return false;
      }
    }
    //alert($(".jqslide-selected ~ .highslide:first").get());

  }

  /**************************************************************************/
  function jqnext()
  {
    var elems = $(".highslide:has(img), .jqslide:has(img)");
    var show;
    for(i=0;i<elems.size();i++)
    {
      if($(elems.get(i)).hasClass("jqslide-selected"))
      {
        //alert($(".jqslide-selected").get());
        if(i==elems.size()-1)
        { show=0;}
        else
        { show=i+1;}

        //Zanimuje zpet
        jqhide();
        //Nastavi novou animaci
        window.setTimeout(function()
        {
          jqslide(elems.get(show));
        },500);
        return false;
      }
    }

    //alert($(".jqslide-selected ~ .highslide:first").get());

  }


  /**************************************************************************/
  function jqbuttonPressed(e)
  {
    //alert(e.which);
    switch(e.which)
    {
      //Posun nahoru
      //case 38:
      case 37:
      return jqprevious();
      break;

      //Posun dolu
      case 39:
      //case 40:
      case 32:
      return jqnext();
      break;

      //Zruseni escapem
      case 27:
      jqhide();
      window.clearInterval(jqslide.jqpresentation);
      break;

      //Prezentace p,P
      case 112:
      case 80:
      jqplay();
      break;

      //Zobraeni plne velikosti - f,F
      case 102:
      case 70:

      jqfullSize();


      break;
    }
  }
  /**************************************************************************/
  function jqplay()
  {
    jqnext();
    window.clearInterval(jqslide.jqpresentation);
    jqslide.jqpresentation=window.setInterval(jqnext,5000);
  }
  /**************************************************************************/
  function jqfullSize()
  {
    //$("a.jqslide-selected").each(function()
    //{
      var nLeft = ($(window).width()-fullWidth)/2;
      var nTop=$(window).scrollTop()+($(window).height()-fullHeight)/2;
      //alert(nLeft+ "F"+nTop );
      $(newImage).stop().css("width",fullWidth);
      w.stop().css("width",fullWidth);
      $(newImage).css("height",fullHeight);
      w.css("height",fullHeight);
      w.css("top",nTop);
      w.css("left",nLeft);
    //}
  }
  /**************************************************************************/
  function jqhide()
  {
     //Zanimuje zpet
     $("a.jqslide-selected").removeClass("jqslide-selected");
     w.fadeOut(500,function(){$(this).stop().hide();});
  }

  /**************************************************************************/
  function animateBack(event)
  {
    if ( typeof animateBack.state== 'undefined' ) {
      animateBack.state = 0;
    }

    //alert(event.type);
    //Jednoduchy automat pro urceni, jestli se kliklo, avsak netahlo
    if(animateBack.state==0 && event.type=="mousedown")
    { animateBack.state++;  }
    else if(animateBack.state==1)
    {
      if(event.type!="mouseup")
      { animateBack.state=0; }
      else
      {
        //Zanimuje zpet
        jqhide();
      }

    }
    //return false;

  }





}

////////////////////////////////////////////////////////////////////////////////
/**
 *Vytvori uzivatelske okno jako plugin pro jquery
 *Parametry:
 *url - url nacteneho textu
 *title - titulek okna
 *text - pokud neni zadane url, pak se zobrazi tento text
 *timeout - cas, za ktery okno zmizi
 *overrideA - priznak, jestli se maji vsechny linky prenastavit tak, aby nacitani probihalo ajaxem
 *overrideForm - jestli se ajaxem maji odesilat formulare
 */
(function($)
{
  $.fn.userWindow = function(params)
  {
    params = $.extend( {url: "",timeout:-1,text:"",title:"",width:"auto",height: "auto"}, params);
    var serverUrl=params.url;


    this.each(function()
    {

      var $t=$(this);



      if($("#user-window").length<1)
      {
        $("body").prepend("<div id=\"user-window\" style=\"left:50%;z-index:98;overflow:hidden;padding:5px;border:1px solid #74a5db;position:absolute;background:#f2f2f2\">"+
        "</div>");
      }
      var $window= $("#user-window");

      $t.updateDimensions=function()
      {
        $window.width(params.width);
        $window.height(params.height);

        $window.css("margin-left",-($window.width()/2));
        $window.css("top",$(window).scrollTop()-($window.height()/2) + $(window).height()/2);

      };
      $t.userWindowClose=function()
      {
        $window.fadeOut("300",function(){$(this).remove()});
      };




      $window.css("top",$(window).scrollTop()+20);

      if(params.text.length==0)
      {
        //params.text="<img src=\"/img/progress.gif\" width=\"32\" height=\"32\" alt=\"\" />";
      }
      //$("#support-window").resizable();
      $window.html("<div id=\"user-head\" style=\"padding-left:40px\" ><div class=\"fl\" id=\"user-title\"></div><a href=\"#\"   class=\"fr\" id=\"user-close\"><img src=\"/img/icons/medium-icons/close.png\" /></a><br class=\"cb\" /></div>"
        +"<div id=\"user-html\">"+"</div>");
      $window.find("#user-html").append(params.text);
      //Zaregistrovani akci pro doplnovani pouze do tohoto okna
      $window.find("#user-html").bind("ajaxComplete",function()
      {
        $window.find("#user-head").css("background-image","none");
        if(params.overrideA)
        {

          $window.find("#user-html a").each(function()
          {
            var href=$(this).attr("href");

            if(href!="#" && href.search(/javascript/i)<0)
            {
              $(this).addClass("simple-ajax")
              .attr("rel","#user-html")
              .data("overrideA",true);
            }
          });

        }
        if(params.overrideForm)
        {

          $window.find("#user-html form")
            .ajaxForm({target:"#user-html"});

        }
      }).bind("ajaxStart",function()
      {
        $window.find("#user-head").css("background","url(/img/progress.gif) bottom left no-repeat");
      });


      $window.find("#user-title").html(params.title);

      $t.updateDimensions();
      //$window.find("#user-head").disableTextSelect();
      $window.draggable({handle:"#user-head"});

      $("#user-head").css("cursor","move");

      $window.find("#user-close").click(function()
      {
        $t.userWindowClose();
        return false;
      });

      //Nacte GET pozadavek z dane adresy
      if(params.url.length>0)
      {
        $.get(params.url,function(text)
        {
          $window.find("#user-html").html(text);

          //Zmizeni oknapo nacteni hlasky
          if(params.timeout>0)
          {
            //Kontrola globalniho casovace
            if(typeof window.userWindowTimer !=="undefined")
            {
              window.clearTimeout(window.userWindowTimer);
            }
            window.userWindowTimer=window.setTimeout(function(){$t.userWindowClose();},params.timeout);

          }
          $t.updateDimensions();
        });
      }
      else
      {
        if(params.timeout>0)
        {
          window.setTimeout(function(){$t.userWindowClose();},params.timeout);
        }
      }



    });

    return this;
  }
})(jQuery);


/******************************************************************************/
(function($)
{
  $.fn.userWindow = function(params)
  {
    params = $.extend( {url: "",timeout:-1,text:"",title:"",width:"auto",height: "auto"}, params);
    var serverUrl=params.url;


    this.each(function()
    {

      var $t=$(this);



      if($("#user-window").length<1)
      {
        $("body").prepend("<div id=\"user-window\" style=\"left:50%;z-index:98;overflow:hidden;padding:5px;border:1px solid #74a5db;position:absolute;background:#f2f2f2\">"+
        "</div>");
      }
      var $window= $("#user-window");

      $t.updateDimensions=function()
      {
        $window.width(params.width);
        $window.height(params.height);

        $window.css("margin-left",-($window.width()/2));
        $window.css("top",$(window).scrollTop()-($window.height()/2) + $(window).height()/2);

      };
      $t.userWindowClose=function()
      {
        $window.fadeOut("300",function(){$(this).remove()});
      };




      $window.css("top",$(window).scrollTop()+20);

      if(params.text.length==0)
      {
        //params.text="<img src=\"/img/progress.gif\" width=\"32\" height=\"32\" alt=\"\" />";
      }
      //$("#support-window").resizable();
      $window.html("<div id=\"user-head\" style=\"padding-left:40px\" ><div class=\"fl\" id=\"user-title\"></div><a href=\"#\"   class=\"fr\" id=\"user-close\"><img src=\"/img/icons/medium-icons/close.png\" /></a><br class=\"cb\" /></div>"
        +"<div id=\"user-html\">"+"</div>");
      $window.find("#user-html").append(params.text);
      //Zaregistrovani akci pro doplnovani pouze do tohoto okna
      $window.find("#user-html").bind("ajaxComplete",function()
      {
        $window.find("#user-head").css("background-image","none");
        if(params.overrideA)
        {

          $window.find("#user-html a").each(function()
          {
            var href=$(this).attr("href");

            if(href!="#" && href.search(/javascript/i)<0)
            {
              $(this).addClass("simple-ajax")
              .attr("rel","#user-html")
              .data("overrideA",true);
            }
          });

        }
        if(params.overrideForm)
        {

          $window.find("#user-html form")
            .ajaxForm({target:"#user-html"});

        }
      }).bind("ajaxStart",function()
      {
        $window.find("#user-head").css("background","url(/img/progress.gif) bottom left no-repeat");
      });


      $window.find("#user-title").html(params.title);

      $t.updateDimensions();
      //$window.find("#user-head").disableTextSelect();
      $window.draggable({handle:"#user-head"});

      $("#user-head").css("cursor","move");

      $window.find("#user-close").click(function()
      {
        $t.userWindowClose();
        return false;
      });

      //Nacte GET pozadavek z dane adresy
      if(params.url.length>0)
      {
        $.get(params.url,function(text)
        {
          $window.find("#user-html").html(text);

          //Zmizeni oknapo nacteni hlasky
          if(params.timeout>0)
          {
            //Kontrola globalniho casovace
            if(typeof window.userWindowTimer !=="undefined")
            {
              window.clearTimeout(window.userWindowTimer);
            }
            window.userWindowTimer=window.setTimeout(function(){$t.userWindowClose();},params.timeout);

          }
          $t.updateDimensions();
        });
      }
      else
      {
        if(params.timeout>0)
        {
          window.setTimeout(function(){$t.userWindowClose();},params.timeout);
        }
      }



    });

    return this;
  }
})(jQuery);


/******************************************************************************/
/**
 *Odesle pozadavek na stejnou url adresu a naplni z ni elementy dane jako ID
 *Parametry:
 *---
 */
(function($)
{
  $.fn.invalidate = function()
  {
    //params = $.extend( {url: "",timeout:-1,text:"",title:"",width:"auto",height: "auto"}, params);
    var url=window.location.href;
    var $t=$(this);
    $.get(url,function(text)
    {
      $t.each(function()
      {
        var id=$t.attr("id");
        $("#"+id).html($(text).find("#"+id).html());
      });
    });

    return this;
  }
})(jQuery);

/**
 *Vytvori uzivatelske okno
 */
function userWindow(html)
{
  if($("#support-window").length<1)
  {
    $("body").append("<div id=\"support-window\" style=\"left:50%;margin-left:-300px;z-index:98;overflow:hidden;padding:5px;border:1px solid #74a5db; position:absolute;width:600px;background:#EEEEEE\">"+
    "</div>");
  }
  $("#support-window").css("top",$(window).scrollTop()+20);
  //$("#support-window").html("<img src=\"../img/progress.gif\" width=\"32\" height=\"32\" alt=\"\" />");

  //$("#support-window").resizable();
  $("#support-window").html("<div id=\"support-head\" ><a href=\"#\"   class=\"fr\" id=\"support-close\"><img src=\"../img/icons/medium-icons/close.png\" /></a><br class=\"cb\" /></div>"
    +"<div id=\"support-html\">"+html+"</div>");
  $("#support-window").draggable({handle:"#support-head"});
  $("#support-window").disableSelection();
  $("#support-head").css("cursor","move");

  $("#support-window  #support-close").click(function()
  {
    $("#support-window").remove();
    return false;
  });
  return $("#support-html");
}

function userWindowClose()
{
  $("#support-window").remove();
}




////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
$(document).ready(function() {


  /**
   *Zobrazi pres input boxy vrstvu s jeho titulkem
   */
  $("input[type=text], input[type=password]").each(function()
  {
    var $t=$(this);
    if($(this).attr("title"))
    {
      var div=$("<div class=\"form-overlay\">"+$(this).attr("title")+"</div>");
      var off=$(this).offset();
      $(div).attr("top",off.top);
      $(div).attr("left",off.left);
      /*$(div).css("padding",$(this).css("padding"));
      $(div).css("margin",$(this).css("margin"));
      $(div).css("border",$(this).css("border"));  */
      $(div).width($(this).width());
      $(div).height($(this).height());
      if($t.val().length>0)
      {$(div).hide(); }
      $(div).click(function()
      {
        $(div).hide();
        $t.trigger("focus");
      });

      $t.bind("focus change",function()
      {
        $(div).hide();
      });
      $t.blur(function()
      {
        if( $t.val().length==0) { $(div).show();}
      });
      $(this).before(div);
    }
  });



  /**
   *Rollmenu
   */
  $("ul.menu-roll").rollmenu();


  /**
   *Umozni dynamicky zobrazovat a skryvat necislovany seznam
   */
  $("ul.dynamic").hover(function()
  {
    $(this).find("li").stop(true,true);
    $(this).find("li").fadeIn(600);
  },function(){
    $(this).find("li:not(.active)").stop(true,true) ;
    $(this).find("li:not(.active)").fadeOut(500);
  });

  //Autor - dynamicky vyber
  $("#autor, .dropdown").each(function()
  {
    if($(this).attr("rel")){
      $(this).authorDropDown({url:$(this).attr("rel")});
    }
  });
////////////////////////////////////////////////////////////////////////////////
  /**
   *Prvky se tridou simple-ajax se navazou na udalosti
   *Nahradi obsah elementu z dane tridy obsahem stranky s odkazem href
   */
   $(".simple-ajax").live("click",function()
   {

     var $t=$(this);
     $.get($(this).attr("href"),function(text)
     {
       var target_selector=$($t.attr("rel"));
       if(target_selector.length>0)
       {
         $(target_selector).html(text);
         //Prepsani cile novych nactenych prvku na dany objekt DOM
         //alert($t.data("overrideA"));
         //if($t.data("overrideA"))
         //{
         //$(target_selector).find("a").attr("rel",$t.attr("rel")).addClass("simple-ajax");

         //}
       }
     });
     return false;
   });


   /**
   *Nacte ajaxovy obsah ze serveru a vlozi ho dovnitr elementu
   */
   $(".simple-ajax-load").each(function()
   {

     $t=$(this);
     $t.html("<img src=\"/img/progress.gif\" />");
     $t.load($t.attr("rel"),function(text)
     {
       $(this).hide().fadeIn(400);
     });
   });


   /**
    * Zobrazeni ajaxoveho okna
    */
   $(".ajax-window").live("click",function()
   {
     $(this).userWindow({title:$(this).attr("title") || "Upozornění",
                         text:$(this).attr("rel"),
                         url:$(this).attr("href"),
                         overrideA:true,
                         timeout:3000,
                         width:"400"});
     return false;
   });

   /**
    * Zobrazeni ajaxoveho okna - okno s formularem
    */
   $(".ajax-window-form").live("click",function()
   {
     $(this).userWindow({title:$(this).attr("title") || "Upozornění",
                         text:$(this).attr("rel"),
                         url:$(this).attr("href"),
                         overrideA:true,
                         overrideForm:true,
                         //timeout:3000,
                         width:"500"});
     return false;
   });



  /**
   *Validace registracnich udaju uzivatele
   */
   var timer;
   function timeOut()
   {
     //alert("timeout");
   }
   $(".registrace_udaj").bind("keydown, keypress",function(e)
   {
     window.clearTimeout(timer);
     timer=window.setTimeout(timeOut,1000);
   });



   $(".highslide").unbind("click");
   $(".highslide,.jqslide").click(function()
  {
    return jqslide(this);
  });



});



