function ar(u,c){
	if(window.XMLHttpRequest)
		req=new XMLHttpRequest();
	else if(window.ActiveXObject)
		req=new ActiveXObject("Microsoft.XMLHTTP");
	if(req){
		if(!c){
			var hF=ac(req);
			req.onreadystatechange=hF;
		}
		req.open("GET",u,1);
		req.send(null);
	}
}
function gt(s,t,ct){
	r='';
	s1=s.indexOf(t);
	if(s1>-1)
		r=s.substring(s1+t.length,s.indexOf(ct));
	return r;	
}
function ac(req){
		return function(){
		if(req.readyState==4){
			if(req.status==200){
				ra=req.responseText;
				var id;
				id=gt(ra,'{i}','{/i}');
				h=gt(ra,'{h}','{/h}');
				sc=gt(ra,'{s}','{/s}');
				ea=document.getElementById(id);
				if(ea)
					ea.innerHTML=h;
				if(sc!='')
					eval(sc);
			}
		}
	}
}

function shpop(aId)
{
	document.getElementById('foot_map_pop').style.display = 'block';
}
function hpop()
{
	document.getElementById('foot_map_pop').style.display = 'none';
}

function urlencode(aS){
	aS=aS.replace(/\%/g,'%25');
	aS=aS.replace(/\&/g,'%26');
	aS=aS.replace(/\?/g,'%3F');
	aS=aS.replace(/\=/g,'%3D');
	aS=aS.replace(/\#/g,'%23');
	aS=aS.replace(/\+/g,'%2B');
	return aS;
}

function sr_txt(aEl)
{
	aEl.value = '';
	aEl.style.color = '#FFF';
}

function srch(aSrType)
{
	var sr_el = document.getElementById('sr_'+aSrType);
	if (sr_el)
	{
		var sr_query = sr_el.value;
		if ((sr_query != '') && (sr_query != 'по дума') && (sr_query != 'по тип') && (sr_query != 'по марка'))
		{
			window.location = URL_PREFIX+'/search/'+aSrType+'/1?q='+sr_query;
		}
	}
}

function srch_word_kp(e)
{
	if(window.event) 
	  	k=event.keyCode;
	else if(e.which) 
	  	k=e.which;
	 if(k==13){
	 	srch(1);
	 }
}

function srch_cat_kp(e)
{
	if(window.event) 
	  	k=event.keyCode;
	else if(e.which) 
	  	k=e.which;
	 if(k==13){
	 	srch(2);
	 }
}

function srch_manuf_kp(e)
{
	if(window.event) 
	  	k=event.keyCode;
	else if(e.which) 
	  	k=e.which;
	 if(k==13){
	 	srch(3);
	 }
}

function vote(aSurvey_id)
{
	var cur_checked = -1;
	var els_radio = document.getElementsByName('survey');
	var cnt_radio = els_radio.length;
	for (var i=0;i<cnt_radio;i++)
	{
		if (els_radio[i].checked)
		{
			cur_checked = els_radio[i].value;
			break;
		}
	}
	
	if (cur_checked != -1)
	{
		ar(URL_PREFIX+'/survey_vote/'+aSurvey_id+'/'+cur_checked);
	}
	else
	{
		alert('Моля, посочете вашия отговор.');
	}
}

$(function () {
        $('.bubbleInfo').each(function () {
        	
            var distance = 10;
            var time = 250;
            var hideDelay = 500;

            var hideDelayTimer = null;

            var beingShown = false;
            var shown = false;
            var trigger = $('.trigger', this);
            
	            var info = $('.popup', this).css('opacity', 0);
	
	            $([trigger.get(0), info.get(0)]).mouseover(function () {
	                if (hideDelayTimer) clearTimeout(hideDelayTimer);
	                if (beingShown || shown) {
	                    // don't trigger the animation again
	                    return;
	                } else {
	                    // reset position of info box
	                    beingShown = true;
	                    
	                    var el_id = info.attr('id');
	                    var new_id = el_id.substr(4)
						var el_pop = document.getElementById('pop_cont_'+new_id);
						
	                    info.css({
	                        bottom: 40,
	                        left: -64 + Math.round(el_pop.clientWidth/2),
	                        display: 'block'
	                    }).animate({
	                        bottom: '-=' + distance + 'px',
	                        opacity: 1
	                    }, time, 'swing', function() {
	                        beingShown = false;
	                        shown = true;
	                    });
	                    
	                }
	
	                return false;
	            }).mouseout(function () {
	                if (hideDelayTimer) clearTimeout(hideDelayTimer);
	                hideDelayTimer = setTimeout(function () {
	                    hideDelayTimer = null;
	                    info.animate({
	                        bottom: '-=' + distance + 'px',
	                        opacity: 0
	                    }, time, 'swing', function () {
	                        shown = false;
	                        info.css('display', 'none');
	                    });
	
	                }, hideDelay);
	
	                return false;
	            });
	        
        });
    });

$(function() {
	$("ul.htl_menu li a.hov").css("opacity","0");
});

 $(document).ready(function() {   
    $("ul.htl_menu li a.hov").mouseover(function() {   
        $(this).animate( { opacity:"1" }, { queue:false, duration:400 } );   
    }).mouseout(function() {   
        $(this).animate( { opacity:"0" }, { queue:true, duration:400 } )   
    });   
         
});      
