$(document).ready(function (){
	$("#screen, #box_2, #footer_navigation, #navigation-first, #nav_secondary").hide();
	$("#screen, #box_2, #footer_navigation, #navigation-first, #nav_secondary").fadeIn(2500);
});


/* show and hide camaleonti*/

 $(document).ready(function(){
    $("#mission, #manoscritto").click(function () {
      $("#camaleonte-img").show(0, function () {
        // use callee so don't have to name the function
        $(this).next().show(0, arguments.callee); 
      });
    });
    $("#collane, #distribuzione").click(function () {
      $("#camaleonte-img").hide(0);
    });
  });



 $(document).ready(function(){
    $("#immagine").click(function () {
      $("#rana-img").show(0, function () {
        // use callee so don't have to name the function
        $(this).next().show(0, arguments.callee); 
      });
    });
	 $("#immagine").click(function () {
      $("#calamaio-img, #grammofono-img, #porta-img").hide(0);
    });
    $("#stampa").click(function () {
      $("#rana-img, #calamaio-img, #porta-img").hide(0);
    }); 
	$("#stampa").click(function () {
      $("#grammofono-img").show(0);
    });
	$("#servizi").click(function () {
      $("#rana-img, #grammofono-img, #porta-img").hide(0);
    }); 
	$("#servizi").click(function () {
      $("#calamaio-img").show(0);
    });
	$("#web").click(function () {
      $("#rana-img, #calamaio-img, #grammofono-img").hide(0);
    }); 
	$("#web").click(function () {
      $("#porta-img").show(0);
    });
  });


/* sexy lightbox 2.2 */

	$(document).ready(function(){
	SexyLightbox.initialize({
          OverlayStyles:{
            'background-color':'#333',
             'opacity': 0.9
          }
        });
	});



/* fade */

$(function () {
        if ($.browser.msie && $.browser.version < 7) return;
        
        $('#navigation li, #navigation2 li, #navigation3 li, #navigation4 li')
            .removeClass('highlight')
            .find('a')
            .append('<span class="hover" />').each(function () {
                    var $span = $('> span.hover', this).css('opacity', 0);
                    $(this).hover(function () {
                        // on hover
                        $span.stop().fadeTo(500, 1);
                    }, function () {
                        // off hover
                        $span.stop().fadeTo(500, 0);
                    });
                });
    });



/** colonne */


$(function(){
	$('.wide').columnize({width:400});
	$('.thin').columnize({columns:3});
	$('.thin2').columnize({width:240, height:130});
	$('.thin3').columnize({columns:1});
});


/** on click */



$(document).ready(function(){
$("#web, #servizi, #stampa, #immagine").click(function(){ 
        $("a.clicked").removeClass("clicked"); 
        $(this).addClass("clicked"); 
        return false;                                        
});
$("#mission, #collane, #distribuzione, #manoscritto").click(function(){ 
        $("a.clicked-green").removeClass("clicked-green"); 
        $(this).addClass("clicked-green"); 
        return false;                                        
});

});


/** scroll to */

jQuery(function( $ ){
		$.easing.elasout = function(x, t, b, c, d) {
			var s=1.70158;var p=0;var a=c;
			if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
			if (a < Math.abs(c)) { a=c; var s=p/4; }
			else var s = p/(2*Math.PI) * Math.asin (c/a);
			return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
		};
		$('a.back').click(function(){
			$(this).parents('div.pane').scrollTo( 0, 800, { queue:true } );
			$(this).parents('div.section').find('span.message').text( this.title );
			return false;
		});
		//just for the example, to stop the click on the links.
		$('ul.links').click(function(e){
			e.preventDefault();
			var link = e.target;
			link.blur();
			if( link.title )
				$(this).parent().find('span.message').text(link.title);
		});
	
	//by default, the scroll is only done vertically ('y'), change it to both.
	$.scrollTo.defaults.axis = 'xy'; 			
	//funzione importante, molti browser non ricaricano lo scroll dal primo LI
	$('div.pane').scrollTo( 0 );//reset all scrollable panes to (0,0)
	$('div.pane1').scrollTo( 0 );//reset all scrollable panes to (0,0)
	$('div.pane2').scrollTo( 0 );//reset all scrollable panes to (0,0)
	$('div.pane3').scrollTo( 0 );//reset all scrollable panes to (0,0)
	$('div.pane4').scrollTo( 0 );//reset all scrollable panes to (0,0)
	$('div.pane6').scrollTo( 0 );//reset all scrollable panes to (0,0)

	$.scrollTo( 0 );//reset the screen to (0,0)
	
	//TOC, shows how to scroll the whole window
	$('#toc a').click(function(){//$.scrollTo works EXACTLY the same way, but scrolls the whole screen
		$.scrollTo( this.hash, 1500, { easing:'elasout' });
		$(this.hash).find('span.message').text( this.title );
		return false;
	});
	
	
//la casa editrice box 2
	var $paneTarget = $('#pane-target');	

	$('#mission').click(function(){
		$paneTarget.stop().scrollTo( 'li:eq(0)', 0 );
	});
	
	$('#collane').click(function(){
		$paneTarget.stop().scrollTo( 'li:eq(1)', 0 );
	});
	
	$('#distribuzione').click(function(){
		$paneTarget.stop().scrollTo( 'li:eq(3)', 0 );
	});
	
	$('#manoscritto').click(function(){
		$paneTarget.stop().scrollTo( 'li:eq(4)', 0);
	});
		
	
	//lo studio grafico box 1
	var $paneTarget6 = $('#pane-target6');	

	$('#immagine').click(function(){
		$paneTarget.stop().scrollTo( 'li:eq(0)', 0 );
	});
	
	$('#stampa').click(function(){
		$paneTarget.stop().scrollTo( 'li:eq(1)', 0 );
	});
	
	$('#servizi').click(function(){
		$paneTarget.stop().scrollTo( 'li:eq(2)', 0 );
	});
		
	$('#web').click(function(){
		$paneTarget.stop().scrollTo( 'li:eq(3)', 0 );
	});
	
});





