// metoda pro nacteni novych vysledku naseptavace mest
var last_subject_serach_place = false;
var subject_serach_place_interval = false;
var subject_place_box = -1;

function updateMatched()  {
  $('#search_matched').load('/suggest/place/', {type: $('#search_type').val(), place: $('#search_place').val()});
}

$(document).ready( function() {

  // naseptavac mest
  $("#location").autocomplete('/suggest/place/', { minChars: 0 });
  $("#place_location").autocomplete('/suggest/place/', { minChars: 0 });
  $("#subject_location").autocomplete('/suggest/place/', { minChars: 0 });

  // hover zvyraznei instruktora
  $(".boxItems .item").hover(
    function() { $(this).addClass("highlight"); }, 
    function() { $(this).removeClass("highlight"); }
  );
  
  // hover submit buttonu filtru
  $(".filter .submit").hover(
    function() { $(this).addClass("s_highlight"); }, 
    function() { $(this).removeClass("s_highlight"); }
  );
  
  // tabxbox filtru
  $(".hpFilter").tabs();

  // fancybox
  /*$("a.fancybox").live('click', function() {
    $(this).fancybox({
      'zoomSpeedIn': 300, 
      'zoomSpeedOut': 300, 
      'overlayShow' :true,
    });
    $(this).click();
    return false;
  });*/
  
    $("a.fancybox").fancybox({
      'zoomSpeedIn': 300,
      'zoomSpeedOut': 300,
      'overlayShow' :true
    }); 
        
   $("a.inline-fancy").fancybox({
    'hideOnContentClick': false ,
    'frameWidth': 870,
    'frameHeight': 500
    });        
 });

// Pregenerovani textu ve formularovy prvek
$(function() {        

  if($(".editable_textarea").length) {
    $(".editable_textarea").editable("http://www.example.cz/save.php", { 
      indicator : "<img src='images/indicator.gif'>",
      type   : 'textarea',
      submitdata: { _method: "put" },
      select : true,
      submit : 'Uložit změny',
      cancel : 'Zrušit',
      cssclass : "editable"
    });
  }
  if($(".editable_textile").length) {
    $(".editable_textile").editable("http://www.example.cz/save.php?renderer=textile", { 
      indicator : "<img src='images/indicator.gif'>",
      loadurl   : "http://www.appelsiini.net/projects/jeditable/php/load.php",
      type      : "textarea",
      submit    : "OK",
      cancel    : "Zrušit",
      tooltip   : "Click to edit..."
    });
  }

  if($(".click").length) {
    $(".click").editable("http://www.appelsiini.net/projects/jeditable/php/echo.php", { 
      indicator : "<img src='images/indicator.gif'>",
      tooltip   : "Click to edit...",
      submit : 'OK',
      cancel : 'Zrušit',
      style  : "inherit"
    });
  }
  
  /*if($(".dblclick").length) {
    $(".dblclick").editable("http://www.appelsiini.net/projects/jeditable/php/echo.php", { 
      indicator : "<img src='images/indicator.gif'>",
      tooltip   : "Doubleclick to edit...",
      event     : "dblclick",
      style  : "inherit"
    });
  };

  $(".mouseover").editable("http://www.appelsiini.net/projects/jeditable/php/echo.php", { 
      indicator : "<img src='images/indicator.gif'>",
      tooltip   : "Move mouseover to edit...",
      event     : "mouseover",
      style  : "inherit"
  });
  
  $("#nosuch").editable("http://www.appelsiini.net/projects/jeditable/php/echo.php", { 
      indicator : "<img src='images/indicator.gif'>",
      type   : 'textarea',
      submit : 'OK'
  });

  /*$(".timepicker").editable("", { 
      indicator : "<img src='images/indicator.gif'>",
      type      : 'timepicker',
      submit    : 'OK',
      cancel    : 'Zrušit',
      tooltip   : "Click to edit..."
  });*/
});

// Vymazani inputu
function swip (elementInput, swipFrom, swipTo)  {
  if (elementInput.value == swipFrom) elementInput.value = swipTo;
}

$.fn.simpleAjaxForm = function(targetURL) {
  var target = $(this);
  $(this).find("form").submit(function() {
    if(!targetURL)
      targetURL = $(this).attr('action');

    var data = $(this).serializeArray();
    target.html('loading');

    $.post(
      targetURL,
      data,
      function(response) {
        target.html(response);

        // rekurzivni zavolani na nove nacteny form
        target.simpleAjaxForm(targetURL);
      }
    );

    return false;
  });
}

var active_comment_block = false;

