$(document).ready(function() {
	//console.log();

	$('UL.members LI.item').each(function(i,a){
		$('H2 A', a).click(function(){
			$(a).toggleClass('closed');
			return false;
		});
	});
	$('UL.members LI.item').addClass('closed');
	
	//swfobject.embedSWF("img/header.swf", "header", "940", "139", "9.0.0", "js/expressinstall.swf",{},{wmode: 'transparent', menu: 'false', quality: 'best'},{});
	$("a").click(function() {
		if ( $(this).attr('rel') == 'openAll' )
		{
			$('UL.members LI.item').removeClass('closed');
		}
		else if ( $(this).attr('rel') == 'closeAll' )
		{
			$('UL.members LI.item').addClass('closed');
		}
	});
	
 	$('#search_formX').submit(function() { 
		//if (parseInt($('#compsearch').val(), 10))
		
		$('#found').text("Leiti 0 firmat");
		
		//KUI FILTRISSE LISADA KA TEGEVUSALAD
		$.get(_var.sSearchURL+'/&query='+$('#compsearch').val()+'&lang='+_var.sLang+'&act='+$('#category').val(),function(responce){  
		
				//KUI FILTRIS ON AINULT NIME OTSING
				//$.get(_var.sSearchURL+'/&query='+$('#compsearch').val()+'&lang='+_var.sLang,function(responce){
				
				//console.log();
				//console.log();
				$('.item').addClass('closed');
				var arrResponce=eval(responce);
				var countfirms;
				countfirms = 0;
					for (var i=0;i<arrResponce.length;i++){
						$('#result_'+arrResponce[i]).removeClass('closed');
						countfirms = countfirms + 1;
					}
				
				if(countfirms ==1)
				{
					$('#found').text("Leiti 1 firma");		
				}else{
					$('#found').text("Leiti " + countfirms + " firmat");
				}
			}
		);
		
		
		//document.getElementById('found').innerHTML = "Leiti " + countfirms + "firmat";
		//document.getElementById('found').innerHTML = 'Leiti 10 firmat';

		/*
		$('UL.members LI.item').each(function(i,a){
			
			if ($('#compsearch').val()=='firma')
			{
				alert('string ok '+$('#compsearch').val()+' sisu '+$('H2 A').text());
				$(a).removeClass('closed');
			}else {
				alert('string pole ok '+$('#compsearch').val()+' sisu '+$(this).children().text());
				$(a).addClass('closed');
				return false;
			};
		});
		*/
		
		return false;
	});
});