var l = true;
//#####################################
$(document).ready(function(){
    $(document).pngFix(); 
     $(function() {$('a.lb').lightBox();});
    //#####################################intro
    if($("#black").length != 0)
    {
      l = false;
      $(".logo").hide();
      $("#body").hide();
      $("#menu").hide();
      $(".logo").css("top","250px");
      
      $("#black").fadeOut(500,function(){
          $(".ziara").fadeIn(1000);
          $(".logo").fadeIn(1000);
          $(".langs").fadeOut(0,function(){ 
          $(".ziara").fadeOut(1000);
          $(".logo").animate({top:"10px"},1000,function(){
            l = true;
            $("#body").fadeIn(700,function(){
              $("#menu").fadeIn(700);
            });
          });
        });
      });
    }
    $(".langs td").click(function(){
      
    });
    $(".logo").click(function(){if(l==true){window.location="/";}});
    //#####################################img-flip
    function mySideChange(front) {
        if (front) {
            $(this).parent().find('div.front').show();
            $(this).parent().find('div.back').hide();
        } else {
            $(this).parent().find('div.front').hide();
            $(this).parent().find('div.back').show();
        }
      }
    $('.is, .list td').hover(
          function () {
              $(this).find('div').rotate3Di('flip', 500, {direction: 'clockwise', sideChange: mySideChange });   
          },
          function () {
              $(this).find('div').rotate3Di('+=180', 500, {direction: 'clockwise', sideChange: mySideChange});
          }
    );
    //#####################################links
    $(".bc-input").click(function(){if($(this).val()=='Váš email'){$(this).val('');}});
    $(".bc-area").click(function(){if($(this).html('Vaše správa')){$(this).val('');}});
    //#####################################gallery
    
    if($(".g-images").length != 0)
    {
      _gallery();
    }
    $(".g-la").click(function(){
      _gallery("back");
      _g_info();
    });
    $(".g-ra").click(function(){
      _gallery("next"); 
    });
    //#####################################disko
    $(".disko-gula").click(function(){
      if($(".ds-table2").is(":hidden")){
        $(".prva").removeClass("zapata");
        $(".prva").addClass("vypata");
        $(".druha").removeClass("vypata");
        $(".druha").addClass("zapata");
        $(".ds-table1").fadeOut(1000);
        $(".ds-table2").fadeIn(1000);
      } else {
        $(".druha").removeClass("zapata");
        $(".druha").addClass("vypata");
        $(".prva").removeClass("vypata");
         $(".prva").addClass("zapata");
        $(".ds-table2").fadeOut(1000);
        $(".ds-table1").fadeIn(1000);
      }
    });
  $(".k-sbm").click(function(){
    i1 = _check($(".k-meno"));
    i2 = _check($(".k-prim"));
    i3 = _is_email($(".k-email"));
    if((i1)&&(i2)&&(i3))
    {
      $(".k-fm").submit();
    }
  }); 

});
//#####################################

function _gallery(smer)
{
  pg = location.href; 
  pr = $(".im1 .g-im").attr("src");
  po = $(".im8 .g-im").attr("src");
  if(pr==null || po==null)
  {
    pr = $(".im1 .g-im-st").attr("src");
    po = $(".im8 .g-im-st").attr("src");
  }
  $(".g-images").fadeOut("slow",function(){
    $.post("/files/gallery.php",{smer:smer,page:pg,prvy:pr,posledny:po},function(data){
      $(".g-images").html(data);
      $(".g-images").fadeIn("slow",function(){
        $(function() {$('a.lb').lightBox();});
        
        $(".g-im").mouseover(function(){
          val = $(this).attr("alt");
          vl = $(this).attr("id");
          vleft = 20+(((vl*1)-1)*77);
          $(".g-info").fadeOut("fast",function(){
            $(".g-info").css("left",vleft+"px");
            $(".g-info").html(val);
            $(".g-info").fadeIn("fast");
            $(".g-im").mouseout(function(){
              $(".g-info").hide();
            });
            $(".g-info").mouseout(function(){
              $(".g-info").hide();
            });
          });
        });
        
        $(".g-im-st").mouseover(function(){
          var dr = $(this).attr("alt");  
          var isrc = $(this).attr("src"); 
          $(".g-info").fadeOut(0,function(){
            if(dr=="w")
            {
              $(".g-info-w").html("<img src='"+isrc+"' alt='' width='459' height='306' />");
              $(".g-info-w").fadeIn(0);
            } else {
              $(".g-info-h").html("<img src='"+isrc+"' alt='' width='206' height='308' />");
              $(".g-info-h").fadeIn(0);
            } 
          });
        });
        $(".glr").mouseout(function(){
          $(".g-info").fadeOut(0);
        });
      });
    });
  });
} 

function _is_email(e)
{
  var str = e.val();
  var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
  if (filter.test(str))
  {
    e.removeClass("f-ir");
    return true
  } else {
    e.addClass("f-ir");
    return false
  }
}
//************************************//
function _check(v)
{
  if (v.val()=="" || v.val()==null)
  {
    v.addClass("f-ir");
    return false;
  } else {
    v.removeClass("f-ir");
    return true
  }
}
//************************************//
