/* -------------------------------------------
set to false to disable the header rotation
---------------------------------------------- */
var enableHeaderRotate = true;



//add new header bg images as necessary (remember to increment the array index by one for each new image). Also
//remember that the first bg image displayed is actualy slideshow[1], not slideshow[0]
var slideShow = new Array();
slideShow[0] = "/img/bodyBG2.jpg";
//slideShow[1] = "img/bodyBG.jpg";
//slideShow[2] = "img/bodyBG3.jpg";


function fadeinSlideshow(elem, imageList, slideDuration, fadeSpeed, current) {

   // get the length of the image array.
   var listSize = imageList.length;   
   // If there's no current image selected, or the value is out of the range of the
   // slideshow, then set the current image to zero.
   if (!current || current >= listSize) current = 0;

   // If there's no slide duration set, set it to 5 seconds.
   if (!slideDuration) slideDuration = 5000;
   // If there's no fade speed set, set it to 1 second.
   if (!fadeSpeed) fadeSpeed = 1000;
   // Set the image's source to the current image's url.
   $(elem).attr("src", imageList[current]);
   // If the current element is at the maximum of the element size, then set the 
   // wrapper's background (aka, the next image) to the first image.
   if (current == (listSize - 1)) {
      $(elem).css("background", "#f4f4ed url(" + imageList[0] + ") no-repeat top center");

   } else {
      // If not, set the next image in the list to the background of the wrapper.
      $(elem).css("background", "#f4f4ed url(" + imageList[current + 1] + ") no-repeat top center");				
   }

   // Hold the current image for a period of time equal to slideDuration. Once that's done, then
   // fade the current image's opacity until the background image shows. Once that is done, then
   // call this same function again with the next image in line.
   $(elem).animate({
      opacity: "1"
   }, slideDuration).animate(
   {
      opacity: "1"
   }, 		
   fadeSpeed, 
   function() { 
      $(this).css("opacity", "1"); 						
      fadeinSlideshow(elem, imageList, slideDuration, fadeSpeed, current + 1);
   });

} // end of function fadeinSlideshow()

function runSlideshow(){
   fadeinSlideshow("body", slideShow, 5000, 1000);
}

if(enableHeaderRotate)
   $(document).ready(runSlideshow);



// jquery.format.1.02.js
$(document).ready(function(){	
   $(".numeric").format({
      precision: 2,
      autofix:true
   });
});
// patie

function showhide(id){
   if (document.getElementById){
      obj = document.getElementById(id);
      if (obj.style.display == "none"){
         obj.style.display = "";
      } else {
         obj.style.display = "none";
      }
   }
}

function url_rozprarsuj(vstupna_url)
{
   var parametre = [];
   var vstupna_url = vstupna_url.split('/');
   for(var i = 0; i < vstupna_url.length-1; i++)
   {
      parametre[i] = vstupna_url[i+1];
   }
   return parametre;
}

function json_rozprarsuj(vstupna_json)
{
   var parametre = [];
   var vstupna_json = vstupna_json.split('|');
   for(var i = 0; i < vstupna_json.length; i++)
   {
      parametre[i] = vstupna_json[i];
   }
   return parametre;
}

$(document).ready(function(){	
   $("a[href*='http://']:not([href*='"+location.hostname+"'])").attr("target","_blank");
   $("a[rel*='external']").attr("target","_blank");
});

// uvod bleskovky
$(document).ready(function(){	
   $("#bleskovky").easySlider({
      auto: true,
      continuous: true,
      numeric: true,
      pause: 5000,
      speed: 300
   });
});

// uvod akordeon
$(document).ready(function(){	
   $("#accordion").accordion({
      header: "h5", 
      event: 'mouseover', 
      collapsible: false
   });

   $('h5.ui-accordion-header').click(function(){
      return false;
   });

});



$(document).ready(function(){	

   $("a.fancy").fancybox();

   $('.help-hore').tipsy({
      gravity: 's'
   });
   $('.help').tipsy({
      gravity: 'w'
   });
   $('.help-title').tipsy({
      gravity: 's'
   });

});



$(document).ready(function(){	

   $('#mask').click(function () {
      $('#mask').hide();
      $('#okno').hide();
   });	



});







/*                 
A K C I E     
 */



/* interpreti */

$(document).ready(function(){


   $('.zmazat-interpreta').click(function(){
      var id;
      var url = $(this).attr("href");

      $("#dialog-zmazat-interpreta").dialog({
         resizable: false,
         modal: true,
         autoOpen: false,
         buttons: {
            'Áno, zmazať': function() {	
               $.ajax({
                  type: "GET",
                  url: '/akcia'+url+'/2',
                  success: function(msg)
                  {
                     $("#li-interpret-"+id).fadeOut(500);

                     if (msg==0)	{
                        $.jnotifica("Interpret bol úspešne odstránený");
                     }
                     else if (msg==1) {
  
                        $.jnotifica("Interpreta sa nepodarilo odstrániť");
                     }
                  }
               });
               $(this).dialog('close');
            },
            'Nie': function() {
               $(this).dialog('close');
            }
         }
      });

      //$.getJSON(url,{step: "1"},dates);

      $.getJSON('/akcia'+url+'/1',{},dates);

      function dates(jsondata)
      {
         $("#dialog-zmazat-interpreta").html(jsondata.otazka);
         id = jsondata.id;
         $('#dialog-zmazat-interpreta').dialog('open');
      }

      return false;


   });

});







