//console.log('declarando variables');
var ajax = new Request.HTML( {
	link :'cancel',
	evalScripts: false
});

var fx = null;
var chain = new Chain();
var container = null;

ajax.addEvent('success', function(responseTree, responseElements, responseHTML, responseJavaScript) {
	
	chain.chain(
		function() {
			fx.start('opacity', '0');
		},
		function() {
			var fake_elem = $('fake') || new Element('div', {
				id: 'fake',
				styles : {
					position: 'absolute',
					visibility: 'hidden',
					width: container.getSize().x
				}
			});
			fake_elem.set('html', responseHTML);
			fake_elem.inject(document.body);
			var newHeight = fake_elem.getSize().y;
			fake_elem.empty();
			fx.start('height', newHeight);
			container.empty();
		},
		function() {
			container.set('html', responseHTML);
			eval(responseJavaScript);
			fx.start('opacity', '1');
		}
	);
	chain.callChain();
	
});

function ajax_transition(href) {
	href = href || 'http://www.nopfilms.com/index.php';
	ajax.get(href);
}

window.addEvent('domready', function() {
	container = $('content_wrapper');
	fx = new Fx.Tween(container, {
		duration: '500',
		link: 'cancel'
	});
	fx.addEvent('complete', function(evt) {
		chain.callChain();
	});
});

