var IS_SHOW_KWICK = false;

$(document).ready(function(){
	
	$("#loc").autocomplete(baseurl+"comuni");
	
	$('#kwicks #hover div').css('left', '-940px');
	
	$('#kwicks #buttons div').mouseover(function(){
		$el = $('#kwicks #hover .'+$(this).attr("class"));
		$opened = false;
		
		$('#kwicks #hover DIV').each( function() {
			if ($(this).css('left') != '-940px' && $(this).attr("class")!=$el.attr("class"))
			{
				$(this).animate({
					marginLeft: parseInt($(this).css('marginLeft'),10) == 0 ?
							$(this).outerWidth() : 0
				}, function() {
					$(this).css('left', '-940px').css('marginLeft', '0');
				});
			}
			else if($(this).css('left') != '-940px')
			{
				$opened = true;
			}
		});
		
		i
		if (!$opened)
		{
			$el.animate({
				left: parseInt($el.css('left'),10) == 0 ?
				-$el.outerWidth() : 0
		    });
		}
	})
	
	$('#kwicks').mouseleave(function(){
		
		$('#kwicks #hover DIV').each( function() {
			if ($(this).css('left') != '-940px')
			{
				$(this).animate({
					marginLeft: parseInt($(this).css('marginLeft'),10) == 0 ?
							$(this).outerWidth() : 0
				}, function() {
					$(this).css('left', '-940px').css('marginLeft', '0');
				});
			}
		});
	})
	
	$('div.accordion h3').click(function(){
		$(this).parent().toggleClass('open');
		return false;
	});


	/* PopUp */
	$('#popup-mask').click(function () { closePopUp(); });
	$('#popup #chiudi').click(function () { closePopUp(); });
	
	if ($(".tickercontainer UL").length>0)
	{
		$('.tickercontainer UL').show().cycle({ 
		    fx: 'turnDown',
		    speed:  500, 
			timeout:  4000,
			cleartypeNoBg: true 
		});
	}
});

function cndAnnunci()
{
	var what = $('#key').attr('value');
	var where = $('#loc').attr('value');
	
	if(what+where=="") {
		alert('Per eseguire una ricerca è necessario selezionare almeno un criterio di ricerca.');
		return false;
	} else return true;		
}

/* PopUp */
function loadPopUp(title, url, data, big)
{
	$("#popup").removeClass("big");
	if (big==1) $("#popup").addClass("big");
	
	//Get the screen height and width  
	var maskHeight = $(document).height();  
	var maskWidth = $(window).width();  

	//Set height and width to mask to fill up the whole screen  
	$('#popup-mask').css({'width':maskWidth,'height':maskHeight});  
	  
	//transition effect   
	$('#popup-mask').fadeTo("fast",0.6);    

	//Get the window height and width  
	var winH = $(window).height();  
	var winW = $(window).width();  
	        
	//Set the popup window to center  
	if (big==1) $('#popup').css('top', 50);
	else		  $('#popup').css('top',  winH/2-100);
	$('#popup').css('left', winW/2-$('#popup').width()/2);
	
	$('#popup #contentAjax').html("<div style='text-align:center'><img src='{/literal}{$smarty.const.BASEURL}{literal}lib/img/site/loader.gif' style='margin:40px 0;'><"+"/div>");
	$("#popup").show();
	$('#popup H3').html(title);
	if (url == '')	$('#popup #contentAjax').html(data);
	else			$('#popup #contentAjax').load(url+"/?a", function() {  });
}
function loadingPopUp()
{
	$('#popup #contentAjax').html("<div style='text-align:center'><img src='{/literal}{$smarty.const.BASEURL}{literal}lib/img/site/loader.gif' style='margin:40px 0;'><"+"/div>");
}
function closePopUp()
{
	$('#popup #contentAjax').html("");
	$('#popup-mask').fadeOut("fast");
	$('#popup').hide();  
}

