var dataRight = {
	'left': '-200px',
	'opacity': '0',
	'z-index': '0'
}
var dataCenter = {
	'left': '-400px',
	'opacity': '1',
	'z-index': '1'
}
var dataLeft = {
	'left': '-600px',
	'opacity': '0',
	'z-index': '0'
}

function MenuItemShow(item, delay) {
	$(item).delay(delay).animate({ 'opacity': '1', 'padding-top': '50px', 'padding-bottom': '0' }, { duration: 300 });
}

function MenuItemFadeTo(item, color) {
	$(item).animate({ color: color }, { duration: 150 });
}

function SlideIn(item) {
	$(item).css(dataRight);
	$(item).animate(dataCenter, { duration: 500, complete: function() { $(item).css(dataCenter); } });
}

function SlideOut(item) {
	$(item).css(dataCenter);
	$(item).animate(dataLeft, { duration: 500, complete: function() { $(item).css(dataLeft); } });
}

function ApplyNav() {
	$('a.nav').live('click', function () { NavClick(this); return false; } );
}

function LoadTo(url, target) {
	$.ajax({
		'url': url,
		'data': {'template': 'ajax'},
		'dataType': 'html',
		'success': function(data) { $(target).html(data); }
	});
}

function NavClick(item) {
	var href   = $(item).attr('href');
	var new_id = 'frame_' + href.replace(/[^a-z0-9]/img, '_');
	var old_id = $('#frames').attr('frame_id');

	if (old_id == new_id) { return false; }
	
	if ($('#' + new_id).length == 0) {
		$('<div></div>').appendTo('#frames').attr('class', 'frame').attr('id', new_id);
		LoadTo(href, '#' + new_id);
	}
	if (old_id) SlideOut('#' + old_id);
	SlideIn('#' + new_id);

	$('#frames').attr('frame_id', new_id);
}

function ShowSkills(node) {
	$('#skills').html($(node).parents('li').children('div').html()); 
	return false;
}

function ShowCard(id, target) {
	var old_id = $(target).attr('card_id');
	var new_id = id; //$(card).attr('href');
	if (new_id == old_id) return;
	$(old_id).fadeOut();
	$(new_id).fadeIn();
	$(target).attr('card_id', new_id);
}
	
$(document).ready(function () {
	ApplyNav();
	$('#frames').animate({ 'top': '-200px', 'bottom': '-200px', 'opacity': '1' }, { duration: 500 });
	$('#menu li').each( function(index) { MenuItemShow(this, index * 100); } );
	$('#menu li a').hover( function () { MenuItemFadeTo(this, '#0077de'); }, function () { MenuItemFadeTo(this, '#fff'); } );
	$('#copy').delay(1000).animate({ 'opacity': '1', 'padding-top': '0' }, { duration: 300 });
	SlideIn('#frames div.frame');
});
