var map=null;
var geoXml=null;
var DATAcount=[[],[],[]];

function loadGoogleMap(url) 
{
  var firstzoom=true;
  if (GBrowserIsCompatible()) 
  {
    $('#map').removeClass('dN');
    map = new GMap2(document.getElementById('map'));
    map.addControl(new GSmallMapControl());
    map.addControl(new GMapTypeControl());
    /*map.enableScrollWheelZoom();*/
    geoXml = new GGeoXml(url);
    map.addOverlay(geoXml);
	  var center = new GLatLng(48.794561,19.400024);
	  map.setCenter(center , 7);
	  geoXml.gotoDefaultViewport(map);
	  GEvent.addListener(map, "zoomend", function(){
      if (firstzoom) if (map.getZoom()>12) map.setCenter(map.getCenter(),12);
      firstzoom=false;
    });
  }
}	
function reloadGoogleMap(url) 
{
  firstzoom=true;
  if (map==null)
    loadGoogleMap(url);
  else 
  {
    $('#map').removeClass('dN');
    geoXml = new GGeoXml(url);
    map.addOverlay(geoXml);
	  center = new GLatLng(48.794561,19.400024);
	  map.setCenter(center , 7);
	  geoXml.gotoDefaultViewport(map);
	  GEvent.addListener(map, "zoomend", function(){
      if (firstzoom) if (map.getZoom()>12) map.setCenter(map.getCenter(),12);
      firstzoom=false;
    });
  }
}

var FORM;
var isRequest=false;
var countRequests=0;

$(function(){
  FORM=$('#search_form');
  /*FORM.submit(function(e){$('body').addClass('waiting');$.post('/estates.php',FORM.serialize(),function(html){$('#estatelist').html(html);$('#estatelistform,#estatelist').removeClass('dN');InitEstateList();$('body').removeClass('waiting');});return false;});*/
});

function sendCountRequest(){
	if (isRequest)
		countRequests++;
	else{
		isRequest=true;
		var x=FORM.serialize();
		countRequests=0;
		$('#fCounts').html('?');
		/*$.post('/lists/count.php',x,function(data){$('#fCounts').html(data);if(data!='')$('#search_form .hint').show();isRequest=false;if(countRequests>0){sendCountRequest()}});*/
		$.post('/lists/count.php',x,function(data){
      $('#fCounts').html(data.P);
      $('#search_form .hint').show();
      $('#search_form div.list:not(#fDU_list) .count').parent().hide();/*html('(0)');*/
      DATAcount=[[],[],[]];
      for(var i=0;i<data.p.length;i++){
        $('#'+data.p[i][0]).html(' ('+data.p[i][1]+')').parent().show();
        try{
        DATAcount[data.p[i][2]].push([data.p[i][3],data.p[i][1]]);
        }catch(err){
        /*$('body').append('#'+data.p[i][0]);*/
        }
      }
      isRequest=false;if(countRequests>0){sendCountRequest()}},'json');
	}
}

function numberFormat(nStr,nDec){
	var dec=1;
	for (var i=0;i<=nDec;i++) dec*=10;
	nStr=Math.round(nStr*dec)/dec;
	nStr += '';
	var x = nStr.split('.');
	var x1 = x[0];
	var x2 = '';
	if (nDec>0){
		x2+=',';
		var j=x.length>1?x[1].length:0;
		for (var i=j;i<nDec;i++) x2+='0';
		if (x.length>1) x2+=x[1];
	}
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1))
		x1 = x1.replace(rgx, '$1' + ' ' + '$2');
	return x1 + x2;
}

function getValueFromItem(el){
  return $(el).attr('value');
}

