window.addEvent('load', 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			
		});
 
});


// 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});
}