function dump(arr,level) {
	var dumped_text = "";
	if(!level) level = 0;
	
	//The padding given at the beginning of the line.
	var level_padding = "";
	for(var j=0;j<level+1;j++) level_padding += "    ";
	
	if(typeof(arr) == 'object') { //Array/Hashes/Objects 
		for(var item in arr) {
			var value = arr[item];
			
			if(typeof(value) == 'object') { //If it is an array,
				dumped_text += level_padding + "'" + item + "' ...\n";
				dumped_text += dump(value,level+1);
			} else {
				dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
			}
		}
	} else { //Stings/Chars/Numbers etc.
		dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
	}
	return dumped_text;
}


//trasforma i link A in immagini semplici, funziona con le gallery di default di wp
function gallery_to_images(container){

var i=0;
var imgs ='';
jQuery('a',container).each(function(){

imgs += '<img class="gallery_js" rel="gallery_js" src="'+jQuery(this).attr('href')+'" alt="'+jQuery(this).attr('href')+'" />';
i++;

});

container.html(imgs);

}


/*
jquery funzione/plugin cicla

*/
(function ($) {

	$.fn.cicla = function (options) {

        // default configuration properties
        var defaults = {
            speed: 300,
            delay: 5000,
            width: 500,
            height:500,
            autocycle:false,
            thumbs:false,
            thumbsource:'.gallery2-thumbs-container',
            progressbar:false
        };

        var options = $.extend(defaults, options);
		
		//var container = $('.container', this);

		var imgss = $('img', this);

//		$(this).width($(this).width()!=0?$(this).width():options.width)
//		.height(imgss.eq(0).height()!=0?imgss.eq(0).height():options.height);
					
/*
		container.width($(this).width()!=0?$(this).width():options.width)
		.height(imgss.eq(0).height()!=0?imgss.eq(0).height():options.height);
*/

//		imgss.width($(this).width()).css('min-height',$(this).height());
		
		var totalwidth= $(this).width();
		
		imgss.css({'width': $(this).width()+'px','height':'auto'});//.height($(this).height());
		
		$(this).css({'overflow':'hidden'});
		
		
	//	imgss.css('position','absolute');
	
		if(imgss.length>1){
		
			imgss.hide();

			$(this).append('<span class="cicla-counter" style="z-index:999;position:absolute;top:10px;left:10px;"></span>');

			
			var imgcounter = $('span.cicla-counter', this);
			//var play=true;
			var e=0;//id numerico foto mostrata
			

			function mostra(eq){
				imgss.fadeOut(options.speed);
				imgss.eq(eq).delay(options.speed).fadeIn(options.speed);
				imgcounter.html(''+(eq+1)+'/'+imgss.length+'');
				
			};

			function next(){
				if(e<imgss.length-1) e++;
				else e=0;
				mostra(e);
			};
			
			function prev(){
				if(e>0) e--;
				else e=imgss.length-1;
				mostra(e);
			};
			
		
		
		
			//init
			mostra(0);

			// variabile ciclo, setTimeout. settata dopo
			var c=0;
			
		//	if(options.thumbs){
			$(options.thumbsource+' span').css('cursor','pointer');
			$(options.thumbsource+' span').click(function(){
				stopCycle();
				$(options.thumbsource+' span').css('opacity',1);
				$(this).css('opacity',0.5);
				e = parseInt($(this).attr('id').substr(9));
				mostra( e );

				});			
			
			
		//	else if(options.autocycle){

				if(options.progressbar) $(this).append('<span id="cicla-progressbar" style="z-index:999;position:absolute;bottom:0;left:0;height:6px;width:0px;display:block;background:#f00;"></span>');
			
				$(this).append('<span id="cicla-status" style="z-index:999;position:absolute;top:30px;left:10px;"></span>');

				$(this).append('<span id="cicla-playpause" class="paused" style="display:block;z-index:998;position:absolute;top:0px;left:'
				+( parseInt($(this).outerWidth())/2-50 )
				+'px;width:100px;height:'+$(this).height()+'px;"></span>');
				
				function cycle(){
					c = setTimeout(function(){next();cycle();}, options.delay);

					$('#cicla-status').html('&#9654;');/*play simbol*/
					$('#cicla-playpause').removeClass('paused');
					
					if(options.progressbar){
						$('#cicla-progressbar').stop().css({width:'0'});
						$('#cicla-progressbar').animate({width:(totalwidth)+'px'},options.delay);
					}
				};
				
				function stopCycle(){
					if(c!=0){
						clearInterval(c);
						c=0;
	
						if(options.progressbar) $('#cicla-progressbar').stop().css({width:'0'});
	
						$('#cicla-status').html('');/*stop symbol &#9724;*/
						$('#cicla-playpause').addClass('paused'); 			
					}
				}
				
				$('#cicla-playpause').click(function(){
						//play=!play;
						if(c!=0) {stopCycle(); }
						else {next(); cycle();  }
						
					});
					
				//start autocycle
	        	if(options.autocycle) cycle();	        	
        //	}
        
        
        	
        //	else{
				$(this).append('<span id="cicla-prev" style="display:block;z-index:998;position:absolute;top:0px;left:0;width:100px;height:'+$(this).height()+'px;cursor:w-resize;"></span>');
			
				$(this).append('<span id="cicla-next" style="display:block;z-index:998;position:absolute;top:0px;right:0;width:100px;height:'+$(this).height()+'px;cursor:e-resize;"></span>');

				//$(this).click(function(){next();});
				$('#cicla-prev').click(function(){stopCycle(); prev();});
				$('#cicla-next').click(function(){stopCycle(); next();});

//        	}
        
        
        	
        
        }//if imgss.lenght > 0
        
	}
 })(jQuery);




jQuery(document).ready(function(){

/*
if(jQuery("#foto-home").length>0){
	jQuery("#foto-home").cicla();
}
*/

	if(jQuery("#foto-home").length>0)
		jQuery("#foto-home").cicla({autocycle:true});
		
	if(jQuery(".gallerizza").length>0)
		jQuery(".gallerizza").cicla({autocycle:false});

	
});


