/*******************************************************************
 * EasterEggs 1.01
 * Developed by Tobias Lidström (feedback@nerdized.com)
 * 
 * This software is licensed under MIT License and is free to use.
 * 
 * Changelog:
 *	2009-04-12 (v1.01):
 *	  * Added EggTargetSize that sets the size for the mouse target.
 *	  * Added browser support for Internet Explorer 6.
 *	  * Bugfix in Internet Explorer 7 and 8.
 *	  * More smooth fading effect.
 *	  * Now uses the eastereggs.css for stylesheet.
 *	2009-04-10 (v1.00):
 * 	  * Inital release.
 * 
 *******************************************************************/

var EasterEggs = new Class({
	Implements: Options,
	options: {
		EggWidth: 150,
		EggHeight: 150,
		EggBasketSize: 50,
		EggTargetSize: 50
	},
	
	initialize: function(options) {
		this.setOptions(options);
		this.FadeState = false;
		document.newElement('link', {
			type: 'text/css',
			rel: 'stylesheet',
			href: 'eastereggs.css'
		}).inject(document.head);
	},
	
	Hunt: function() {
		new Element('div', {
			'id': 'eastereggs'
		}).inject(document.body);
		if (typeof(window.innerWidth) == 'number') {
			this.win_width = window.innerWidth;
			this.win_height = window.innerHeight;
		} else {
			this.win_width = document.documentElement.clientWidth;
			this.win_height = document.documentElement.clientHeight;
		}
		this.pos_left = $random(0, this.win_width - (this.options.EggWidth + this.options.EggBasketSize));
		this.pos_top = $random(0, this.win_height - (this.options.EggHeight + this.options.EggBasketSize));

		$('eastereggs').setStyles({
			top: this.pos_top,
			left: this.pos_left,
			width: this.options.EggTargetSize,
			height: this.options.EggTargetSize
		});
		
		$('eastereggs_basket').setStyles({
			top: this.pos_top,
			left: this.pos_left,
   			width: this.options.EggWidth,
    		height: this.options.EggHeight
		});
		
		$('eastereggs').addEvent('mouseover', function() {
			if (this.FadeState == false) {
				$('eastereggs_basket').setStyle('display', 'block');
				new Fx.Tween('eastereggs_basket', {duration: 1200}).start('opacity', '0', '1');
				this.FadeState = true;
				$('eastereggs').setStyle('display', 'none');
			}
		}.bind(this));
	}
});

var EasterEggs = new EasterEggs({
	EggWidth: 100,
	EggHeight: 174
});

if (Browser.Engine.trident) {
	window.addEvent('load', function() {
		EasterEggs.Hunt();
	});
} else {
	window.addEvent('domready', function() {
		EasterEggs.Hunt();
	});
}
