function mCustomScrollbars(){
	/* 
	malihu custom scrollbar function parameters: 
	1) scroll type (values: "vertical" or "horizontal")
	2) scroll easing amount (0 for no easing) 
	3) scroll easing type 
	4) extra bottom scrolling space for vertical scroll type only (minimum value: 1)
	5) scrollbar height/width adjustment (values: "auto" or "fixed")
	6) mouse-wheel support (values: "yes" or "no")
	7) scrolling via buttons support (values: "yes" or "no")
	8) buttons scrolling speed (values: 1-20, 1 being the slowest)
	*/
	$("#mcs5_container").mCustomScrollbar("horizontal",0,"easeOutQuad",1,"auto","yes","no",20); 
}

/* function to fix the -10000 pixel limit of jquery.animate */
$.fx.prototype.cur = function(){
    if ( this.elem[this.prop] != null && (!this.elem.style || this.elem.style[this.prop] == null) ) {
      return this.elem[ this.prop ];
    }
    var r = parseFloat( jQuery.css( this.elem, this.prop ) );
    return typeof r == 'undefined' ? 0 : r;
}

/* function to load new content dynamically */
function LoadNewContent(id,file){
	$("#"+id+" .customScrollBox .content").load(file,function(){
		mCustomScrollbars();
	});
}

function calcula(objeto){
	$.ancho = 0;
	$('#detalle'+objeto+' .scroll-pane p img').each(function(){
		$.ancho += $(this).outerWidth();
		$.ancho += 21;
	})
	if($.ancho <= 600){
		$.ancho = 600;
	}
	//$.ancho  = $.ancho*2;
	//console.log($.ancho);

	$('#detalle'+objeto+' .scroll-pane p').css({'width':$.ancho});
	//return($.ancho);
}


function proyectos(){
	$('.project').click(function(){
		//console.log('Proyecto: '+$(this).attr('rel'));
		//console.log('Relativo a:'+$($($(this).parent()).parent()).parent().attr('rel'));
		$.proyecto = $(this).attr('rel');
		$.relativo = $($($(this).parent()).parent()).parent().attr('rel');
		    			$('#detalle'+$.relativo+' .scroll-pane p').css({'width':'0px'});
		    			$('.jspPane').css({'left':'0px'});
		$('.detalle[id!="detalle'+$.relativo+'"]').slideUp();
		$.ajax({
  			url: 'inc/modules/detalle/left.php?id='+$.proyecto+'&lang='+$('#idioma').val(),
			success: function(data) {
    		$('#detalle'+$.relativo+' > .left' ).html(data);
    		//console.log('Contenido lado izquierdo cargado.');
  			}
		});
		$.ajax({
  			url: 'inc/modules/detalle/right.php?id='+$.proyecto,
			success: function(data){
	    		$('#detalle'+$.relativo+' .right .scroll-pane p' ).html(data);
	    		//console.log('Contenido lado derecho cargado.');
	
    			//console.log('Abrimos el desplegable');
    			$('#detalle'+$.relativo).slideDown();

    			$('.scroll-pane').jScrollPane(
					{
						autoReinitialise: true,
						autoReinitialiseDelay: 10
					}
				);
	    		$.anchoEspecifico = $('#detalle'+$.relativo+' .right .scroll-pane p input').attr('value');
	    		//console.log('Ancho: '+$.anchoEspecifico);
	    		$('#detalle'+$.relativo+' .scroll-pane p').css({'width':$.anchoEspecifico});

				/*
				setInterval("calcula("+$.relativo+")",10);
				setTimeout("calcula("+$.relativo+"); console.log('Calculando: "+$.relativo+" en ms 100')",100)
				setTimeout("calcula("+$.relativo+"); console.log('Calculando: "+$.relativo+" en ms 300')",300)
				setTimeout("calcula("+$.relativo+"); console.log('Calculando: "+$.relativo+" en ms 500')",500)
				setTimeout("calcula("+$.relativo+"); console.log('Calculando: "+$.relativo+" en ms 1000')",1000)
				setTimeout("calcula("+$.relativo+"); console.log('Calculando: "+$.relativo+" en ms 1500')",1500)
				setTimeout("calcula("+$.relativo+"); console.log('Calculando: "+$.relativo+" en ms 2000')",2000)
				setTimeout("calcula("+$.relativo+"); console.log('Calculando: "+$.relativo+" en ms 2500')",2500)
				setTimeout("calcula("+$.relativo+"); console.log('Calculando: "+$.relativo+" en ms 3000')",3000)
				setTimeout("calcula("+$.relativo+"); console.log('Calculando: "+$.relativo+" en ms 5000')",5000)
				//setTimeout("calcula("+$.relativo+"); console.log('recalculado a 10000')",10000)
	  			//$.ancho = 0;
	  			*/
  			}
		});
	})
	$('.close').click(function(){
		$('#detalle'+$(this).attr('rel')).slideUp();
	})
}

function slides(){
	$('.slideshow').cycle({
		fx: 'fade',
		speed:    2500, 
    	timeout:  4000
	});
	$('.slideshow2').cycle({
		fx: 'fade',
		speed:    1500, 
    	timeout:  1500
	});
}