/* forum - pridat - kategoriu */

$(document).ready(function(){


   $('.zmazat-prispevok').click(function(){
      var id;
      var url = $(this).attr("href");

      $("#dialog-zmazat-prispevok").dialog({
         resizable: false,
         modal: true,
         autoOpen: false,
         buttons: {
            'Áno, zmazať': function() {	
               $.ajax({
                  type: "GET",
                  url: '/akcia'+url+'/2',
                  success: function(msg)
                  {
                     $("#forum-prispevoktext-"+id).hide();
                     $("#forum-prispevok-"+id).hide();

                     if (msg==0)	{
           
                        $.jnotifica("Príspevok bol úspešne odstránený");
                     }
                     else if (msg==1) {
             
                        $.jnotifica("Príspevok sa nepodarilo odstrániť");
                     }
                  }
               });
               $(this).dialog('close');
            },
            'Nie': function() {
               $(this).dialog('close');
            }
         }
      });

      //$.getJSON(url,{step: "1"},dates);

      $.getJSON('/akcia'+url+'/1',{},dates);

      function dates(jsondata)
      {
         $("#dialog-zmazat-prispevok").html(jsondata.otazka);
         id = jsondata.id;
         $('#dialog-zmazat-prispevok').dialog('open');
      }

      return false;


   });




   $('#pridat-prispevok').live("click", function(){

      var prispevok = $("#forum #prispevok").val();
      var id = $("#forum #forum-id").val();

      var dataString = 'text='+ prispevok+'&id='+id;  
      $.ajax({  
         type: "POST",  
         url: "/inc/ajax/forum-pridat-prispevok.php",  
         data: dataString,  
         success: function(data) {

            var odpoved = data.split("|"); 
            if (odpoved[0]=='0')
            {
               $("#forum #prispevok").val('');
     
               $.jnotifica("Príspevok bol úspešne pridaný.");
               $("table tbody").prepend("<tr><td colspan=\"2\" style=\"font-size:13px\"><div class=\"lightDivider\" style=\"margin-top:10px; margin-bottom:10px;\"></div><br />"+odpoved[1]+"</td></tr>             <tr><td colspan=\"2\" class=\"subinfo\"><a href=\"/profil/"+odpoved[2]+"\"> "+odpoved[3]+" </a> "+odpoved[4]+" "+odpoved[5]+" | <a href=\"#reagovat\" rel=\"nofollow\">reagovať</a><form class=\"komentovat\" action=\"\"><div class=\"reakcia\"><textarea class=\"elastic\" rows=\"3\" cols=\"50\"></textarea><input type=\"submit\" name=\"odoslat\" value=\"odoslat\" class=\"forum-reagovat button right\" /></div></form><div class=\"clear\"></div></td></tr>");
            }
            else if (odpoved[0]=='1')
            {
       
               $.jnotifica("Príspevok sa nepodarilo pridať. Ospravedlňujeme sa, na odstránení závady pracujeme");
            }   
            else if (odpoved[0]=='2')
            {
       
               $.jnotifica("Text príspevku je príliš krátky");
            }
         }

      }); 

      return false;

   });  









   $('.forum-reagovat').live("click", function(){
      var id = $(this).parent().children("input[name*='prispevok-id']").val();
      var prispevok = $('#reakcia-text-'+id).val();



      var dataString = 'prispevok='+ prispevok+'&id='+id;  
      $.ajax({  
         type: "POST",  
         url: "/inc/ajax/forum-pridat-reakciu.php",  
         data: dataString,  
         success: function(data) {

            var odpoved = data.split("|"); 
            if (odpoved[0]=='0')
            {				
               $('#reakcia-text-'+id).val('');
               $('#reakcia-text-'+id).parent().parent().fadeOut(500); 

       
               $.jnotifica("Reakcia bola úspešne pridaná");


               $("#forum-prispevok-"+id).children().children('.prispevok-reakcie').append("<table><tr><td colspan=\"2\" style=\"padding-top:10px\" class=\"prispevok-reakcia\">"+odpoved[1]+"</td></tr>                          <tr><td colspan=\"2\" class=\"subinfo prispevok-reakcia\" style=\"padding-bottom:10px\"><a href=\"/profil/"+odpoved[2]+"\"> "+odpoved[3]+" </a> "+odpoved[4]+" "+odpoved[5]+"</td></tr></table>");


            }
            else if (odpoved[0]=='1')
            {

               $.jnotifica("Nepodarilo sa reagovať na príspevok. Ospravedlňujeme sa, na odstránení závady pracujeme");
            }   
            else if (odpoved[0]=='2')
            {
    
               $.jnotifica("Reakcia na príspevok je príliš krátka");
            }

         }

      }); 

      return false;

   });  













   $('#pridat-kategoriu').click(function(){
      var nazov = $("#forum input#kategoria-nazov").val();
      var popis = $("#forum textarea#kategoria-popis").val();

      var dataString = 'nazov='+ nazov + '&popis=' + popis;  
      $.ajax({  
         type: "POST",  
         url: "/inc/ajax/forum-pridat-kategoriu.php",  
         data: dataString,  
         success: function(data) {
            if (data=='0')
            {
               window.location.replace("/forum");
       
               $.jnotifica("Kategória bola úspešne pridaná");
            }
            else if (data=='1')
            {
        
               $.jnotifica("Kategóriu sa nepodarilo pridať. Ospravedlňujeme sa, na odstránení závady pracujeme");
            }   
            else if (data=='2')
            {
   
               $.jnotifica("Názov kategórie alebo jej popis sú príliš krátke");
            }

         }  
      });  
      return false;		
   });

   $('#pridat-temu').click(function(){
      var nazov = $("#forum input#tema-nazov").val();
      var popis = $("#forum textarea#tema-popis").val();
      var rodic = $("#forum #tema-rodic").val();

      var dataString = 'nazov='+ nazov + '&popis=' + popis+'&rodic=' + rodic;  
      $.ajax({  
         type: "POST",  
         url: "/inc/ajax/forum-pridat-temu.php",  
         data: dataString,  
         success: function(data) {

            var odpoved = data.split("|"); 
            if (odpoved[0]=='0')
            {
               window.location.replace("/forum/"+odpoved[1]);
     
               $.jnotifica("Téma bola úspešne pridaná");
            }
            else if (odpoved[0]=='1')
            {
        
               $.jnotifica("Tému sa nepodarilo pridať. Ospravedlňujeme sa, na odstránení závady pracujeme");
            }   
            else if (odpoved[0]=='2')
            {
        
               $.jnotifica("Názov kategórie alebo jej popis sú príliš krátke");
            }

         }  
      });  
      return false;		
   });

});





