var Container = new Class
({
	__container: null,
	__logo: null,
	__footer: null,
	__heart: null,
	__cups: null,
		
	initialize: function()
	{
		this.__container = $("container");
		this.__logo = $("logo");
		this.__footer = $("footer");
		this.__heart = $("heart");
		this.__cups = $("cups");
	},
	
	scrollUp: function()
	{
		var duration = 5000;
		
		new Fx.Morph(this.__container, { 'duration': duration })
		.start
		({
			"clip": ["506px, 1000px, 1215px, 0", "0, 1000px, 711px, 0"],
			"top": 0
		});
		
		new Fx.Morph(this.__logo, { 'duration': duration })
		.start
		({
			"top": 0
		});
		
		new Fx.Morph(this.__heart, { 'duration': duration })
		.start
		({
			"top": 0
		});
		
		new Fx.Morph(this.__cups, { 'duration': duration })
		.start
		({
			"top": 760
		});
		
		new Fx.Morph(this.__footer, { 'duration': duration })
		.start
		({
			"top": 0
		});
	},
	
	scrollDown: function()
	{
		var duration = 3000;
		
		new Fx.Morph(this.__container, { 'duration': duration })
		.start
		({
			"clip": ["0, 1000px, 711px, 0", "506px, 1000px, 1215px, 0"],
			"top": -506
		});
		
		new Fx.Morph(this.__logo, { 'duration': duration })
		.start
		({
			"top": 506
		});
		
		new Fx.Morph(this.__heart, { 'duration': duration })
		.start
		({
			"top": -400
		});
		
		new Fx.Morph(this.__cups, { 'duration': duration })
		.start
		({
			"top": 506
		});
		
		new Fx.Morph(this.__footer, { 'duration': duration })
		.start
		({
			"top": 506
		});
	}
});

var FloatingHeart = new Class
({
	__element: null,
	__horizonLevel: 711,
	__groundLevel: 900,
	__sceneWidth: 1000,
	
	initialize: function()
	{
		this.__element = new Element("div");
	},
	
	randomize: function()
	{
		this.__element.setProperty("class", "");
		this.__element.addClass(["small", "medium", "large", "extralarge", "extraextralarge"].getRandom());
		
		this.__element.setStyles
		({
			"top": Math.random() * this.__horizonLevel,
			"left": Math.random() * this.__sceneWidth
		});
	},
	
	moveToGround: function()
	{
		this.__element.setStyles
		({
			"top": this.__groundLevel * (Math.random() * 0.2 + 0.9),
			"opacity": 0
		});
	},
	
	startRising: function()
	{
		var risingDuration;
		
		if (this.__element.hasClass("small"))
			risingDuration = 7500;
		else if (this.__element.hasClass("medium"))
			risingDuration = 7000;
		else if (this.__element.hasClass("large"))
			risingDuration = 6500;
		else if (this.__element.hasClass("extralarge"))
			risingDuration = 6000;
		else if (this.__element.hasClass("extraextralarge"))
			risingDuration = 5500;
		
		new Fx.Morph(this.__element, { "duration": risingDuration * (Math.random() * 0.2 + 0.9)})
		.start
		({
			"top": Math.random() * this.__horizonLevel
		});

		new Fx.Morph(this.__element, { "duration": risingDuration / 5 })
		.start
		({
			"opacity": 1
		});
	},
	
	startFloat: function()
	{
		var size = this.__element.getSize();
		
		var floatingHorizontal = this.__element.animate()
			.tween("margin-left", size.x / -8, { "duration": 1500 })
			.tween("margin-left", size.x / 8, { "duration": 1500 })
			.repeat();

		var floatingVertical = this.__element.animate()
			.tween("margin-top", size.y / -4, { "duration": 2500 })
			.tween("margin-top", size.y / 12, { "duration": 2500 })
			.repeat();
		
		floatingHorizontal.start();
		floatingVertical.start();
	},
	
	toElement: function()
	{
		return this.__element;
	}
});

var Hearts = new Class
({
	__container: null,
	
	initialize: function()
	{
		this.__container = $("hearts");
	},
	
	startRising: function(count)
	{
		this.__container.empty();
		
		var startMicrotime = new Date().getTime();
		
		for (var i = 0; i < count; i++)
		{
			var heart = new FloatingHeart();
			heart.randomize();
	
			this.__container.grab(heart);
			
			heart.moveToGround();
			heart.startFloat.delay(Math.random() * 600, heart);
			heart.startRising.delay(Math.random() * 2000, heart);
			
			if (new Date().getTime() - startMicrotime > 20)
				break;
		}
	},
	
	startFloating: function(count)
	{
		this.__container.empty();

		var startMicrotime = new Date().getTime();

		for (var i = 0; i < count; i++)
		{
			var heart = new FloatingHeart();
			heart.randomize();
	
			this.__container.grab(heart);
			
			heart.startFloat.delay(Math.random() * 600, heart);
			
			if (new Date().getTime() - startMicrotime > 20)
				break;
		}
	}
});

window.addEvent
(
	"domready",
	function()
	{
		var body = document.getElement("body");
		
		if (body.getSize().y < 780)
		{
			body.setStyle("height", 780);
			document.getElement("#frame").setStyle("top", 780 / 2);
		}
	}
);
