// LOAD-ORDER: 140

var ENDPOINT_LI_CLASS = "endpoint";
var AUTOEXPAND_PREF_KEY = "VIEW_FIRST_VIA_JS";

var CH_VW_MODE_KEY = 'chapter_view_mode';



function chapter_view_mode_changed(ev) {
	
	var value = ev.element().value;
	
	PREFS.savePref( CH_VW_MODE_KEY , value );
	
	location = ''; /* RELOAD    IE6 no understand anythinnnn , see THE rails solution. */
	
}

function adjustCombo(){	
		
		var value = PREFS.findPref(CH_VW_MODE_KEY);
		
		if(value) {
			
			$('chapter-view-controls').down('select').value = value;
			
			if(value == AUTOEXPAND_PREF_KEY) {
				
					expandLinks();
				
			}
			
		}
			
		/* hook-up an event listener on combo */
		$('chapter-view-controls').down('select').observe( 'change' , chapter_view_mode_changed );				
			
	
}

function expandLinks(){
				
		if( M2_LINKS ) {
			var _1stPMNode = M2_LINKS.get1stPMNode();
			_1stPMNode.toggleTargetChild();
		}
		
}



document.observe(	'dom:loaded' , 
					function() { 
					
						/* adjust the combo! */
						if( $('chapter-view-controls') )
											adjustCombo();
											
					}
				);
				
