// JavaScript Document

if(navigator.appName=="Microsoft Internet Explorer"){IE = true;}else{IE=false}
if(navigator.appName=="Netscape"){Mozilla = true;}else{Mozilla=false}
if(navigator.appName=="Opera"){Opera = true;}else{Opera=false}

hovering_item = function(obj){
   $(obj).attr("class","item_hover")
   $(obj).mouseout(function(){
      $(this).attr("class","item")
   })
}

loadwin = function () {
   $(".main_menu_item").hover(
      function(){
         srcs = $(this).attr("src").split("/")
         srcs = srcs[srcs.length-1].split("_")
         _src = srcs[0];
         $(this).attr("src","img/buttons/"+_src+"_1.gif")
      },function(){
         srcs = $(this).attr("src").split("/")
         srcs = srcs[srcs.length-1].split("_")
         _src = srcs[0];
         $(this).attr("src","img/buttons/"+_src+"_0.gif")
      }
   );
   $("input[type=submit]").each(
      function(){
         $(this).addClass("submit")
         $(this).hover(function(){
            this.className = "submit_hover"
         },function(){
            this.className = "submit"
         })
      }
   );
   $(".item").hover(function(){
        $(this).attr("class","item_hover")
      },function(){
        $(this).attr("class","item")
      })
   $(".main_menu_item").click(function(){
         srcs = $(this).attr("src").split("/")
         srcs = srcs[srcs.length-1].split("_")
         _src = srcs[0];
         location.href = _src+".php";
      }
   )
   $("input[name=category]").each(
      function(){
         $(this).addClass("submit")
         $(this).click(function(){
            $(this).parent().children().each(function(){
               this.setAttribute("active",false);
               this.className = "submit";
            })
            this.setAttribute("active",true);
            this.className = "submit_hover";
            cont = $(document.getElementById("container"));
            loader = $(document.getElementById("loading_icon"));
            $(loader).fadeIn();
            clb = $(this);
             setTimeout(function(){$.post("portfolio_context.php",{type : clb.attr("sign")},
                function (data) {
                   $(cont).slideUp(1000,function(){
                      $(cont).html(data.getElementsByTagName("data")[0].childNodes[0].nodeValue)
                      $(cont).slideDown(1000);
                      $(loader).fadeOut();
                   })
                }, "xml");
             },1500)
         });
         $(this).hover(function(){
            this.className = "submit_hover"
         },function(){
            if(this.getAttribute("active") != "true") {
               this.className = "submit"
            }
         }
         )
      }
   )
}


window.onload = loadwin


open_popup = function (ev) {
   if(Mozilla){
      w = document.width;
   } else if (Opera) {
      w = window.innerWidth;
   } else {
      w = document.body.clientWidth;
   }

   if(!Mozilla) {
      ev = window.event;
   }
   
   elm = document.createElement("div");
   elm.style.width = parseInt(w)+"px";
   elm.className="shadow";
   elm.style.height = "3000px";
   elm.style.display = "none";
   document.body.appendChild(elm);
   $(elm).fadeIn();
   inel = document.createElement("div");
   inel.className="popup";
   iht = jQuery("<center><img src='img/icons/loading.gif' alt=''></center>");
   iht.appendTo(inel)
   inel.style.left = Math.round(w/2-400)+"px";
   if(Opera) {
      inel.style.top = (parseInt(document.body.scrollTop)+50)+"px";
   }else if (IE){
      inel.style.top = (parseInt(document.body.scrollTop)+50)+"px";
   }else{
      inel.style.top = (parseInt(ev.pageY)-parseInt(ev.clientY)+50)+"px";
   }
   if(inel.style.top==""){inel.style.top = "50px"}
   document.body.appendChild(inel);
   $(inel).fadeIn()
   return [inel, elm, iht];
}

show_plack = function (id, ev) {
   pop = new open_popup(ev)
   $.post("ext/lib.php", {load_plack : id},
     function(data){
         this_title = data.getElementsByTagName("title")[0].childNodes[0].nodeValue
         this_id = data.getElementsByTagName("id")[0].childNodes[0].nodeValue
         this_desc = data.getElementsByTagName("desc")[0].childNodes[0].nodeValue
         this_src = data.getElementsByTagName("image")[0].childNodes[0].nodeValue
         if(this_desc == ""){this_desc = "<i>bez popisku</i>"}
         pop[2].slideUp("normal",function(){
         pop[2].html("<h2>"+this_title+"</h2><b>ID placky:</b> "+this_id+"<br>"+this_desc+"<br><img src='ext/image.php?show_plack="+this_src+"' alt=''>")
         pop[2].slideDown()})
         document.onmousedown = function () {
           $(pop[0]).fadeOut("normal",function(){document.body.removeChild(pop[0])});
           $(pop[1]).fadeOut("normal",function(){document.body.removeChild(pop[1])});
           document.onmousedown = null;
         }
     }, "xml");
}

load_article = function (whr, id) {
   $.post("ext/lib.php", {load_article : id},
     function(data){
         $(whr).parent().slideUp(500,function(){
            this_title = data.getElementsByTagName("title")[0].childNodes[0].nodeValue
            this_text = data.getElementsByTagName("text")[0].childNodes[0].nodeValue
            this_date = data.getElementsByTagName("date")[0].childNodes[0].nodeValue
            this_image = data.getElementsByTagName("image")[0].childNodes[0].nodeValue
            $(this).html("<h1>"+this_title+"</h1><b>"+this_date+"</b><br><img align='right' hspace='20' vspace='10' src='upload/intro/"+this_image+".gif' alt=''>"+this_text);
            $(this).slideDown(500);
         })
     }, "xml");
}

show_gr = function (id, ev) {
   pop = new open_popup(ev)
   $.post("ext/lib.php", {load_gr : id},
     function(data){
         this_title = data.getElementsByTagName("title")[0].childNodes[0].nodeValue
         this_id = data.getElementsByTagName("id")[0].childNodes[0].nodeValue
         this_desc = data.getElementsByTagName("desc")[0].childNodes[0].nodeValue
         if(this_desc == ""){this_desc = "<i>bez popisku</i>"}
         pop[2].slideUp("normal",function(){
         pop[2].html("<h2>"+this_title+"</h2>"+this_desc+"<br><br><img src='ext/image.php?show_gr="+this_id+"' alt=''>")
         pop[2].slideDown()})
         document.onmousedown = function () {
           $(pop[0]).fadeOut("normal",function(){document.body.removeChild(pop[0])});
           $(pop[1]).fadeOut("normal",function(){document.body.removeChild(pop[1])});
           document.onmousedown = null;
         }
     }, "xml");
}
show_info_pop = function (html, ev) {
   pop = new open_popup(ev)
   pop[2].slideUp("normal",function(){
   pop[2].html(html)
   pop[2].slideDown()})
   document.onmousedown = function () {
     $(pop[0]).fadeOut("normal",function(){document.body.removeChild(pop[0])});
     $(pop[1]).fadeOut("normal",function(){document.body.removeChild(pop[1])});
     document.onmousedown = null;
   }
}

