window.addEvent('load', function() {
  if(typeof(DD_belatedPNG) != 'undefined') {
      DD_belatedPNG.fix('.pngIe');      
  } 
});

function addToTW(link) { 
  window.open('http://twitter.com/share?url='+ encodeURIComponent(link),'TWTR','width=620,height=440,menubar,location,status,scrollbars=1');      
  return false;
}

function fbShare(link) {
    window.open('http://www.facebook.com/sharer.php?u='+ encodeURIComponent(link),'FCB','width=620,height=440,menubar,location,status,scrollbars=1');
    return false;
}

var LeftMenu = function(){
	var odkazy;

	this.construct = function(){
		var tthis = this;
		
		//this.skryjMenu();
		odkazy = $$('a[class=kategorie],a[class~=active]');
		
		for(var i=0;i<odkazy.length;i++)
			{
			odkazy[i].addEvent('focus',function(){if(this.blur)this.blur()});
			this.priradFunkci(odkazy[i]);
			}
	}
	
	this.priradFunkci = function(odkaz){
		var tthis = this;
	
		if(odkaz.hasClass('active'))
			{
			odkaz.addEvent('click',function(event){tthis.zbal(event,this);});
			}
		else
			{
			odkaz.addEvent('click',function(event){tthis.rozbal(event,this);});
			}
	}
	
	this.zbalAktivni = function(vyjimka){
    for(var i=0;i<odkazy.length;i++)
			{
			if(!odkazy[i].hasClass(vyjimka) && odkazy[i].hasClass('active'))
			  {
		    this.zbal(false,odkazy[i]);
			  }
      }
  }
	
	this.rozbal = function(event,objekt){
	  this.zbalAktivni('nonClose');
		var tthis = this;
		objekt.addClass('active');
		var submenu = objekt.getProperty('href');
		$$(submenu).setStyle('display','block');
		$$(submenu).slide('hide').slide('in');
		objekt.removeEvents('click');
		objekt.addEvent('click',function(event){tthis.zbal(event,this);});
		event.stopPropagation();
		event.preventDefault();
	}
	
	this.zbal = function(event,objekt){
		var tthis = this;
		objekt.removeClass('active');
		var submenu = objekt.getProperty('href');
		$$(submenu).slide('out');
		$$(submenu).setStyle('display','none');
		objekt.removeEvents('click');
		objekt.addEvent('click',function(event){tthis.rozbal(event,this);});
		if(event!=false)
		  {
      event.stopPropagation();
		  event.preventDefault();
		  }
	}
	
	this.construct();
};


var CheckSearch = function(){
  this.sel1;
  this.sel2;
  this.sel3;
  this.submit;

  this.konstrukt = function(){
    var tthis = this;
    if($('search'))
      {
      this.sel1 = $('search_typ_nemovitosti');
      this.sel2 = $('search_okres');
      this.sel3 = $('search_typ_nabidky');
      this.submit = $('search_submit');
      this.sel1.addEvent('change',function(){tthis.checkSelected();});
      this.checkSelected();
      }
  }
  
  this.checkSelected = function(){
    var porovnani = this.sel1.getSelected().getProperty('value');
    if(porovnani == '') {
      this.sel2.setProperty('disabled','disabled');
      this.sel3.setProperty('disabled','disabled');
      this.submit.setProperty('disabled','disabled');
      if($('dispoWrap')) {
          $('dispoWrap').setStyle('display', 'none');
      }
      if($('dispoDumWrap')) {
          $('dispoDumWrap').setStyle('display', 'none');
      }  
    }
    else {
      this.sel2.removeProperty('disabled');
      this.sel3.removeProperty('disabled');
      this.submit.removeProperty('disabled');
      
      if($('dispoWrap')) {
          if(porovnani == 'byty') {
              $('dispoWrap').setStyle('display', 'block');
          } else {
              $('dispoWrap').setStyle('display', 'none');
          }          
      }
      
      if($('dispoDumWrap')) {
          if(porovnani == 'domy') {
              $('dispoDumWrap').setStyle('display', 'block');
          } else {
              $('dispoDumWrap').setStyle('display', 'none');
          }          
      } 
    }
  }
  
  this.varovani = function(){
    alert('Pro hledání musíte nejdříve zvolit typ nemovitosti.');
  }
  
  
  this.konstrukt();
}