/* text - tlacit */
$(document).ready(function(){	
   var id = $("#texty #id-textu").val();

   $('#tlacit').click(function() {
      var msg;

      var WinPrint = window.open('','xxx','width=600,height=600');

      $.ajax({
         type: "GET",
         url: "/inc/ajax/texty-tlacit.php",
         data: "id="+id,
         success: function(msg){
            WinPrint.document.write(msg);
            WinPrint.document.close();
            WinPrint.focus();
            WinPrint.print();
            WinPrint.close();
         }
      });

      return false;
   });

});         

/* text - pridat */
$(document).ready(function(){	

   $('#pridat-text').click(function(){
      var nazov = $("#texty input#nazov").val();
      var kategoria = $("#texty select#kategoria").val();
      var text = $("#texty textarea#text").val();

      var dataString = 'nazov='+ nazov + '&text=' + text + '&kategoria=' + kategoria;  
      $.ajax({  
         type: "POST",  
         url: "/inc/ajax/texty-pridat-text.php",  
         data: dataString,  
         success: function(data) {
            if (data=='0')
            {
               var nazov = $("#texty input#nazov").val('');
               var text = $("#texty textarea#text").val('');
         
               $.jnotifica("Text bol úspešne pridaný do databázy. Ďakujeme");
            }
            else if (data=='1')
            {
      
               $.jnotifica("Text sa nepodarilo pridať. Ospravedlňujeme sa, na odstránení závady pracujeme");
            }   

         }  
      });  
      return false;		
   });

});

/* anketu - zmazat */
$(function() {

   $('.zmazat-anketu').click(function(){
      var id;
      var url = $(this).attr("href");

      $("#dialog-zmazat-anketu").dialog({
         resizable: false,
         modal: true,
         autoOpen: false,
         buttons: {
            'Áno, zmazať': function() {	
               $.ajax({
                  type: "GET",
                  url: '/akcia'+url+'/2',
                  success: function(msg)
                  {
                     $("#anketa-div-"+id).slideUp();

                     if (msg==0)	{
                  
                        $.jnotifica("Anketa bola úspešne odstránená");
                     }
                     else if (msg==1) {
                
                        $.jnotifica("Anketu sa nepodarilo odstrániť");
                     }
                  }
               });
               $(this).dialog('close');
            },
            'Nie': function() {
               $(this).dialog('close');
            }
         }
      });

      //$.getJSON(url,{step: "1"},dates);

      $.getJSON('/akcia'+url+'/1',{},dates);

      function dates(jsondata)
      {
         $("#dialog-zmazat-anketu").html(jsondata.otazka);
         id = jsondata.id;
         $('#dialog-zmazat-anketu').dialog('open');
      }

      return false;


   });


   return false;

});

