
_timer = null;
_page = null;
_person = null;
_people = new Array();
_peopleTween = null;

// ---------------------------------------------------------------------------

function loadPage (anchor) {
	// get url parts
	var href = $(anchor).attr('href');
	if (window.urchinTracker) urchinTracker(href);
	var parts = cleanSplit(href, '/');
	parts.reverse();
	// deactivate old active link
	$('#sideNavActiveLink').removeAttr('id');
	$('#sideNavActiveProjArrow').remove();
	// activate current link
	$(anchor).attr('id', 'sideNavActiveLink');
	$(anchor).append('<img src="_img/shared/sidenav_arrow.gif" id="sideNavActiveProjArrow" />');
	// clear background image
	$('#mainContent').css({backgroundImage:'none'});
	// get page name
	_person = (parts[1] == 'people') ? parts.shift() : null;
	var pg = parts[1]+'-'+parts[0];
	// load page
	if (pg != _page) {
		_page = pg;
		$('#content').html('<p id="loadingPage"><img src="_img/shared/spinner.gif" width="14" height="14" /> Loading Page</p>');
		clearTimeout(_timer);
		_timer = setTimeout('doLoadPage()', 100);
	} else {
		 loadCallback(false);
	}
}
function doLoadPage(){
	var pg = _page+'.php';
	$('#content').load(pg, null, function(){
		loadCallback(true);
	});
}
function loadCallback (init) {
	$('#content').removeClass('extraTall');
	switch (_page) {
		case 'about-people':
			$('#content').addClass('extraTall');
			var y = -(300 * (_people[_person] + 1));
			//if (y == 0) y = 1;
			if (init) {
				_peopleTween = new Tween($('#peopleMover').get(0), 'top');
				$('#peopleMover').css('top', y);
			} else {
				_peopleTween.start(null, y, 10, 'easeout');
				//$('#peopleMover').animate({top:y}, 450, 'easeout', function(){
					//$(this).css('top', y);
				//});
			}
			$('#mainContent').css({backgroundImage:'url(_img/people/'+_person+'_bg.jpg)'});
		break;
		case 'about-studios':
			if (init) {
				//new studioSlideshow('sanfrancisco');
				//new studioSlideshow('nashville');
				$('#sanfrancisco, #nashville').show();
				$('#sfphotos').cycle({ 
					fx:     'fade', 
					speed:  300, 
					next:   '#sanfrancisco', 
					timeout: 0 
				});
				$('#nashphotos').cycle({ 
					fx:     'fade', 
					easing: 'easeInOutQuad',
					speed:  300, 
					next:   '#nashphotos', 
					random: 1,
					timeout: 0 
				});
			}
		break;
	}
}

// ---------------------------------------------------------------------------

function studioSlideshow (id) {
	this.count = 0;
	this.imgs = $('#'+id+' p img');
	this.cap = $('#'+id+' p.caption');
	var t = this;
	$('#'+id+' p.photos').click(function(){
		var img = $(t.imgs).get(t.count);
		$(img).removeClass('activeStudioPhoto');
		if (++t.count > t.imgs.length - 1) t.count = 0;
		var img = $(t.imgs).get(t.count);
		$(img).addClass('activeStudioPhoto');
		$(t.cap).html($(img).attr('alt'));
		$(this).fadeIn('normal');
	});
	$('#'+id+' p.photos img').each(function(i){
		this.onmouseover = function(){
			$(this).css('border-color', '#ccc');
		};
		this.onmouseout = function(){
			$(this).css('border-color', '#000');
		};
	});
}

// ---------------------------------------------------------------------------

$(document).ready(function(){
	// activate nav menu
	$('#sideNavMenu a').click(function(){
		loadPage(this);
		return false;
	});
	// create people array
	$('#sideNavMenu ul.people a').each(function(i){
		var href = $(this).attr('href');
		var parts = cleanSplit(href, '/');
		var name = parts[parts.length - 1];
		_people[name] = i;
	});
	// load the first page
	var a = (hasPageParams()) ? $('#sideNavMenu a[@href*='+getLastPageParam()+']').get(0) : null;
	var activeAnchor = a ? a : $('#sideNavMenu a').get(0);
	loadPage(activeAnchor);
});

// ---------------------------------------------------------------------------