function SetDescC(n,c,x){
	var s='';
	if (c && $('#'+n).attr('checked'))
		s=c;
	if (!c)
		s=$('#'+n).val();
	if (x && s!='')
		s=' '+x+': '+s;
	if (s!='')
		s=' &raquo; '+s;
	$('#'+n+'_desc').html(s);
}
function SetDesc(o){
	var n=o.data_name;
	var x=$('li.checked',o.data_list);
	var s='';
	if (o.template){
	   if (o.data_val.val()!=0)
	     s=$(x[0]).html();
  }else
  	for (var i=0;i<x.length;i++)
  		if ($(x[i]).children('input').val()!=0){
  			s+=(s==''?'':'; ')+$(x[i]).children('.value').html();
  			if (o.groups)
  				s+='('+$(x[i]).parent().parent().children('.value').html()+')';
  		}
	o.data_text.html(s==''?o.translate:s);
	if (s!=''){
		if (o.desc && o.desc[0] && o.desc[0]!='') 
			s=' '+o.desc[0]+' '+s;
		if (o.desc && o.desc[1] && o.desc[1]!=''){
			if ((o.minvalue && $('#'+o.minvalue+'_desc').html()=='')||(!o.minvalue && !o.maxvalue))
				s=' &raquo; '+o.desc[1]+': '+s;
			else
				if(o.maxvalue)
					s=' &raquo; '+o.desc[1]+': '+s;
		}
		else
			s=' &raquo; '+s;
	}
	o.data_desc.html(s);
	/*$('#'+n+'_desc .count').remove();
	$('#'+n+'_desc ul,#'+n+'_desc input,#'+n+'_desc img').remove();*/
}

function l_dropdown(e,o){
	var t=o.treeview;
	var m=o.multiselect;
	e=$(e);
	p=e.parent()/*.parent()*/;
	if (!e.hasClass('noout')){
		if (e.hasClass('out')){
			e.removeClass('out');
			p.children('ul').hide();
		}
		else{
			RefreshZoznam(p,o);
			e.addClass('out');
			p.children('ul').show();
			SetDesc(o);
			var DataCount=DATAcount[o.dataIndex];
			for (var i=0;i<DataCount.length;i++){
			 $('#'+o.data_name+'_c_'+DataCount[i][0]).html(' ('+DataCount[i][1]+')').parent().show();
			}
		}
	}
	var l=o.data_list;
	l.css('width','auto');
	var w=l.children('ul').innerWidth()+32;
	if (w<o.data_text.parent().width())w=o.data_text.parent().width();
	l.css('width',w+'px');
}
function l_checkbox(e,o){
	var m=o.multiselect;
	var n=o.data_name;
	var x,d,p;
	e=$(e);
	if (!m){
	 if(o.treeview){
  		$('li.check',o.data_list).removeClass('checked');
  		$('input',o.data_list).removeAttr('checked');
  		e.addClass('checked');
  		e.children('input').attr('checked','checked');
  		o.data_text.html(e.html());
  		o.data_list.data('value',e.children('input').val());
	 }else{
  		$('li.check.checked',o.data_list).removeClass('checked');
			e.addClass('checked');
			o.data_text.html(e.html());
			o.data_val.val(getValueFromItem(e));
  		if (x=o.data_list.data('minvalue')) {$('#'+x+'_list').trigger('valuechange');}
  		if (x=o.data_list.data('maxvalue')) {$('#'+x+'_list').trigger('valuechange');}
   }
		o.data_list.hide();
	}
	else{
		im=e.children('img.check');
		p=e/*.parent()*/;
		if (e.hasClass('checked')){
			RefreshZoznam(p,o);
			e.removeClass('checked');
			im.removeClass('checked');
			e.children('input').removeAttr('checked');
			/*ak su nejake poddata a je vytvoreny potomok kt je zafajknuty tak daj childchecked*/
			d=getData(DATA[o.dataIndex],p);x=d[0];d=d[1];
			if (d && (d.length>0) && ($('ul li.checked',p).length>0))
				im.addClass('childchecked');
			else
				im.removeClass('childchecked');
			p.parent().parent()/*.children('a')*/.children('img.check').trigger('parentuncheck');

		}
		else
			if ((im.hasClass('childchecked'))&&(!o.deselectparent))
			{
				im.removeClass('childchecked');
				$('ul img.check',p).trigger('uncheck');
				p.parent().parent().children('img.check').trigger('parentuncheck');
			}
			else
			{
				e.addClass('checked');
				im.addClass('checked');
				e.children('input').attr('checked','checked');

/*				RefreshZoznam(p,o);*/
        if (!o.deselectparent)
				  $('ul img.check',p).trigger('check');
				if (o.deselectparent)
				  p.parent().parent().children('img.check').trigger('parentuncheck');
				else
				  p.parent().parent().children('img.check').trigger('childcheck');

				if (o.oncheck_check) {$('#'+o.oncheck_check).attr('checked','checked');}
			}
	}
	SetDesc(o);
	sendCountRequest();
	if (n=='fRM') refreshDU();
}

