function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}


function Decimales(Numero, Decimales) {

	pot = Math.pow(10,Decimales);
	num = parseInt(Numero * pot) / pot;
	nume = num.toString().split('.');

	entero = nume[0];
	decima = nume[1];

	if (decima != undefined) {
		fin = Decimales-decima.length; }
	else {
		decima = '';
		fin = Decimales; }

	for(i=0;i<fin;i++)
	  decima+=String.fromCharCode(48); 

	num=entero+'.'+decima;
	return num;
}

// initialise plugins
$(document).ready(function() {
	$('#menuhori ul').superfish();

	$('#menuhori > ul').lcmsDistHorizontal();	
	$('.menupie').lcmsDistHorizontal();	
	$('#slideshowpage').lcmsSlideShow();
	$('ul.sf-menu > li').lcmsVertAlign(); // Alinear contenido vertical dentro de los li
	$('ul.sf-menu > li > ul > li').lcmsVertAlign(); // Alinear contenido vertical dentro de los li
	
	$('.alivert').lcmsVertAlign();	
	

	$('a.mosaico, a.mosaicolast').bind("click", function(){										  
		var _href= $(this).attr("href");
		$('#fotoG').attr("src",_href);
		return false;
		
	});

	$(".scrollableg").scrollable({circular: true,  speed: '1500'}).navigator().autoscroll();
	
	
	
	
		
});

/* Reparte el ancho total entre los hijos al 100% del contenedor */
(function( $ ){
  $.fn.lcmsDistHorizontal = function() {
   
    var $t = $(this);
	
	var anchoCont = $t.width();
	var numItems  = $t.children().size();
	var anchoItem = Math.floor(anchoCont/numItems);
	//alert(anchoCont+" - "+numItems+ " - "+anchoItem);
 	$t.children().width(anchoItem);	
  };
})( jQuery );



/* Alinear su contenido verticalmente */
(function( $ ){
  	$.fn.lcmsVertAlign = function() {

		var $t = $(this);
		var offset=0;
		// Solo buscamos elementos de primer nivel		
		$t.find(":first").each(function() {
			$(this).wrapInner('<div class="lcmsvert" />');
		
    		$(this).children('.lcmsvert').css({
        		overflow: 'hidden'
    		});
    	
			var box_height     = $(this).children().height();
    		var container_height = $(this).height();
    		var center_pad     = (container_height - box_height)/2;
    		$(this).children('.lcmsvert').css('padding', (center_pad + offset) + 'px 0 ' + (center_pad - offset) + 'px');
  		});
  };
})( jQuery );


/* Slide show */
(function( $ ){
  $.fn.lcmsSlideShow = function() {
	  
    var $t = $(this);
	   
    setInterval(function() {

		var $active = $t.children('.active');
    	if ($active.length == 0) $active = $t.children(':last');
		// los elementos se muestran en el orden que esten en el codigo
    	//var $next =  $active.next().length ? $active.next() :  $t.children(':first');

		// los elementos se muestran de forma aleatoria
		var $sibs  = $active.siblings();
    	var rndNum = Math.floor(Math.random() * $sibs.length );
    	var $next  = $($sibs[ rndNum ]);	
		$active.addClass('last-active');

    	$next.css({opacity: 0.0})
        						.addClass('active')
        						.animate({opacity: 1.0}, 1000, function() {
            						$active.removeClass('active last-active');
        						});
	
	}, 5000);
  
  };
})( jQuery );


