(function(){
	EYE.Menu = function(){
		var 
			currentSub = false,
			currentItem = false,
			initialItem = false,
			initialSub = false,
			timer = null,
			mousenter = function(e){
				hideSub(true);
				if (document.getElementById($(this).attr('rel'))) {
					currentSub = document.getElementById($(this).attr('rel'));
					$(currentSub).show();
					$(this).addClass('active');
					currentItem = this;
				}
				clearTimeout(timer);
			},
			mouseleave = function(e){
				timer = window.setTimeout(hideSub, 100);
			},
			hideSub = function(fromNew){
				if (currentSub) {
					$(currentSub).hide();
					currentSub = false;
				}
				if (currentItem) {
					$(currentItem).removeClass('active');
					currentItem = false;
				}
				if (fromNew !== true) {
					currentSub = initialSub;
					currentItem = initialItem;
					$(initialItem).addClass('active');
					if (initialSub) {
						$(initialSub).show();
					}
				} else {
					
				}
			},
			mousenterSub = function(){
				clearTimeout(timer);
			};
		return {
			init: function(){
				$('ul.navigation a')
					.bind('mouseenter', mousenter)
					.bind('mouseleave', mouseleave);
				$('ul.navigationDrop')
					.bind('mouseenter', mousenterSub)
					.bind('mouseleave', mouseleave);
				$('ul.navigation a.active').each(function(){
					currentItem = initialItem = this;
					if (document.getElementById($(this).attr('rel'))) {
						currentSub = initialSub = document.getElementById($(this).attr('rel'));
						$(initialSub).show();
					}
				});
				$('#search').each(function(){
					this.origValue = this.value;
					$(this).bind('blur', function(){
						if (this.value == '') {
							this.value = this.origValue;
						}
					}).bind('focus', function(){
						if (this.origValue == this.value) {
							this.value = '';
						}
					});
				});
			}
		};
	}();
	
	EYE.Iframe = function(){
		return {
			init: function(){
				$('div.iFrameOverlay a:eq(1)')
					.bind('click', function(){
						$('div.iFrameOverlay').hide();
						this.blur();
						return false;
					});
				$('a.appIframe').bind('click', function(){
					$('div.iFrameOverlay').show();
					$('iframe').attr('src', $(this).attr('href'));
					this.blur();
					return false;
				});
			}
		};
	}();
	EYE.register(EYE.Menu.init, 'init');
	EYE.register(EYE.Iframe.init, 'init');
})();