function refreshDU(){
  if(comboLists[9]){
    var kat='';
    $('#fRM_list li.checked > input').each(function(i,ei){
      kat+=(kat==''?'':',')+$(ei).val();
    });
    
    $.post('/lists/du.php',FORM.serialize()+'&KAT='+kat,function(data){
      DATA[6]=data;
      $('#fDU_list ul').html('');
      comboLists[9].trigger('refreshList');
      sendCountRequest()
    },'json')
  }
}

function refreshLists(u,x,onlydata){var u1='';if(x)for(var i=0;i<x.length;i++)u1+='&data'+x[i]+'=true';$.getJSON(u+'?'+u1,function(data){
  if(!DATA)DATA=new Array(7);for(var i in data){DATA[i]=data[i];}
  if (!onlydata){refreshAllLists()}refreshDU();sendCountRequest();
})};
function refreshAllLists(){
  if(comboLists.length>0)for(var i=0;i<comboLists.length;i++){
    /*comboLists[i].refreshList();*/comboLists[i].trigger('refreshList');
    
}}
function refreshList(o){
	var n=o.data_name;
	var m=o.multiselect;
	var t=o.treeview;
	var v=o.layers;
	var l=o.data_list;

  if(o.template){
		RefreshZoznam(l,o,1,[0]);
  }else
    if(DATA){
		  var d=DATA[o.dataIndex];
		  RefreshZoznam(l,o,0,d);
	  } 
};
function getData(d,p){
	var x=new Array();
	var id;
	var ok;
	do{
		id=p.data('id');
		if (id) x.unshift([p,id]);
		else break;
	}while (p=p.parent().parent());
	if (x.length>0){ 
    for(var ii=0;ii<x.length;ii++){
  		ok=false;
  		for(var jj=0;jj<d.length;jj++){
  			if (d[jj][0]==x[ii][1]){
  				d=d[jj][4];
  				ok=true;
  				break
  			}
  		}
  		if (!ok) break
  	}
  	if (ii>=x.length) ii--;
	}else
		ii=-1;
	return [ii+1,d];
}
function VytvorItem(d,o,x,checked){
	x=1*x;
	var m=o.multiselect;
	var t=o.treeview;
	var n=o.data_name;
	var v=o.layers;
	var g=o.groups;
	var l=o.data_list;
	
	var ialign=(o.itemsalign?' style="text-align:'+o.itemsalign+'"':'');
	var value;
	var c='';
	var s='';
	var elz=(d[4] && d[4].length>0);
	var aclass=(m && t?(elz?'drop':''):'check');

	if (o.hidecount1 && o.hidecount2)
		c='';
	else{
		if (!o.hidecount1 && !o.hidecount2)
			c=' ('+d[2]+'/'+d[1]+')';
		else
			if (!o.hidecount1)
				c=' ('+d[1]+')';
			else
				c=' ('+d[2]+')';
		
  	if(g){
      if(x==0)s+='<img src="/i/_.gif" class="drop'+(elz?'':' noout')+'" />';
  	  if(x>0)s+='<img src="/i/_.gif" class="check'+(checked?' checked':'')+'" />';
  	  s='<li id="'+n+'_item_'+d[0]+'"'+ialign+' class="'+aclass+(checked?' checked':'')+'">'+s;
    }
    else{
      if(t)s+='<img src="/i/_.gif" class="drop'+(elz?'':' noout')+'" />';
  	  if(m)s+='<img src="/i/_.gif" class="check'+(checked?' checked':'')+'" />';
      c=' ('+0+')';
      styl=' style="display:none"';
  	  s='<li id="'+n+'_item_'+d[0]+'"'+ialign+' class="'+aclass+(checked?' checked':'')+'"'+styl+'>'+s;
    }    
    if (!g || (g && x>0))c='<span class="count" id="'+n+'_c_'+d[0]+'">'+c+'</span>';else c='';
	}
	
	/*if (o.valuepattern && d[0]>0){
		var VALUE=d[3];
		var subValue;
		value=o.valuepattern;
		var values=value.split('[');
		value=values[0];
		for (var j=1;j<values.length;j++){
			values[j]=values[j].split(']');
			if (values[j].length>1){
				eval('subValue='+values[j][0]+';');
				value+=subValue+values[j][1];
			}
			else
				value+=subValue+values[j][0];
		}
	}
	else*/
		value=d[3];

	s+='<input type="checkbox" id="'+n+'_input_'+d[0]+'" value="'+d[0]+'" name="'+n+'_chck'+(v?'['+x+']':'')+'[]"'+(checked?' checked="checked"':'')+' /><span class="value">'+value+'</span>'+c+'</li>';
	return s;	
}
function RefreshZoznam(elx,o,x,d,nodesc){
  if(x==='') x=false;
  if(d=='') d=false;
	var t=o.treeview;
	var m=o.multiselect;
	var n=o.data_name;
	var v=o.layers;
	var l=o.data_list;
	var dd=o.dropdown?o.dropdown:0;
	
  if (!d || x==false) {d=getData(DATA[o.dataIndex],elx);x=1*d[0];d=d[1];}

	var minvalue;
	var maxvalue;
	
	var e=null;
	var doplnit;
	var s='';
	var pomNode;
	if(d && d.length>0){
		if (elx.children('ul').length==0) if(x==0)elx.html('<ul></ul>');else elx.append('<ul></ul>');
		pomNode=elx.children('ul');
		if(t||m){
		  var d4;
    	/*if (o.minvalue){ minvalue=$('#'+o.minvalue+'_list').data('value');}
    	if (o.maxvalue){ maxvalue=$('#'+o.maxvalue+'_list').data('value');}*/
  		for (var i=0;i<d.length;i++) /*if((!o.minvalue && !o.maxvalue)||(o.minvalue && (minvalue==0 || d[i][0]==0 || d[i][0]>=minvalue))||(o.maxvalue && (maxvalue==0 || d[i][0]==0 || d[i][0]<=maxvalue)))*/{
        /*preddefinovanie hodnoty pri refreshi zoznamu*/
  			if ($('#'+n+'_item_'+d[i][0]).length==0)
  				doplnit=true;
  			else {
  				doplnit=false;
  				e=$('#'+n+'_item_'+d[i][0]);
  			}
  
  			if (doplnit){
  				s=VytvorItem(d[i],o,x);
  				if (e)
  					e.after(s);
  				else
  					pomNode.prepend(s);
  				e=$('#'+n+'_item_'+d[i][0]);
  				e.data('id',d[i][0]);
  				d4=d[i][4];
  				if ((x<dd)&& d4 &&(d4.length>0)) {
            RefreshZoznam(e,o,x+1,d4,true)/*l.dropDown($('img.drop',e));*/
            e.children('.drop').addClass('out');
			      e.children('ul').show();
          }
  			}
  			/*vypisanie prednastavenej hodnoty do textoveho pola*/
  			/*if (!firsttime && !m && (isvalue!='')) $('#'+n+'_list').parent().children('cite').children('span').html(value);*/
  		}
  		/*else
  			if ($('#'+n+'_item_'+d[i][0]).length>0)
  				$('#'+n+'_item_'+d[i][0]).remove();*/
  		if (elx.children('li.checked').length>0) 
  			$('img.check',elx).trigger('check');
  		if (x==0 && l.data('values') &&(!nodesc))
  			SetValues(d,o);
		}else{
    	if (o.minvalue)minvalue=$('#'+o.minvalue+'_val').val();
    	if (o.maxvalue)maxvalue=$('#'+o.maxvalue+'_val').val();
      
      if(o.minvalue||o.maxvalue){
        var d0;
        $('li',pomNode).each(function(item,ei){
          d0=getValueFromItem($(ei));
          if((o.minvalue && (minvalue==0 || d0==0 || d0>=minvalue))||(o.maxvalue && (maxvalue==0 || d0==0 || d0<=maxvalue)))
            $(ei).show();
          else
            $(ei).hide();
        });
      }else{
    		var str='';
    		var checkItems=$('li.checked',l);
    		
      	var value,dd,d0,d3;
      	var c='';
      	var s='';
  
        for (var i=0;i<d.length;i++){
          d0=d[i][0];
          d3=d[i][3];
          if((!o.minvalue && !o.maxvalue)||(o.minvalue && (minvalue==0 || d0==0 || d0>=minvalue))||(o.maxvalue && (maxvalue==0 || d0==0 || d0<=maxvalue))){
          	if (o.hidecount1 && o.hidecount2)
          		c='';
          	else{
          		if (!o.hidecount1 && !o.hidecount2)
          			c=' ('+d[i][2]+'/'+d[i][1]+')';
          		else
          			if (!o.hidecount1)
          				c=' ('+d[i][1]+')';
          			else
          				c=' ('+d[i][2]+')';
          	  c='<span class="count" id="'+n+'_c_'+d[i][0]+'">'+c+'</span>';
          	}
          	
          	if (o.valuepattern && d0>0){
          		var VALUE=d3;
          		var subValue;
          		value=o.valuepattern;
          		var values=value.split('[');
          		value=values[0];
          		for (var j=1;j<values.length;j++){
          			values[j]=values[j].split(']');
          			if (values[j].length>1){
          				eval('subValue='+values[j][0]+';');
          				value+=subValue+values[j][1];
          			}
          			else
          				value+=subValue+values[j][0];
          		}
          	}
          	else
          		value=d3;
          	pomNode.append('<li class="check" value="'+d0+'"><span class="value">'+value+'</span>'+c+'</li>');
          }
          }
      	/*if (checkItems.length>0){
  				e=$(checkItems[0]);
  				e.addClass('checked');
  				o.data_text.html(e.html());
  				$('#'+n+'_val').val(getValueFromItem(e));
   			}else*/{
        	var v=l.data('values');
        	if (v=='')v=false;
        	if (v){
        	   $('li',o.data_list).removeClass('checked');
    				e=$('li[value='+v[0]+']',o.data_list);
    				e.addClass('checked');
    				o.data_text.html(e.html());
    				o.data_val.val(v[0]);
    				/*l.data('values',false);*/
     			}
      }
      }
    }
	}
	else
		elx.remove('ul');

	if(!nodesc) SetDesc(o);
}

