$(document).ready(function(){
  Shadowbox.init({ handleOversize: "drag", modal: true });
  $(function() {$("a[rel^='lightbox']").lightbox(); });
  $(function() { $(".jqtransform").jqTransform(); });
  $('#vip').lofJSidernews( { interval:4000, direction:'opacity', auto: false, isPreloaded : false, duration:500, easing:'easeInOutSine' });
  $("#temaCarousel").jCarouselLite({ btnPrev: "#btn-prev", btnNext: "#btn-next", auto: 8000, speed: 350, visible: 5 });


  /* kalendar */
  // $(".calendar span.calendar_selected_month").click(function() { $(".calendar").slideUp(); $(".calendar2").slideDown(); });
  // $(".calendar2 span.calendar_selected_month").click(function() { $(".calendar2").slideUp(); $(".calendar").slideDown(); });
  $(".cal-act-item").hover(function(){
    $(this).css("z-index","2"); $(this).find(".event-info").css({ left: "0px", display: "block" });
  }, function(){
    $(this).css("z-index","1").find(".event-info").css("display","none");
  });
  $(".cal-act-item-weekend").hover(function(){
    $(this).css("z-index","2"); $(this).find(".event-info").css({ right : "0px", display: "block" });
  }, function(){
    $(this).css("z-index","1").find(".event-info").css("display","none");
  });
  /* konec kalendar */

  $(".regionItem:nth-child(3n+2)").css("margin","0 20px 0px 20px");
  $(".regionItem").eq(-3).css("border-bottom","1px solid #b2d7ed");
  $(".regionItem").eq(-2).css("border-bottom","1px solid #b2d7ed");
  $(".regionItem").eq(-1).css("border-bottom","1px solid #b2d7ed");

  $(".calItem:first").css("border-top","1px solid #b2d7ed");

  $(".clenVedeni:nth-child(4n)").css("margin-right","0");


  $("a#loginLink").click(function () { $("#searchForm").slideUp(); $("#loginForm").slideDown(); });
  $("#loginForm span.close").click(function () { $("#loginForm").slideUp(); });
  $("#searchLink").click(function () { $("#loginForm").slideUp(); $("#searchForm").slideDown(); });
  $("#searchForm span.close").click(function () { $("#searchForm").slideUp(); });

  $("#searchForm").hover(function() {
    $("#searchForm input.bigInput").css("color","#474747");
  },function(){
    if ($("#searchForm input.bigInput").val() == "zadejte hledaný výraz") {
      $("#searchForm input.bigInput").css("color","#bfbfbf");
    }
  });


  $(".submenu .prepinac").click(function () {
    if ($(this).parent(".submenu").hasClass("open") == true) {
      $(this).parent(".submenu").removeClass("open");
    } else {
      $(this).parent(".submenu").addClass("open");
    }
  });

/*
  $(".submenu .prepinac").click(function () {
    if ($(".submenu").hasClass("open") == true) { $(".submenu").removeClass("open"); }
    else { $(".submenu").removeClass("open"); $(".submenu").addClass("open"); }
  });
*/

  $("#twitter div").tweet({
    avatar_size: 0,
    count: 1,
    query: "from:odscz",
    loading_text: "načítám poslední zprávu z  twitter.com/ods ..."
  });

  $("#sharebox").hover(function(){
    $("#share-item").fadeIn(300);
  },function(){
    $("#share-item").fadeOut(300);
  });

  $('.showtool').each(function() {
    $(this).qtip({
      content: { url: $(this).attr('rel') },
      position: {
        target: 'mouse',
        adjust: { mouse: true, x: -3, y: -10 },
        corner: { tooltip: 'bottomMiddle' }
      },
      style: {
        name: 'dark',
        width: 220,
        background: '#333333',
        border: { width: 0, radius: 0, color: '#333333' },
        tip: true
      }
    });
  });


   $('.showtool2[title]').qtip({
        content: {
          text: false
        },
        position: {
          target: 'mouse',
          adjust: { mouse: true, x: -3, y: -10 },
          corner: { tooltip: 'bottomMiddle' }
        },
        style: {
          name: 'dark',
          width: 220,
          background: '#333333',
          border: { width: 0, radius: 0, color: '#333333' },
          tip: true
        },
        show: { effect: { length: 50 } }
     });

    /* regslider*/
    $('#regslide').nivoSlider({
      effect: 'fade',
      directionNav: true,
      directionNavHide: true,
      captionOpacity: 0.8,
      controlNav:false,
      controlNavThumbs:false,
      controlNavThumbsFromRel:true,
      pauseTime: 5000,
    });

    var sirka_RegSlide_nav = $("#regslide .nivo-controlNav").width();
    var sirka_RegSlide = $("#regslide").width();
    $("#regslide .nivo-controlNav").css("margin-left",sirka_RegSlide / 2 - sirka_RegSlide_nav / 2);
    /* regslider */

   /* rozbalovani okresu*/
   $("#region .ico-down").click(function () {
     $(this).parent().parent().parent().find("ul.rsods").toggleClass("none");
     $(this).toggleClass("ico-up");
   });
   /* /rozbalovani okresu */

});