/*Jquery serial scroll*/

jQuery.easing.easeOutQuart = function (x, t, b, c, d) {
	return -c * ((t=t/d-1)*t*t*t - 1) + b;
};

jQuery(function( $ ){
	$('#screen').serialScroll({
		target:'#sections',
		items:'li', // Selector to the items ( relative to the matched elements, '#sections' in this case )
		prev:'img.prev',// Selector to the 'prev' button (absolute!, meaning it's relative to the document)
		next:'img.next',// Selector to the 'next' button (absolute too)
		axis:'xy',// The default is 'y' scroll on both ways
		navigation:'#navigation li a',
		duration:0,
		force:true, 
		onBefore:function( e, elem, $pane, $items, pos ){
			e.preventDefault();
			if( this.blur )
				this.blur();
		},
		onAfter:function( elem ){
		}
	});
	
	$('#screen3, #screen4').serialScroll({
		target:'#sections3, #sections4',
		items:'li', // Selector to the items ( relative to the matched elements, '#sections' in this case )
		prev:'img.prev',// Selector to the 'prev' button (absolute!, meaning it's relative to the document)
		next:'img.next',// Selector to the 'next' button (absolute too)
		axis:'xy',// The default is 'y' scroll on both ways
		navigation:'#navigation li a',
		duration:800,// Length of the animation (if you scroll 2 axes and use queue, then each axis take half this time)
		force:true, // Force a scroll to the element specified by 'start' (some browsers don't reset on refreshes)

		onBefore:function( e, elem, $pane, $items, pos ){

			e.preventDefault();
			if( this.blur )
				this.blur();
		},
		onAfter:function( elem ){
			//'this' is the element being scrolled ($pane) not jqueryfied
		}
	});
	
	var $news = $('#news-ticker');//we'll re use it a lot, so better save it to a var.
	$news.serialScroll({
		items:'div',
		duration:2000,
		force:true,
		axis:'y',
		easing:'linear',
		lazy:true,// NOTE: it's set to true, meaning you can add/remove/reorder items and the changes are taken into account.
		interval:1, // yeah! I now added auto-scrolling
		step:2 // scroll 2 news each time
	});	
	
	$('#add-news').click(function(){
		var 
			$items = $news.find('div'),
			num = $items.length + 1;
			
		$items.slice(-2).clone().find('h4').each(function(i){
			$(this).text( 'News ' + (num + i) );
		}).end().appendTo($news);
	});
	$('#shuffle-news').click(function(){//don't shuffle the first, don't wanna deal with css
		var shuffled = $news.find('div').get().slice(1).sort(function(){
			return Math.round(Math.random())-0.5;//just a random number between -0.5 and 0.5
		});
		$(shuffled).appendTo($news);//add them all reordered
	});
	
	$('#screen5').serialScroll({
		target:'#sections5',
		items:'img', // Selector to the items ( relative to the matched elements, '#sections' in this case )
		prev:'img.prev',// Selector to the 'prev' button (absolute!, meaning it's relative to the document)
		next:'img.next',// Selector to the 'next' button (absolute too)
		axis:'xy',// The default is 'y' scroll on both ways
		navigation:'#navigation li a',
		duration:800,// Length of the animation (if you scroll 2 axes and use queue, then each axis take half this time)
		force:true, // Force a scroll to the element specified by 'start' (some browsers don't reset on refreshes)

		onBefore:function( e, elem, $pane, $items, pos ){

			e.preventDefault();
			if( this.blur )
				this.blur();
		},
		onAfter:function( elem ){
			//'this' is the element being scrolled ($pane) not jqueryfied
		}
	});
	
	/*personalizzazioni serial scroll*/
	
		/*box 1*/
	
	/*box 1*/
		$('#screen3 .prev').hide();
    	$('#screen3 .next').click(function () {
		$('#screen3 .prev').fadeIn(2000);
    });  

		$('#screen4 .prev').hide();
    	$('#screen4 .next').click(function () {
		$('#screen4 .prev').fadeIn(2000);
    });  
});

