$(document).ready(function(){

/* Nascondi i messaggi d'errore e di successo */
if($('.failure').length != 0) { $('.failure').hide(); }
if($('.success').length != 0) { $('.success').hide(); }

/* Invia la chiave di ricerca */
$('#search_push').click(function() { doSearch(); });
$('#search_key').keyup(function(e) { if(e.keyCode == 13) doSearch(); });

// Reindirizzi tutti i link del sito in un'altra pagina
$('.post p a').each(function() { $(this).attr('target', '_blank'); });

// Riduci tutti i video
$('.post object').each(function() {
	var w = $(this).attr('width');
	var h = $(this).attr('height');
	
	// Riduci il video in proporzione
	if(w > 564) {
		h = h * 564 / w; w = 564;	
		$(this).attr('width', w);
		$(this).attr('height', h);
		$(this).children('embed').attr('width', w);
		$(this).children('embed').attr('height', h);
	}
});

// Riduci tutte le immagini
$('.post img').each(function() {
	var w = $(this).attr('width');
	var h = $(this).attr('height');
	
	// Riduci il video in proporzione
	if(w > 564) {
		$(this).removeAttr("width")
			.removeAttr("height")
			.css({ width: "", height: "" });
		h = h * 564 / w;
		w = 564;	
		$(this).attr('width', w)
				.attr('height', h)
				.css({ width: w, height: h });
	}
});

})

/* Funzione che invia la chiave di ricerca */
function doSearch() {
	var search_key = $('#search_key').val();
	if(search_key == '') {
		alert('Inserisci una chiave di ricerca valida.');
	} else {
		top.location = '/posts.php/k/'+ search_key.replace(' ', '_');
	}
}