/* text - zmazat */
$(function() {

   $('.zmazat-text').click(function(){
      var id;
      var url = $(this).attr("href");

      $("#dialog-zmazat-text").dialog({
         resizable: false,
         modal: true,
         autoOpen: false,
         buttons: {
            'Áno, zmazať': function() {	
               $.ajax({
                  type: "GET",
                  url: '/akcia'+url+'/2',
                  success: function(msg)
                  {
                     $("#text-li-"+id).slideUp();

                     if (msg==0)	{
                  
                        $.jnotifica("Text bol úspešne odstránený");
                     }
                     else if (msg==1) {
                
                        $.jnotifica("Text sa nepodarilo odstrániť");
                     }
                  }
               });
               $(this).dialog('close');
            },
            'Nie': function() {
               $(this).dialog('close');
            }
         }
      });

      //$.getJSON(url,{step: "1"},dates);

      $.getJSON('/akcia'+url+'/1',{},dates);

      function dates(jsondata)
      {
         $("#dialog-zmazat-text").html(jsondata.otazka);
         id = jsondata.id;
         $('#dialog-zmazat-text').dialog('open');
      }

      return false;


   });

	
	
	
	
	
	
	
	
   $('#texty .zmazat-kategoriu').click(function(){
      var id;
      var url = $(this).attr("href");

      $("#dialog-zmazat-kategoriu").dialog({
         resizable: false,
         modal: true,
         autoOpen: false,
         buttons: {
            'Áno, zmazať': function() {	
               $.ajax({
                  type: "GET",
                  url: '/akcia'+url+'/2',
                  success: function(msg)
                  {
                     $("#kategoria-li-"+id).slideUp();

                     if (msg==0)	{
                
                        $.jnotifica("Kategória bola úspešne odstránená");
                     }
                     else if (msg==1) {
                 
                        $.jnotifica("Kategóriu sa nepodarilo odstrániť");
                     }
                  }
               });
               $(this).dialog('close');
            },
            'Nie': function() {
               $(this).dialog('close');
            }
         }
      });

      //$.getJSON(url,{step: "1"},dates);

      $.getJSON('/akcia'+url+'/1',{},dates);

      function dates(jsondata)
      {
         $("#dialog-zmazat-kategoriu").html(jsondata.otazka);
         id = jsondata.id;
         $('#dialog-zmazat-kategoriu').dialog('open');
      }

      return false;


   });

//return false;

});





/* text - poslat emailom */
$(function() {
   var id = $("#id-textu").val();
   var text = $("#input-text"), email = $("#input-email");
   $('#odoslat-emailom').click(function(){

      $("#input-email").removeClass("ui-state-error");
      $("#input-text").removeClass("ui-state-error");

      $("#validateTips").css("display","none");

      $.ajax({
         type: "GET",
         url: '/inc/ajax/texty-odoslat-email.php',
         data: "id="+id+"&step=1",
         success: function(msg)
         {
            $("#email-text").html(msg);	
            $('#dialog-odoslat-email').dialog('open');					
         }
      });	
      return false;
   });

   $("#dialog-odoslat-email").dialog({
      resizable: false,
      modal: true,
      autoOpen: false,
      buttons: {
         'Odoslať email': function() {
            var bValid = true;
            bValid = bValid && checkLength(text,"<span class=\"ui-icon ui-icon-alert\"></span> Maximálna dĺžka správy je 100 znakov",0,100);
            bValid = bValid && checkRegexp(email,/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i,"<span class=\"ui-icon ui-icon-alert\"></span> neexistujúca emailová adresa");
            if (bValid) {			
               var emailval = $("#input-email").val();
               var textval = $("#input-text").val();
               $.ajax({
                  type: "GET",
                  url: '/inc/ajax/texty-odoslat-email.php',
                  data: "id="+id+"&email="+emailval+"&text="+textval+"&step=2",
                  success: function(msg)
                  {
                     if (msg==0)	{
                  
                        $.jnotifica("Text bol úspešne odoslaný");
                     }
                     else if (msg==1) {
                  
                        $.jnotifica("Text sa nepodarilo odoslať");
                     }
                  }
               });
               $(this).dialog('close');			
            }
         },
         'Zavrieť': function() {
            $(this).dialog('close');
         }
      }
   });



   /* na stiahnutie - zmazat kategoriu */
   $(function() {

      $('#na-stiahnutie .zmazat-kategoriu').click(function(){
         var id;
         var url = $(this).attr("href");

         $("#dialog-zmazat-kategoriu").dialog({
            resizable: false,
            modal: true,
            autoOpen: false,
            buttons: {
               'Áno, zmazať': function() {	
                  $.ajax({
                     type: "GET",
                     url: '/akcia'+url+'/2',
                     success: function(msg)
                     {
                        $("#kategoria-li-"+id).slideUp();

                        if (msg==0)	{
                 
                           $.jnotifica("Kategória bola úspešne odstránená");
                        }
                        else if (msg==1) {
                    
                           $.jnotifica("Kategóriu sa nepodarilo odstrániť");
                        }
                     }
                  });
                  $(this).dialog('close');
               },
               'Nie': function() {
                  $(this).dialog('close');
               }
            }
         });

         //$.getJSON(url,{step: "1"},dates);

         $.getJSON('/akcia'+url+'/1',{},dates);

         function dates(jsondata)
         {
            $("#dialog-zmazat-kategoriu").html(jsondata.otazka);
            id = jsondata.id;
            $('#dialog-zmazat-kategoriu').dialog('open');
         }

         return false;


      });


      return false;

   });


   /* zmazat reklamu */
   $('.zmazat-reklamu').click(function(){
      var id;
      var url = $(this).attr("href");

      $("#dialog-zmazat-reklamu").dialog({
         resizable: false,
         modal: true,
         autoOpen: false,
         buttons: {
            'Áno, zmazať': function() {	
               $.ajax({
                  type: "GET",
                  url: '/akcia'+url+'/2',
                  success: function(msg)
                  {
                     $("#reklama-li-"+id).slideUp();

                     if (msg==0)	{
                  
                        $.jnotifica("Reklama bola úspešne odstránená");
                     }
                     else if (msg==1) {
                 
                        $.jnotifica("Reklamu sa nepodarilo odstrániť");
                     }
                  }
               });
               $(this).dialog('close');
            },
            'Nie': function() {
               $(this).dialog('close');
            }
         }
      });

      //$.getJSON(url,{step: "1"},dates);

      $.getJSON('/akcia'+url+'/1',{},dates);

      function dates(jsondata)
      {
         $("#dialog-zmazat-reklamu").html(jsondata.otazka);
         id = jsondata.id;
         $('#dialog-zmazat-reklamu').dialog('open');
      }

      return false;

   });


});



