$(document).ready(function(){	
	Shadowbox.init();
	
	$("#listado_destacados").carouFredSel({
		pauseDuration : 10,
		scroll : {
			items           : 4,
			duration        : 1500
		},
		auto : false,
		prev : {   
			button  : "#destacadas_ant",
			key     : "left",
			duration: 1500
		},
		next : {
			button  : "#destacadas_sig",
			key     : "right",
			duration: 1500
		},
		items: 4
	});
	
	$("#listado_enlaces").carouFredSel({
		pauseDuration : 10,
		scroll : {
			items           : 4,
			duration        : 1500
		},
		auto : false,
		prev : {   
			button  : "#enlaces_ant",
			key     : "left",
			duration: 1500
		},
		next : {
			button  : "#enlaces_sig",
			key     : "right",
			duration: 1500
		},
		items: 4
	});
	
	$("#propiedades_destacadas a.imagen")
		.hover(function(){
			$(this).find("span").stop().animate({opacity: 0.5},500);	
		}, function(){
			$(this).find("span").stop().animate({opacity: 0},250);	
		}
	);
	
	$("#destacadas_lateral a.imagen")
		.hover(function(){
			$(this).find("span").stop().animate({opacity: 0.5},500);	
		}, function(){
			$(this).find("span").stop().animate({opacity: 0},250);	
		}
	);
	
	$("#listado_enlaces a.imagen")
		.hover(function(){
			$(this).find("span").stop().animate({opacity: 0.5},500);	
		}, function(){
			$(this).find("span").stop().animate({opacity: 0},250);	
		}
	);
	
});

var actual = 1;

function mover_portafolio(total){
	$("#elemento_"+actual).fadeOut(1600, function(){
			for(i=1; i<=total; i++){
				indice_actual = parseInt($("#elemento_"+i).css("z-index"));
				$("#elemento_"+i).css("z-index", parseInt(indice_actual)+1);
			}
			$("#elemento_"+actual).css("z-index", "1");
			anterior = actual;
			if(actual < total){
				actual++;
			}
			else{
				actual = 1;	
			}
			$("#elemento_"+actual).fadeIn(1600);
			$("#elemento_"+anterior).css("display", "block");
	});
}

function newsletterSubmit(enlace, value){
	var filter=/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
	if (filter.test(value)) {
		$('#enlaceNewsletter').attr('href', enlace+'?email='+value);
		Shadowbox.init();
		Shadowbox.open({
			content:    $('#enlaceNewsletter').attr('href'),
			player:     "iframe",
			height:     150,
			width:      500
		});	
	
		
	}
	else{
		$('.newsletter #email').val('');
		$('.newsletter #email').focus(); 
	}
}
