//'heights' for the different nav sections
var rels = { }

//-- standard ready steady don't hold me back
$(document).ready(function() {
	//add nav click handlers
	$("#nav").children().click(onNavClick)
	
	//portfolio click handerls
	$(".portnav").children().click(onPortClick)
	
	//Ok, something different now
	$(document).scroll(winScroll)
})
//--  end ready

//when the window is scrolled, lets do a bit of parallax magic
function winScroll(e) {
	
	//get offset
	var scoff = window.pageYOffset
	
	//update positions
	moveContentTo(scoff)
	
	//for for points of build in or out
	$(".section").each(function() {
		var dis = $(this)
		if(isScrolledIntoView(this)) {
			dis.animate({ left: 0 }, 500)
		} else {
			dis.css({left: 900 })
		}
	})
	
}//--end winScroll

//-- when a port number is clicked, tween to that entery
function onPortClick(e) {
	//get num
	var num = $(e.target).html()
	
	//move to that num
	$("#portholder").animate({"left": num * 600}, 500)
}//--end onPortClick

//-- when a nav is clicked, lets go somewhere else for once
function onNavClick(e) {

	//change active nav
	$('.active').removeClass('active')
	$(e.target).addClass('active')

	//move to content
	targHeight = $("#"+$(e.target).html()).position().top - 70
	moveContentTo(targHeight)
}//-- end onNavClick

//-- parralax all the content to a certain location
function moveContentTo(amt) {

	//move that content
	$("#content").css({ top: -amt })
		
	//some paralax because its awesome
	$("#sky").css({ top: -amt*.2 })
	$("#buildings").css({ top: (-amt*.3) - 700 })
	$("#trees").css({ top: (-amt*.6) - 500 })
	$("#people").css({ top: -amt*.9 })
	$("#groond").css({ top: -amt*1 })
}//--end moveContentTo



function isScrolledIntoView(elem)
{
    var docViewTop = $(window).scrollTop();
    var docViewBottom = docViewTop + $(window).height();

    var elemTop = $(elem).offset().top;
    var elemBottom = elemTop + $(elem).height();

    return ((elemBottom >= docViewTop) && (elemTop <= docViewBottom));
}
