var Site = {
	
	start: function(){
	
		if ($('content-museo')) Site.initAccordion();
		
		if ($('content-home')) {
		var number=(Math.floor(Math.random()*3)+1);
		$('content-home').setStyle('background', 'transparent url("http://www.fortedivinadio.it/img/home'+number+'.jpg") top left no-repeat');
		}
		
		if ($('montagna')) {
		$('submenu').getElement('a[id=frontiere]').addEvent('click', function(){
			window.open('http://www.fortedivinadio.it/frontiere','Frontiere','height=640,width=1024,resizable=yes,status=no,toolbar=no');
		});
	  }
	},
	
	initAccordion: function() {
		var accordion = new Accordion('div.toggler', 'div.element', {
		show: 1,
		opacity: true,
		onActive: function(toggler, element){
			var anchor = $E('a', toggler);
			anchor.toggleClass('active');
			return false;
			},
	
		onBackground: function(toggler, element){
			var anchor = $E('a', toggler);
			anchor.removeClass('active');
		}
	}, $('content-museo'));

	},
	
	startGallery: function() {
		var currentPic=1;
		myGallery = new gallery($('myGallery'), {
		timed: false,
		showCarousel: false,
		showArrows: false,
		embedLinks: false
		});
	$('nav-go-next').onclick=function(){
		myGallery.nextItem(currentPic);
		currentPic++;
		}
	$('nav-go-prev').onclick=function(){
		Site.checkGallery('prev');
		return false;
		}	
	$('max-pic').innerHTML=myGallery.maxIter;
		},
	
	checkGallery: function(verso){
	var myGallery;
	if(verso=='next'){
		myGallery.nextItem(currentPic);
		currentPic++;
		}
		
	if(verso=='prev'){
		myGallery.prevItem(currentPic);	
		currentPic--;	
		}
	if(currentPic>myGallery.maxIter){
		currentPic=1;
		}
	if(currentPic<=0){
		currentPic=myGallery.maxIter;
		}	
	$('current-pic').innerHTML=currentPic;	

	}
}

window.addEvent('domready', Site.start);

