$(document).ready(init);

tab_attivo="tab-evidenza-1";
interval="";

function init(){
	$(".menulist li:even").addClass("alt");
	$("#commenti li:even").addClass("alt");
	$(".thumbgallery li:even").addClass("alt");
	$(".paginator a:even").addClass("alt");
	$("#loginbar").hide();
	$("#advsearchbar").hide();

	$(".tab-evi").click(function(){
		clearInterval(interval);
		return tabEvidenza($(this).attr("id"));							 
	}); 

$("form").EasyForms( );
$(".googlesearchform").submit(function(){
	var _1=$("input[@name=search-radio][@checked]").val();
	$("#googlesearchbox").val($("#search-key").val()+"+more:"+_1);
});

// quando faccio blur ed ho cambiato valore
$("#search-key").change(function(){  });
$(".login-btn").click(function(){ $("#loginbar").slideToggle("slow");return false; });
$(".boxetto_open").click(function(){ $("#boxetto").slideToggle("slow");return false; });
$("#advsearch").click(function(){ $("#advsearchbar").slideToggle("slow");return false; });

$("input.stdinput,textarea.stdinput").focus(function(){
	$(this).addClass("stdinput-sel");
}).blur(function(){
	$(this).removeClass("stdinput-sel");
});

$("#aaa").click(function() {$(".articolo-body p").css({ "font-size":"1.6em"});return false;});
$("#aa").click(function() {$(".articolo-body p").css({ "font-size":"1.4em"});return false;});
$("#a").click(function() {$(".articolo-body p").css({ "font-size":"1.2em"});return false;});

$("a[@rel=popupimg]").click(function() { openwin($(this).attr("href"),"PopUpImg", "scrollbars=no,tollbar=no,width=980,height=720"); return false;});

$("#cercaConcessionario").click(function() {alert("Servizio di prossima attivazione");return false;});
$("a[@rel=inarrivo]").click(function() {alert("Prossimamente...");return false;});


$("#submitcomment").click(function() {
	if($("input[@name=comment-title]").val()=="Titolo del commento"){
		$("input[@name=comment-title]").focus();
		alert("Inserisci il titolo del commento");
		return false;
	}
	if($("input[@name=comment-name]").val()=="Il tuo nome"){
		$("input[@name=comment-name]").focus();
		alert("Inserisci il tuo nome");
		return false;
	}
	if($("input[@name=comment-email]").val()=="Il tuo indirizzo email (*)"){
		$("input[@name=comment-email]").focus();
		alert("Inserisci la tua email (non verra' pubblicata)");
		return false;
	}
	if($("textarea[@name=comment-text]").val()=="Testo del tuo commento"){
		$("input[@name=comment-text]").focus();
		alert("Inserisci il testo del commento");
		return false;
	}
	return true;	
});



$("#search-marca").change(function(){
	if($("#search-marca").val()=="0"){ alert("Selezionare una marca dall'elenco"); return false; }
	if($("#search-radio-articoli").attr("checked"))
		window.location = "/archivio/"+$("#search-marca").val();	
	else if($("#search-radio-foto").attr("checked"))
		window.location = "/foto/marca/"+$("#search-marca").val();	
});


}


function elencoMarca(tipo, elenco){
	var tt=tipo;
	//alert("Metto elenco marca per elenco '"+elenco+"' e tipo "+tt);
	$.getJSON("/pages/scripts/populate_marca.php",{ tipo: tt}, function(j){
		var options='';
		for (var i = 0; i < j.length; i++) {
			options += '<option value="' + j[i].optionValue + '">' + j[i].optionDisplay + '</option>';
		}
		$("#"+elenco).html(options);
		$('#'+elenco+' option:first').attr('selected', 'selected');
	})
	// FINE AJAX populate.php modello
}

function tabEvidenza(newtab){
	if(newtab==tab_attivo) return false;
	$("#"+tab_attivo).parent().removeClass("tabs-selected");	
	$("#"+newtab).parent().addClass("tabs-selected");
	$("#section-"+tab_attivo).hide();
	$("#section-"+newtab).show();
	tab_attivo=newtab;
	return false;
}

var w = null;
function openwin(theURL,winName,features) {
	if(w==null || w.closed){ w = window.open("", winName,features); }
	w.location.href = theURL; w.focus();
}

jQuery.fn.EasyForms=function(){this.find("label").not(".radiolabel").each(function(){var _9=$(this);var _a=$(this).siblings("input,textarea");$(this).siblings("input,textarea").val(_9.html());_a.click(function(){if($(this).val()==$(this).prev("label").html()){$(this).val("");}});_a.blur(function(){if($(this).val()==""){$(this).val($(this).prev("label").html());}});_9.hide();});};

