var loadingBlink;
var dhome = false;
var preLoadImgAr = Array();

function mZona(capa,showLoad){
	if(showLoad){showLoading();}
	$(".zonaContent").hide();
	$('#'+capa).fadeIn('fast')
}
function showLoading(txt){
	$('#loadingAjax').show();	
}

function hideLoading(){
	$('#loadingAjax').hide();
	$(".bannertop").css("visibility","visible");
	$(".bannertop").animate({opacity:1},500,"swing")
}

function preLoadImg(){
    preload_image_object = new Image();
	var i = 0;
       for(i=0; i<=preLoadImgAr.length; i++) 
         preload_image_object.src = WROOT+preLoadImgAr[i];
}

function slideShowImg(id) {
	var idt = id+"Txt";
    var $active = $('#'+id+' img.active');
	 var $activet = $('#'+idt+' div.activet');

    if ( $active.length == 0 ) $active = $('#'+id+' img:last');
	if ( $activet.length == 0 ) $activet = $('#'+idt+' div:last');

    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('#'+id+' img:first');
	var $nextt =  $activet.next().length ? $activet.next()
        : $('#'+idt+' div:first');

    // uncomment the 3 lines below to pull the images in random order    
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );
    $active.addClass('last-active');
	$activet.addClass('last-activet');
	
	$activet.fadeOut(600,function(){	
		$next.css({opacity: 0.0})
			.addClass('active')
			.animate({opacity: 1.0}, 600, function() {
				$active.removeClass('active last-active');
				$activet.removeClass('activet last-activet');
				$nextt.addClass('activet').fadeIn(600);			  
		});
	});   
}

function homeNoticies(){
	$.ajax({
			type: "POST",
			url:"admin/noticies/AJ_homeNoticies.php",			
			data:"aj=llistar2",
			success:function(response){
				
				var llista = response.firstChild;
				
				var tmpHTML;
				$("#scrollNews").empty();
				$(llista).children().each(function(){
												   
					tmpHTML = '<div class="noticia">';
					tmpHTML += '<div class="data">'+$(this).find("data").text()+'</div>';
					tmpHTML += '<div class="linia"></div>';
					tmpHTML += '<div class="text">'+$(this).find("noticia").text();
					tmpHTML += ' <a href="home/noticia.php?n='+$(this).find("adjunta").text()+'">+m&aacute;s</a></div>';
					tmpHTML += '</div>';
					$("#scrollNews").append(tmpHTML);							
				});
				$("#scrollNews").jScrollPane({scrollbarWidth:6});
				if($("#scrollNews").is(":empty")){
					$("#scrollNews").html("<div style=\"padding-top:20px;font-style:italic\">No hay noticias</div>");
				}
			}
	});		
}
function letraDni(dni){
		cadena="TRWAGMYFPDXBNJZSQVHLCKET"
		posicion = (dni.substring(0,8) % 23);
		letra = cadena.substring(posicion,posicion+1)
		if(letra==dni.substring(8)){return true;}
		else{return false;}
	} 
	function validarDni(dni){
		var r =  false;
		var valor = dni.toUpperCase();
		
		if(valor.length >= 9){
			if(valor.substring(0,8) == parseInt(valor.substring(0,8))){
					if(letraDni(valor)){r=true;}
					else{alert("La letra del DNI introducido no es correcta");}
			}else{
				if(valor.substring(1,8) == parseInt(valor.substring(1,8))){
					r=true;
				}else{
					alert("El DNI introducido no es correcto");}
				}
		}else{
			alert("El dni introducido no es correcto");
		}
		
		return r;
	}
	
function homeVideoShow(){
	window.scrollTo(0,0);
	$("html, body").css("overflow","hidden");
	$("#homeBanner1Div").css("visibility","hidden");
	$("#videoHomeDiv").css("opacity","0");
	$("#videoHomeDiv").show();
	
	$("#videoHomeDiv").fadeTo('normal',0.8,function(){
		$("#videoHomeDivOverlay").fadeIn('fast',function(){
				flowplayer("videoHome", "../flv/flowplayer-3.1.5.swf", { 
				clip:  { 
					autoPlay: true, 
					autoBuffering: true 
				} 
				}); 												 
		});				   
	});
}

function homeVideoShowHide(){
	$("#homeBanner1Div").css("visibility","visible");
	$("#videoHomeDivOverlay").hide();
	$("#videoHomeDiv").fadeOut('fast');
	$("html, body").css("overflow","auto");
	flowplayer("videoHome", "../flv/flowplayer-3.1.5.swf", { 
				clip:  { 
					autoPlay: false, 
					autoBuffering: true 
				} 
				}); 	
}	
	
	
$.fn.extend({  
     reset: function() {  
     return this.each(function() {  
             $(this).is('form') && this.reset();  
     });  
     }  
 }); 
(function($)
{
	$.fn.blink = function(options)
	{
		var defaults = { delay:310 };
		var options = $.extend(defaults, options);
		
		return this.each(function()
		{
			var obj = $(this);
			loadingBlink = setInterval(function()
			{
				if($(obj).parent().css("display") == "none"){clearInterval(loadingBlink);}
				if($(obj).css("display") == "none")
				{
					$(obj).fadeIn(110);
				}
				else
				{
					$(obj).fadeOut(110);
				}
			}, options.delay);
		});
	}
}(jQuery))
var userAgent = navigator.userAgent.toLowerCase();
$.browser = {
	    version: (userAgent.match( /.+(?:rv|it|ra|ie|me)[\/: ]([\d.]+)/ ) || [])[1],
	    chrome: /chrome/.test( userAgent ),
	    safari: /webkit/.test( userAgent ) && !/chrome/.test( userAgent ),
	    opera: /opera/.test( userAgent ),
	    msie: /msie/.test( userAgent ) && !/opera/.test( userAgent ),
	    mozilla: /mozilla/.test( userAgent ) && !/(compatible|webkit)/.test( userAgent )
	};