var cheil = new function(){
	
	var _self;
	var navBackgroundColor;
	var navTextColor;
	
	return {
		start:function(){
			_self = this;
			_self.navBackgroundColor = "white";
			_self.addressInit();
			_self.loadNav();
			cheil.resize();
			//MOZ HACK
			if(jQuery.browser.mozilla) jQuery('#container').css('height', 4800);
			jQuery(window).resize(function(){
				cheil.resize();
			});
		},
		
		loadNav:function(){
			cheil.resetNav();
			//LINK ACTIONS
			jQuery('nav a').each(function(i, obj){
				var link = jQuery(obj);
				link.click(function(){
					jQuery.address.value(jQuery(this).attr('href'));
					link.blur();
					return false;
				});
			});
			//CHANGE COLORS BASED ON SCROLL POSITION
			jQuery(window).bind('scroll', function() {
				cheil.colorNav();
			});
			//ACTIVATE DETAIL LINKING
			jQuery('a').each(function(i, obj){
				if(typeof(jQuery(obj).attr('rel')) != "undefined"){
					var link = jQuery(obj);
					link.click(function(){
						jQuery(obj).parent().parent().parent().parent().addClass('sub');
						jQuery(obj).parent().parent().parent().find('.default').fadeOut(500);
						jQuery(obj).parent().parent().parent().find('.detail').fadeIn(500);
						cheil.colorNav();
					});
				}
			});
			jQuery('.close').each(function(i,obj){
				jQuery(obj).click(function(){
					jQuery(obj).parent().parent().parent().removeClass('sub');
					jQuery(obj).parent().parent().find('.default').fadeIn(500);
					jQuery(obj).parent().parent().find('.detail').fadeOut(500);
					cheil.colorNav();
				});
			});
		},
		
		resetNav:function(){
			jQuery('nav div').each(function(i, obj){
				//INIT STYLE
				var _openWidth = jQuery(obj).find('a').width() + 18;
				jQuery(obj).animate({width:0}, {duration:150, queue:false, easing:'easeOutExpo', complete:function(){
					jQuery(obj).css('background-color', 'transparent');
					jQuery(obj).find('a').fadeOut(100);
					jQuery(obj).width(13);
				}});
				//MOUSEOVER
				jQuery(obj).bind('mouseenter', function(){
					jQuery(obj).css('background-color', cheil.navBackgroundColor);
					jQuery(obj).animate({width:_openWidth}, {duration:150, queue:false, easing:'easeOutExpo', complete:function(){
						jQuery(obj).find('a').fadeIn(100);
					}});
				});
				//MOUSEOUT
				jQuery(obj).bind('mouseleave', function(){
					jQuery(obj).animate({width:0}, {duration:150, queue:false, easing:'easeOutExpo', complete:function(){
						jQuery(obj).css('background-color', 'transparent');
						jQuery(obj).find('a').fadeOut(100);
						jQuery(obj).width(13);
					}});
				});
			});
		},
		
		colorNav:function(){
			windowTop = jQuery(window).scrollTop();
			if(windowTop > 730){
				jQuery('nav div').each(function(i, obj){
					jQuery(obj).addClass('red');
					jQuery(obj).removeClass('white');
					cheil.navBackgroundColor = "#FA1431";
					jQuery(obj).find('a').css('color', 'white');
				});
			}else if(windowTop < 700){
				if(jQuery('#press').hasClass('sub')){
					jQuery('nav div').each(function(i, obj){
						jQuery(obj).addClass('red');
						jQuery(obj).removeClass('white');
						cheil.navBackgroundColor = "#FA1431";
						jQuery(obj).find('a').css('color', 'white');
					});
				}else{
					jQuery('nav div').each(function(i, obj){
						jQuery(obj).addClass('white');
						jQuery(obj).removeClass('red');
						cheil.navBackgroundColor = "white";
						jQuery(obj).find('a').css('color', '#FA1431');
					});
				}
			}
		},
		
		//PARALLAX
		parallax:function(el){
			jQuery(window).bind('scroll', function() {
				windowTop = jQuery(window).scrollTop();
				//position coeff
				newCoord = windowTop * -.45;
				jQuery(el).each(function(i,obj){
					objTop = jQuery(obj).offset().top;
					if(windowTop > objTop){
						jQuery(obj).css({
							"margin-top": newCoord + "px"
						});
					}else if(windowTop > (objTop+jQuery(obj).height())){
						
					}
				});
			});
		},
		
		//ADDRESS STUFF
		addressInit:function(){
			if(jQuery.address.path() != "/"){
				cheil.addressLoad();
			}
			// ADD TIMEOUT TO CREATE LISTENER SO WE DON'T LOAD ON PAGE INIT
			setTimeout(function(){
				jQuery.address.change(function(event){
					cheil.addressLoad();
				});
			}, 1000);

		},

		addressLoad:function(obj){
			_v = jQuery.address.path().split('/')[1];
			if(_v != ""){
				var _position;
				if(_v == "people"){
					_v = "buz";
				}
				_position = jQuery('#'+_v).offset().top;
				if(_v == "about"){
					_position += 75;
				}
				jQuery('html,body').animate({scrollTop:_position}, 400);
				cheil.resetNav();
			}
		},
		
		resize:function(){
			_w = jQuery(window).width();
			if(_w > 1280){
				jQuery('nav').css('margin-left', Math.floor((jQuery(window).width() - 1280)/2));
			}else{
				jQuery('nav').css('margin-left', 0);
			}
		},
		
		//SHARING
		popupShare:function(url, title) {
			if(!window.screenX && !window.screenY) {
				window.screenX = window.screenLeft;
				window.screenY = window.screenTop;
			}
			var popupPosition = {
				x: (window.screenX + window.innerWidth / 2.0),
				y: (window.screenY + window.innerHeight / 2.0)
			};
			var DEFAULT_POPUP_SHARING = 'menubar=0, resizable=0, location=0, toolbar=0, status=0, scrollbars=1, titlebar=0, left=' + (popupPosition.x - 225) + ', top=' + (popupPosition.y - 250) + ', width=550, height=500';
			window.open(url, title, DEFAULT_POPUP_SHARING);
		}
	}
}
