Cufon.replace('h1', { color: '-linear-gradient(#666666, #000000)' });
Cufon.replace('h1.nemovitost', { color: '#000000' });
Cufon.replace('.h1');
Cufon.replace('h2');
Cufon.replace('.prc');

var inputfileWidth = "87px";
var inputfileText = "Procházet...";
var inputtextSideWidth = "6px";
var inputtextHeight = "26px";
var inputtextPadding = "4px 3px 4px 1px";

var search = "Klíčové slovo";
var posDialog;

$(document).ready(function() {

  $("#search #keyword, #search #keyword2").focus(function () {
    if($(this).val()==search) { $(this).val(''); }
  }).blur(function () {
    if($(this).val()=="") { $(this).val(search); }
  });
  
  if($.browser.mozilla) { $("#search select").css("border","none"); }
  if($.browser.opera) { $("#search select").css("marginTop","2px"); }
  
  $("#setlanga").click(function() {
    $("#setlang").slideToggle();
  });
  
  $("#pronajem").click(function() {
    $("#tabprodej").hide();
    $("#tabpronajem").show();
    $("#searchmenu").css("backgroundPosition","0 -35px");
  });
  $("#prodej").click(function() {
    $("#tabpronajem").hide();
    $("#tabprodej").show();
    $("#searchmenu").css("backgroundPosition","0 0");
  });
  
  $(".params select").change(function() {
    window.location = $(this).val();
  });
  
  $(".register .formstep").not(":eq(0)").hide();
  $("#moveend").hide();
  $("#moveright").css("visibility","visible");
  var step = 1;
  var totalstep = $(".register .formstep").length;
  $("#moveleft").click(function() {
    step = step-1;
    if(step!=totalstep) { $("#moveright").css("visibility","visible").find("span").html((step+1)+" / "+totalstep);$("#moveend").hide(); } else { $("#moveright").css("visibility","hidden");$("#moveend").show(); }
    if(step!=1) { $("#moveleft").css("visibility","visible").find("span").html((step-1)+" / "+totalstep); } else { $("#moveleft").css("visibility","hidden"); }
    $(".register .formstep").hide();
    $(".register .formstep:eq("+(step-1)+")").show();
  });
  $("#moveright").click(function() {
    step = step+1;
    if(step!=totalstep) { $("#moveright").css("visibility","visible").find("span").html((step+1)+" / "+totalstep);$("#moveend").hide(); } else { $("#moveright").css("visibility","hidden");$("#moveend").show(); }
    if(step!=1) { $("#moveleft").css("visibility","visible").find("span").html((step-1)+" / "+totalstep); } else { $("#moveleft").css("visibility","hidden"); }
    $(".register .formstep").hide();
    $(".register .formstep:eq("+(step-1)+")").show();
  });
  
  
  $('#content input:file').each(function() {
    var width = $(this).width();
    var height = inputtextHeight;
    var button = $('<span class="filebutton" style="width:'+inputfileWidth+';height:'+height+';display:inline;position:absolute;overflow:hidden;margin-left:5px;margin-top:4px;float:left;">');
    var filename = $('<input type="text" class="file" style="display:inline;width:'+width+'px;height:14px;background:#fcfcfc;" disabled="disabled">').addClass($(this).attr("class"));
    $(this).css({ "position": "absolute", "height":height, "width":inputfileWidth, "display": "inline", "cursor": "pointer", "opacity": "0.0","z-index": "5" });

    $('<span class="filewrap"></span>').insertAfter($(this));
    $(this).appendTo($(this).next());
    $(this).before(filename);
    $(this).parent().append(button);
    $(this).appendTo($(this).next());
    $(this).parent().append('<span class="filetext" style="width:'+inputfileWidth+';line-height:'+height+';">'+inputfileText+'</span>');

    if ($.browser.mozilla) {
       if (/Win/.test(navigator.platform)) {
          $(this).css("margin-left", "-121px");                    
       } else {
          $(this).css("margin-left", "-181px");                    
       };
    } else {
       $(this).css("margin-left", 0);                
    };
    if($.browser.msie) {
       $(this).next().css({ "margin-left": "5px","vertical-align":"top","margin-top":"6px"});
       if($.browser.version<=7) {
         filename.css("width",width+10+"px");
       }
    }
    if($.browser.opera) {
      filename.css("width",width+10+"px");
    }
    $(this).bind("change", function() { 
      filename.val($(this).val());
    });
  });
  
  $(".padpolozky table tr:odd th, .padpolozky table tr:odd td").css("background","#efefef");
  
  var dlouhytext = $(".popis").text().length;
  if(dlouhytext>389) {
    var txt = $(".popis").text();
    $(".popis").html((txt.substring(0,389))+'<span class="tecky">...</span><span class="pokracovani">'+(txt.substring(389,dlouhytext))+'</span>');
    $('<a id="moretext" href="javascript:void(0)">more...</a>').insertAfter(".popis");
    $("#moretext").click(function() {
      $(this).prev().find(".tecky").remove();
      $(this).prev().find(".pokracovani").show();
      $(this).fadeOut(500, function() {
        $(this).remove();
      });
      $(this).prev().show();
    });
  }
  
  $(".star-rating a").hover(function() {
    $(this).parent().parent().find(".current-rating").css("display","none");
  }, function() {
    $(this).parent().parent().find(".current-rating").css("display","block");
  });
  
  if($("#tabbers a.active").length==0) {
    $("#tabbers a:eq(0)").addClass("active");
    $("#tab-"+$("#tabbers a.active").attr("rel")).show();
  } else {
    $("#leftsidebar .whiteform .form div[id^='tab-']").hide();
    $("#tab-"+$("#tabbers a.active").attr("rel")).show();
  }
  $("#tabbers a").click(function() {
    $("#leftsidebar .whiteform .form div[id^='tab-']").hide();
    $("#tab-"+$(this).attr("rel")).show();
    $("#tabbers a").removeClass("active");
    $(this).addClass("active");
  });

  
  $('#leftsidebar #tab-photo a').lightBox();
  
  $("#search select[name='region']").change(function() {
    var text = $.ajax({ url: "/?plugin=Reality&action=getRegionsInSelectBox&ajax=true&writeAll=true&id="+$(this).val(), async: false }).responseText;
    //var text = $.ajax({ url: "ajax.html?id="+$(this).val(), async: false }).responseText;
    if(text!="") {
      $(this).parent().parent().parent().find("select[name=spec]").html(text);
    }
  });

  $("select[name='region1']").change(function() {
    var text = $.ajax({ url: "/?plugin=Reality&action=getRegionsInSelectBox&ajax=true&writeAll&id="+$(this).val(), async: false }).responseText;
    //var text = $.ajax({ url: "ajax.html?id="+$(this).val(), async: false }).responseText;
    if(text!="") {
      $(this).parent().find("select[name=region2]").html(text);
    }
  });

  $("select[name='region2']").change(function() {
    var text = $.ajax({ url: "/?plugin=Reality&action=getRegionsInSelectBox&ajax=true&id="+$(this).val(), async: false }).responseText;
    //var text = $.ajax({ url: "ajax.html?id="+$(this).val(), async: false }).responseText;
    if(text!="") {
      $(this).parent().find("select[name=region3]").html(text);
    }
  });

  if($("#mapka").length) {
    $("#mapka #k1hover, #mapka #k2hover, #mapka #k3hover, #mapka #k4hover, #mapka #k5hover, #mapka #k6hover").css({"opacity":"0","display":"inline-block"});
    $("#mapka .k1 .klink a").hover(function() { $("#mapka #k1hover").animate({opacity:1},350); }, function() { $("#mapka #k1hover").animate({opacity:0},350); });
    $("#mapka .k2 .klink a").hover(function() { $("#mapka #k2hover").animate({opacity:1},350); }, function() { $("#mapka #k2hover").animate({opacity:0},350); });
    $("#mapka .k3 .klink a").hover(function() { $("#mapka #k3hover").animate({opacity:1},350); }, function() { $("#mapka #k3hover").animate({opacity:0},350); });
    $("#mapka .k4 .klink a").hover(function() { $("#mapka #k4hover").animate({opacity:1},350); }, function() { $("#mapka #k4hover").animate({opacity:0},350); });
    $("#mapka .k5 .klink a").hover(function() { $("#mapka #k5hover").animate({opacity:1},350); }, function() { $("#mapka #k5hover").animate({opacity:0},350); });
    $("#mapka .k6 .klink a").hover(function() { $("#mapka #k6hover").animate({opacity:1},350); }, function() { $("#mapka #k6hover").animate({opacity:0},350); });
  }
  
});

