$(document).ready(function() {
 
	$(".project_thumb, .project_thumb_last").hover(function() { //On hover...
 
		//var thumbOver = $(this).find("img.img_gris").attr("src"); //Obtiene la imagen y la asigna a 'thumbOver'
 
		//Especifica imagen de fondo(thumbOver) en el tag <a> - Establece la posición en el pie
		//$(this).find("a.thumb").css({'background' : 'url(' + thumbOver + ') no-repeat center bottom'});
 
		//Fade out de la imagen hasta opacidad 0
		$(this).find("img.img_gris").stop().fadeTo('fast', 0 , function() {
			$(this).hide() //Hide the image after fade
		});
		$(this).find("img.img_azul").stop().fadeTo('fast', 0 , function() {
			$(this).hide() //Hide the image after fade
		});
		
		$(this).find(".thumb_title span.activo a").animate({color: '#009CE1'}, "fast");
	} , function() { //al hacer el over out...
		//Fade the image to full opacity 
		$(this).find("img.img_gris").stop().fadeTo('fast', 1).show();
		$(this).find("img.img_azul").stop().fadeTo('fast', 1).show();
		$(this).find(".thumb_title span.activo a").animate({color: '#A3A19F'}, "fast");
	});
	
	$('#featured').orbit({
		animation : "horizontal-push",
		afterSlideChange: textSlides		
	});
	
	$('#featured2').orbit({
		animation : "horizontal-push",
		advanceSpeed: 20000,
		afterSlideChange: textSlides
	});
	
	$('ul#paginacion_blog a').click(function() {
		var id = $(this).attr("id");
		changePanel(id);
		return false;
	});
	
	$('#panelAnterior').click(function () {
		var id = $('ul#paginacion_blog a.active').attr("id");
		id = parseInt(id) - 1;
		if (id>=0) {
			changePanel(id);
		}
		return false;
	});
	$('#panelPosterior').click(function () {
		var id = $('ul#paginacion_blog a.active').attr("id");
		id = parseInt(id) + 1;
		if ($('div#paneles div.panel-' + id).length>0) {
			changePanel(id);
		}
		return false;
	});
	
});

function changePanel(id) {
	$('div#paneles div.panelBlock').hide();
	$('div#paneles div.panel-' + id).show();
	
	$('ul#paginacion_blog a').removeClass("active");
	$('ul#paginacion_blog li').removeClass("active");
	$('ul#paginacion_blog a#' + id).addClass("active");
	$('ul#paginacion_blog li#' + id).addClass("active");
	
	$.scrollTo( 0,0,{ duration: 1000 } );
}

function textSlides() {
	//var theTitle = $(this).attr('textCaption');
	//var theLink = $(this).attr('textLink');
	
	var id  = $(this).attr('id');
	var theTitle = $("#textCaption" + id).val();
	var theLink = $("#textLink" + id).val();
	
	//$("span#titleDestacado").text(theTitle).fadeIn().delay(2000).fadeOut(200);
	$('span#titleDestacado').animate({opacity: 0 }, 200, function() { $("span#titleDestacado").html(theTitle).animate({opacity: 100 }, 200)});
	$("span#linkDestacado").html(theLink);
}
