$(document).ready(function(){
    //$("#paieska").focus().autocomplete("listas.php", {max:5, width:330});
    $('.down-list').width($('.dropdown-menu').width()-2);

    $('.dropdown-menu').hover(
      function () {
        $('.menu-first', this).addClass('slide-down'); 
        $('.down-list', this).slideDown(100);
      }, 
      function () {
        obj = this;
        $('.down-list', this).slideUp(100, function(){ $('.menu-first', obj).removeClass('slide-down'); });
      }
    );
    
    /*$('.trinti').click(function(e){
       var baba=$(this).attr("href");
       var kas=window.location + baba;
       window.location(kas); 
       return false;
       e.preventDefault();
    });*/
    
    $(".input1").change(function() {                  
        $('.keyc').val(this.value);                  
    });
});

function empty (mixed_var) { 
    var key;
    mixed_var = mixed_var.replace(/^\s*|\s*$/g,'');    
    if (mixed_var === "" ||
        mixed_var === 0 ||
        mixed_var === "0" ||
        mixed_var === null ||        mixed_var === false ||
        typeof mixed_var === 'undefined'
    ){
        return true;
    } 
    if (typeof mixed_var == 'object') {
        for (key in mixed_var) {
            return false;
        }        return true;
    }
 
    return false;
}



function suggest(inputString){
		if(inputString.length == 0) {
			$('#suggestions').fadeOut();
		} else { 
		$('#paieska').addClass('load');
			$.post(dir+"/autosuggest.php", {queryString: ""+inputString+""}, function(data){
				if(data.length > 3) {
					$('#suggestions').fadeIn();
					$('#suggestionsList').html(data);
					$('#paieska').removeClass('load');
				}else{
				    $('#suggestions').fadeOut();
				}
			});
		}
	}

	function pildom(thisValue) {
		$('#paieska').val(thisValue);
		setTimeout("$('#suggestions').fadeOut();", 600);
		document.getElementById('paieska').blur();
		setTimeout("document.gpaieska.submit();", 600);
	}

function keitimas(kur)
{
  if (kur != 2)
    $("#paieska2").focus().autocomplete("listas2.php", {max:5, width:330});
  else
    $("#paieska2").focus().autocomplete("listas.php", {max:5, width:330});
}

function makeSublist(parent,child,isSubselectOptional,childVal)
{
	$("body").append("<select style='display:none' id='"+parent+child+"'></select>");
	$('#'+parent+child).html($("#"+child+" option"));
	
		var parentValue = $('#'+parent).attr('value');
		$('#'+child).html($("#"+parent+child+" .sub_"+parentValue).clone());
	
	childVal = (typeof childVal == "undefined")? "" : childVal ;
	$("#"+child+' option[@value="'+ childVal +'"]').attr('selected','selected');
	
	$('#'+parent).change( 
		function()
		{
			var parentValue = $('#'+parent).attr('value');
			$('#'+child).html($("#"+parent+child+" .sub_"+parentValue).clone());
			if(isSubselectOptional) $('#'+child).prepend("<option value='none'> -- Select -- </option>");
			$('#'+child).trigger("change");
                        $('#'+child).focus();
		}
	);
}

var numas=new Array();
var stop =new Array();
var hovered = new Array();

function stopas(id)
{
    stop[id] = -1;
}

function keiciam(id,laikas)
{
    stop[id]++;
    numas[id]++;
    
    $.get(dir + "hover.php?r="+id+"&f="+numas[id],
    function(data){
        kas = data.split("|");
        
        if(stop[id]>0)
        {
                /*laikas=1500;
                if(numas[id]==1) laikas=100;
                else laikas==1500;
                if(console) console.log(data+" "+laikas+" "+numas[id]+" "+stopas[id]);
                */
                //setTimeout("document.getElementById('thumbas"+id+"').src = '"+ kas[1] +"'; keiciam("+id+");", laikas);
                setTimeout("document.getElementById('thumbas"+id+"').src = '"+ kas[1] +"'; keiciam("+id+");", 1500);
        }
        
        if(kas[2] == 1) numas[id] = 0;
    });	  	 
}

function emotion(ka, kur)
{
    document.getElementById(kur).value = document.getElementById(kur).value + ka;
}