$(document).ready(function() {
  /*
   * Komentare - Nova odpoved
   */
  $('.add_comment_overlay').live('click', function() {
    active_comment_block = {
      'model': $(this).attr('rel').substr(0, $(this).attr('rel').lastIndexOf('_')),
      'scope': $(this).attr('rel').substr($(this).attr('rel').lastIndexOf('_')+1)
    };
    return showOverlayContent(false, $(this).attr('href'), 720, 450);
  });

  /*
   * Komentare - Odpovedet na existujici prispevek
   */
  $('.reply_comment_overlay').live('click', function() {
    var el = $(this).parents('.discussion').find('.add_comment_overlay').attr('rel');
    active_comment_block = {
      'model': el.substr(0, el.lastIndexOf('_')),
      'scope': el.substr(el.lastIndexOf('_')+1)
    };

    return showOverlayContent(false, $(this).attr('href'), 720, 450);
  });                                             
  /*
   * Live search na HP
   */     
  var previousSerialize = new Array();
  function _checkVal() {
    $('.liveSearch').each(function() {
      //alert($(this).attr('id'));
      //alert($(this).attr('id'));
      if($(this).serialize() != previousSerialize[$(this).attr('id')]) {
        // obnoveni poctu nalezenych vysledku
        //alert($(this).attr('action'));
        var parent = $(this);
        if($(this).hasClass('liveSerachForm'))
         var action = $('#'+$(this).attr('id')+'_submit').attr('action');
        else
         var action = $(this).attr('action');

        var data = $(this).serialize()/*.replace(/form_id/, 'form_ad')*/;
        $.post(
          action,
          data,
          function(response) {
            var results = parseInt(response);
            if(isNaN(results))
             results = 0;
  
            parent.find('.results strong').text(results);
          }
        );
        previousSerialize[$(this).attr('id')] = $(this).serialize();
      }
    });
  }
  // v pravidelnych intervalech budeme kontrolovat, zda nedoslo ke zmene formulare

  _checkVal();                                    
  var interval = setInterval(_checkVal, 500);    

  /*
   * Email obfuscate
   */
  $('a.js-email').each(function() {
    $(this).attr('href', $(this).attr('href').replace('(zavinac)', '@'));
    $(this).text($(this).text().replace('(zavinac)', '@'));
  });
  $('span.js-email').each(function() {
    $(this).text($(this).text().replace('(zavinac)', '@'));
  });
  
  $('.clickable-item').click(function(){
    document.location = $(this).find('a.detail').attr('href');
    return false;
   });
   
  $(".clickable-item").hover(function(){ 
    $(this).addClass("clickable-item-hover"); 
  },function(){ 
    $(this).removeClass("clickable-item-hover"); 
  });
   
  $('.article-author').click(function(e){
    document.location = $(this).find('a').attr('href');
    return false;
   });
           /*
    $(function(){
      $('#mainMenu .menu-blog a').click(function(){
      window.open(this.href);
      return false;
      });
    });  */   
});

/*
 * Pruhovane tabulky
 */
$(document).ready(function() {
	$('table.stripped tr').each(function(i) {
		if(!(i%2))
			$(this).addClass('odd');
		});
});

/*
 * Hover tabulky
 */
if($.browser.msie && $.browser.version < 7) {
	$(document).ready(function() {
		$('table.hover tr').hover(function(){$(this).addClass('hover');}, function(){$(this).removeClass('hover');});
	});
}

/*
 * Klikatelne tabulky
 */
$(document).ready(function() {
	$('table.clickable tr').click(function() {
		var a = $(this).find('a');
		if(a.length) {
			document.location = a[0].href;
		}
	});
	$('table.clickable tr a').click(function(event) {
		event.stopPropagation();
	});
});


/* ----------------------------------------------------------------
 * FILE: core.js
 * ----------------------------------------------------------------
 * Created: 30-12-08 (dd-mm-yy)
 * Website: Elevate Web Design
 * ---------------------------------------------------------------
*/
/*
$core = {

    context : false,
    
    getContext: function() {
        if(this.context === false) {
            this.context = $("#content");
        }
        return this.context;
    },
    
    init : function() {        
        $('body').addClass('js');
        
        this.prepareScrollTo();
        if($('#latest-work').length > 0) this.prepareLatestWork();
    },
    
    prepareLatestWork : function() {
        if($.browser.msie && $.browser.version < 7.0) {
            $('#latest-work li .details').remove();
        } else {    
            $('#latest-work li').hover(function() {
                $(this).children('div.details').stop(true, true).fadeIn().removeClass('hide');
            }, function() {
                $(this).children('div.details').stop(true, true).fadeOut().addClass('hide');
            });
        }
    },

    prepareScrollTo : function() {
        $('a[href^="#"]', this.getContext()).click(function(e) {  
            e.preventDefault();
            $('html, body').animate({ 
                scrollTop: $($(this).attr("href")).offset().top 
            }, 500);
        });        
    }    

}

$(function() {
    $core.init();
});
*/



//  Mapa
function map(howMuch, element) {
  if(howMuch < 8) {
    document.getElementById('map_cz').style.backgroundPosition = "0px -"+(howMuch*202)+"px";
  } else {
    document.getElementById('map_cz').style.backgroundPosition = "-324px -"+((howMuch-7)*202)+"px";
  }
 
 if(element) {
  if(howMuch!=0 && subject_place_box!=howMuch){
   $('#hp-places-box').html('<img src="'+BreezyCMS_URL+'public/images/loader.gif" />');
   $.get($(element).attr('href'), function(data){$('#hp-places-box').html(data)});
  }

  subject_place_box = howMuch;
 }
}


// jquery EasySlider na HP
$(document).ready(function(){
  if($('#hp_top_slider').length) {
    $('#hp_top_slider').easySlider({
      prevId: 'easySlider_prev',
      prevText: 'Předchozí',
      nextId: 'easySlider_next',
      nextText: 'Následující'});
  };
});
