/**
 * florianpichler.de
 */

(function($) { window.addEvent('domready', function() { if (screen.width > 640) {
	//$(document.documentElement).removeClass('csstransforms3d');
	//Modernizr.csstransforms3d = false;
	
	
	var b = $(document.body),
		vcard = b.getElement('section.vcard'),
		vcardWrap = new Element('div.vcardwrap'),
		vcardFront = new Element('div.front'),
		about = b.getElement('aside'),
		aboutHeadline = about.getElement('h2'),
		aboutText, icon,
		resize,
		vcardY = vcard.getSize().y,
		vcardFrontY,
		t = false,
		hFx = new Fx.Tween(vcardWrap, {
			'property': 'height'
		}),
		mFx = new Fx.Tween(vcardWrap, {
			'property': 'margin-top'
		});

	//Resize
	resizeHandler = function(dest) {
		var d = dest || vcardWrap.getSize().y,
			y = (window.getSize().y - d )*0.3;
		mFx[(dest)?'start':'set']((y>0)?y:0);
	};
	window.addEvent('resize', resizeHandler);

	//General
	vcardWrap.grab(vcardFront).wraps(vcard);
	vcardFrontY = vcardFront.getSize().y;
	vcard.adopt(new Element('div.ct'), new Element('div.ct'));

	hFx.set(vcardFrontY);

	$$(vcardFront, vcard.getElements('.ct')).addEvent('click', function() {
		vcardWrap.toggleClass('flip');
		hFx.options.transition = Fx.Transitions.Back[(t)?'easeIn':'easeOut'];
		hFx.start((!t) ? vcardY : vcardFrontY);
		if (!Modernizr.csstransforms3d) {
			vcardFront.tween('height', (!t) ? 0 : vcardFrontY);
		}
		resizeHandler((!t) ? vcardY : vcardFrontY);
		t = !t;
	});
	resizeHandler();

	//About 
	aboutText = new Element('div.wrap').inject(aboutHeadline, 'after'),
	icon = new Element('span.icon', {
		'title': aboutHeadline.get('html')
	}).inject(aboutHeadline,'after');
	$$(icon,aboutHeadline).addEvent('click', function() {
		about.toggleClass('show');
	});
	about.getElements('p').inject(aboutText);
} }); })(document.id);

