//<![CDATA[
jQuery(function($) {
// extends one gallery class to the other to use the <li> without problems.

$('.jcarousel-skin-tango').addClass('gallery');	

// make automatically the thumbnails

var options = {
	history   : true, // activates the history object for bookmarking, back-button etc.
	insert : '#main_image',
	clickNext : true,
        onImage : function(image,caption,thumb) {
		image.css('display','none').fadeIn(200);
		caption.css('display','none').fadeIn(200);

		var top = ( $('#contenedor ').height() - $('#contenedor #main_image').height() ) / 2;
    		// fetch the thumbnail container
		var _li = thumb.parents('li');

    		$('#contenedor #main_image').css('margin-top', top);
    		
    		// fade out inactive thumbnail
		_li.siblings().children('img.selected').fadeTo(100,0.6);
						
		// fade in active thumbnail
		thumb.fadeTo('fast',1).addClass('selected');
		
		$('#main_image').trigger('img_change');


    	},
        
	onThumb : function(thumb) {// thumbnail effects goes here
		// fetch the thumbnail container
		var _li = thumb.parents('li');
		
		// if thumbnail is active, fade all the way.
		var _fadeTo = _li.is('.active') ? '1' : '0.9';
				
		// fade in the thumbnail when finished loading
		thumb.css({display:'none',opacity:_fadeTo}).fadeIn(500);
				
		// hover effects
		thumb.hover(
			function() { thumb.fadeTo('fast',1); },
			function() { _li.not('.active').children('img').fadeTo('fast',0.6); } // don't fade out if the parent is active
			)
	}
};
$('ul.gallery').galleria(options);

// $("ul.gallery li a").attr("class","noscale");

// how many pictures we have? This is for the gallery to cycle with non black spaces or a few, but not infinit like in a bug.
var cuantas_son = $('ul.gallery li').size();
cuantas_son=Math.round(cuantas_son/2);

 $(".jcarousel-prev-horizontal").text('<<...');		
 $(".jcarousel-next-horizontal").text('...más>>');	
//fin 

jQuery(document).ready(function() {
    jQuery('#mycarousel').jcarousel({
    //Config
    vertical:true,
    scroll:4,

    initCallback: mycarousel_initCallback

    });
});

var active = false;
var gal = jQuery('#gallerytitle');

var slideshow,
slideshowPause =  3 
 
gal.find('.start').css("cursor", "pointer").click(function() {
 
	if (!active) 
	{
		active = !active;
		 $('#slideshow').fadeIn()
  	
        	 // set interval when slideshow is enabled
        	 slideshow = window.setInterval(function()
        	 {
        	     $.galleria.next()
        	 }, slideshowPause * 1000)
    	}
});

gal.find('.stop').css("cursor", "pointer").click(function() {

	if (active) 
	
	{
        $('#slideshow').fadeOut()
 
        // clear interval when slideshow is disabled
        window.clearInterval(slideshow)	
	}

});
 
}); 
 
     function mycarousel_initCallback(carousel) {
 	    jQuery('#main_image').bind('img_change',function() {
 		    var num = parseInt((jQuery('.caption').text()).split(":",1)[0])-1;
 	        carousel.scroll(num);
 	        return false;
 	    });
	};
  //]]>