/*AEH WEBSITE JQUERY INTERACTION CODE
(c) 2011, Daniel Freese*/

$(document).ready(function(){

	/*NAVIGATION PAGE CHANGE*/
	$('#navlist a').click(function() {
	
		pagename="#"+$('.active').attr('id')+'_page';
		newpage="#"+$(this).attr('id');
		$('.active').removeClass('active');
		$(newpage).addClass('active');
		$(pagename).slideUp('slow',	function() 
									{
									pagename=newpage+'_page';
									$(pagename).slideDown('slow');
									}
							);
		
		
		return false;	  	  
	});
	
	/*SOCIAL LINKS HOVER ANIMATION*/	
	$("#friends a").hover(function() {
        $(this).stop().animate({ marginTop: "-10px" }, 200);
        },
		function(){
        $(this).stop().animate({ marginTop: "0px" }, 300);
        });

		
		
	/*VOCALIAS BIO SHOW/HIDE*/
	$('.clickhere').click(function() {
		biotoshow='#'+$(this).attr('name')+'_bio';
		if ($(biotoshow).hasClass('hidebio')==true) 
			{
				$(biotoshow).slideDown('slow');
				$(biotoshow).removeClass('hidebio');
			}
		else 	{ 	$(biotoshow).slideUp('slow');
					$(biotoshow).addClass('hidebio');
				}
	});
	
	$(".clickhere").hover(function() {
        $(this).css({ color: "#2D4E77" });
        },
		function(){
        $(this).css({ color: "#E10108" });
        });

	/*OPENING OF NEW WINDOW WITH GOOGLEMAPS*/
	$('.postcode').click(function() {
	URL = $(this).attr('href');
	id = 'postcode';
	window.open(URL, id , 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=800,height=600');
	return false;
	});
	
	/*REDIRECT TO ACTIVIDADES PAGE WHEN CLICKING ON PROXIMO ACTIVIDAD*/
	$('#ticketstub').click(function() {
	display = $('#actividades_page').css('display');
	if (display=='none'){ $('#actividades').click(); }
	else {return false;}
	});
	
	/*VALIDATING AND AJAX CALL FROM CONTACTAR PAGE*/
	$("#emailform").validate({
							rules: 
							{
							firstname: "required",
							lastname: "required",
							email: 	{
							required: true,
							email: true
									}
							},
							messages: {
							firstname: "Por favor escribe su nombre",
							lastname: "Por favor escribe su apellidos",
							email: 	{
							required: "Por favor escribe su email",
							email: "Por favor comprueve su direccion"
									}
							},
							submitHandler: function() { 
														var datatosend = $('#emailform').serialize();
														$.ajax({
																type: "POST",
																url: "php/sendmail.php",
																data: datatosend,
																success: function(msg){
																			$('#message').html(msg);
																			$(':input','#emailform')
																			.not(':button, :submit, :reset, :hidden')
																			.val('')
																			}
														});
														}

	});
	
	/*REDIRECT TO CONTACTAR PAGE WHEN CLICKING ON EL FORMULARIO ON ASOCIARSE PAGE*/
	$('#formulario').click(function() {
	$('#contactar').click(); 
	return false;
	});
	
	/*FOTOS PAGE*/
	$('.rightarrow').click(function() {
			if( $(this).siblings('div.thumbcont').children('ul').is(':animated') ){ return false;}
			var horpos = parseInt($(this).siblings().children('ul').css('left'));
			if (horpos==0) {$(this).siblings('div.leftarrow').css('display','block');}
			$(this).siblings('div.thumbcont').children('ul').animate({left: '-=750'},3000); 
			
	});
	$('.leftarrow').click(function() {
			if( $(this).siblings('div.thumbcont').children('ul').is(':animated') ){ return false;}
			var horpos = parseInt($(this).siblings().children('ul').css('left'));
			if (horpos==(-750)) {$(this).css('display','none');}
			$(this).siblings().children('ul').animate({left: '+=750'},3000); 
	});
	
	/*NAMING CONVENTION: GALLERIES 1...  THUMBNAILS 1...  LARGE PHOTOS (600PX*400PX) 1_BIG.JPG.....*/
	$('#fotos_page ul img').click(function() {
			var galnum = $(this).closest('div.thumbcont').attr('id');
			var imgname = $(this).attr('alt');
			var imgname = 'images/galleries/gallery'+galnum+'/large/'+imgname+'.jpg';
			
			$('#bigphoto p').text(imgname);
			$('#bigphoto img').attr('src' ,imgname);
			$('#bigphoto').show('slow');
			
	});
	$('#close').click(function() {
			$('#bigphoto').hide('slow');
			
	});
	
	
	
});
