
Element.extend(
{
	hide: function() 
	{
		return this.setStyle('display', 'none');
	},
	
	show: function() 
	{
		return this.setStyle('display', '');
	}
});

var DropdownMenu = new Class({	
	initialize: function(element)
	{
		$A($(element).childNodes).each(function(el)
		{
			if(el.nodeName.toLowerCase() == 'li')
			{
				$A($(el).childNodes).each(function(el2)
				{
					if(el2.nodeName.toLowerCase() == 'ul')
					{
						$(el2).hide();
						
						el.addEvent('mouseover', function()
						{
							el2.show();
							return false;
						});

						el.addEvent('mouseout', function()
						{
							el2.hide();
						});
						new DropdownMenu(el2);
					}
				});
			}
		});
		return this;
	}
});

window.addEvent('domready', function() { 

    /**
     * Assigns ReMooz behavior to all anchors with the .remooz class

	ReMooz.assign('a.remooz', {
			'origin': 'img',
			'dragging': false, // disable dragging
			'centered': true, // resize to center of the screen, not relative to the source element
			'resizeFactor': 0.7 // resize to maximum 80% of screen size			
		});
   */
	
new DropdownMenu($('dropdownMenu'))
	
		
});


// aggiungo un link non intrusivo
function ajax_click(linkable, targetId)
{
	ajax_callback(linkable.href, targetId);
}

// eseguo il callback e faccio l'update di un target
function ajax_callback(requestUrl, targetId)
{
	var fadeIn = new Fx.Morph(targetId, {duration:250});

	var fadeOut = new Fx.Morph(targetId,{
	        duration: 250,
			onStart: function() {
				// $('ajax_loader').addClass('ajax_loader');
			},
	        onComplete: function () {
			    var req = new Request.HTML({
			        url: requestUrl,
					evalResponse: true,
					evalScripts: true,
			        onSuccess: function(html) {
			            // Clear the text currently inside the results div.
			            $(targetId).set('text', '');
			            // Inject the new DOM elements into the results div.
			            $(targetId).adopt(html);
			        },
			        // Our request will most likely succeed, but just in case, we'll add an
			        // onFailure method which will let the user know what happened.
			        onFailure: function() {
			            $(targetId).set('text', 'The request failed.');
			        },
					onComplete: function() {
						// $('ajax_loader').removeClass('ajax_loader');
						fadeIn.start({opacity:1});
					}
			    }).send();

			}
	}).start({opacity:0});
}

// esegue il submit di un form in post e la callback ajax
function ajax_submit(formId, targetId)
{	
	var fadeIn = new Fx.Morph(targetId, {duration:250});

	var fadeOut = new Fx.Morph(targetId,{
	        duration: 250,
			onStart: function() {
				// $('ajax_loader').addClass('ajax_loader');
			},
	        onComplete: function () {
			    var req = new Request.HTML({
			        url: $(formId).action,
					evalResponse: true,
					evalScripts: true,
			        onSuccess: function(html) {
			            // Clear the text currently inside the results div.
			            $(targetId).set('text', '');
			            // Inject the new DOM elements into the results div.
			            $(targetId).adopt(html);
			        },
			        // Our request will most likely succeed, but just in case, we'll add an
			        // onFailure method which will let the user know what happened.
			        onFailure: function(){
			            $(targetId).set('text', 'The request failed.');
			        },
					onComplete: function() {
						// $('ajax_loader').removeClass('ajax_loader');
						fadeIn.start({opacity:1});
					}
			    }).post($(formId));

			}
	}).start({opacity:0});
}
