var Site = {

	start: function(){
		var roar = new Asset.javascript('js/roar.js', {
			onload: function(){
				notificationRoar = new Roar({ position: 'topLeft', duration: 5000, margin: {x:50,y:50} });
				var roarstyles = new Asset.css('css/roar.css');
				$$('.roar').setStyle('width',window.innerWidth);
			}
		});
		Site.scrollSite();
		Site.contact();
		Site.projects();
		Site.login();
	},
	
	login: function(){
		loginForm = $('loginform');
		loginForm.addEvent('submit', function(e) {
			e.stop();
			var jsonRequest = new Request.JSON({
				url: this.action,
				data: loginform,
				onSuccess: function(response){
    				if(response.success==true){
						notificationRoar.alert('Thank you', response.msg);
						loginform.reset();
					}else{
						notificationRoar.alert('Error', response.msg);
					}
				},
				onFailure:  function(){
					notificationRoar.alert('Error', response.msg);
				},
				onException:  function(){
					notificationRoar.alert('Error', response.msg);
				}
			}).send();
		});
	},
	
	projects: function(){
		$$('.project').each(function(el){
			var wrapper = new Element('div');
			var content = el.get('html');
			el.empty();
			wrapper.set('html',content); 
			wrapper.inject(el);

			el.addEvents({
				'mouseenter': function(){
					var height = this.getFirst().clientHeight;
					var width = this.getFirst().clientWidth;
					this.set('morph', {
						duration: 500,
						link: 'cancel'
					}).morph({'height': height, 'width': width});
				},
				'mouseleave': function(){
					this.set('morph', {
						duration: 1000,
						link: 'cancel'
					}).morph('.project');
				}
			})
		});
	},
	
	scrollSite: function(){
		var scroll = new Fx.Scroll2('contentwrapper', {
			duration: 2000,
			offset: {'x': -20, 'y': -20},
			link: 'cancel',
			transition: Fx.Transitions.Cubic.easeInOut,
			wheelStops: false
		});
		$$('a[href^="#"]').addEvent('click', function() {
			var target = document.getElement(this.get('href'));
			if(target){ scroll.toElement(target); }
			return false;
		});
	},
	
	contact: function(){
		contactform = $('contactfrm');
		contactform.addEvent('submit', function(e) {
			e.stop();
			var jsonRequest = new Request.JSON({
				url: this.action,
				data: contactform,
				onSuccess: function(response){
    				if(response.success==true){
						notificationRoar.alert('Thank you', response.msg);
						contactform.reset();
					}else{
						notificationRoar.alert('Error', response.msg);
					}
				},
				onFailure:  function(){
					notificationRoar.alert('Error', response.msg);
				},
				onException:  function(){
					notificationRoar.alert('Error', response.msg);
				}
			}).send();
		});
	}
}

window.addEvent('domready', function(){
	Site.start();
})