$(document).ready(function(){
	elpath=window.location+"_";
	if(elpath.substr(elpath.length-10,8)=="#imagen_" || elpath.substr(elpath.length-11,8)=="#imagen_" || elpath.substr(elpath.length-9,8)=="#archivo"){
		$('#path_proyecto a').html('<span>&lt;-</span> Archivo de proyectos');
		$('#path_proyecto a').attr('href','/archivo');
		$('#path_proyecto').attr('class','');
		$('#path_logico').css({'left':'130px'});
		$('#path_proyecto a').css({'padding-left':'49px'});
		
	}
	fp_ajusta_titulos();
	fp_pon_flash();
	fp_cierra_titulo_si_enlace_a_imagen();
});

var descripciones_posicion_top=Array();


fp_ajusta_titulos=function(){
	$('#datos_h1 h1').css('background-position',($('#datos_h1 h1').width()+33)+'px -38px');
	$('#datos_h1 h1').click(function(){
		fp_descripciones_cambia();
	});
	$('#datos_h1 h1').mouseover(function(){
		if(fp_descripciones_visibles){
			$(this).css('background-position',($('#datos_h1 h1').width()+33)+'px -90px');
		} else {
			$(this).css('background-position',($('#datos_h1 h1').width()+33)+'px -132px');
		}
		
	});
	$('#datos_h1 h1').mouseout(function(){
		if(fp_descripciones_visibles){
			$(this).css('background-position',($('#datos_h1 h1').width()+33)+'px 4px');
		} else {
			$(this).css('background-position',($('#datos_h1 h1').width()+33)+'px -38px');
		}
	});
	$('#proyecto_ficha a.enlace_web').css('background-position','-1000px 4px');
	$('#proyecto_ficha a.enlace_web').mouseover(function(){
		$(this).css('background-position',($('#proyecto_ficha a.enlace_web').width()+33)+'px -46px');
	});
	$('#proyecto_ficha a.enlace_web').mouseout(function(){
		$(this).css('background-position',($('#proyecto_ficha a.enlace_web').width()+33)+'px 4px');
	});
	
	if(esie6){
		$('div.dato_1_linea_1').css('top',(128+$('div#descripciones').height()-96)+"px");
		// $('div.dato_1_linea_1').css('top',"0px");
		// descripciones_posicion_top[0]=(128+$('div#descripciones').height()-96);
		$('div.dato_1_linea_2').css('top',(128+$('div#descripciones').height()+32-96)+"px");
		// $('div.dato_1_linea_2').css('top',"0px");
		// descripciones_posicion_top[1]=(128+$('div#descripciones').height()+32-96);	
	} else {
		$('div.dato_1_linea_1').css('top',(128+$('div#descripciones').height())+"px");
		// $('div.dato_1_linea_1').css('top',"96px");
		// descripciones_posicion_top[0]=(128+$('div#descripciones').height());
		$('div.dato_1_linea_2').css('top',(128+$('div#descripciones').height()+32)+"px");
		// $('div.dato_1_linea_2').css('top',"96px");
		// descripciones_posicion_top[1]=(128+$('div#descripciones').height()+32);
	}

}

fp_descripciones_cambia=function(){
	if(esie6){
		var suma=-191;
	} else {
		var suma=0;
	}
	if(fp_descripciones_visibles){
		$('div#descripciones').animate({'opacity':'0', 'left':(355+suma)+'px'},100,function(){
			$('div#descripciones').css('display','none');
		});
		$('div.dato_1_linea_1').animate({'opacity':'0', 'left':(545+suma)+'px'},100,function(){
			$('div.dato_1_linea_1').css('display','none');
		});
		$('div.dato_1_linea_2').animate({'opacity':'0', 'left':(545+suma)+'px'},100,function(){
			$('div.dato_1_linea_2').css('display','none');
		});
		$('#datos_h1 h1').css('background-position',($('#datos_h1 h1').width()+33)+'px -132px');
		fp_descripciones_visibles=false;
	} else {
		$('div#descripciones').css('left',(555+suma)+'px')
		$('div.dato_1_linea_1').css('left',(645+suma)+'px')
		$('div.dato_1_linea_2').css('left',(645+suma)+'px')

		$('div.dato_1_linea_2').css('display','block').animate({'opacity':'0'},50,function(){
			$('div.dato_1_linea_2').css('display','block').animate({'opacity':'1', 'left':(545+suma+suma)+'px'},100,function(){
				$('#proyecto_ficha a.enlace_web').css('background-position',($('#proyecto_ficha a.enlace_web').width()+33)+'px 4px');
			});
		});

		$('div.dato_1_linea_1').css('display','block').animate({'opacity':'0'},25,function(){
			$('div.dato_1_linea_1').css('display','block').animate({'opacity':'1', 'left':(545+suma+suma)+'px'},100);
		});
		//$('div#descripciones').css('display','block').animate({'opacity':'0'},50,function(){
			$('div#descripciones').css('display','block').animate({'opacity':'1', 'left':(355+suma)+'px'},100);
		//});
	
		
		$('#datos_h1 h1').css('background-position',($('#datos_h1 h1').width()+33)+'px -90px');
		fp_descripciones_visibles=true;
	}
}

