$(function(){
	var events = new Array();
	
	$('.timeline-event-data').each(function(){
		var offset = $(this).height() + 30;
		$(this).css('margin-top','-' + offset + 'px').css({
			'opacity':0,
			'display':'none'
		});
	});
	
	$('.timeline-event').each(function(){
		events.push(parseInt($(this).find('.timeline-year').text()));
	});
	
	$('.timeline-year').mouseover(function(){
		$(this).prev('div').css('display','block');
		$(this).prev('div').stop().animate({'opacity':1});
	}).mouseout(function(){
		$(this).prev('div').stop().animate({'opacity':0},function(){
			$(this).css('display','none');
		});
	});
	
	var width = $('#timeline hr:first').width() - Math.floor($('#timeline hr:first').width() * .2);
	var startYear = events[0];
	var endYear = events[events.length - 1];
	var yearCount = endYear - startYear;
	var yearSpacing = Math.floor(width/yearCount);
	
	if(yearSpacing < 30){
		var defecit = events.length * (30 - yearSpacing);
		var spacesCount = yearCount - events.length;
		var spacesMargin = yearSpacing + Math.floor(defecit/spacesCount);
		yearSpacing = 30;
	}else{
		var spacesMargin = yearSpacing;	
	}
	
	var currentMargin = Math.floor($('#timeline hr:first').width() * .02);
	for(i=startYear;i<=endYear;i++){
		if($.inArray(i,events) != -1){
			$('#timeline-year-' + i).css('margin-left',currentMargin);
			currentMargin += yearSpacing;
		}else{
			currentMargin += spacesMargin;
		}
	}
});

$(document).ready(function(){
	$("#forgotten_password_button").click(function(){
		$("#forgotten_password_form").slideToggle("slow");
	});
});