/*                 
M O D U L     
 */



/* vyhladavanie */
$(document).ready(function(){	

   var inputvyhladavanie = $('#input-vyhladavanie');

   inputvyhladavanie.focus(function () {
      if (  inputvyhladavanie.val()=='Hľadaj ...' )
      {
         inputvyhladavanie.val('');
         inputvyhladavanie.css({
            color: "#000"
         });
      }
      return false;
   });

   inputvyhladavanie.blur(function () {
      if ( inputvyhladavanie.val()=='' )
      {
         inputvyhladavanie.css({
            color: "#999"
         });
         inputvyhladavanie.val('Hľadaj ...');
      }
      return false;
   });

});

/* anketa */
$(document).ready(function(){	

   $("#modul-anketa a.odpoved").live("click", function() { 
      var url = $(this).attr("href");
      if (url=='#')
      {
         return false;
      }
      else
      {
         $("#modul-anketa").load( url );
         return false;
      }
   });

});

/* prihlasovanie */
$(document).ready(function(){	

   $('#prihlas').click(function(){
      var login = $("input#login").val();
      var password = $("input#password").val();

      var dataString = 'login='+ login + '&password=' + password;  
      $.ajax({  
         type: "POST",  
         url: "/inc/ajax/prihlasovanie.php",  
         data: dataString,  
         success: function(data) {  
            if (data=='0')
            {
               window.location.replace(document.location.href);
            }
            else if (data=='1')
            {
     
               $.jnotifica("Nesprávne prihlasovacie meno alebo heslo");
               $("input#login").val('');
               $("input#password").val('');
            }   
            else if (data=='3')
            {
       
               $.jnotifica("Vaše konto ešte nebolo aktivované");
               $("input#login").val('');
               $("input#password").val('');
            }   
            else if (data=='2')
            {
         
               $.jnotifica("Vyplňte prosím prihlasovacie meno aj heslo");
            }
         }  
      });  
      return false;		
   });

   $('#odhlasit').click(function () {
      $.post("/inc/ajax/odhlasit.php",
         function(data){
            if (data=='0')
            {
               window.location.replace("/");
            }
            else
            {
        
               $.jnotifica("Nepodarilo sa odhlásiť uživateľa");
            }
         });
   });

   $('#odhlasit-top').click(function () {
      $.post("/inc/ajax/odhlasit.php",
         function(data){
            if (data=='0')
            {
               window.location.replace("/");
            }
            else
            {
     
               $.jnotifica("Nepodarilo sa odhlásiť uživateľa");
            }
         });
   });

   $('#prihlasit-top').click(function () {
      $("#modul-prihlasovanie").effect('pulsate', {
         times:2
      });
      return false;
   });



   $(".nutne-prihlasenie").live("click", function() { 
      $("#modul-prihlasovanie").effect('pulsate', {
         times:2
      });

      $.jnotifica("Na vykonanie tejto operácie je nutné sa prihlásiť");
      return false;
   });

});






















/*                        
GLOBALNE FUNKCIE     
 */


function updateTips(t) {
   tips = $("#validateTips");
   tips.html(t).effect("highlight",{
      color:"#ccc"
   },1500);
}


function checkLength(o,n,min,max) {

   if ( o.val().length > max || o.val().length < min ) {
      o.addClass('ui-state-error');
      updateTips(n);
      return false;
   } else {
      return true;
   }

}

function checkRegexp(o,regexp,n) {

   if ( !( regexp.test( o.val() ) ) ) {
      o.addClass('ui-state-error');
      updateTips(n);
      return false;
   } else {
      return true;
   }

}






$().ready(function() {

   function selectItem(li) {
      if (li.extra) {
         location.href=li.extra[1];
      }
   }

   function formatItem(row) {
      return row[0] + "<br><span class=\"italic subinfo\">" + row[1] + "</span>";
   }

   $("#input-vyhladavanie").autocomplete("/inc/ajax/vyhladavanie.php", {
      minChars:2,
      matchSubset:false, 
      matchContains:false, 
      cacheLength:20, 
      onItemSelect:selectItem, 
      formatItem:formatItem, 
      selectOnly:1, 
      width:'172px'
   });
   $("#input-vyhladavanie-full").autocomplete("/inc/ajax/vyhladavanie.php", {
      minChars:2,
      matchSubset:false, 
      matchContains:false, 
      cacheLength:20, 
      onItemSelect:selectItem, 
      formatItem:formatItem, 
      selectOnly:1, 
      width:'460pxpx'
   });




   $('input-vyhladavanie').click(function() {
      $("#form-vyhladavanie").submit();
   });

});






