var TKORS = (typeof Class == "object") ? Class.create() : {};
TKORS = {
	init: function() {

		$('scroller').hide();
		this.nav = $$('#nav li a');
		this.nav.each(function(val) {
			if (val.target === '') {
				val.href = 'javascript: void(0);';
				val.title = val.title.toUpperCase();
				val.observe('click', function() {
					TKORS.loadPage(val.id);
				});
			}
		});
		
		if (location.hash !== '') {
			this.loadPage(location.hash.replace('#',''), true);		
		} else {
			this.loadPage('home', true);
		}
	},

	initScrollLayers: function() {
		this.wndo1 = new dw_scrollObj('scroll', 'scroller', null);
		this.wndo1.setUpScrollbar("dragBar", "track", "v", 0, 0);
	    this.wndo1.setUpScrollControls('scrollbar', true, 'v');
	},
	
	loadPage: function(page, start) {
		if (typeof start === 'undefined') { $('scroller').hide(); }
		new Ajax.Updater('scroller', '../' + page + '.php', {
			method: 'get',
			evalScripts: true,
			onComplete: function() { 
				TKORS.setActiveNav(page);
				new Effect.Appear('scroller', {
					afterFinish: function() {
						TKORS.initScrollLayers();
					}
				});
			}
		});	
		document.location.hash = page;
		document.title = 'The King of Rocksprings | ' + this.ucwords(page);
		$('container').writeAttribute('class', page);

	},
	
	setActiveNav: function(page) {
		this.nav.each(function(v) {
			if (v.id === page) {
				v.up().addClassName('active');
			} else {
				v.up().removeClassName('active');
			}
		});
		Cufon.refresh();
	},
	ucwords: function (str) {
    	return (str+'').replace(/^(.)|\s(.)/g, function ( $1 ) { return $1.toUpperCase( ); } );
	}

}

document.observe('dom:loaded', function() {
	TKORS.init();
});