// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

var Loading = new Class({
	initialize: function(update) {
		$(update).setHTML('<img src="/images/loading2.gif" alt="carregando" />')
	}
});

var Contact = new Class({
	initialize: function(form) {
		new Loading('contact_actions');
		$(form).send({ 
			update: 'contact_form',
			onComplete: function(e) {
				new Fx.Style('contact_actions', 'opacity').start(0,1);
			}
		});
	}
});

var AlertMe = new Class({
	initialize: function(form) {
		new Loading('alertme');
		$(form).send({ 
			update: 'alertme',
			onComplete: function(e) {
				new Fx.Style('alertme', 'opacity').start(0,1);
			}
		});
	}
});

var Portfolio = new Class({
	childs: [],
	ul: null,
	details: null,
	
	initialize: function() {
		this.getobjects();
	},

	getobjects: function() {
		this.childs = $('projetos').getElement('ul').getElements('li');
		this.ul = $('projetos').getElement('ul');
		this.details = $('projetos').getElement('div[class=infos]');
	},

	next: function() {
		var that = this;
		
		that.setinfo(1);
		
		new Fx.Style(that.details, 'opacity', { duration:100 }).set(0);
		new Fx.Style(that.childs[0], 'width', { }).start(180);
		new Fx.Style(that.ul, 'left', { }).start(-186);
		new Fx.Style(that.childs[1], 'width', {
			onComplete: function() {
				that.childs[0].injectAfter(that.childs[that.childs.length - 1]);
				new Fx.Style(that.ul, 'left', { }).set(0);
				new Fx.Style(that.details, 'opacity', { duration:100 }).start(1);
			}
		}).start(398);
	},
	
	previous: function() {
		var that = this;
		
		that.childs[that.childs.length - 1].injectBefore(that.childs[0]);
		
		that.getobjects();
		that.setinfo(0);
		
		new Fx.Style(that.details, 'opacity', { duration:100 }).set(0);
		new Fx.Style(that.ul, 'left', { }).set(-186);
		new Fx.Style(that.childs[1], 'width', { }).start(180);
		new Fx.Style(that.ul, 'left', { }).start(0);
		new Fx.Style(that.childs[0], 'width', { 
			onComplete: function() {
				new Fx.Style(that.details, 'opacity', { duration:100 }).start(1);
			}
		}).start(398);
	},
	
	setinfo: function(i) {		
		var j = this.childs[i].getElement('a').getProperty('rel');
		
		$('project_name').setHTML(PotfolioData[j].name);
		//$('project_name').setProperty('title',PotfolioData[j].name);
		$('project_date').setHTML(PotfolioData[j].date);
		$('project_type').setHTML(PotfolioData[j].services);
		$('project_description').setHTML(PotfolioData[j].description);
		
		if (PotfolioData[j].url != null) {
			//$('project_name').setProperty('href',PotfolioData[j].url);
			$('project_url').setProperty('href',PotfolioData[j].url);
			$('project_url').setStyle('display','block');

		} else {
			//$('project_name').setProperty('href','#');
			$('project_url').setProperty('href','#');
			$('project_url').setStyle('display','none');

		}
	}
});

window.addEvent('domready', function(){
	new MultiBox('mb', { useOverlay: false });
	new Asset.image('/images/loading2.gif');
});

