				
/* funciones gestion imagen de fondo*/				
				
					function CargaPagina() {					
						$('#capa_background').find('.capa_loading').show();//show loading status image
							$.when(loadImages()).done(function(){
								$.when(MostrarImagenFondo()).done(function(){
										//ocultar el loading
										$('#capa_background').find('.capa_loading').hide();	
										$().clearQueue();								
								});
						 });
					}
					
					/* precargar imagenes */
					function loadImages() {
						return $.Deferred(
						function(dfd) {
							var total_images 	= $ItemImages.length,
							loaded			= 0;
							for(var i = 0; i < total_images; ++i){
								
								$('<img/>').load(function() {
									++loaded;
									if(loaded === total_images)
										dfd.resolve();
								}).attr('src' , $ItemImages[i]);
							}
						}
					).promise();
					}					
					
					function MostrarImagenFondo() {
						return $.Deferred(
						function(dfd) {
							//ajsutar dimensiones
							AjustarImagen($('#capa_background').find('.capa_bgimage'));
							$('#capa_background').find('.capa_bgimage').fadeIn(400, dfd.resolve);
						}
					).promise();
					}
					

					
					/* cambiar imagen fondo */
					function CambiarImagenFondo(url,opacidad) {
						$capa_bgimage= $('#capa_background').find('.capa_bgimage');
						
						$('.capa_overlay').fadeTo(500,opacidad)
						
						if($capa_bgimage.attr('src') === url)
						return false;
								
						var $itemImage = $('<img src="'+url+'" alt="Background" class="capa_bgimage"/>');
						$itemImage.insertBefore($capa_bgimage);
						AjustarImagen($itemImage);
						
						$capa_bgimage.fadeOut(500, function() {
							$(this).remove();
							$capa_bgimage = $itemImage;
						});
						$itemImage.fadeIn(500);																		
					}


				 function AjustarImagen($img) {
						var w_w	= $(window).width(),
						w_h	= $(window).height(),
						r_w	= w_h / w_w,
						i_w	= $img.width(),
						i_h	= $img.height(),
						r_i	= i_h / i_w,
						new_w,new_h,
						new_left,new_top;
							
						if(r_w > r_i){
							new_h	= w_h;
							new_w	= w_h / r_i;
						}
						else{
							new_h	= w_w * r_i;
							new_w	= w_w;
						}
							
						$img.css({
							width	: new_w + 'px',
							height	: new_h + 'px',
							left	: (w_w - new_w) / 2 + 'px',
							top		: (w_h - new_h) / 2 + 'px'
						});
						$('.capa_overlay').css({							
							width	: new_w + 'px',
							height	: new_h + 'px',
							left	: (w_w - new_w) / 2 + 'px',
							top		: (w_h - new_h) / 2 + 'px'});
							
							
					}
					
					





/* funciones generales*/
function transicion(url){
	//carga mediante ajax la url que recibe usando una transicion de fade
	$('.contenido').animate({'opacity':0},500,function(){
		$.get(url, function(data) {
			$('.contenido').html(data);
			$('.contenido').animate({'opacity':1},300);				
																									
		});	
	});
}


function AjustarNaranja(){	
	if ($("#naranjaderecha").length > 0){
		var anchonaranja= $('#naranjaderecha').width();
		var anchoventana= $(window).width();
		var diferencia= anchoventana-960;
		if(diferencia<=anchonaranja){
			$('#naranjaderecha').css({'right':-(anchonaranja-diferencia)+'px'});
		}else{
			$('#naranjaderecha').css({'right':'0px'});
		}	
	}
}

function MostrarNaranja(){
		$('#naranjaderecha').fadeIn(500);
}
function QuitarNaranja(){	
		$('#naranjaderecha').hide();	
}



function validar(){
	if (!$('#usuario').val()){
		$('#usuario').parent().find('.error').fadeIn(300);
		return false;
	}

	if (!$('#contrasenya').val()){
		$('#contrasenya').parent().find('.error').fadeIn(300);
		return false;			
	}	
		
	$('.error').hide();
	
	//$('#mensajeerror').html('<img src="images/anim.gif">');
	
	$('.capa_loading').show();
	$('#mensajeerror').show(100);
	
	setTimeout('envia()', 2000);	
}

function envia(){
	
	 $.ajaxSetup ({  
         cache: false,
		 contentType: "application/x-www-form-urlencoded;charset=ISO-8859-15"
     });  
	 
	valorusuario=$("#usuario").val();	
	valorpassword=$("#contrasenya").val();	

	$.post("AjaxLogin.php", {usuario: valorusuario,contrasenya:valorpassword},   	
	function(data){
	 	if(data=='login'){
			//redirecciona
			window.location = "privadoLocalizaciones.php"
		}else{
			//mostrar error
			$('#mensajeerror').html(data).delay(500).fadeIn(1000);
		}
	});
	
	$('.capa_loading').hide();	

}

	function mostrarImagenes() {
		
		var images = $('.boxdirectores img').length;//Contamos la cantidad de imagenes
		if (i >= images) {// Loopeamos las imagenes
			clearInterval(int);//Cuando llegue a la ultima imagen el loop acaba
		}
		$('.boxdirectores img').eq(i).animate({'opacity':'1'},100);//Damos Fade a imagen escondidas una a una
		i++;//Agregamos un contador
	} 
