$(document).ready(function() {
	// Custom easing
	$.easing.custom = function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t*t + b;
		return -c/2 * ((t-=2)*t*t*t - 2) + b;
	}
	
	$("#images-container").scrollable({
		size: 1,
		loop: true,
		keyboard: false,
		easing: 'custom', 
		speed: 700
	}).navigator("#thumbnails li");

	$('input[type=file]').each(function(){
		/*$(this).addClass('file').addClass('hidden');*/
		$(this).parent().append($('<div class="fakefile" />').append($('<input type="text" />').attr('id',$(this).attr('id')+'_fake')).append($('<a class="btn file">Examinar</a>')));
		
		$(this).bind('change', function() {
			$('#'+$(this).attr('id')+'_fake').val($(this).val());
		});
		$(this).bind('mouseout', function() {
			$('#'+$(this).attr('id')+'_fake').val($(this).val());
		});
	});
	
	$('#main-nav > li').hover(function(){
		$(this).addClass('hover');
	},function(){
		$(this).removeClass('hover');
	});
	
	// FUNCION QUE SE ENCARGA DE CAMBIAR DE IDIOMA
	$('.cambio_de_idioma').click(function() {
		$.ajax({
			type: "POST",
			url: path_fichero_cambio_idioma,
			data: "idi="+this.lang,
			success: function(vars){
				$("#form_tmp_idiomas").remove();
				$("<form>").attr({"method" : "POST", "id" : "form_tmp_idiomas", "name" : "form_tmp_idiomas"}).appendTo("body");
				
				$('body :input').each( function () {
					$("<input>").attr({"type": "hidden", "id" : $(this).attr("id"), "name" : $(this).attr("name"), "value" : $(this).val()}).appendTo("#form_tmp_idiomas");
				});
			
			/*	$('#form_tmp_idiomas :input').each( function () {
					alert($(this).attr("id") + " = "+ $(this).val());
				});*/
				
				$('#form_tmp_idiomas').submit();
			}
		 });
	});
	
	//	FUNCION QUE SE ENCARGA DE LOS PORGRAMAS
	$('.menu_programas').click(function() {
		var nombre_formulario = "formulario-programas";
		$("#"+nombre_formulario).remove();
		$("<form>").attr({"action" : path_proyectos+this.title+"/", "method" : "POST", "id" : nombre_formulario, "name" : nombre_formulario}).appendTo("body");
		$("<input>").attr({"type": "hidden", "id" : "id_programa", "name" : "id_programa", "value" : this.lang}).appendTo("#"+nombre_formulario);
		$('#'+nombre_formulario).submit();
	});
});
