document.oncontextmenu = function(){return false}

$(function(){
// carga de las fotos
	$('#summary').fadeIn('slow');
	
	/**
	 * All the functions below, are used to update the summary div
	 * That is not the objective of the plugin, the really important part 
	 * is the one right below. The option placeholder, and threshold.
	 */
	$.preload( '#content img', {//the first argument is a selector to the images
		onRequest:request,
		onComplete:complete,
		onFinish:finish,
		threshold: 2 //'2' is the default, how many at a time, to load.
	});
	
	function update( data ){
		$('#done').html( ''+data.done );
		$('#total').html( ''+data.total );
		$('#loaded').html( ''+data.loaded );
		$('#failed').html( ''+data.failed );
	};
	function complete( data ){
		update( data );
		$('#image-next').html( 'none' );//reset the "loading: xxxx"
		$('#image-loaded').html( data.image );
	};
	function request( data ){
		update( data );
		$('#image-next').html( data.image );//set the "loading: xxxx"
	};
	function finish(){//hide the summary
		$('#summary').fadeOut('slow');
	};

// movimiento de las fotos
// RETRATOS
//	var anchoRetr =  "560";
	var anchoRetr =  $('#retratos li').find('img:first').width();
	var cuantosRetr = $('#retratos li').size();
	var sumaTotalRetr = cuantosRetr*560-560;

	$('#nav_next_retr').click(function(){
		var margenIzqRetr = parseInt($('#retratos ul').css("left").substring(0,$('#retratos ul').css("left").indexOf("px")));
		var sumaNextRetr = margenIzqRetr-560;
		
		if(margenIzqRetr < -sumaTotalRetr-560/2.5 || margenIzqRetr == -sumaTotalRetr){
			$('#retratos ul').stop();
		} else {
			$('#retratos ul').animate({'left':sumaNextRetr},{queue:false, duration:600, easing:"easeOutExpo"});
		}
		
	});
	$('#nav_prev_retr').click(function(){
		var margenIzqRetr = parseInt($('#retratos ul').css("left").substring(0,$('#retratos ul').css("left").indexOf("px")));
		var sumaPrevRetr = margenIzqRetr+560;
		
		if(margenIzqRetr > 0 || margenIzqRetr == 0){
			$('#retratos ul').stop();
		} else {
			$('#retratos ul').animate({'left':sumaPrevRetr},{queue:false, duration:600, easing:"easeOutExpo"});
		};
		
	});

	// MISCELANEOS
		var anchoMisc =  $('#retratos li').find('img:first').width();
		var cuantosMisc = $('#miscelaneos li').size();
		var sumaTotalMisc = cuantosMisc*800-800;

		$('#nav_next_misc').click(function(){
			var margenIzqMisc = parseInt($('#miscelaneos ul').css("left").substring(0,$('#miscelaneos ul').css("left").indexOf("px")));
			var sumaNextMisc = margenIzqMisc-800;

			if(margenIzqMisc < -sumaTotalMisc+800/2.5 || margenIzqMisc == -sumaTotalMisc){
				$('#miscelaneos ul').stop();
			} else {
				$('#miscelaneos ul').animate({'left':sumaNextMisc},{queue:false, duration:800, easing:"easeOutExpo"});
			}

		});
		$('#nav_prev_misc').click(function(){
			var margenIzqMisc = parseInt($('#miscelaneos ul').css("left").substring(0,$('#miscelaneos ul').css("left").indexOf("px")));
			var sumaPrevMisc = margenIzqMisc+560;

			if(margenIzqMisc > 0 || margenIzqMisc == 0){
				$('#miscelaneos ul').stop();
			} else {
				$('#miscelaneos ul').animate({'left':sumaPrevMisc},{queue:false, duration:600, easing:"easeOutExpo"});
			};

		});


	
	// OBJETOS
		var anchoObj =  $('#retratos li').find('img:first').width();
		var cuantosObj = $('#objetos li').size();
		var sumaTotalObj = cuantosObj*560-560;

		$('#nav_next_obj').click(function(){
			var margenIzqObj = parseInt($('#objetos ul').css("left").substring(0,$('#objetos ul').css("left").indexOf("px")));
			var sumaNextObj = margenIzqObj-560;

			if(margenIzqObj < -sumaTotalObj+560/2.5 || margenIzqObj == -sumaTotalObj){
				$('#objetos ul').stop();
			} else {
				$('#objetos ul').animate({'left':sumaNextObj},{queue:false, duration:600, easing:"easeOutExpo"});
			}

		});
		$('#nav_prev_obj').click(function(){
			var margenIzqObj = parseInt($('#objetos ul').css("left").substring(0,$('#objetos ul').css("left").indexOf("px")));
			var sumaPrevObj = margenIzqObj+560;

			if(margenIzqObj > 0 || margenIzqObj == 0){
				$('#objetos ul').stop();
			} else {
				$('#objetos ul').animate({'left':sumaPrevObj},{queue:false, duration:600, easing:"easeOutExpo"});
			};

		});

	// Peoples
		var anchoPeoples  =  $('#retratos li').find('img:first').width();
		var cuantosPeoples = $('#peoples li').size();
		var sumaTotalPeoples = cuantosMisc*800-800;

		$('#nav_next_peoples').click(function(){
			var margenIzqPeoples = parseInt($('#peoples ul').css("left").substring(0,$('#peoples ul').css("left").indexOf("px")));
			var sumaNextPeoples = margenIzqPeoples-800;

			if(margenIzqPeoples < -sumaTotalPeoples+800/2.5 || margenIzqPeoples == -sumaTotalPeoples){
				$('#peoples ul').stop();
			} else {
				$('#peoples ul').animate({'left':sumaNextPeoples},{queue:false, duration:800, easing:"easeOutExpo"});
			}

		});
		$('#nav_prev_peoples').click(function(){
			var margenIzqPeoples = parseInt($('#peoples ul').css("left").substring(0,$('#peoples ul').css("left").indexOf("px")));
			var sumaPrevPeoples = margenIzqPeoples+560;

			if(margenIzqPeoples > 0 || margenIzqPeoples == 0){
				$('#peoples ul').stop();
			} else {
				$('#peoples ul').animate({'left':sumaPrevPeoples},{queue:false, duration:600, easing:"easeOutExpo"});
			};

		});

// opacidad del nav			
	$('#nav_prev_retr, #nav_next_retr, #nav_next_obj, #nav_prev_obj, #nav_next_misc, #nav_prev_misc, #nav_next_peoples, #nav_prev_peoples').hover(
		function(){
			$(this).fadeTo(200,1.0); //fadeIn
		},
		function(){
			$(this).fadeTo(200,0.5); //fadeOut
		}
	);
// movimiento de botones		
	$('.boton').hover(
		function(){
			$(this).animate({right:10},{duration:1000, easing:'easeOutExpo', queue:false});
		},
		function(){
			$(this).animate({right:0},{duration:1000, easing:'easeOutExpo', queue:false});
		}
	);
	
	$('.boton').click(function(){
		$(this).show({right:30});	  
	});
	
	
// mov de las galerias de fotos

	$('#btn_retratos').click(function(){
		$('#content').animate({top:0},900, 'easeOutCirc');
		$('#posicion').animate({top:342},900, 'easeOutCirc');
	});
	$('#btn_miscelaneos').click(function(){
		$('#content').animate({top:-900},900, 'easeOutCirc');
		$('#posicion').animate({top:387},900, 'easeOutCirc');
	});
	$('#btn_objetos').click(function(){
		$('#content').animate({top:-1800},900, 'easeOutCirc');
		$('#posicion').animate({top:430},900, 'easeOutCirc');
	});
	$('#btn_peoples').click(function(){
		$('#content').animate({top:-2700},900, 'easeOutCirc');
		$('#posicion').animate({top:480},900, 'easeOutCirc');
	});
	
// esconde toda la shit

	$('#escondeTodo').click(function(){
		$(this).animate({top:-200},900, 'easeOutBack');
		$('#display').animate({left:-330},900, 'easeOutBack');
		$('.fotos').animate({left:-330},900, 'easeOutBack');
		$('#footer').animate({left:-330},900, 'easeOutBack');
		$('#caja, #contacto').animate({top:-1000},900, 'easeOutBack');
		$('#xiiivii').animate({right:-160},900, 'easeOutBack');
		$('#nav_prev_retr,#nav_prev_obj,#nav_prev_misc,#nav_prev_peoples').animate({left:330}),900, 'easeOutBack';
		$('#nav_next_retr,#nav_next_obj,#nav_next_misc,#nav_next_peoples').animate({right:0},900, 'easeOutBack');
		$('#muestraTodo').show().animate({bottom:0},900, 'easeOutBack');
	});
	$('#muestraTodo').click(function(){
		$(this).animate({bottom:-100},900, 'easeOutBack').hide();
		$('.fotos').animate({left:0},900, 'easeOutBack');	
		$('#footer').animate({left:30},900, 'easeOutBack');
		$('#display').animate({left:10},900, 'easeOutBack');
		$('#xiiivii').animate({right:0},900, 'easeOutBack');
		$('#nav_prev_retr,#nav_prev_obj,#nav_prev_misc,#nav_prev_peoples').animate({left:340}),900, 'easeOutBack';
		$('#nav_next_retr,#nav_next_obj,#nav_next_misc,#nav_next_peoples').animate({right:330},900, 'easeOutBack');
		$('#escondeTodo').show().animate({top:10},900, 'easeOutBack');
	});


		
//show info
	$("a#about").click(function () {
		$("#caja").animate({top:0},900, 'easeOutSine');
		$("#contacto").animate({top:-1000},500, 'easeOutSine');
		$("#escondeTodo").animate({top:-200},'slow');
		$('#nav_prev_retr,#nav_prev_obj,#nav_prev_misc,#nav_prev_peoples').animate({left:710});
	});
	
	$("a#contact").click(function () {
		$("#contacto").animate({top:0},900, 'easeOutSine');
		$("#caja").animate({top:-1000},500, 'easeOutSine');
		$("#escondeTodo").animate({top:-200},'slow');
		$('#nav_prev_retr,#nav_prev_obj,#nav_prev_misc,#nav_prev_peoples').animate({left:710});
    });
	
	$("a#cerraruno").click(function () {
		$("#caja").animate({top:-1000},'slow');
		$('#escondeTodo').show().animate({top:10},'slow');
		$('#nav_prev_retr,#nav_prev_obj,#nav_prev_misc,#nav_prev_peoples').animate({left:340});
    });
	
	$("a#cerrardos").click(function () {
		$("#contacto").animate({top:-1000},'slow');
		$('#escondeTodo').show().animate({top:10},'slow');
		$('#nav_prev_retr,#nav_prev_obj,#nav_prev_misc,#nav_prev_peoples').animate({left:340});
    });
	
// :focus y :blur a los campos de contacto
	$('#datos input, #datos textarea').each(function(){
		var msg = $(this).val();
		$(this).focus(function(){	
			if ($(this).val() == msg){
				$(this).val("");
			}
		});
		$(this).blur(function(){
			if (jQuery.trim($(this).val()) == ""){
				$(this).val(msg);			
			}	
		});
	});

// validate the comment form when it is submitted
	$("#datos").validate();
	
//hide all the images on the page
	

}); // end domReady baby!

//abrir en ventanas externas
function externalLinks() {
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];
		if (
			anchor.getAttribute("href") && ( 
			anchor.getAttribute("rel") == "external" || 
			anchor.getAttribute("rel") == "external nofollow" || 
			anchor.getAttribute("rel") == "nofollow external" )
			)
		anchor.target = "_blank";
	}
}

// preloader imgs