function SetValues(d,o){

	function setValues(d,v,parents){
		var k,s,p;
		if (!parents)parents=new Array();
		if (d)
		for (var i=0;i<d.length;i++){
			parents.push(d[i]);
			for (var j=0;j<v.length;j++){
				if (d[i][0]==v[j]){
					for (k=0;k<parents.length;k++)
						if ($('#'+n+'_item_'+parents[k][0]).length==0){
							if (k==0)
								p=$('#'+n+'_list');
							else
								p=$('#'+n+'_item_'+parents[k-1][0]);
							s=VytvorItem(parents[k],o,k,(k==parents.length-1));
							if (p.children('ul').length==0) 
								p.append('<ul>'+s+'</ul>');
							else
								p.children('ul').append(s);
							$('#'+n+'_item_'+parents[k][0]).data('id',parents[k][0]);
							if (k==parents.length-1)
								p.children('a').children('img.check').trigger('childcheck');
					}
					v.slice(j,1);
				}
			}
			v=setValues(d[i][4],v,parents);
			parents.pop();
		}
		return v;
	}
		
	var l=o.data_list;
	var n=o.data_name;
	var v=l.data('values');
	if (v=='')v=false;
	if (v){
		for (var j=0;j<v.length;j++)
			if ($('#'+o.data_name+'_item_'+v[j]).length>0){
				if (o.multiselect){
					$('#'+o.data_name+'_item_'+v[j]+' > img.check').trigger('check');
				} else {
					e=$('#'+o.data_name+'_item_'+v[j]);
					$('li.check',o.data_list).removeClass('checked');
					$('input',o.data_list).removeAttr('checked');
					e.addClass('checked');
					e.children('input').attr('checked','checked');
					o.data_text.html(e.html());
  				/*$('.count',o.data_text).remove();
      		$('ul,input,img',o.data_text).remove();*/
					o.data_list.data('value',e.children('input').val());
					v=null;
					break;
				}				
				v.slice(j,1);
			}
		if (v && v.length>0)
			v=setValues(d,v);
		l.data('values',null);
	}
}
function hideList(n){$('#'+n+'_list').hide()};
function hideAllLists(){for (var i=0;i<comboLists.length;i++) comboLists[i].hide()};
function createCombo(n,o){/*n-nazov,o-options*/
	var tmout=null;
	var element=$('#'+n);
	if(!o.treeview) o.treeview=false;
	if(!o.multiselect) o.multiselect=false;
	{
  	$('#FORM_desc').append('<span id="'+n+'_desc"></span>');
  	
  	element.hide();
  	element.wrap('<div class="combobox-blok"></div>');
  	element.after('<div class="combobox"><cite><span>'+$('#'+n+' option[value=0]').text()+'</span></cite><div id="'+n+'_list" class="list">&nbsp;</div></div>');
  	o.translate=$('#'+n+' option[value=0]').text();
  	if((!o.multiselect)&&(!o.treeview)){
      element.after('<input type="hidden" id="'+n+'_val" name="'+n+'_chck[0]" value="'+(o.values?o.values[0]:element.val())+'" />');
      o.data_val=$('#'+n+'_val');
    }
    var blok=element.parent();
  	var textbox=blok.children('.combobox').children('cite');
  	var list=$('#'+n+'_list');
  	o.data_name=n;
  	o.data_list=list;
  	o.data_blok=blok;
  	o.data_text=textbox.children('span');
  	o.data_desc=$('#'+n+'_desc');
  	
    if(o.template){
      list.html('<ul>'+$('#'+o.template).html())+'</ul>';
      if (o.values){
    		o.data_text.html($('li[value='+o.values[0]+']',o.data_list).addClass('checked').html());
    		o.values=false;
     	}
    }
  	list.hide();
  	if (!o.multiselect && o.values) list.data('value',o.values[0]);
  	if (o.width) textbox.children('span').css('width',o.width+'px');
  	if (o.zindex) blok.css('z-index',o.zindex);
  	var width=parseInt(textbox.children('span').css('width'))+parseInt(textbox.css('padding-right'))-parseInt(list.css('padding-right'))+parseInt(textbox.css('padding-left'))-parseInt(list.css('padding-left'));
  	width+='px';
  
  	textbox.click(function(){
      if(list.css('display')=='none'){
        hideAllLists();
        list.show();
        if(list.children('ul').length>0){
          list.css('width','auto');
          var w=list.children('ul').innerWidth()+32;
          if (w<textbox.parent().width())w=textbox.parent().width();
          list.css('width',w+'px')
        }else 
          list.css('width',textbox.parent().width());
        if ((n=='fLC')&&(LOC!=null)){
          $('#fLC_input_'+LOC[0]).parent().children('img.drop').click();
          $('#fLC_input_'+LOC[1]).parent().children('img.drop').click();
          LOC=null;
        }
      }else 
        hideAllLists();
    });
  	blok.mouseover(function(){clearTimeout(tmout)});
  	blok.mouseout(function(){tmout=setTimeout('hideList(\''+n+'\')',1000)});
  
  	list.data('values',o.values);
  
  	list.refreshList=function(){refreshList(o)};
  	list.dropDown=function(el){l_dropdown(el,o)};
  
  	comboLists.push(list);
  
  	if (o.minvalue) list.data('minvalue',o.minvalue);
  	if (o.maxvalue) list.data('maxvalue',o.maxvalue);
  	list.bind('valuechange',function(e){list.refreshList();});
  	list.bind('refreshList',function(e){list.refreshList();});
  
  	/*prednastavenie rutin udalosti*/
  	/**/
  	if (o.treeview){
  		$('img.drop',o.data_list).live('click',function(e){
  			l_dropdown($(this),o);
  			o.data_list.scrollTop($(this).parent().position().top+o.data_list.scrollTop());
  			/*alert($(this).offset().top+','+$(this).position().top+','+o.data_list.scrollTop());*/
        return false;
  		});
  		/*$('li.drop',o.data_list).live('click',function(e){
  			l_dropdown($(this).children('img.drop'),o);
  		});*/
  		$('li',o.data_list).live('click',function(e){
  		  if ($(this).children('img.drop').hasClass('noout')){
    			if ($(this).children('img.check').length>0) 
            l_checkbox($(this),o);
        }else
          $(this).children('img.drop').click();
  		});
  	}
  	else
  		$('li.check',o.data_list).live('click',function(e){
  			l_checkbox($(this),o);
  		});
  	
  	if (o.multiselect){
  		$('img.check',o.data_list).live('click',function(e){
  			l_checkbox($(this).parent(),o);return false;
  		});
  	
  		$('img.check',o.data_list).live('check',function(e){
  			var t=$(this);
  			var p=t.parent();
  			t.addClass('checked');
  			p.addClass('checked');
  			p.children('input').attr('checked','checked');
  		});
  	
  		$('img.check',o.data_list).live('uncheck',function(e){
  			var t=$(this);
  			var p=t.parent();
  			t.removeClass('checked');
  			t.removeClass('childchecked');
  			p.removeClass('checked');
  			p.children('input').removeAttr('checked');
  		});
  	
  		$('img.check',o.data_list).live('parentuncheck',function(e){
  			var t=$(this);
  			var p=t.parent();
  			var p1=p.parent().parent();
  			t.removeClass('checked');
  			p.removeClass('checked');
  			p.children('input').removeAttr('checked');
  			if ($('ul li.checked',p1).length>0)
  				t.addClass('childchecked');
  			else
  				t.removeClass('childchecked');
  			p1/*.parent().parent().children('a')*/.children('img.check').trigger('parentuncheck');
  		});
  	
  		$('img.check',o.data_list).live('childcheck',function(e){
  			var t=$(this);
  			var p=t.parent();
  			var p1=p.parent().parent();
  			if ($('ul li.checked',p1).length>0)
  				t.addClass('childchecked');
  			else
  				t.removeClass('childchecked');
  			p1/*.parent().parent().children('a')*/.children('img.check').trigger('childcheck');
  		});
  	}
  		
  	/*koniec rutin*/
  }
};
