function debug(arg){
	if (window.console)
		console.log(arg);
}

var _settings = {
	validate : {
		errorPlacement: function (error, element) {
			element.addClass("error").parents(".ctrlHolder:eq(0)").addClass("error");
			error.insertAfter(element);
		},
		success: function (label) {
			label.removeClass('error');
			label.parents(".ctrlHolder:eq(0)").removeClass('error');
		}
	}
};

$(document).ready(function(){
	$('.innerfade').innerfade({ 
		animationtype: 'fade', 
		speed: 'normal', 
		timeout: '5000', 
		type: 'sequence', 
		containerheight: 'auto', 
		runningclass: 'innerfade' 
		});
	
	$("a", ".home .miniature").live("click", function(){
		var _self = $(this);
		var _id_galleria = $(".id", _self).text();
		var _current_id_galleria = $(".currentid", _self).text();
		var _currents_ids_galleria = $(".currentid", ".home .miniature");
		var _gallerie = $("div.galleria", ".home .content");
		var _galleria = $("#galleria_" + _id_galleria);
		var _miniatura = $("#miniatura_" + _id_galleria);
		var _current_id_miniatura = $("#miniatura_" + _current_id_galleria);
		
		_gallerie.hide();
		_galleria.show();
		_miniatura.hide();
		_current_id_miniatura.show();
		_currents_ids_galleria.text(_id_galleria);
		
		return false;
	});
	
	$("a", ".home .screenshots").live("click", function(){
		var _self = $(this);
		var _id_video = $(".id", _self).text();
		var _current_id_video = $(".currentid", _self).text();
		var _currents_ids_video = $(".currentid", ".home .screenshots");
		var _videos = $("div.video", ".home .content");
		var _video = $("#video_" + _id_video);
		var _screenshot = $("#screenshot_" + _id_video);
		var _current_id_screenshot = $("#screenshot_" + _current_id_video);
		
		_videos.hide();
		_video.show();
		_screenshot.hide();
		_current_id_screenshot.show();
		_currents_ids_video.text(_id_video);
		
		return false;
	});
	
	$("a.regione, .coordinatori #mappa").live("click", function(){
		var _id_regione = $("span", this).text();
		var _e = $(".elenco", ".coordinatori");
		var _str_elenco = false;
		
		$.ajax({
			type: "GET",
			dataType: "json",
			url: URL + "/professionismo/ajaxnomeregione/id/" + _id_regione,
			success: function(_nome_regione){
				_e.empty()
				_str_elenco = "<h3>" + _nome_regione + "</h3><h4>Coordinatori:</h4>";
				
				$.ajax({
					type: "GET",
					dataType: "json",
					url: URL + "/professionismo/ajaxcoordinatoriregione/id/" + _id_regione,
					success: function(_dati){
						if (_dati){
							_str_elenco += "<ul>";
							$.each(_dati, function(_chiave, _valore){
								_str_elenco += "<li>";
								if (_valore.is_dettaglio_coordinatore == 1){
									_str_elenco += "<a href='" + URL + "/professionismo/coordinatore/regione/" + _id_regione + "/id/" + _valore.id_coordinatore + "' class='coordinatore'>" +
												   _valore.nome_coordinatore + " " + _valore.cognome_coordinatore +
												   "</a>";
								} else {
									_str_elenco += _valore.nome_coordinatore + " " + _valore.cognome_coordinatore;
								}
								_str_elenco += "</li>";
							});
							_str_elenco += "</ul>";
						}
						_e.append(_str_elenco);
						_e.show();
					},
					error: function(richiesta, stato){
						$.jGrowl('Errore nella chiamata AJAX', { sticky: true });
					}
				});
			},
			error: function(richiesta, stato){
				$.jGrowl('Errore nella chiamata AJAX', { sticky: true });
			}
		});
		
		return false;
	});
	
	$('.galleria .immagine a').lightBox();
	$('a.foto', ".catera_campioni").lightBox();
	$('a.immagine', ".incampo_strutture").lightBox();
	$('a.immagine', ".fuoricampo_strutture").lightBox();
});

var timeout         = 500;
var closetimer		= 0;
var ddmenuitem      = 0;

function jsddm_open()
{	jsddm_canceltimer();
	jsddm_close();
	ddmenuitem = $(this).find('ul').eq(0).css('visibility', 'visible');}

function jsddm_close()
{	if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');}

function jsddm_timer()
{	closetimer = window.setTimeout(jsddm_close, timeout);}

function jsddm_canceltimer()
{	if(closetimer)
	{	window.clearTimeout(closetimer);
		closetimer = null;}}

$(document).ready(function()
{	$('#jsddm > li').bind('mouseover', jsddm_open);
	$('#jsddm > li').bind('mouseout',  jsddm_timer);});

document.onclick = jsddm_close;

