// JavaScript Document
jQuery(document).ready(function(){

     Cufon.replace('.cufon, div.Menu ul.firstLevel > li > a, div.Header div.Message p.message, div.Header div.Links p, div.MainItemHeader h1, div.MainRight div.Registration a, div.MainItem div.MainItemBody table.sliders td.td4 div a, div.Donate p, div.Donate div.LeftItemBody div.button a span, div.Donate2 div.LeftItemBody div.buttonMore a span, div.Donate2Green div.LeftItemBody div.buttonMore a span, div.Cols2b div.button a span, div.Cols2b h1, div.Donate2 p.text, div.Donate2Green div.LeftItemBody p.text, div.Rozc h2, div.Rozc div.button a span');

     /* fb */
     $(".MainRight").children(".LeftItem:last").hide();

     /* teplomer */
     var tWholePx = 162;
     var tWhole = 3500000; 
     
     var tMove = (tWholePx-((tWholePx/100)*(tSoFar/(tWhole/100))));
     if (tSoFar <= 250000){ tMove = 150; }
     tSoFar = FormatNumberBy3(tSoFar, " ", " ");

     //alert(tMove);
     $("div.Teplomer .Moving span").html(tSoFar+" Kč");
     $("div.Teplomer .Moving").animate({
          top: tMove+'px'
     }, 1500, function(){ 
          //hotovo
     });
     $("div.TeplomerEN .Moving span").html("CZK "+tSoFar);
     $("div.TeplomerEN .Moving").animate({
          top: tMove+'px'
     }, 1500, function(){ 
          //hotovo
     });
     /* end teplomer */

     /* init */
     $("div.MainItemBody").each(function(){
          $(this).children("div.type2row:last").css("background","none");
     });
     /*$("div.Cols1All").children("div.halfItem:even").each(function(){
          $(this).addClass("halfItemLeft");
     });*/
     
     
     $('a.galerie').lightBox({fixedNavigation:true});

     /* tisk mapy */
     $("div.tiskMapy img").each(function(){
          //
     });
     $("a#Mapa").each(function(){
          mapaSrc = $("a#Mapa").attr("href");
          $("div.tiskMapa a").attr("href","/tiskMapa.php?src="+mapaSrc);
     });

     /* homepage 
     x = 2;
     $("div.Header").everyTime(5000, function(){
          $("div.Header > div.HeaderBack01, div.Header > div.HeaderBack02, div.Header > div.HeaderBack03").hide();
          $("div.Links > p").hide();
          $("div.Header > div.HeaderBack0"+x).show();
          $("div.Links > p.claim0"+x).show();
          x++;
          if (x==4){ x = 1; }
     });
*/




     /* TOP MENU */
     /* init */     
     $("ul.secondLevel").each(function(){
          $(this).children("li:first").addClass("first");
          var x = parseInt($(this).parent("li").width());
          var posLeft = 150-x;
          $(this).css("left","-"+posLeft+"px");
     });
     $("ul.thirdLevel").each(function(){
          $(this).children("li:first").addClass("first");
     });     
     /* dropdown */
     $("div.Menu ul.firstLevel > li").mouseover(function(){
          $(this).addClass("Hover");
          $(this).children("a").addClass("Hover");
          $(this).children("ul.secondLevel").css("visibility","visible");
     });
     $("div.Menu ul.firstLevel > li").mouseleave(function(){
          $(this).removeClass("Hover");
          $(this).children("a").removeClass("Hover");
          $(this).children("ul.secondLevel").css("visibility","hidden");
     });
     $("div.Menu ul.secondLevel > li").mouseover(function(){
          $(this).addClass("Hover2");          
     });
     $("div.Menu ul.secondLevel > li").mouseleave(function(){
          $(this).removeClass("Hover2");
     });     
     $("div.Menu ul.secondLevel > li").mouseover(function(){
          $(this).children("ul.thirdLevel").css("visibility","visible");
     });     
     $("div.Menu ul.secondLevel > li").mouseleave(function(){
          $(this).children("ul.thirdLevel").css("visibility","hidden");
     });
     $("div.Menu ul.thirdLevel > li").mouseover(function(){
          $(this).addClass("Hover2");          
     });
     $("div.Menu ul.thirdLevel > li").mouseleave(function(){
          $(this).removeClass("Hover2");
     }); 
     /* */
     $("ul.thirdLevel").each(function(){          
          var x = $(this).parent("li").height();
          $(this).css("top","0px");
     });
 
});


// function to format a number with separators. returns formatted number.
// num - the number to be formatted
// decpoint - the decimal point character. if skipped, "." is used
// sep - the separator character. if skipped, "," is used
function FormatNumberBy3(num, decpoint, sep) {
  // check for missing parameters and use defaults if so
  if (arguments.length == 2) {
    sep = ",";
  }
  if (arguments.length == 1) {
    sep = ",";
    decpoint = ".";
  }
  // need a string for operations
  num = num.toString();
  // separate the whole number and the fraction if possible
  a = num.split(decpoint);
  x = a[0]; // decimal
  y = a[1]; // fraction
  z = "";


  if (typeof(x) != "undefined") {
    // reverse the digits. regexp works from left to right.
    for (i=x.length-1;i>=0;i--)
      z += x.charAt(i);
    // add seperators. but undo the trailing one, if there
    z = z.replace(/(\d{3})/g, "$1" + sep);
    if (z.slice(-sep.length) == sep)
      z = z.slice(0, -sep.length);
    x = "";
    // reverse again to get back the number
    for (i=z.length-1;i>=0;i--)
      x += z.charAt(i);
    // add the fraction back in, if it was there
    if (typeof(y) != "undefined" && y.length > 0)
      x += decpoint + y;
  }
  return x;
}
