/**
* These bits of javascript are written specifically for Naidoc
* and are an extension of the Prototype and Scriptaculous libraries.
*/
var Naidoc = {
	Version: 		'1.0.0',
	init: 			function()
	{
		Naidoc.initSlider();
		Naidoc.initProfiles();
	},
	initSlider: 	function()
	{
		var initValue	= 2010;
		var slider = new Control.Slider('slidePointer',
										'slideBar', 
										{
											range: 			$R(1985,2010),
											values:			$R(1985,2010),
											sliderValue: 	initValue,
											onChange: 		Naidoc.showYearPanel 
										}
										);
		Naidoc.showYearPanel(initValue);
	},
	initProfiles: 	function()
	{
		$$('div.all-slides')[0].hide()
		var thisId;
		// hide profiles
		for (a = 0; a < $$('div.profile').length; a++){
			thisId = $$('div.profile')[a].id;
			$$('div.profile')[a].hide();
			$$('#'+ thisId +' a.close')[0].setAttribute('href', 'javascript:Naidoc.hideProfile("'+thisId+'");');
		}
		
		var thisURLParts;
		// update links to profiles
		for (a = 0; a < $$('div.awards a').length; a++){
			thisURLParts = $$('div.awards a')[a].href.split('#',2);
			if (thisURLParts.length == 2) {	
				$$('div.awards a')[a].setAttribute('href', 'javascript:Naidoc.showProfile("'+ thisURLParts[1] +'");');
			}
		}
		$$('div.all-slides')[0].show();
	},
	showYearPanel: 	function(year)
	{
		var panelId = 'year_'+year;
		// hide all other year panels
		for (a = 0; a < $$('div.awards').length; a++){
			if ($$('div.awards')[a].id != panelId){
				$$('div.awards')[a].hide();
			}
		}
		
		// hide all profile panels
		for (a = 0; a < $$('div.profile').length; a++){
			$$('div.profile')[a].hide();
		}
			
		// show new
		if ($(panelId)){
			$(panelId).show();
		}
	},
	showProfile: 	function(elementId)
	{
		// hide the year panel;
		Naidoc.showYearPanel('');
		$(elementId).show();
	},
	hideProfile: 	function(elementId)
	{
		$(elementId).hide();
		var idParts	= elementId.split('_',2);
		// hide the year panel;
		if (idParts[1]){
			Naidoc.showYearPanel(idParts[1]);
		}
	}
}

Event.observe(window, 'load', Naidoc.init, false);