$(document).ready(function() {
   $('ul#filter a').click(function() {
      var n =0;
      $(this).css('outline','none');
      $('ul#filter .active').removeClass('active');
      $(this).parent().addClass('active');

      var filterVal = $(this).attr('class').toLowerCase();

      if(filterVal == 'all') {
         $('ul#vysledky-hladania li.hidden').fadeIn(0).removeClass('hidden');
      } else {

         $('ul#vysledky-hladania li').each(function() {
            if(!$(this).hasClass(filterVal)) {
               $(this).fadeOut(0).addClass('hidden');


            } else {
               $(this).fadeIn(0).removeClass('hidden');
            }
         });

      }

      n = $("#vysledky-hladania li:visible").length;  

      if (n==0) {
         $("ul#vysledky-hladania").append('<li class="ziadne-vysledky">V tejto sekcii neboli nájdené žiadne výsledky</li>');
      }
      else {
         $('ul#vysledky-hladania li.ziadne-vysledky').remove();
      }

      //		alert(n);
      return false;
   });
});
//objednavky

$(document).ready(function() {
   $('.objednavky-filter').click(function() {
      var url = $(this).attr("href");
      var rozparsovana = url_rozprarsuj(url);

      if (rozparsovana[1]=='filter')
      {
         $('#objednavky ul').hide();
         $('ul#rok'+rozparsovana[2]).show();
         $('.objednavky-filter').removeClass('aktualna');
         $('#objednavky-filter-'+rozparsovana[2]).addClass('aktualna');		
         $('.suma_spolu').hide();
         $('#suma_'+rozparsovana[2]).show();
      }
      else
      {
         $('#objednavky ul').show();
         $('.objednavky-filter').removeClass('aktualna');
         $('#objednavky-filter-vsetko').addClass('aktualna');
         $('#objednavky-filter-vsetko').addClass('aktualna');
         $('.suma_spolu').hide();
         $('#suma_vsetky').show();
      }
      return false;
   });
});


// inzeraty

$(document).ready(function() {

   $('.zmazat-inzerat').click(function(){
      var id;
      var url = $(this).attr("href");

      $("#dialog-zmazat-inzerat").dialog({
         resizable: false,
         modal: true,
         autoOpen: false,
         buttons: {
            'Áno, zmazať': function() {	
               $.ajax({
                  type: "GET",
                  url: '/akcia'+url+'/2',
                  success: function(msg)
                  {
                     $("#inzerat-div-"+id).slideUp();

                     if (msg==0)	{
             
                        $.jnotifica("Inzerát bol úspešne odstránený");
                     }
                     else if (msg==1) {
   
                        $.jnotifica("Inzerát sa nepodarilo odstrániť");
                     }
                  }
               });
               $(this).dialog('close');
            },
            'Nie': function() {
               $(this).dialog('close');
            }
         }
      });

      //$.getJSON(url,{step: "1"},dates);

      $.getJSON('/akcia'+url+'/1',{},dates);

      function dates(jsondata)
      {
         $("#dialog-zmazat-inzerat").html(jsondata.otazka);
         id = jsondata.id;
         $('#dialog-zmazat-inzerat').dialog('open');
      }

      return false;


   });
});



//uzivatel / profil
$(document).ready(function() {

   $('#uzivatel-inzeraty .zobrazit-vsetky-inzeraty').click(function() {
      $(this).parent().children('ul.hidden').slideDown(1000);
      $(this).slideUp( 550 );
      return false
   });

   $('#uzivatel-texty .zobrazit-vsetky-texty').click(function() {
      $(this).parent().children('ul.hidden').slideDown(1000);
      $(this).slideUp( 550 );
      return false
   });



   /* zmazat reklamu */
   $('.zmazat-uzivatela').click(function(){
      var id;
      var url = $(this).attr("href");

      $("#dialog-zmazat-uzivatela").dialog({
         resizable: false,
         modal: true,
         autoOpen: false,
         buttons: {
            'Áno, zmazať': function() {	
               $.ajax({
                  type: "GET",
                  url: '/akcia'+url+'/2',
                  success: function(msg)
                  {
                     $("#uzivatelia .obsah-plny").html('<h2>Profil bol odstránený</h2>');

                     if (msg==0)	{
                        $.jnotifica("Užívateľ bol úspešne odstránený");
                     }
                     else if (msg==1) {
           
                        $.jnotifica("Užívateľa sa nepodarilo odstrániť");
                     }
                  }
               });
               $(this).dialog('close');
            },
            'Nie': function() {
               $(this).dialog('close');
            }
         }
      });

      $.getJSON('/akcia'+url+'/1',{},dates);

      function dates(jsondata)
      {
         $("#dialog-zmazat-uzivatela").html(jsondata.otazka);
         id = jsondata.id;
         $('#dialog-zmazat-uzivatela').dialog('open');
      }

      return false;

   });

});















//forum
$(document).ready(function() {

   $('.zobrazit-vsetky-temy').click(function() {
      $(this).parent().children('ul.hidden').slideDown(1000);
      $(this).slideUp( 550 );
      return false
   });

   $('.elastic').elastic();


   $("#forum table tr td a[href=#reagovat]").live("click", function()
   {
      $(this).parent("td").children(".komentovat").css("display","block"); 
      $(this).parent("td").children(".komentovat").children(".reakcia").children("textarea").focus();
      return false;
   });


   $("#forum .komentovat .reakcia textarea").blur(function () {
      if($(this).val() == "")
      {
         $(this).parent(".reakcia").parent(".komentovat").fadeOut(500); 
         return false;
      }
   });


   //
   $('#forum #blocked').block({
      message: 'Ak chcete prispievať do fóra musíte sa <a href="/registracia" rel="nofollow" class="nutne-prihlasenie">prihlásiť</a>, ak nemáte svoj účet <a href="/registrovat" rel="nofollow"><strong>zaregistrujte sa</a>'
   }); 


   $("a[href=#page]").click(function (){
      javascript:window.scrollTo(0,0);
   return false;
   });





   $("a.neprihlaseny").click(function ()	{

      $.jnotifica("Pre vykonanie tejto akcie musíte byť prihlásený");
   });
//


});



