window.addEvent('domready', function(){

	
    // let's skip the automatic setup because we don't have any
    // properly configured link elements on the page
    //skipSetup: true
    /*var options = {
		modal: true,
		continuous: true,
        resizeLgImages:     true,
        keysClose:          ['c', 27] // c or esc
    };
    Shadowbox.init(options);*/
	Shadowbox.init({
		handleOversize:     "drag",
		displayNav:         true,
		handleUnsupported:  "remove",
		overlayColor:  "#fff",
		overlayOpacity:  "1",
		autoplayMovies:     false
	});

    var MainLinks = $$('a.main-menu-item');
    var links = $$('a.menu-item');
	var contents = $$('#dettaglio div');
	var contents_txt = $('dettaglio_txt');
	
	//var preview = $$('#dettaglio');
	var MyGallery = $$('#galleria2');
	
	var mySlideGallery = new Fx.Slide('galleria2', {mode: 'horizontal'}).hide();
	
	//var myChain = new Chain();

	//PARTE MEDIA
	contents.each(function(ContentElement,index) {
	
		ContentElement.addEvent('mouseenter', function(){
			ContentElement.removeClass('preview');										   
			ContentElement.addClass('preview-on');
			//links[index].addClass('menu-item-on');
			links[index].set('styles', {
				'color': '#d93589' // HOVER 
			});
		});
		ContentElement.addEvent('mouseleave', function(){
			ContentElement.removeClass('preview-on');
			ContentElement.addClass('preview');										   
			//links[index].removeClass('menu-item-on');
			links[index].set('styles', {
				'color': '#c0bebe'
			});
		});
		
		ContentElement.addEvent('click', function(e){
			links[index].set('styles', {
				'font-weight': 'bold',
				'color': '#d93589' // CLICCATO
				
			});
			e = new Event(e);
			contents.morph({'opacity': '0'});
			contents_txt.morph({'opacity': '0'});
			e.stop();

			(function(){
				mySlideGallery.toggle();
				MyGallery.load( links[index].get('href') );
			}).delay(800, this);
			
		});
		
	});
	
	//PARTE TESTUALE
	links.each(function(LinkElement,index) {
	
		LinkElement.addEvent('mouseover', function(){
			//LinkElement.addClass('menu-item-on');
			LinkElement.set('styles', {
				'color': '#d93589' // VIOLA
			});
			contents[index].addClass('preview-on');
		});
		LinkElement.addEvent('mouseout', function(){
			//LinkElement.removeClass('menu-item-on');
			LinkElement.set('styles', {
				'color': '#c0bebe'
			});
			contents[index].removeClass('preview-on');
		});
		
	
		LinkElement.addEvent('click', function(e){
			e = new Event(e);
			
            //hide the rest
			for(var j = 0; j < links.length; j++){
				//if(j!=index) links[j].slideOut();
				if(j!=index){
					mySlideGallery.slideOut();
					//links[j].removeClass('menu-item-on');
					links[j].set('styles', {
						'font-weight': 'normal', // tutti i menu tranne quello selezionato
						'color': '#c0bebe'
					});
				}
			}
			//LinkElement.addClass('menu-item-on');
			LinkElement.set('styles', {
				'font-weight': 'bold',  // menu selezionato dopo il click
				'color': '#d93589'		// la proprieta viola nn funziona	
				
			});
			
			//Clear the text currently inside the results div.
			(function(){
				MyGallery.set('text', '');
			//MyGallery.set('html', '<div>Loading content..</div>', '<p></p>');
			}).delay(800, LinkElement);

			contents.morph({'opacity': '0'});
			contents_txt.morph({'opacity': '0'});
			e.stop();
			(function(){
					mySlideGallery.toggle();
					
					//MyGallery.load('gallery.php');
					MyGallery.load( LinkElement.get('href') );
					
			}).delay(800, LinkElement);
		});
	
	});

	
});

