// TODO
$(function() {
	$('.scroll-pane-priv').jScrollPane();
		   
	playSlideshowPriv = true;
	
    $('#mycarousel-priv li').each(function(idx) {
        $(this).data('index', (idx++));
    });
	
	$('#mycarousel-priv a').each(function(idx) {
		//alert(jQuery(this).attr("href"));
		jQuery(this).click(	function() {		 
						//alert(jQuery(this).attr("href"));
						Galleria.get(1).show(idx);
						Galleria.get(1).pause();
						playSlideshowPriv = false;
						
						return false;
						});
	});
	
	$('#mycarousel-priv img').each(function(idx) {
		//alert(jQuery(this).attr("src"));
		jQuery(this).click(	function() {	
						//alert(jQuery(this).attr("src"));
						Galleria.get(1).show(idx);
						Galleria.get(1).pause();
						playSlideshowPriv = false;
						
						return false;
						});
	});
	
    $('#mycarousel-priv').jcarousel({
        scroll: 1,
        initCallback: initCallbackFunction//,
		//buttonNextCallback: mycarousel_corp_buttonNextCallback,
   		//buttonPrevCallback: mycarousel_corp_buttonPrevCallback
    })
    
	$('#mycarousel-priv-div .jcarousel-prev').click(function() {
		Galleria.get(1).pause();												 
		//playSlideshowPriv = false;
	});
	
	$('#mycarousel-priv-div .jcarousel-next').click(function() {
		Galleria.get(1).pause();
		//playSlideshowPriv = false;
	});
	
    function initCallbackFunction(carousel, state) {	 
        $('#gallery-priv').bind('image-loaded', function(event, index, total) {
			
			// reach the end?
			if (playSlideshowPriv) {
				if ((index > 3) && (index < total)) {
					carousel.next();
				}
			}
			
            //carousel.scroll(idx);
            return false;
        });
	};

    // load and fade-in thumbnails
    $('#mycarousel-priv li img').css('opacity', 0).each(function() {    
        if (this.complete || this.readyState == 'complete') { 
			//alert('here 1');
			$(this).animate({'opacity': 1}, 300)
		} 
        else {
			///alert('here 2');
			$(this).load(function() { $(this).animate({'opacity': 1}, 300) }); 
		}
    });
});