window.addEvent('domready', function() {
    
    $$('a[href^="mailto:"]').each( function(elm){
        elm.set('href', elm.get('href').replace(/\[tecka\]/g ,'.') );
        elm.set('href', elm.get('href').replace(/\[zavinac\]/g ,'@') );
        elm.set('html', elm.get('html').replace(/\[tecka\]/g ,'.') );
        elm.set('html', elm.get('html').replace(/\[zavinac\]/g ,'@') );     
    });        
});

function startup(){
	var leftMenu = new LeftMenu();
	var checkSearch = new CheckSearch();
};
$(document).addEvent('domready',startup);






var _hpScrlr = false;
var _hpSact = false;
var _hpSmax = false;
var _hpScanMove = false;
var _hpSstep = 246;
var _hpSway = 1;
var _hpSshow = 4;
var _hpSduration = 3000;
var _hpSdelay = 4000;

window.addEvent('domready', function(){
  if($('sliderBox') && $('tipBoxSlidder')) {
    hpSprods = $$('#sliderBox .tip');
    if(hpSprods.length > _hpSshow) {
      _hpScrlr = new Fx.Scroll('tipBoxSlidder', { duration: _hpSduration } );
      _hpSact = 0; 
      _hpSmax = $('sliderBox').getSize().x;
      $('sliderBox').addEvents({
                            mouseover: function(){
                              _hpScanMove = false;
                            },
                            mouseout: function(){
                                _hpScanMove = true;
                            }
                        });
      _hpScanMove = true;    
      var nu = hpScroller.delay(500);
    }
  }   	
});



function hpScroller() {    
  if(_hpScrlr) { // zjistime jestli nam existuje pozadovany FX

      if(_hpSdelay < _hpSduration) { // pro pripad ze by nekdo nastavil delay mezi posuny mensi nez dobu trvani 
          _hpSdelay = _hpSduration; 
      }
      
      if(_hpScanMove) {
          
          
      
          _hpSact = _hpSact + (_hpSway * _hpSstep); // spocitame kam mame jit
          if(_hpSact < 0 ) { // osetrime abychom nepodtekli
            _hpSact = 0;
          }
          
                                       
          _hpScrlr.start( _hpSact , 0); // zavolame posun
                
          // a ted dopocitame jestli nemame priste zvysovat nebo snizovat
           
          if( (_hpSact + _hpSshow*_hpSstep) >= (_hpSmax-_hpSstep+1) ) {
            _hpSway = -1;
          }
          
          
          if( (_hpSact) <= 0 ) {
            _hpSact = 0;  
            _hpSway = 1;
          }      
      }
      
      
      var zpozdeni = hpScroller.delay(_hpSdelay);              
  }
}



var img_hpScrlr = false;
var img_hpSact = false;
var img_hpSmax = false;
var img_hpScanMove = false;
var img_hpSstep = 116;
var img_hpSway = 1;
var img_hpSshow = 3;
var img_hpSdelay = 5000;
var img_count = 0;

window.addEvent('domready', function(){
  if($('imgSlider') && $('slideImg')) {
    hpSprods = $$('#imgSlider a img');
   
    if(hpSprods.length > img_hpSshow) {
      img_hpScrlr = new Fx.Scroll('slideImg');
      $('detailNextImg').addEvent('click',
      function(event)
        {
        if(img_count<hpSprods.length-3)
          {
          img_count=img_count+1;
          img_hpScrlr.start(img_hpSstep*img_count,0);
          $('detailPrevImg').addClass('detailOpenPrev');
          }
          
        if(img_count == hpSprods.length-3)
          {
          $('detailNextImg').addClass('detailCloseNext');
          }
        event.stopPropagation();
        event.preventDefault();
      });
      
      $('detailPrevImg').addEvent('click',
      function(event)
        {
        if(img_count > 0)
          {
          img_count=img_count-1;
          img_hpScrlr.start(img_hpSstep*img_count,0);
          $('detailNextImg').removeClass('detailCloseNext');
          }
        if(img_count == 0)
          {
          $('detailPrevImg').removeClass('detailOpenPrev');
          }
        event.stopPropagation();
        event.preventDefault();
      });
      
      img_hpSact = 0; 
      img_hpSmax = $('imgSlider').getSize().x;
      img_hpScanMove = true;    
    }
  }   	
});


function tiskni() {
  print();
  return false;
}

