$(document).ready(function() {
	$('li:first').addClass('first');

	$('input.default-value').each(function() {
		$(this).focus(function() {
			if ($(this).attr('title') == $(this).attr('value')) {
				$(this).attr('value', '');
				$(this).removeClass('default-value');
			}
		});
		$(this).blur(function() {
			if (!$(this).attr('value')) {
				$(this).attr('value', $(this).attr('title'));
				$(this).addClass('default-value');
			}
		});
	});
	
	$('#home-recent li h3').addClass('acs');
	$('#home-recent li p.desc').addClass('acs');
	$('#home-recent li p.preview').css('display', 'none');
	$('#home-recent li:first h3').removeClass('acs');
	$('#home-recent li:first p.desc').removeClass('acs');
	$("#home-recent li p.thumb").hover(
		function () {
			$('#home-recent li h3').addClass('acs');
			$('#home-recent li p.desc').addClass('acs');
			//$('#home-recent li p.preview').css('display', 'none');
			$(this).parent().children('h3').removeClass('acs');
			$(this).parent().children('p.desc').removeClass('acs');
		}, 
		function () {
		}
  );
	$("#home-recent li p.thumb").click(function () {
		$('#home-recent li p.preview').hide();
		$(this).parent().children('p.preview').fadeIn(400);
		$(this).parent().children('p.preview').css('margin-top', -($(this).parent().children('p.preview').height()));
	});
	
	$('.accordion .tab').css('display', 'none');
	$('.accordion h3 a').each(function() {
		$(this).click(function() {
			if (!$(this).parent().hasClass('active')) {
				$('.accordion h3 a').each(function() {
					if ($(this).parent().hasClass('active')) {
						$(this).parent().next().hide('blind');
						$(this).parent().removeClass('active');
					}
				});
				$(this).parent().addClass('active');
				$(this).parent().next().show('blind', false, 1000);
			} else {
				$(this).parent().next().hide('blind');
				$(this).parent().removeClass('active');
			}
			return false;
		});
	});
	
	$(".accordion h3 a").hover(function() {
		$(this).animate({ color: "#6699cc" }, 100);
	},function() {
		if (!$(this).parent().hasClass('active')) {
			$(this).animate({ color: "#ccc" }, 700);
		}
	});
	
	$("#clients li a").fancybox();
	
	$('#projects li a').click(function() {
		$('#projects li').removeClass('active');
		$('#column-d .project').hide();
		$(this).parent().addClass('active');
		$($(this).attr('href')).show('blind');
		return false;
	});
	$('#column-d .project').hide();
	$('#column-d .project:first').show();
	$('#projects li:first').addClass('active');
	
	if (window.location.href.indexOf('#') != -1) {
		var sId = window.location.href.slice(window.location.href.indexOf('#'));
		$(sId).show('blind', false, 1000);
		$('.accordion h3 a').each(function() {
			if (sId == $(this).attr('href')) {
				$(this).parent().addClass('active');
			}
		});
	}
	
	$('#contact form').hide();
	$('#contact a.more').click(function() {
		if (!$(this).parent().hasClass('active')) {
			$('#contact form').show('blind');
			$(this).parent().addClass('active');
		} else {
			$('#contact form').hide('blind');
			$(this).parent().removeClass('active');
		}
		return false;
	});
	$('#contact h2 a').click(function() {
		if (!$('#contact a.more').parent().hasClass('active')) {
			$('#contact form').show('blind');
			$('#contact a.more').parent().addClass('active');
		} else {
			$('#contact form').hide('blind');
			$('#contact a.more').parent().removeClass('active');
		}
		return false;
	});
	$('#contact form').submit(function() {
		if ('' == $('#contact-name').val() || '' == $('#contact-email').val()) {
			alert('Los campos "Nombre" e "Email" son obligatorios');
			return false;
		} else {
			return true;
		}
	});
	
	$('#home-facebook iframe').hide();
	$('#home-facebook h2 a').click(function() {
		if (!$(this).parent().hasClass('active')) {
			if ($('#home-twitter h2').hasClass('active')) {
				$('#home-twitter ul').hide('blind');
				$('#home-twitter h2').removeClass('active');
			}
			$('#home-facebook iframe').show('blind');
			$(this).parent().addClass('active');
		} else {
			$('#home-facebook iframe').hide('blind');
			$(this).parent().removeClass('active');
		}
		return false;
	});

	$('#home-twitter ul').hide();
	$('#home-twitter h2 a').click(function() {
		if (!$(this).parent().hasClass('active')) {
			if ($('#home-facebook h2').hasClass('active')) {
				$('#home-facebook iframe').hide('blind');
				$('#home-facebook h2').removeClass('active');
			}
			$('#home-twitter ul').show('blind');
			$(this).parent().addClass('active');
		} else {
			$('#home-twitter ul').hide('blind');
			$(this).parent().removeClass('active');
		}
		return false;
	});
});
