function file_exists (url) {
    var req = this.window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
    if (!req) {throw new Error('XMLHttpRequest not supported');}
    req.open('HEAD', url, false);
    req.send(null);
    if (req.status == 200){
        return true;
    }
    return false;
}

//Especificamos a jQuery los navegadores (Útil para diferenciar Safari de Chrome).
var userAgent = navigator.userAgent.toLowerCase();
jQuery.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 )
};


$(window).bind("unload", function() { // ... 
		carga();						  
 });

$(document).ready(function(){
	
	carga();
	
});




function carga(){
	
						
		
		jQuery.each(jQuery.browser, function(i, val) {
		
			if(i=="msie" && jQuery.browser.version.substr(0,3)=="8.0"){
				//alert('8');
			} 
		
		
			if(i=="msie" && jQuery.browser.version.substr(0,3)=="7.0"){
				//alert('7');
			}
		
		
			if(i=="msie" && jQuery.browser.version.substr(0,3)=="6.0"){
				//alert('6');
			}
		
		
			if($.browser.mozilla){
				//alert('fire');
			}
		
		
			if($.browser.opera){
				//$('head').append('<link rel="stylesheet" href="css/browsers/opera.css" type="text/css" />');
			}
		
		
			if($.browser.safari){
				//$('head').append('<link rel="stylesheet" href="css/browsers/safari.css" type="text/css" />');
			}
		
		
			if($.browser.chrome){
				//$('head').append('<link rel="stylesheet" href="css/browsers/chrome.css" type="text/css" />');
			}
		
	});
		
		
		
						
function preloadImages(id) {
    var c = new Array();
	
    $(id+' img').each( function(j) {
        c[j] = new Image();
        c[j].src = this.src;
		
		


		
        if (( $.browser.msie )&&(this.name!='none')) {
			
            //this.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled='true',sizingMethod='image',src='"+ this.src +"')"; 
        }
    });

}


preloadImages('body');
			
						
						
						
						
function imageresize() {
    
	if ($(window).width()<=1024){
		
		$('#cuerpo').css("left",'0%');
		$('#cuerpo').css("margin-left",'0px');
		

	}else{
		if ($(window).width()>=1152){
			$('#cuerpo').css("width",'1152px');
			$('#cuerpo').css("left",'50%');
			$('#cuerpo').css("margin-left",'-576px');
		}else{
			$('#cuerpo').css("left",'50%');
			$('#cuerpo').css("margin-left",'-45%');
		}
	}
	
	
	
	
	var div_ancho = $("#cuerpo").width();
	
	
	
	
	$('.fotoit').css("width",div_ancho+'px');
	$('.fotositem').css("width",div_ancho+'px');
	var div_alto = parseInt((div_ancho*711)/1668);
	
	
	$('#fotos').css("height",div_alto+'px');
	$('#fotosriel').css("height",div_alto+'px');
	
	
	//$("#info").html("LEFT: "+posicionReal.left+ " TOP: "+posicionReal.top);
}
			
			
$(window).bind("resize", function(){
			imageresize();
		});
  //llamada cuando la ventana cambia de tamaño
imageresize();



$("a[rel=group]").fancybox({
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'titlePosition' 	: 'over',
				'overlayColor'		: '#000000',
				'overlayOpacity'	: 0.75,
				'titleFormat'       : function(title, currentArray, currentIndex, currentOpts) {
				    return '<span id="fancybox-title-over">'+title+'<br>Imagen ' +  (currentIndex + 1) + ' de ' + currentArray.length + '</span>';
				}
			});



diapo = 1;
diapomini = 1;



function pasadia(id){
	
	diapo=id;
	ta = id -1;
	ta = ta*($("#fotos").width()+5);
	
					 $('#fotosriel').animate({marginLeft: '-'+ta+'px' }, {duration: 1000,specialEasing: {marginLeft: 'easeInOutBack'},complete: function() {}});
											
	
	}
	
	
	
function pasaauto(){
	
	//alert ($('#fotosriel').attr('rel'));
	diapo++;
	if (diapo==(parseInt($('#fotosriel').attr('rel'))+1))
		diapo=1;
	imageresize();
	
	
	
	pasadia(diapo);
	
	$.timeout(function() {pasaauto(); }, 7000);
}
$.timeout(function() {pasaauto(); }, 7000);





function btnnoticias(){
	
	//alert ($('#fotosriel').attr('rel'));
	
	
		$('.buttonnotfon2').animate({opacity: '0' }, {duration: 1000,specialEasing: {marginLeft: 'easeInOutBack'},complete: function() {
																																	 
																																	 
																															$.timeout(function() {
																																			   
																																	$('.buttonnotfon2').animate({opacity: '1' }, {duration: 1000,specialEasing: {marginLeft: 'easeInOutBack'},complete: function() {	 $.timeout(function() {btnnoticias(); }, 600);}});	   
																																			   
																																			   
																																			   
																																			   }, 600);		 
																																	 
																																	 }});
	
	
	
	
}
$.timeout(function() {btnnoticias(); }, 600);




$("#fotoverimg").hover(
  function () {
    $(this).attr({src:"img/verfotob.png"}); 
  },
  function () {
    $(this).attr({src:"img/verfoto.png"}); 
  }
);


$("#fotosubeimg").hover(
  function () {
    $(this).attr({src:"img/subeb.png"}); 
  },
  function () {
    $(this).attr({src:"img/sube.png"}); 
  }
);


$("#videoverimg").hover(
  function () {
    $(this).attr({src:"img/vervideob.png"}); 
  },
  function () {
    $(this).attr({src:"img/vervideo.png"}); 
  }
);


$("#videosubeimg").hover(
  function () {
    $(this).attr({src:"img/subevideob.png"}); 
  },
  function () {
    $(this).attr({src:"img/subevideo.png"}); 
  }
);


$('#contact #enviar').live("click", function()
	{
		
		var ok=true;
		var elmail=$('#contact INPUT[name=mail]').val();
		var elnombre=$('#contact INPUT[name=nombre]').val();
		var lafoto=$('#contact INPUT[name=foto]').val();
		
		if (elnombre=='')
		{
			var ok=false;
			$('#contact INPUT[name=nombre]').css('border','1px solid red');
			$('#statusnombre').html('El nombre es obligatorio');
			
			
		}else{
			
			$('#contact INPUT[name=nombre]').css('border','0px');
			$('#statusnombre').html('');
		}
		
		if (elmail=='')
		{
			var ok=false;
			$('#contact INPUT[name=mail]').css('border','1px solid red');
			$('#statusnombre').html('El mail es obligatorio');
			
			
		}else{
			
			$('#contact INPUT[name=mail]').css('border','0px');
			$('#statusnombre').html('');
		
		}
		if ((elmail.length>7) && (elmail.lastIndexOf(".") > 2) && (elmail.indexOf("@") > 0) && (elmail.lastIndexOf(".") > (elmail.indexOf("@")+1)) && (elmail.indexOf("@") == elmail.lastIndexOf("@") && (elmail.lastIndexOf(".")<(elmail.length-2))))
		{
			$('#contact INPUT[name=mail]').css('border','0px');
		}
		else
		{
			var ok=false;
			$('#contact INPUT[name=mail]').css('border','1px solid red');
			$('#statusemail').html('El E-mail no es correcto');
			
		}
		
		
		
		if (lafoto=='')
		{
			var ok=false;
			$('#contact INPUT[name=foto]').css('border','1px solid red');
			$('#statusnombre').html('La foto es obligatoria');
			
			
		}else{
			
			$('#contact INPUT[name=foto]').css('border','0px');
			$('#statusnombre').html('');
		}
		
		if (ok==true)
		{
			
			document.forms.contact.submit();
			
		}else{
		return false;
		}
	});




}
