attachments = {
	init : function() {
		var attachmentContainer = $(document.body).getElement('.attachments');
		if (!attachmentContainer) { return false; }
		
		attachmentContainer.set('morph', {duration: 500, transition: Fx.Transitions.Sine.easeOut});
	
		var attachments = attachmentContainer.getElements('li');
	
		var currentAttachment = attachmentContainer.getElement('.current');
		currentAttachment.set('morph', {duration: 500, transition: Fx.Transitions.Sine.easeOut});
	
		attachmentContainer.morph({'padding-left':(($('body').getSize().x - 960) / 2) + 365});
	
		attachments.each(function(attachment) {
			// FLICKR ATTACHMENTS
			if(attachment.hasClass('flickr')) {
				var attachmentLink = attachment.getElement('a');
				attachment.set('morph', {duration: 500, transition: Fx.Transitions.Sine.easeOut});
		
				attachment.addEvent('mouseenter', function(){
					if(attachment != currentAttachment) {
						attachment.morph({'opacity':[.25,.7]});
					} else {
						attachmentLink.set('styles',{'display':'block'});
					}
				});
				attachment.addEvent('mouseleave', function(){
					if(attachment != currentAttachment) {
						attachment.morph({'opacity':.25});
					} else {
						attachmentLink.set('styles',{'display':'none'});
					}
				});
				attachment.addEvent('click', function(){
					if(attachment != currentAttachment) {
						attachmentContainer.morph({'margin-left':(($('body').getSize().x - 960) / 2) + 365 - attachment.getPosition(attachmentContainer).x});
						attachment.morph({'opacity':[.25,1]});
						attachmentLink.set('styles',{'display':'block'});
						currentAttachment.morph({'opacity':.25});
						currentAttachment.toggleClass('current');
						currentAttachment = attachment;
						attachment.toggleClass('current');
					}
				});
			}
		
			//VIMEO ATTACHMENTS
			if(attachment.hasClass('vimeo')) {
				attachment.adopt(new Element('div', {'class': 'overlay'}));
				attachment.set('morph', {duration: 500, transition: Fx.Transitions.Sine.easeOut});
		
				attachment.addEvent('mouseenter', function(){
					if(attachment != currentAttachment) {
						attachment.morph({'opacity':[.25,.7]});
					} else {
						attachment.getElement('div').set('styles',{'width':'1px'});
					}
				});
				attachment.addEvent('mouseleave', function(){
					if(attachment != currentAttachment) {
						attachment.morph({'opacity':.25});
					} else {
						attachment.getElement('div').set('styles',{'width':'355px'});
					}
				});
				attachment.addEvent('click', function(){
					if(attachment != currentAttachment) {
						attachmentContainer.morph({'margin-left':(($('body').getSize().x - 960) / 2) + 365 - attachment.getPosition(attachmentContainer).x});
						attachment.morph({'opacity':[.25,1]});
						currentAttachment.morph({'opacity':.25});
						currentAttachment.toggleClass('current');
						currentAttachment = attachment;
						attachment.toggleClass('current');
					}
				});
			}
		});
	}
}

prevLink = {
	init : function() {
		var link = $(document.body).getElement('.navPrev');
		if (!link) { return false; }
		
		link.addEvent('click', function(e){
			new Event(e).stop();
			$(document.body).set({'class':'rotatePrev'});
			$(document.body).morph({'opacity':[1,0]});
			(function(){
				window.location = this.get('href');
		    }).delay(500, this);
		});
	}
}

nextLink = {
	init : function() {
		var link = $(document.body).getElement('.navNext');
		if (!link) { return false; }
		
		link.addEvent('click', function(e){
			new Event(e).stop();
			$(document.body).set({'class':'rotateNext'});
			$(document.body).morph({'opacity':[1,0]});
			(function(){
				window.location = this.get('href');
		    }).delay(500, this);
		});
	}
}

window.addEvent('domready', function() {
	attachments.init();
	prevLink.init();
	nextLink.init();
	
	konami = new Konami(function(){
		$(document.body).toggleClass('rotated');
	});
});

window.addEvent('load', function() {
	$(document.body).getElements('.body p').each(function(paragraph) {
		var eop = new Element('span', {'styles':{'display':'inline-block'}});
		paragraph.adopt(eop);
		if(paragraph.getNext()) {
			if(eop.getPosition(paragraph).x < 330 && paragraph.getNext().get('tag') == 'p') {
				paragraph.getNext().set('styles',{'margin-top':'-25px'});
			}
		}
	});
});
