
	// SMS objects used in this client:
	var infoBubble = null;
	var nsesContent = false;
	var linkToPageOpen = false;
	var resCheckInterval ='';
	
	// Set up event listeners and actions on the Strand Map, on load:
	SMSEvent.addListener(StrandMap,"onload", setUpStrandMap);
	function setUpStrandMap() {
		
		// Set up handlers for actions on the StrandMap:
		infoBubble = StrandMap.getInfoBubble();		
		
		SMSEvent.addListener(StrandMap,"onbenchmarkselect",onBenchmarkSelect);
		SMSEvent.addListener(StrandMap,"onprintviewdisplay",onPrintViewDisplay);
		
		// Use the built-in tabs for displaying related benchmarks and nses standards:
		infoBubble.addBuiltinTab("nsdlaligned","Top Picks");
	
		// Create the 'Resources' tab and set it's handler:
		infoBubble.addBuiltinTab("nsdlrelated","Related Resources");
		
		// Use the built-in tabs for displaying related benchmarks and nses standards:
		infoBubble.addBuiltinTab("nses","NSES Standards");
		
		// Use the built-in tabs for displaying related benchmarks and nses standards:
		infoBubble.addBuiltinTab("relatedbenchmarks","Related Benchmarks");
		
		// When a benchmark is selected by the user, make sure the resourcesTab is displayed:
		SMSEvent.addListener(StrandMap,"onbenchmarkselect", function() {
			nsesContent = false;
			infoBubble.hideTabPane(true);
			infoBubble.hideTab(_nsdlrelatedTab);
			infoBubble.hideTab(_nsdlalignedTab);
			var bmJson = StrandMap.getSelectedBenchmarkRecordJson();
			var sa = bmJson.itemRecord.Data.Standards.toString().split('+');
			if(sa[0] == 'NSES'){
				nsesContent	= true;
				infoBubble.showTab(_nsesTab);
			} else {
				infoBubble.hideTab(_nsesTab);
			}
			StrandMap.getNsdlRelatedResources();
			infoBubble.selectTab(_nsdlalignedTab);
		});
		StrandMap.enableMisconceptions(true);
		// register misconceptions click
		if($('smsMisconceptionsLink')){
			Event.observe($('smsMisconceptionsLink'),'click', trackMisconceptions);
		}
	}

	function onBenchmarkSelect() {
		var id = StrandMap.getSelectedBenchmarkId();
		var mapId = StrandMap.getMapId();
		googleTrack('/content_click/bubble/'+mapId+'/'+id+'/');
		
		// reset page trackers
		resPager = 'page_0_4';
		resStrictPager = 'page_0_4';
		
		infoBubble.setTitle("Benchmark Details");
		infoBubble.setBuiltinContent("benchmarkrelatedmaps");
		
		registerTabs();
		startResCompleteCheck()
	}
	function onPrintViewDisplay() {	
		Event.observe($('mapPdfButton'),'click', trackPrintPdf);
		var inputs = document.getElementsByTagName("input");
		
		Event.observe(inputs[inputs.length - 1], 'mouseup',trackPrintButtons);
		
	}

	function chooseActiveTab(){
		if(alignedResExists != false){
			infoBubble.selectTab(_nsdlalignedTab);
			infoBubble.showTab(_nsdlalignedTab);
			if(relatedResExists != false){
				infoBubble.showTab(_nsdlrelatedTab);	
			}
		} else if(relatedResExists != false){
			infoBubble.selectTab(_nsdlrelatedTab);	
			infoBubble.showTab(_nsdlrelatedTab);
		} else if(nsesContent != false){
			infoBubble.selectTab(_nsesTab);	
		} else{
			infoBubble.selectTab(_bmTab);	
		} 
	
		infoBubble.showTabPane();
		clearInterval(resCheckInterval);
	}
	function startResCompleteCheck(){
		resCheckInterval = setInterval("checkResourcesComplete()",500);
	}
	function checkResourcesComplete(){
		if(relatedResComplete == true && alignedResComplete == true){
			chooseActiveTab();
		}	
	}

	// ----- Other JS for the NSDL client page:
	
	function onPageLoad() {
		var body = document.getElementsByTagName('body')[0];
		Event.observe('contentArea', 'mousedown', onBodyClick, false);
		if($('smsMapTitleBarRight')){
			var a_links = $('smsMapTitleBarRight').getElementsByTagName("a");
			Event.observe(a_links[a_links.length - 1], 'mouseup',trackViewLink);
		}
		nsdlSmsTracker._trackPageview();
		rollupTracker._trackPageview();		
	}
	Event.observe(window, 'load', onPageLoad, false);		
	
	function onBodyClick() {
		if(isHelpDown)	
			toggleHelp();
	}
	
	function trimString (str) {
  		str = this != window? this : str;
  		return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
	}
	function trimws (str) {
		str = str.replace(/^\s+/, '');
		for (var i = str.length - 1; i >= 0; i--) {
			if (/\S/.test(str.charAt(i))) {
				str = str.substring(0, i + 1);
				break;
			}
		}
		return str;
	}
	
	var isHelpDown = false;
	function toggleHelp(){
		if(isHelpDown) {
			if($('smsBrowse')){
				$('smsBrowse').className = 'smsForm';
			}
			Effect.BlindUp('smsUsage',{duration:0.1});
		}
		else{
			if($('smsBrowse')){
				$('smsBrowse').className = 'hide';
			}
			Effect.BlindDown('smsUsage',{duration:0.1});
			googleTrack('/content_click/link/help/');
		}
		isHelpDown = !isHelpDown;
	}
		
	function gup( name )
	{
	  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	  var regexS = "[\\?&]"+name+"=([^&#]*)";
	  var regex = new RegExp( regexS );
	  var results = regex.exec( window.location.href );
	  if( results == null )
	    return "";
	  else
	    return results[1];
	}
	

