
$j().ready(function() {
	application.ui = {
		_init : function(){
			
			application.ui.windowObserver = new windowObserver();

			application.ui.fullScreenImages = new fullScreenImages();
		     
			application.ui.footerPopup = new footerPopup();
			
			if ( $j('body').hasClass('gallery') ) { application.ui.gallery = new gallery(); } else { application.ui.closeContent = new closeContent(); }
			if ( $j('body').hasClass('friends') ) { application.ui.friends = new friends(); }
			if ( $j('#PressGallery').length ) { application.ui.pressGallery = new pressGallery(); }	
		
			this.navigationPrimary();
			this.navigationContent();
			//this.fonts();
			this.map();
			this.tweets();
			
			// External links
			$j('.external').click(function(event) {
		          event.preventDefault();
		          event.stopPropagation();
		          window.open(this.href, '_blank');
		    });
		   	
		},
		navigationPrimary : function(){
			var self = this;
			var navItemsLevel1 = $j('.navigation-primary.desktop-only ul li.level-1-item');
			navItemsLevel1.hover(
				function(){
					navItemsLevel1.removeClass('level-1-item-hover');
					if (!$j(this).hasClass('level-1-item-hover')) {
						$j('ul.level-2', this).slideDown({
							duration: 200,
							easing: '',
							complete: function(){
								$j(this).parent().addClass('level-1-item-hover');
							}
						});
					}			
				},
				function(){
					if ($j(this).hasClass('level-1-item-hover')) {
						$j('ul.level-2', this).slideUp({
							duration: 200,
							easing: '',
							complete: function(){
								$j(this).removeClass('level-1-item-hover');
							}
						});
					}
				}
			);
			var navItemsLevel2 = $j('.navigation-primary ul li.level-2-item');
			navItemsLevel2.hover(
				function(e){
					//e.stopPropagation();
					navItemsLevel2.removeClass('level-2-item-hover');
					$j(this).addClass('level-2-item-hover');
				},
				function(e){
					//e.stopPropagation();
					navItemsLevel2.removeClass('level-2-item-hover');
				}
			);
		},
		navigationContent : function(){
			var self = this;
			$j('.navigation-content').hover(
				function(){
					$j('li',this).slideDown(200);
				},
				function(){
					$j('li:not(.a)',this).slideUp(200);
				}
			);
		},
//		fonts : function(){
//			var self = this;
//			Cufon.replace('.navigation-primary ul li ul li.level-2-item a', { hover : { color: '#ffffff'} });
//			Cufon.replace('.navigation-primary ul li.level-1-item a', { hover : { color: '#818285'} });
//			Cufon.replace('.navigation-primary ul li ul li.level-2-item a', { color: '#ffffff'});
//			Cufon.replace('.navigation-secondary ul li a', { hover : { color: '#818285'} });
//			Cufon.replace('.navigation-content ul li a');
//			Cufon.replace('.navigation-content-horizontal ul li a', { fontSize: '14px' });
//			Cufon.replace('h2');
//			Cufon.replace('h3');
//		},
		map : function(){
			var self = this;
			if ( $j('#MapButton').size() > 0 ){
				$j("#MapOverlay").overlay().load();
				$j('#MapButton').click(function(){
					$j("#MapOverlay").overlay().load();
				});
			}
			
		},
		tweets : function(){
			var self = this;
			$j('#TwitterToggle').toggle(
				function(){ $j("#Tweet").show(); },
				function(){ $j("#Tweet").hide(); }
			);
			$j("#Tweet .c-tweet-content").tweet({
        avatar_size: 0,
        count: 1,
				username: "5ive15ifteen",
        loading_text: "searching twitter..."
      },function(){ alert('done'); }).bind("empty", function() { $j(this).append("No matching tweets found"); });		
		}
	};
	application.ui._init();
});
