$(document).ready(function() {
	// Obrir en pagina nova els enllaços externs
	$("a[@rel]").click(function() {
		if ((this.rel.indexOf("popup") >= 0) || (this.rel.indexOf("external") >= 0)) {
			window.open(this.href);
			return false;
		}
	});
	$("a[@rel]").click(function() {
		if (this.rel.indexOf("legal") >= 0) {
			window.open(this.href, "","menubar=0,resizable=0,width=581,height=256"); 
			return false;
		}
	});	
	$("#anadir-favoritos").click(function(){
		window.external.AddFavorite($("#anadir-favoritos").attr("href"),'JeuxJeux.com - Jeux gratis');
		return false;
	});
	var i = 0;
	$.each( $(".rotation"), function(){
		i = i+1;		
	});
	i = i - 1;
	$("#rotation-up").click(function(){
		var k = 0;
		var tmp_text_0 = $("#rotation-0").html();
		for (j=0;j<=i;j++) {
			k = j+1;
			if (k > i) {				
				$("#rotation-"+j).html(tmp_text_0);
				var tmp_juega = $("#rotation-0 a").attr("href");
				var tmp_juega_title = $("#rotation-0 a").attr("title");
				$("#novedades-juega").attr("href", tmp_juega);
				$("#novedades-juega").attr("title", tmp_juega_title);
			} else {
				var tmp_text = $("#rotation-"+k).html();
				$("#rotation-"+j).html(tmp_text);
			}
		}
		return false;
	});
	$("#rotation-down").click(function(){
		var k = 0;
		var tmp_text_0 = $("#rotation-"+i).html();
		for (j=i;j>=0;j--) {
			k = j-1;
			if (k < 0) {
				$("#rotation-0").html(tmp_text_0);
				var tmp_juega = $("#rotation-0 a").attr("href");
				var tmp_juega_title = $("#rotation-0 a").attr("title");
				$("#novedades-juega").attr("href", tmp_juega);
				$("#novedades-juega").attr("title", tmp_juega_title);
			} else {
				var tmp_text = $("#rotation-"+k).html();
				$("#rotation-"+j).html(tmp_text)
			}
		}
		return false;
	});	
	$("#select-votar").change(function(){
		$.ajax({
			type: "POST",
			url: "ajax_sumarvotos.php",
			data: "id="+this.value,
			success: this.disabled = true
		})
	});
	$("#frm_buscador").submit(function(){		
		busqueda = document.getElementById("busqueda").value
		if (busqueda != "") {
			pageTracker._trackPageview ('/buscar?q=' + busqueda );
			$.ajax({
				type: "POST",
				url: "ajax_anadir_busqueda.php",
				data: "busqueda="+busqueda,
				succes: window.location="/jeux-du-"+busqueda+".html"
			});		
			/*window.location="juegos-de-"+busqueda+".html";*/
		}
		return false;
	});	
	$("#sb-buscar").click(function(){
		busqueda = document.getElementById("busqueda").value
		if (busqueda != "") {
			pageTracker._trackPageview ('/buscar?q=' + busqueda );
			/*window.location="juegos-de-"+busqueda+".html";*/
			$.ajax({
				type: "POST",
				url: "ajax_anadir_busqueda.php",
				data: "busqueda="+busqueda,
				succes: window.location="/jeux-du-"+busqueda+".html"
			});
		}
		return false;
	});
	/*var html = $.ajax({
		type: "POST",
		url: "ajax_juegos_todos.php",
		async: false
	}).responseText;
	$("#juegos-lista-juegos-texto-todos-box").append(html);*/	
});	