// JavaScript Document
$(document).ready(function(){
	/* Funciones Previas */
	var a = 0;
	var b = 0;
	var c = $('#num').val();
	$('ul.port_lista').css({'width': (c*720)+1440}); 
	$('.pantalla').css({'height':$(window).height()})
	/* Al modificar el tamano */
	$(window).resize(function(){
	 var hash=window.location.hash;
							  
	$('.pantalla').css({'height':$(window).height()})
	  $('html').animate({ scrollTop: $(hash).offset().top});})
	$('#menu li a').click(ScrollDiv);
	$('#menu li a').hover(function(){$(this).addClass('active');}, function(){var hr = $(this).attr('href');
if(hr == window.location.hash && window.location.hash != '' ){} else {$(this).removeClass('active');}});
	
	$('#link_folio').click(ScrollFolio);	
	$('.a_next').click(function(){cierra();
	 if(b < c){b++; str = $('ul.port_lista').css('margin-left').replace('px', ''); $('ul.port_lista').animate({'margin-left': str-720}); }
																											 return false});	
		$('.a_back').click(function(){cierra();
	 if(b >= 0){b--; str = $('ul.port_lista').css('margin-left').replace('px', ''); $('ul.port_lista').animate({'margin-left': Number(str)+720}); }
																											 return false});	
	$('.port_foto li').hover(function(){$(this).children('.img1').animate({'opacity': 0});}, function(){$(this).children('.img1').animate({'opacity': 1});})
	
	$('#contact_form').submit(function() {
  $("#contact_form").parent().load('contacto.php?' + $(this).serialize());
  return false;
});
	$('.img1').click(imgClick);
	$('#cerrar').live('click', cerrarImg);
	})



function ScrollDiv(){
	
	var ref = $(this).attr('href');
	$('#menu li a').removeClass('active');

	    $('html').animate({ scrollTop: $(ref).offset().top});
		$(this).addClass('active');

		
		window.location.replace(ref)
		return false

	}
function ScrollFolio(){
	
	$('ul.port_lista').animate({'margin-left':-720});
	return false
	
}

function imgClick(){
	var title = $(this).attr('title');
	var rel = $(this).attr('rel');
	var alt = $(this).attr('alt');

	if(alt.indexOf("youtube") == -1){
		
	$(this).parent().parent().hide('slow');
	$(this).parent().parent().siblings('.hidden').load('image.php?src=' + rel, function(){$(this).children('.obj_img').html('<h3>' + title +'<h3>');$(this).children('.desc_img').html('<p>'+alt+'</p>'); $(this).show('slow'); })
	}
	else {
	$(this).parent().parent().hide('slow');
	$(this).parent().parent().siblings('.hidden').load('image.php?alt=' + encodeURIComponent(alt), function(){$(this).children('.obj_img').html('<h3>' + title +'<h3>'); $(this).show('slow'); })
	
	}
}

function cerrarImg(){
	$(this).parent().hide('slow');
	$(this).parent().siblings('.port_foto').show('slow');
}
function cierra(){
	$('.hidden').hide(); $('.port_foto').show(); }
	
function miHoverOut(){
var hr = $(this).attr('href');
if(hr == window.location.hash){};
alert(hr);

}
