jQuery().ready(function(){
  jQuery("a#callyou").fancybox();
  jQuery("#callyouform form").submit(function() {
    if(jQuery("#callyouform form input[type=text]").val() == "") {
      alert("Vyplňte vaše telefonní číslo.");
      return false;
    } else {
      return true;
    }
  });
});


 function checkEmail(){
    re = new RegExp("^[_a-zA-Z0-9\.\-]+@[_a-zA-Z0-9\.\-]+\.[a-zA-Z]{2,4}$");
    if (!re.test(document.getElementById("email").value)) {
      window.alert("Emailová adresa nemá správný formát / The email adress is invalid");
      return false;
    } else {
    return true;
    }
}


function showImage(img,xwidth,yheight){

  var winl = (screen.width - xwidth) / 2;
  var wint = (screen.height - yheight) / 2;
  var a = window.open("","new","left="+winl+",top="+wint+",width="+xwidth+",height="+yheight);

  if (parseInt(navigator.appVersion) >= 4) { a.window.focus(); }

  a.document.writeln('<html>');
  a.document.writeln('<head><title>Velký náhled</title></head>');
  a.document.writeln('<body style="margin:0;padding:0;">');
  a.document.writeln('<a href="#" onclick="window.close();"><img src="'+img+'" border="0" width="'+xwidth+'" height="'+yheight+'" alt="klikni pro zavření okna"></a>');
  a.document.writeln('</body>');
  a.document.writeln('</html>');
  a.document.close();
}

function checkPoptavka(){

if(document.poptavka.Jmeno.value==""){
window.alert('Vyplňte jméno a příjmení.');
document.poptavka.Jmeno.focus();
  return false;
}


if(document.poptavka.Ulice.value==""){
window.alert('Vyplňte místo stavby.');
document.poptavka.Ulice.focus();
  return false;
}


re = new RegExp("^[_a-zA-Z0-9\.\-]+@[_a-zA-Z0-9\.\-]+\.[a-zA-Z]{2,4}$");
  if (!re.test(document.poptavka.Email.value)) {
     window.alert("Emailová adresa nemá správný formát");
     document.poptavka.Email.focus();
     return false;
} 

}

//galerie v pruhu
//largeCntID-id divka obsahujici vsechny velke obrazky
//showCntID-id divka obsahujici velky obrazek+text ktery se ma ukazat v largeCntID
//imgID-id obrazku u ktereho zkontroluji velikost
function switchLarge(largeCntID,showCntID,imgID)
{
  var largeCnt=document.getElementById(largeCntID);
  if(largeCnt)
  {
    //schovam vsechny velke obrazky
    var divs=largeCnt.getElementsByTagName("div");
    var xxx="";
    for(var i=0;i<divs.length;i++)
    {
      if(divs[i].id.search(/gallery/)!=-1)
      {
        divs[i].style.display="none";
      }
    }
    //zobrazim pozadovany obsah
    var showCnt=document.getElementById(showCntID);
    if(showCnt)
    {
      showCnt.style.display="";
    }
    //nastavim velikost obrazku
    var img=document.getElementById(imgID);
    if(img)
    {
      setMaxImg(img,530,530);
    }
  }
}

//nastaveni rozmeru obrazku ma max velikost-kvuli IE 6, rozmery zadavat v px
function setMaxImg(el,maxwidth,maxheight)
{
  try
  {
    if(el)
    {
      if(el.width>=maxwidth)
      {
        el.style.width=maxwidth+"px";
        el.style.height="auto";
      }
      if(el.height>=maxheight)
      {
        el.style.height=maxheight+"px";
        el.style.width="auto";
      }
    }
  }catch(e){}
}

//zobrazeni bubliny
//parent-prvek vuci kteremu se vypocita pozice umisteni bubble
//elID-id bubble
function showBubble(parent,elID,imgSrc)
{
  var el=document.getElementById(elID);
  if(el)
  {
    //vypocitam pozici rodice
    var pLeft=parent.offsetLeft;
    var pTop=parent.offsetTop;
    var pHeight=parent.offsetHeight;
    //upravim pozici bubble
    el.style.left="9px";//(pLeft-186)+
    el.style.top=(pTop+pHeight+4)+"px";//(pTop-120)
    //nastavim zmizeni bubble
    el.onclick=function(){
      el.style.display="none";
    }
    //nastavim src ibrazku v bubble
    var imgEl=document.getElementById(elID+"_img");
    if(imgEl)
    {
      //imgEl.src=imgSrc;
      //zmensini na max 486*486px
      if(imgEl.width>=imgEl.height)
      {
        imgEl.style.width="486px";
        imgEl.style.height="auto";
      }
      else
      {
        imgEl.style.height="486px";
        imgEl.style.width="auto";
      }
    }
    //zobrazim bubble
    el.style.display="block";
    //posunu stranku
    //el.scrollIntoView(false);
    //schovam všechny ostatni bubble kdyby se nektera nahodou neschvala z onmouseout
    var elCnt=document.getElementById("gallery_cnt");
    if(elCnt)
    {
      var divs=elCnt.getElementsByTagName("div");
      for(var i=0;i<divs.length;i++)
      {
        if(divs[i]!=el && divs[i].className.search(/bubble/)!=-1)
        {
          divs[i].style.display="none";
        }
      }
    }
  }
}
//skryti bubliny
function hideBubble(elID)
{
  el=document.getElementById(elID);
  if(el)
  {
    el.style.display="none";
  }
}