function sedive(a) {
  grayscale($('#'+a));
}

function showIt(prvek) {
  $('.hide-img').css('display','none');
  $('#xy'+prvek).css('display','block');
}

function hideIt() {
  $('.hide-img').css('display','none');
}

function prehraj_video(idv) {
  $.get("/ajax.php", { idv: idv },
   function(data){
     $("#video-"+idv).html(data);
   });
}


function pustVideo(typ,kde,co) {
  if (typ==1) {
    jwplayer(kde).setup({
      flashplayer: oo+"jw/player.swf",
      file: co,
      controlbar: "bottom",
      autostart: true ,
      height: 380,
      width: 650,
      skin: oo+"jw/lionslight.zip"
    });
  }

  if (typ==2) {
    document.getElementById(kde).innerHTML='<iframe width="650" height="388" src="http://www.youtube.com/embed/'+co+'?wmode=transparent&autoplay=1&loop=1" frameborder="0" allowfullscreen></iframe>';
  }

  if (typ==3) {
    jwplayer(kde).setup({
      flashplayer: oo+"jw/player.swf",
      file: 'livestream',
      streamer:'rtmpt://212.67.79.203/AVT-BRNO',
      controlbar: "bottom",
      autostart: true ,
      height: 380,
      width: 650,
      skin: oo+"jw/lionslight.zip"
    });
  }

}


function ozivKalendar() {

  $(".cal-act-item").hover(function(){
    $(this).css("z-index","2"); $(this).find(".event-info").css({ left: "0px", display: "block" });
  }, function(){
    $(this).css("z-index","1").find(".event-info").css("display","none");
  });
  $(".cal-act-item-weekend").hover(function(){
    $(this).css("z-index","2"); $(this).find(".event-info").css({ right : "0px", display: "block" });
  }, function(){
    $(this).css("z-index","1").find(".event-info").css("display","none");
  });

}


function gid(co) { return document.getElementById(co);  }

function ajax(stranka, kam, hlaska, akcePo) {
 if (hlaska===undefined) { hlaska="načítám ..."; }
 var httpRequest;

 if (typeof window.ActiveXObject != 'undefined') {
   httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
 } else {
   httpRequest = new XMLHttpRequest();
 }
 httpRequest.open("GET", stranka, true);
 httpRequest.onreadystatechange= function () {
   processRequest(httpRequest, kam, hlaska, akcePo)
 };
 httpRequest.send(null);
}

function processRequest(httpRequest, kam, hlaska2, akcePo) {
 if (httpRequest.readyState == 4) {
   if(httpRequest.status == 200) {
     if (typeof kam == 'string') {
       document.getElementById(kam).innerHTML = httpRequest.responseText;
       if (akcePo!==undefined) { eval(akcePo); }
     }
     if (typeof kam == 'function') {
       kam(httpRequest.responseText);
     }
   } else {
     // alert("Chyba pri nacitani stanky " + httpRequest.status +" : "+ httpRequest.statusText);
     // if (potom!='') eval(potom);
   }
 } else {
   if ((typeof kam=='string') && (kam!='') && (hlaska2!='')) {
    document.getElementById(kam).innerHTML = hlaska2;
   }
 }
}


function polickoLabel(pole,label) {
  if (gid(pole).value=='') {
      gid(label).style.color='#ff5555';
      pl_ok=false;
    } else {
      gid(label).style.color='';
      pl_ok=true;
    }
  return pl_ok;
}

function polickoLabelC(pole,label) {
  if (gid(pole).checked=='') {
      gid(label).style.color='#ff5555';
      pl_ok=false;
    } else {
      gid(label).style.color='';
      pl_ok=true;
    }
  return pl_ok;
}

function polickoShoda(pole1,pole2,label1,label2) {
  if (gid(pole1).value!=gid(pole2).value) {
      gid(label1).style.color='#ff5555';
      gid(label2).style.color='#ff5555';
      pl_ok=false;
    } else {
      gid(label1).style.color='';
      gid(label2).style.color='';
      pl_ok=true;
    }
  return pl_ok;
}

function kontrolaRegistrace() {
   ok=true;
   if (!polickoShoda('i5','i6','l5','l6')){ok=false;}
   if (!polickoLabel('i1','l1')){ok=false;}
   if (!polickoLabel('i2','l2')){ok=false;}
   if (!polickoLabel('i3','l3')){ok=false;}
   if (!polickoLabel('i4','l4')){ok=false;}
   if (!polickoLabel('i5','l5')){ok=false;}
   if (!polickoLabel('i7','l7')){ok=false;}
   if (!polickoLabel('i8','l8')){ok=false;}
   if (!polickoLabelC('i9','l9')){ok=false;}
   return ok;
}

