
$j = $; //jQuery.noConflict();

$(function(){
    $('#Searchfield').keydown(function(e){
        if (e.keyCode == 13) {
            document.forms["form_search"].submit();
            return false;
        }
    });
});

$j(document).ready(function(){
	// disable old events

	$j('li.Level0Item > ol').hide();

	$j('li.Level0Item').mouseover(function(){
		$j('> ol', this).slideDown();
	}).mouseout(function(){
		$j('> ol', this).slideUp();
	});
	
	var search_val = $("#SearchInput input[name=s]").val();
	if(!$("#SearchInput input[name=s]").val())
		$("#SearchInput input[name=s]").val(search_title);
	
	$("#SearchInput input[name=s]").focus(function(){
		if($(this).val() == search_val || $(this).val() == search_title)
			$(this).val("");
	})
	$("#SearchInput input[name=s]").blur(function(){
		if($(this).val() == '')
			$(this).val(search_title);
	})
	$("#SearchInput form").submit(function(){
		if($(this).find("input[name=s]").val() == search_title)
			$(this).find("input[name=s]").val("");
	});
	
	
	$j("#Searchfield").autocomplete({
		source: "/"+site_language+"/search_values.php",
		minLength: 2
	});
	
	$("#chooseCountry").hover(
		function()
		{
			clearTimeout(tid);
			LanguageSlideDown();
		}
		,
		function()
		{
			tid = setTimeout("LanguageSlideUp()",slideUpTimeout);
		}
	);
	
	$("#languageSelector .language").hover(function()
		{
			$(this).addClass("selected");
			clearTimeout(tid);
		},
		function()
		{
			$(this).removeClass("selected");
			tid = setTimeout("LanguageSlideUp()",slideUpTimeout);
		}
	);
	
	$('a.image-popup').lightBox();
	
	
});

/*
 * Image preview script 
 * powered by jQuery (http://www.jquery.com)
 * 
 * written by Alen Grakalic (http://cssglobe.com)
 * 
 * for more info visit http://cssglobe.com/post/1695/easiest-tooltip-and-image-preview-using-jquery
 *
 */
 
this.imagePreview = function(){	
	/* CONFIG */
		
		xOffset = 10;
		yOffset = 30;
		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result
		
	/* END CONFIG */
	$j("a.preview").hover(function(e){
		$j("body").append("<p id='preview'><img src='"+ this.title +"' alt='Image preview' /></p>");								 
		$j("#preview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");						
    },
	function(){	
		$j("#preview").remove();
    });	
	$j("a.preview").mousemove(function(e){
		$j("#preview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};

var tid;
var slideUpTimeout = 700;
function LanguageSlideDown()
{
	if(!$("#languageSelector:visible").length)
		$("#languageSelector").slideDown("fast");
}
function LanguageSlideUp()
{
	$("#languageSelector").slideUp("fast");
}

