(function($){
	$.extend( jQuery.easing,{
		easeOutElastic: function (x, t, b, c, d) {
			var s=1.70158;var p=0;var a=c;
			if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
			if (a < Math.abs(c)) { a=c; var s=p/4; }
			else var s = p/(2*Math.PI) * Math.asin (c/a);
			return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
		}
	});
	var EYE = window.EYE = function() {
		var _registered = {
			init: []
		};
		return {
			init: function() {
				$.each(_registered.init, function(nr, fn){
					fn.call();
				});
				$('#entries div.entryContent, #entries div.photos').each(function(){
					$('a', this).zoomimage();
				});
			},
			windowResize: function() {
				if(_registered.winResize) {
					$.each(_registered.winResize, function(nr, fn){
						fn.call();
					});
				}
			},
			extend: function(prop) {
				for (var i in prop) {
					if (prop[i] != undefined) {
						this[i] = prop[i];
					}
				}
			},
			register: function(fn, type) {
				if (!_registered[type]) {
					_registered[type] = [];
				}
				_registered[type].push(fn);
			}
		};
	}();
	$(EYE.init);
	$(window).bind('resize', EYE.windowResize);
	
	EYE.navigation = function(){
		var pos = {
			'aboutUs': 57,
			'offer': 83,
			'services': 19,
			'products': 19,
			'portfolio': 115,
			'contact': 68
		};
		return {
			init: function(){
				EYE.navigation.resize();
				$('#navigation a').each(function(){
					var el = this;
					el.origLeft = this.offsetLeft;
					el.origTop = pos[el.id];
					el.origWidth = this.offsetWidth;
					el.origHeight = this.offsetHeight;
					setTimeout(
						function(){
							
							$(el ).animate({top: pos[el.id]}, 2000, 'easeOutElastic');
						},
						300 + Math.random()*2000
					);
				}).bind('mouseenter', function(){
					$(this)
						.stop()
						.animate({
							top: this.origTop - 10,
							left: this.origLeft - 10,
							width: this.origWidth + 20,
							height: this.origHeight + 20
						}, 400, 'easeOutElastic');
				}).bind('mouseleave', function(){
					$(this)
						.stop()
						.animate({
							top: this.origTop,
							left: this.origLeft,
							width: this.origWidth,
							height: this.origHeight
						}, 400, 'easeOutElastic');
				});
			},
			resize: function(){
				var scr = EYE.getScroll();
				$('#wrapper').css('height', scr.h + 'px');
			}
		};
	}();
	
	$(window).bind('load', EYE.navigation.init);
	EYE.register('winResize', EYE.navigation.resize);
})(jQuery);