$(document).ready(function() {



   jQuery.fn.maxLength = function(max){
      this.each(function(){
         var type = this.tagName.toLowerCase();
         var inputType = this.type? this.type.toLowerCase() : null;
         if(type == "input" && inputType == "text" || inputType == "password"){
            this.maxLength = max;
         }
         else if(type == "textarea"){
            this.onkeypress = function(e){
               var ob = e || event;
               var keyCode = ob.keyCode;
               var hasSelection = document.selection? document.selection.createRange().text.length > 0 : this.selectionStart != this.selectionEnd;
               return !(this.value.length >= max && (keyCode > 50 || keyCode == 32 || keyCode == 0 || keyCode == 13) && !ob.ctrlKey && !ob.altKey && !hasSelection);
            };
            this.onkeyup = function(){
               if(this.value.length > max){
                  this.value = this.value.substring(0,max);
               }
            };
         }
      });
   };

   $(".maxlenght-750").maxLength(750);  
   $(".maxlenght-5000").maxLength(5000);  



});

















/* kosik */

/* pridat polozku do kosa */
$(document).ready(function() {
   $('.pridat-polozku').click(function(){
      var id;
      var url = $(this).attr("href");
      var rozparsovana = url_rozprarsuj(url);
      var pocet_kusov = $("#pocet_kusov").val();

      var dataString = 'id='+ rozparsovana[2] + '&pocet_kusov=' + pocet_kusov;  

      $.ajax({  
         type: "POST",  
         url: "/inc/ajax/kosik-pridat-polozku.php",  
         data: dataString,  	
         success: function(data) {
            test = json_rozprarsuj(data);
            if (test[0]=='0')
            {
               $('#album-'+rozparsovana[2]).effect('highlight', {
                  color: "#EFEEE7"
               }, 'slow');
               $('.kosik-pocet-poloziek').html(test[1]);
               $('.kosik-cena-celkom').html(test[2]);
               $('.kosik-cena-spolu').html(test[3]);
               $.jnotifica("Tovar bol úspešne pridaný do košíka");
            }
            else if (test[0]=='1')
            {
 
               $.jnotifica("Tovar sa do košíka nepodarilo pridať");
            }   

         }  
      });  

      return false;	

   });


   $('.odobrat-polozku').click(function(){
      var id;
      var url = $(this).attr("href");
      var rozparsovana = url_rozprarsuj(url);
      id = rozparsovana[2];
      $.ajax({
         type: "GET",
         url: '/akcia'+url,
         success: function(data)
         {
            test = json_rozprarsuj(data);



            test = json_rozprarsuj(data);
            if (test[0]==0)	
            {
               $("#kosik-li-"+id).slideUp();
               $('.kosik-pocet-poloziek').html(test[1]);
               $('.kosik-cena-celkom').html(test[2]);
               $('.kosik-cena-spolu').html(test[3]);
	
               $.jnotifica("Tovar bol z košíka úspešne odobratý");
            }
            else if (test[0]==1)
            {

               $('.kosik-pocet-poloziek').html(test[1]);
               $('.kosik-cena-celkom').html(test[2]);
               $('.kosik-cena-spolu').html(test[3]);
               $("#kosik-li-"+id).children('.cena-polozky').html(test[4]+' €')
  
               $.jnotifica("Tovar bol z košíka úspešne odobratý");
            }
            else if (test[0]==2) {

               $.jnotifica("Tovar sa z košíka nepodarilo odobrať");
            }
         }
      });


      return false;


   });

});





















/* PLAYER */

