		var bgAnimationIsOn = true;	
			
			//$(function() {
			$(document).ready(function(){
				
				//bg image width is 3246 ( 6492 x2 )
				
				//alert("ok");
				var bg_x = 0;
				var bg_change = -.1;
				var bgIsAnimating = false;
				var bgScrollInterval;
				var currentSectionNum = 0;
				var isAnimating = false;
				
				var navArray = new Array('.home','.about', '.web', '.illustration', '.music', '.contact');
				
				function beginSlowScroll(){
					
					bg_x = parseFloat($('#bg').css('marginLeft'));

					bgScrollInterval = setInterval(function() {
						
						if(bgAnimationIsOn){
						
						if(bg_change < 1 || bg_change > -1){
							bg_change *= 1.1;
						
							if(bg_change>1){
								bg_change = 1;
							}
							if(bg_change<-1){
								bg_change = -1;
							}
						}
						
						bg_x += bg_change;
						
						if (bg_x < -22722){
							bg_x += 19476;
						}
						
						if (bg_x > -3246){
							bg_x -= 19476;
						}
						
						$('#bg').css({marginLeft: bg_x+'px'});
						
						}
						
					}, 50);
					
				}
				
				beginSlowScroll();
				
				$('.home').click(
					function (e) {
						scrollContent(0);
					}
				);
				
				$('.about').click(
					function (e) {
						scrollContent(1);
					}
				);
				
				$('.web').click(
					function (e) {
						scrollContent(2);
					}
				);		

				$('.illustration').click(
					function (e) {
						scrollContent(3);
					}
				);	
				
				$('.music').click(
					function (e) {
						scrollContent(4);
					}
				);		

				$('.contact').click(
					function (e) {	
						scrollContent(5);
					}
				);
				
				function scrollContent(newSection){
					if(!isAnimating && newSection != currentSectionNum){
						
						removeSectionImg();
						
						$(navArray[currentSectionNum]).removeAttr("id");
						if(newSection != 6){
							$(navArray[newSection]).attr("id","menu-current");
						}

						isAnimating = true;
						clearInterval(bgScrollInterval);
						var amtToScrollbg = parseFloat($('#bg').css('marginLeft')) + (currentSectionNum-newSection) * 2000;
						
						if(amtToScrollbg > 0){
							amtToScrollbg = 0;
						}
						
						var amtToScrollcontent = newSection * 6000;
						
						$('#bg').animate({marginLeft: amtToScrollbg+'px'}, 3000, 'easeInOutQuint', function() {animCompleteHandler(newSection);});
						$('#content').animate({scrollLeft: amtToScrollcontent+'px'}, {duration: 3000, easing: 'easeInOutQuint'});
					}
				}
				
				function animCompleteHandler(newSection){
					isAnimating = false;
					bgAnimationIsOn = true;
					if(currentSectionNum < newSection){
						bg_change = -.1;
					}else{
						bg_change = .1;
					}
					
					showSectionImg(newSection);
					
					currentSectionNum = newSection;
					beginSlowScroll();
				}
				
				function removeSectionImg(){
					if(currentSectionNum == 4){
						hideHeadphones();
					}
					if(currentSectionNum == 5){
						hideTypewriter();
					}
				}
				
				function showSectionImg(newSection){
					if(newSection == 4){
						showHeadphones();
					}
					if(newSection == 5){
						showTypewriter();
					}
				}
				
				
				function showHeadphones(){
					$('#headphones').animate({marginTop: '0'}, {duration: 750, easing: 'easeOutBounce'});
					$('#headphones-shadow').animate({marginTop: '730px'}, {duration: 750, easing: 'easeOutBounce'});
				}
				
				function hideHeadphones(){
					$('#headphones').animate({marginTop: '-470px'}, {duration: 1000, easing: 'easeInQuint'});
					$('#headphones-shadow').animate({marginTop: '1200px'}, {duration: 1000, easing: 'easeInQuint'});
				}
				
				function showTypewriter(){
					var h = $(window).height();
					$('#typewriter').css({marginTop: h+'px'});
					$('#typewriter').css({visibility: 'visible'});
					$('#typewriter').animate({marginTop: '200px'}, 750, 'easeOutQuint');
				}
				function hideTypewriter(){
					var h = $(window).height();
					$('#typewriter').animate({marginTop: h + 'px'}, 750, 'easeInQuint', function() {showHideObjects('#typewriter',false);});
				}
				
				function showHideObjects(obj,isVisible){
					if(isVisible){
						$(obj).css({visibility: 'visible'});
					}else{
						$(obj).css({visibility: 'hidden'});
					}
				}
				
				if($(location).attr('href') == "http://wwwcarlprescott.com/#thanks"){
					$('.home').attr("id","");
					scrollContent(6);
				}
				
				
            });