fp_pon_flash=function(){

	$('div.flash_foto').each(function(){
		var autoplay=($(this).attr('class').indexOf('autoplay')>0)?1:0;
		var loop=autoplay;
		var show_portrait=1-autoplay;
		var params = $(this).attr('id').substr(1).split('_');

				$(this).children('span').css('position','absolute');
				$(this).children('span').css('display','block');
				$(this).children('span._1').css('width',params[1]+'px');
				$(this).children('span._1').css('height','0px');
				$(this).children('span._1').css('border-top','1px solid #fff');

				$(this).children('span._2').css('left', ((params[1]*1)-1)+'px');
				$(this).children('span._2').css('width', '0px');
				$(this).children('span._2').css('height', params[2]+'px');
				$(this).children('span._2').css('border-right','1px solid #fff');
				 
				$(this).children('span._3').css('top', ((params[2]*1)-1)+'px');
				$(this).children('span._3').css('width',params[1]+'px');
				$(this).children('span._3').css('height','0px');
				$(this).children('span._3').css('border-bottom','1px solid #fff');
				
				$(this).children('span._4').css('left', '0px');
				$(this).children('span._4').css('width','0px');
				$(this).children('span._4').css('height',params[2]+'px');
				$(this).children('span._4').css('border-left','1px solid #fff');
				if($.browser.chrome){ // para subsanar un error de chrome mac
					$(this).children('div').flash({
						// test_flashvars.swf is the flash document
						swf:	
				'http://vimeo.com/moogaloop.swf?clip_id='+params[0]+'&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait='+show_portrait+'&amp;color=00f909&amp;fullscreen=1',
						flashvars: {
							 clip_id: params[0],
							 server:'vimeo.com',
							 color:'00f909',
							autoplay:autoplay,
						     show_portrait: show_portrait,
						     show_byline: 0,
						     show_title: 0,
							fullscreen:1
							//,
							 //js_api: 1, // required in order to use the Javascript API
							 //js_onLoad: 'vimeo_player_loaded'//, // moogaloop will call this JS function when it's done loading (optional)
							 //js_swf_id: 'v'+params[0]+'_'+params[1]+'_'+params[2] // this will be passed into all event methods so you can keep track of multiple moogaloops (optional)
						},
						width: params[1]+'px',
						height: params[2]+'px',
						params: {
							allowscriptaccess: 'always',
							allowfullscreen: 'true',
							wmode: 'transparent'
						}
						});
						
				} else {
					
					$(this).children('div').flash({
						// test_flashvars.swf is the flash document
						swf:	
				'http://vimeo.com/moogaloop.swf?clip_id='+params[0]+'&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait='+show_portrait+'&amp;color=00f909&amp;fullscreen=1&loop='+loop,
						flashvars: {
							 clip_id: params[0],
							 server:'vimeo.com',
							 color:'00f909',
							autoplay:autoplay,
						     show_portrait: show_portrait,
						     show_byline: 0,
						     show_title: 0,
							fullscreen:1,
							loop:loop
							//,
							 //js_api: 1, // required in order to use the Javascript API
							 //js_onLoad: 'vimeo_player_loaded'//, // moogaloop will call this JS function when it's done loading (optional)
							 //js_swf_id: 'v'+params[0]+'_'+params[1]+'_'+params[2] // this will be passed into all event methods so you can keep track of multiple moogaloops (optional)
						},
						width: params[1]+'px',
						height: params[2]+'px',
						params: {
							allowscriptaccess: 'always',
							allowfullscreen: 'true',
							wmode: 'transparent'
						}
						});
				}
				$(this).css('height',(Math.ceil(params[2]/16)*16)+'px');
					

	});
		
	
}
fp_amplia_pie_de_ficha=function(){
	//console.log(($(window).height()-(96+$('#proyecto_ficha div.recurso:last-of-type').height()))+'px');
	var altura=($(window).height()-(96+$('#proyecto_ficha div.recurso:last-of-type').height()));
	altura=altura>=0?altura:0;
	$('#proyecto_ficha').css('padding-bottom',altura+'px');
//	proyecto_ficha
}

$(window).ready(function(){
	fp_amplia_pie_de_ficha();
});
$(window).resize(function(){
	fp_amplia_pie_de_ficha();
});

$(function(){
    $('a[href*=#]').click(function() {
    	if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') 
        	&& location.hostname == this.hostname) {
            var $target = $(this.hash);
            $target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
            if ($target.length) {
                var targetOffset = $target.offset().top;
                $('html,body').animate({scrollTop: targetOffset}, 200);
				setTimeout('document.location.href="#'+this.hash.slice(1)+'";',201);

				return false;
            }
        }
    });
});

fp_cierra_titulo_si_enlace_a_imagen=function(){ //cierra directamente
	// elpath=window.location+"_";
	// if(elpath.substr(elpath.length-10,8)=="#imagen_" || elpath.substr(elpath.length-11,8)=="#imagen_"){
		$('div#descripciones').css('opacity','0');
		// $('div#descripciones').css('display','none');
		$('div.dato_1_linea_1').css('opacity','0');
		// $('div.dato_1_linea_1').css('display','none');
		$('div.dato_1_linea_2').css('opacity','0');
		// $('div.dato_1_linea_2').css('display','none');
		//$('#datos h1_h1').css('background-position',($('#datos_h1 h1').width()+33)+'px -132px');
		fp_descripciones_visibles=false;
	// }
	
}

