jQuery(document).ready(function() {

	if ($('#boxMainLinksAccordion')) {
		var boxAccordion = $('#boxMainLinksAccordion');

		// assign behaviour to togglers
		boxAccordion.accordion({header: 'h4', active: false, collapsible: true, autoHeight: false});
		
	}

	if ($('#boxMainSearchBy')) {
	
		if ($('#archive-select-ym')) { 
			$('#archive-select-ym').bind('change', 
				function() { document.location.href = $(this).val(); } 
			); 
		}

		if ($('#archive-select-cat')) { 
			$('#archive-select-cat').bind('change', 
				function() { document.location.href = ("/index.php?cat="+$(this).val()); }
			); 
		}

	}

	if ($('#boxMainSearchAdvanced')) {
		var asMain = $('#boxMainSearchAdvanced');
		var asTxt = $('#asTxt',asMain);
		var asCat = $('#cat',asMain);
		var asY   = $('#asY',asMain);
		var asM   = $('#asM',asMain);
		var asSbm = $('#asSbm',asMain);

		var asQuery = [];
		
		if (asSbm) { 
			asSbm.bind('click',
				function() { 
				
				if (asTxt) { if (asTxt.getValue() != "") { asQuery.push("s="+encodeURIComponent(asTxt.getValue())); } /* else { alert('Inserire una parola o una frase nel campo di ricerca.'); return; }*/ }
				if (asCat) { if (!["-1",""].contains(asCat.getValue())) { asQuery.push("cat="+asCat.getValue()); } }
				if (asY)   { if (asY.getValue() != "") { asQuery.push("year="+asY.getValue()); } }
				if (asM)   { if (asM.getValue() != "") { asQuery.push("monthnum="+asM.getValue()); } }
				document.location.href = ("/?"+asQuery.join('&'));

				}
			); 
			asSbm.onclick = function(){return false;}
		}
	}

	if ($('a.obfuscated')) {
	
		var mlt = "";
		$(["mai",'lto',":ro","cca",'@ca',"millo",'blog',".it"]).each(function(){  mlt += this; }); 
		$('a.obfuscated').each( function(){ $(this).attr('href',mlt); } );

	}

	/* Warning: Google Ads sono remoti, quindi non avendo accesso via JS a dimini esterni... nada!
	   Inoltre l'evento pu˜ essere assegnato solo sul load effettivo della pagina (al domready magari sta 
	   ancora facendo la richiesta al server Google: window.addEvent('load', (function() {...}) );
	   Infine, Firefox non gestisce bene la cosa, e Google usa il load nella pagina corrente (vedi un
	   esempio di script che fa il tracking qui: http://www.seobook.com/archives/001370.shtml)


	if ($('boxMainGoogleAds')) {
	
		$ES('#boxMainGoogleAds a').each( 
			function(lnk){ 
				lnk.addEvent('click', (
					// google analytics - goal tracking
					function(event) { console.log('helo',event.target); pageTracker._trackPageview('/googleadclick/'); }).bindAsEventListener(this) 
				); 
			} 
		);

	}
	*/

});