$(document).ready(function() {

   if ($('#jquery_jplayer').length != 0)
   {

      $("#jquery_jplayer").jPlayer({
         ready: function() {
            displayPlayList();
            playListConfig( playItem );
         },
         oggSupport: false
      })
      .jPlayerId("play", "player_play")
      .jPlayerId("pause", "player_pause")
      .jPlayerId("stop", "player_stop")
      .jPlayerId("loadBar", "player_progress_load_bar")
      .jPlayerId("playBar", "player_progress_play_bar")
      .jPlayerId("volumeMin", "player_volume_min")
      .jPlayerId("volumeMax", "player_volume_max")
      .jPlayerId("volumeBar", "player_volume_bar")
      .jPlayerId("volumeBarValue", "player_volume_bar_value")
      .onProgressChange( function(loadPercent, playedPercentRelative, playedPercentAbsolute, playedTime, totalTime) {
         var myPlayedTime = new Date(playedTime);
         var ptMin = (myPlayedTime.getUTCMinutes() < 10) ? "0" + myPlayedTime.getUTCMinutes() : myPlayedTime.getUTCMinutes();
         var ptSec = (myPlayedTime.getUTCSeconds() < 10) ? "0" + myPlayedTime.getUTCSeconds() : myPlayedTime.getUTCSeconds();
         $("#play_time").text(ptMin+":"+ptSec);

         var myTotalTime = new Date(totalTime);
         var ttMin = (myTotalTime.getUTCMinutes() < 10) ? "0" + myTotalTime.getUTCMinutes() : myTotalTime.getUTCMinutes();		
         var ttSec = (myTotalTime.getUTCSeconds() < 10) ? "0" + myTotalTime.getUTCSeconds() : myTotalTime.getUTCSeconds();

         if (ttSec === parseInt(ttSec,10))
         {
            $("#total_time").text(ttMin+":"+ttSec);
         }
      })
      .onSoundComplete( function() {
         playListNext();
      });

      $("#ctrl_prev").click( function() {
         playListPrev();
         return false;
      });

      $("#ctrl_next").click( function() {
         playListNext();
         return false;
      });

      function displayPlayList() {
         for (i=0; i < myPlayList.length; i++) {
            //$("#playlist_list ul").append("<li id='playlist_item_"+i+"'>"+ myPlayList[i].name +"</li>");
            var tmp_id = myPlayList[i].id;
            $("#playlist_item_"+i).data( "index", i ).hover(
               function() {
                  //if (playItem != $(this).data("index")) {
                  $(this).addClass("playlist_hover");
               //}
               },
               function() {
                  $(this).removeClass("playlist_hover");
               }
               ).click( function(myPlayList) {
               var index = $(this).data("index");
               //if (playItem != index) {
               playListChange( index );
            //} else {
            //	$("#jquery_jplayer").play();
            //}
            });

            $("#playlist_item_"+i).click(function() {
               //$("#song_nazov").text($(this).text());
               return false;
            });

         }
      }

      function playListInit(autoplay) {
         if(autoplay) {
            playListChange( playItem );
         } else {
            playListConfig( playItem );
         }
      }

      function playListConfig( index ) {
         $("#playlist_item_"+playItem).removeClass("playlist_current");
         $("#playlist_item_"+index).addClass("playlist_current");
         playItem = index;
         $("#jquery_jplayer").setFile(myPlayList[playItem].mp3);
      }

      function playListChange( index ) {
         $("#jquery_jplayer").pause();
         playListConfig( index );
         $("#jquery_jplayer").play();
      }

      function playListNext() {

         if (playItem+1 == myPlayList.length)
         {
            var index = (playItem+1 < myPlayList.length) ? playItem+1 : 0;
            //$("#song_nazov").text($('#playlist_item_'+index).text());
            playListChange( index );

            if (myPlayList[playItem+1].ukazka==0)
            {
               var i=playItem+1;
               while (myPlayList[i].ukazka==0)
               {
                  var index = (i+1 < myPlayList.length) ? i+1 : 0;
                  //$("#song_nazov").text($('#playlist_item_'+index).text());
                  playListChange( index  );
                  //alert(index +' '+ i + ' - ' +myPlayList[i].ukazka);
                  i++;
               }			
            }
            else
            {
               var index = (playItem+1 < myPlayList.length) ? playItem+1 : 0;
               //$("#song_nazov").text($('#playlist_item_'+index).text());
               playListChange( index );
            }

         }
         else
         { 

            if (myPlayList[playItem+1].ukazka==0)
            {			
               var i=playItem+1;
               while (myPlayList[i].ukazka==0)
               {
                  var index = (i+1 < myPlayList.length) ? i+1 : 0;
                  if (i+1 == myPlayList.length) {
                     var i = -1
                  };
                  //$("#song_nazov").text($('#playlist_item_'+index).text());
                  playListChange( index  );
                  //alert(index +' '+ i + ' - ' +myPlayList[i].ukazka);
                  i++;
               }			
            }
            else
            {
               var index = (playItem+1 < myPlayList.length) ? playItem+1 : 0;
               //$("#song_nazov").text($('#playlist_item_'+index).text());
               playListChange( index );
            }

         }

      }

      //

      function playListPrev() {

         if (playItem-1 == -1)
         {
            var index = (playItem-1 > -1) ? playItem-1 : myPlayList.length-1;
            //$("#song_nazov").text($('#playlist_item_'+index).text());
            playListChange( index );
            if (myPlayList[playItem-1].ukazka==0)
            {
               var i=playItem-1;
               while (myPlayList[i].ukazka==0)
               {
                  var index = (i-1 > -1) ? i-1 : myPlayList.length-1;
                  //$("#song_nazov").text($('#playlist_item_'+index).text());
                  playListChange( index );
                  i--;
               }			
            }
            else
            {
               var index = (playItem-1 > -1) ? playItem-1 : myPlayList.length-1;
               //$("#song_nazov").text($('#playlist_item_'+index).text());
               playListChange( index );
            }
         }
         else
         {

            if (myPlayList[playItem-1].ukazka==0)
            {
               var i=playItem-1;
               while (myPlayList[i].ukazka==0)
               {
                  var index = (i-1 > -1) ? i-1 : myPlayList.length-1;
                  //$("#song_nazov").text($('#playlist_item_'+index).text());
                  playListChange( index );
                  i--;
               }			
            }
            else
            {
               var index = (playItem-1 > -1) ? playItem-1 : myPlayList.length-1;
               //$("#song_nazov").text($('#playlist_item_'+index).text());
               playListChange( index );
            }
         }

      }


   }

});