function setError(objectId) {
  $("#"+objectId).css("border","1px solid #ff0000");
}

function kontrola() {
  var kont = "0";
  $("#jmeno, #email, #zprava").attr("style","");

  if($("#jmeno").val()=="") { setError("jmeno"); kont = "1"; }
  if($("#email").val()=="") { setError("email"); kont = "1"; }
  if($("#zprava").val()=="") { setError("zprava"); kont = "1"; }

  if(kont=="1") { return false; } else { return true; }    
}
function kontrolaComment() {
  var kont = "0";
  $("#jmenocomment, #emailcomment, #comment").attr("style","");

  if($("#commentjmeno").val()=="") { setError("commentjmeno"); kont = "1"; }
  if($("#commentemail").val()=="") { setError("commentemail"); kont = "1"; }
  if($("#comment").val()=="") { setError("comment"); kont = "1"; }

  if(kont=="1") { return false; } else { return true; }    
}
function changeTab() {
  $("#tabprodej").hide();
  $("#tabpronajem").show();
  $("#searchmenu").css("backgroundPosition","0 -35px");
}
function showForm(url) {
  // PRIDA FORMULAR NA STRANKU
  $("body").append('<div id="JK-overlay"></div><div id="JK-window"><div id="JK-content"></div></div>');
  var overlay = $("#JK-overlay");
  var contentTable = $("#JK-window");
  var content = $("#JK-content");
  
  $.get(url, function(data) {
    content.html(data);
    content.append('<a class="close" href="javascript:hideForm()"><img src="img/close.gif" alt="X"/></a>');
    Cufon.replace('h1');
  });

  if(document.all) {
    if(document.body.scrollHeight > document.body.offsetHeight) { overlay.height(document.body.scrollHeight + 'px'); } else { overlay.height(document.body.offsetHeight + 'px'); }
    if(/msie|MSIE 6/.test(navigator.userAgent)) {
       overlay.css("position","absolute");
       contentTable.css("position","absolute");
       posDialog = window.setInterval(setPos, 15);
    }
    $("select").css("visibility","hidden");
  }
}
function hideForm() {
  // ODSTRANI FORMULAR ZE STRANKY
  $("#JK-overlay").remove();
  $("#JK-window").remove();
  if(document.all) {
    window.clearInterval(posDialog);
    $("select").css("visibility","visible");
  }
}
function setPos() {
  // UPDATUJE POZICI DIALOGU PRI POSOUVANI V IE 6
  var div = $('#JK-window');
  var top = 100;
  if(div!=null) {
     if(screen.height<700) top = 15;
     div.css("top", top + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop) + 'px');
  }
}


window.onbeforeprint = function() { $("#logo img").attr("src", "img/real-estate_ie6.png"); }
window.onafterprint = function() { $("#logo img").attr("src", "img/real-estate.png"); }
