$(document).ready(function(){
		var current_nav = 'home';
		
		scroll_function = function(){
			if($(window).scrollTop() > $('#about').offset().top - 220) {
				$('#back_to_top').stop().animate({marginLeft:0, opacity:1}, 1);
			} else if($('#back_to_top').css('marginLeft') == '0px') {
				$('#back_to_top').stop().animate({opacity:1}, 1, function(){
					$('#back_to_top').css('marginLeft', '0px');
				});
			}
		
			$(".content").each(function(index) {
				var h = $(this).offset().top;
				var y = $(window).scrollTop();
							
				if(y + 360 >= h && y < h + $(this).height() && $(this).attr('id') != current_nav) {
					
					//alert($(this).attr('id') + " " + current_nav);
					//alert(index);
					current_nav = $(this).attr('id');
									
					$('#access').animate({opacity:1}, 250, function() {
						$('.nav').removeClass('active');
						$('.nav_' + current_nav).addClass('active');	
						Cufon.refresh();
												
						return false;
					});					
				}
			});	
		}
		
		$(window).scroll(function(){
			scroll_function();
		});
		
		scroll_function();
		
		$(".nav").click(function(event){
			//prevent the default action for the click event
			event.preventDefault();
	
			//get the full url - like mysitecom/index.htm#home
			var full_url = this.href;
	
			//split the url by # and get the anchor target name - home in mysitecom/index.htm#home
			var parts = full_url.split("#");
			var trgt = parts[1];
						
			if(current_nav != trgt) {
			
				current_nav = trgt;
				//get the top offset of the target anchor
				var target_offset = $("#"+trgt).offset();
				var target_top = target_offset.top - 192;
				
				if(current_nav == 'work') {
					if($(window).height() < 800)
						target_top = $('#work').offset().top - 192;
				}				
		
				//goto that anchor by setting the body scroll top to anchor top
				if( $.browser.opera) {
					$('html').animate({scrollTop:target_top}, 500);
				} else {
					$('html, body').animate({scrollTop:target_top}, 500);
				}
			}
		});
		
		$('.work_container').hover(function(){
			$(this).contents('.col_overlay').fadeIn('fast'); //animate({opacity:1},250);
		}, function(){
			$(this).contents('.col_overlay').fadeOut('fast');
		});
		
		position_logo = function(){
			var top = (($(window).height()/2) - 122 - 50);
			if(top < 200)
				top = 200;
			$('#logo').css('top', top);
		}
		
		$(window).resize(function() {
			position_logo();
		});
		
		position_logo();
		
	});
