SMSEvent.addListener(StrandMap,"onload", setUpStrandMap);

var infoBubble = null;
var resourcesTab = null;
var parms = window.location.search.parseQuery();

function setUpStrandMap() {
				
	StrandMap.enableMisconceptions(true);
	infoBubble = StrandMap.getInfoBubble();	
	SMSEvent.addListener(StrandMap,"onbenchmarkselect",onBenchmarkSelect);
	SMSEvent.addListener(StrandMap,"onprintviewdisplay",onPrintViewDisplay);
	
	
	// Create the 'Resources' tab and set it's handler:
	resourcesTab = new InfoBubbleTab('DLESE Resources');
	infoBubble.addTab(resourcesTab); 
	SMSEvent.addListener(StrandMap,"onbenchmarkselect",resourcesTabCallback);
	
	//infoBubble.addBuiltinTab('nsdlaligned', 'NSDL Top Picks');
	//infoBubble.addBuiltinTab('nsdlrelated', 'NSDL Resources');
	infoBubble.addBuiltinTab("nses","NSES Standards");
	infoBubble.addBuiltinTab("relatedbenchmarks","Related Benchmarks");
	
}
function onBenchmarkSelect() {
	infoBubble.setTitle("Benchmark Details");
	infoBubble.setBuiltinContent("benchmarkonly");
	infoBubble.selectTab(resourcesTab);
}
function onPrintViewDisplay() {
	sendResRequest(0,'printView');
}
function openPrintView() {
	var bmId = StrandMap.getSelectedBenchmarkId();
	if(bmId != null)	
		window.location='?view=print&id='+parms.id+'&bm='+bmId;
	else
		window.location='?view=print&id='+parms.id;
}

function resourcesTabCallback() {	
	sendResRequest(0);
}

function sendResRequest(offset,context) {
	resourcesTab.setContent('Loading...');
	
	if(!offset)
		offset = 0;		
	
	var bmId = StrandMap.getSelectedBenchmarkId();
	if(bmId == null)
		return;
	
	var reqUrl = "tabs/all_resources_tab.jsp?bm="+ bmId + "&mapId="+ StrandMap.getMapId() + "&alls="+offset;
	
	new Ajax.Request(
		reqUrl,
		{
			method: 'get', 			
			onSuccess: function (response) {
				var c;
				if(response.responseText) {
					resourcesTab.setContent(response.responseText);
					if(context && context == 'printView')
						StrandMap.setPrintViewContent('<div class="pvHeading" style="padding-bottom:5px">DLESE Resources</div>'+response.responseText);
				}
			},
			onFailure: function (response) {
				resourcesTab.setContent('No resources are available');
			}			
	});
}

function openSelectedMap() {
	var s = $('id');
	var id = s.options[s.selectedIndex].value;
	if(id.length > 0)
		window.location = '?id='+id;
	else
		window.location = './';
}


