
$(document).ready(function(){	
	
	accesibilidad();
	
		
	$("#escudo").click(function(){
		var a = $("#menu_vecinos a").html();
		if (a == "Herritarrak"){
			window.location =("http://www.larraga.es/eu");
		}else{
			window.location =("http://www.larraga.es/");
		}
		
	});
	$(".superior").css("font-size","24px");
	detectarNavegador();		
	
});


function imprSelec(nombre)
{
	var ficha = document.getElementById(nombre);
	var ventimp = window.open(' ', 'popimpr');
	ventimp.document.write( ficha.innerHTML );
	ventimp.document.close();
	ventimp.print( );
    ventimp.close();
}
			
			
function moverSidebar(){
    var offset = $("#menu_fiesta").offset();
	var topPadding = 25;
        $(window).scroll(function() {
            if ($("#menu_fiesta").height() < $(window).height() && $(window).scrollTop() > offset.top) { /* LINEA MODIFICADA POR ALEX PARA NO ANIMAR SI EL SIDEBAR ES MAYOR AL TAMAÑO DE PANTALLA */
                    $("#menu_fiesta").stop().animate({
                        marginTop: $(window).scrollTop() - offset.top + topPadding
                    });
                } else {
                    $("#menu_fiesta").stop().animate({
                        marginTop: 0
					});
                };
    });

}

function accesibilidad(){

		 // Donde queremos cambiar el tamaño de la fuente
		  var donde = $('.mitexto');
		  var sizeFuenteOriginal = donde.css('font-size');
		  var cuantos = 0;
		  
		  // Resetear Font Size
		  $(".resetearFont").click(function(){
			donde.css('font-size', sizeFuenteOriginal);
			cuantos = 0;
			$('.scrollbar1').tinyscrollbar();
			$('.scrollbar2').tinyscrollbar();
		  });
		  // Aumentar Font Size
		  $(".aumentarFont").click(function(){
			if (cuantos < 2){
				var sizeFuenteActual = donde.css('font-size');
				var sizeFuenteActualNum = parseFloat(sizeFuenteActual, 10);
				var sizeFuenteNuevo = sizeFuenteActualNum*1.2;
				donde.css('font-size', sizeFuenteNuevo);
				cuantos = cuantos + 1;
				$('.scrollbar1').tinyscrollbar();
				$('.scrollbar2').tinyscrollbar();
				
				return false;
			}else{
				
			}
		  });
		  // Disminuir Font Size
		  $(".disminuirFont").click(function(){
			if (cuantos > 0){
				var sizeFuenteActual = donde.css('font-size');
				var sizeFuenteActualNum = parseFloat(sizeFuenteActual, 10);
				var sizeFuenteNuevo = sizeFuenteActualNum*0.8;
				donde.css('font-size', sizeFuenteNuevo);
				cuantos = cuantos - 1;
				$('.scrollbar1').tinyscrollbar();
				$('.scrollbar2').tinyscrollbar();
				return false;
			}else{
				
			}
		  });

}


function galeria(num) {
	/* This code is executed after the DOM has been completely loaded */

	var totWidth=0;
	var positions = new Array();
	var j = num;
	
	
		
	
	$('#slides' + j + ' .slide').each(function(i){
		/* Loop through all the slides and store their accumulative widths in totWidth */
		positions[i]= totWidth;
		totWidth += $(this).width();

		/* The positions array contains each slide's commulutative offset from the left part of the container */

		if(!$(this).width())
		{
			alert("Please, fill in width & height for all your images!");
			return false;
		}
	});

	$('#slides' + j).width(totWidth);

	/* Change the cotnainer div's width to the exact width of all the slides combined */

	$('#thumbs' + j + ' ul li a').click(function(e){

		/* On a thumbnail click */
		$('li.menuItem').removeClass('act').addClass('inact');
		$(this).parent().addClass('act');

		var pos = $(this).parent().prevAll('.menuItem').length;

		$('#slides' + j).stop().animate({marginLeft:-positions[pos]+'px'},450);
		/* Start the sliding animation */

		e.preventDefault();
		/* Prevent the default action of the link */
	});

	$('#thumbs' + j + ' ul li.menuItem:first').addClass('act').siblings().addClass('inact');
	/* On page load, mark the first thumbnail as active */

}
function pintarSlider(){

		var html = "";
		var superior = 9;
		var inferior = 1;
		var numPosibilidades = superior - inferior; 
		var aleat2, aleat3 = 0;
		var aleat = -1;
		
		
		aleat = Math.random() * numPosibilidades;
		aleat = Math.round(aleat);
		aleat = parseInt((inferior) + aleat);

		if (aleat >= (superior - 1)){
			if (aleat == superior){
				aleat2 = aleat - 1;
				aleat3 = aleat - 2;
			}else{
				aleat2 = superior;
				aleat3 = aleat - 1;
			}
		}else {
			aleat2 = aleat + 1;
			aleat3 = aleat + 2;
		}
		
		
		html += "<ul>";
		html += "<li><img src='http://www.larraga.es/img/slider0.png' alt='Css Template Preview' /></a></li>";
		html += "<li><img src='http://www.larraga.es/img/slider" + aleat + ".jpg' alt='Css Template Preview' /></a></li>";
		html += "<li><img src='http://www.larraga.es/img/slider" + aleat2 + ".jpg' alt='Css Template Preview' /></a></li>";
		html += "<li><img src='http://www.larraga.es/img/slider" + aleat3 + ".jpg' alt='Css Template Preview' /></a></li>";
		html += "</ul>";
		

		$("#slider").html(html);
		
}function comprobarAcuerdos(idioma){
	var acu1 = $("#acu1 h1").html();
	var acu2 = $("#acu2 h1").html();
	var acu3 = $("#acu3 h1").html();
	
	if (acu3 == ""){
		$("#acu3").hide();
		if (acu2 == ""){
			$("#acu2").hide();
			if (acu1 == ""){
				$("#acu1").hide();
				switch(idioma){
						case "es":	$("#ver_mas_acuerdos").html("<a href='../blog/?cat=4' title='ir a la sección de Noticias' class='mitexto'>No hay acuerdos para mostrar</a>");
									break;
						case "eu":	$("#ver_mas_acuerdos").html("<a href='../blog/?cat=4&lang=eu' title='ir a la sección de Noticias' class='mitexto'>Ez da udal hitzarmenik topatu</a>");
				}
			}
		}
	}
	
	var art1 = $("#art h1").html();
	var art2 = $("#art2 h1").html();
	var art3 = $("#art3 h1").html();
	
	if (art3 == ""){
		$("#art3").hide();
		if (art2 == ""){
			$("#art2").hide();
			if (art1 == ""){
				$("#art1").hide();
				switch(idioma){
						case "es":	$("#ver_mas_noticias").html("<a href='../blog/' title='ir a la sección de Noticias' class='mitexto'>No hay noticias para mostrar</a>");
									break;
						case "eu":	$("#ver_mas_noticias").html("<a href='../blog/&lang=eu' title='ir a la sección de Noticias' class='mitexto'>Ez da berririk topatu</a>");
				}
			}
		}
	}
	

}

