/**
 * JS
 * @author Darío Ruellan <druellan@ecimtech.com>
 * @author Gustavo Salvini <gsalvini@ecimtech.com>
 * @copyright ecimTech 2009
 * @import: jquery/jquery.quicksearch.js
 */

$(function()
{

	// Zebra
	$(".eventlist .row:odd").addClass("odd");

	// Provisualizacion de imagen
	$(".eventlist .hover a.img").tipsy(
	{
		content: '<span class="thumb"></span>',
		fade: true,
		gravity: 's'
	});
	$(".eventlist .hover a.img").mouseover(function()
	{
		var id = $(this).attr("rel");
		$.get('?action=peek/getthumb_films&id='+id, function(thumb)
		{
			$(".tipsy .tipsy-inner span").html('<img src="'+thumb+'" width="100" />'); 
		});
	});
	
	// Provisualizacion de sedes
	$(".eventlist .hover a.place").tipsy(
	{
		content: '<span class="thumb"></span>',
		fade: true,
		gravity: 's'
	});
	$(".eventlist .hover a.place").mouseover(function()
	{
		var id = $(this).attr("rel");
		$.get('?action=peek/getthumb_places&id='+id, function(thumb)
		{
			$(".tipsy .tipsy-inner span").html('');
			if (thumb) 
			{
				$(".tipsy .tipsy-inner span").html('<img src="' + thumb + '" width="100" /><br/>eventos en la sede');
			}
			else 
			{
				$(".tipsy .tipsy-inner span").html('eventos en la sede');
			}
		});
	});

	// Quicksearch
	$(".eventlist .row").quicksearch(
	{
		attached: 'div.searchbox',
		labelText: '&nbsp;',
		inputText: 'Búsqueda rápida',
		loaderText: ' <span class="spinner"></span>',
		onBefore: function()
		{
			if ($("div.searchbox input.qs_input").val() ) {
				$(".eventlist .letters").hide();
			} else {
				$(".eventlist .letters, .eventlist h3").show();
			}
		},
		onAfter: function()
		{
			setTimeout("updateQS()", 400);
			setTimeout("updateQS()", 1000);			
		}
	});

})

function updateQS()
{
//	console.log("QuickSearch H3 Check");
	$(".eventlist .group").each(function()
	{
		var l = $(".row:visible",this).size();
		if ( l == 0)
			$("h3", this).hide();
		else
			$("h3", this).show();
	});
}


