// resourcesDetails.js
var displayWidget = false;
var widgetDisplayedId="";
var flashArray = new Array();

function goToResources() {		
	document.getElementById("feedbackContainer").style.visibility='hidden';
	
	/**Uncomment below if you want to return to previously opened resource rather than list
	*/
	//if (displayWidget) {
	//	openWidget(widgetDisplayedId);
	//} else {
		loadResourceList();
	//}
}

function loadResourceList() {
	displayScorcher = 0;
	displayWidget = false;

	document.body.style.cursor = "wait";

	url = "/AJAXGetResources"
	data = "loadResource=1&fromRefresh="+fromRefresh+"&conceptId="+conceptId;
    sendHttpRequest();
}

function saveWidgetDetails(whichWidget) {
	document.body.style.cursor = "wait";
	
	url = "/AJAXRecordWidget"
	data = "widgetId="+whichWidget+"&conceptId="+conceptId;
    sendHttpRequest();
}

function loadResourcesStructure() {
	/*
	var _targ=document.getElementById("contentLeftDiv");
	var html='';
	html+='<div id="headingContainer" style=\"float:left;\">'
	html+='	<div id="whichWalkthrougDiv">Resource list</div>'
	html+='</div>'
	html+='<div id="questionContainer">'
	html+='		<div id="sectIndInstruct">Select a resource from the list.</div>'
	html+='	<div id="sectIndContainer">'
	html+='	</div>'
	html+='</div>'
	_targ.innerHTML=html;
	
	//xHeight("questionContainer", xHeight("contentDiv")-xHeight("headingContainer")-8);  // 8px is for the padding-bottom for the contentDiv
	*/
}

function openWidget(whichWidget) {
	saveWidgetDetails(whichWidget);
	setupTabDetails("resources");

	displayWidget = true;
	widgetDisplayedId=whichWidget;

	document.getElementById("headingContainer").innerHTML="";
	document.getElementById("sectIndContainer").innerHTML="Insert flash widget here";
	document.getElementById("questionContainer").style.backgroundColor="#BCD2F4";
	adjustWidget();
	//readjust for maximum height
	xHeight("questionContainer",xHeight("contentDiv")-16);
	xHeight("headingContainer",8);
	
	var fo = new FlashObject(flashArray[whichWidget], "widget", "100%", "100%", "7");
	fo.addParam("FlashVars","fullscreen=false");
	fo.write("questionContainer");
	
}

function loadWidgetFullScreen(widgetLocation) {	
	var feedWidth = screen.availWidth - 50
	var feedHeight = screen.availHeight - 70
	var w = feedWidth/3, h = feedHeight/3, cw = w/2, ch = h/2;

	if (window.screen) {
		cw = Math.floor((screen.availWidth / 2) - (feedWidth / 2));
		ch = Math.floor((screen.availHeight / 2) - (feedHeight /2));
	}
	
	var flash = flashArray[widgetDisplayedId];
	if(flash == undefined)flash = widgetLocation;
	// remove & from the widget name and replace with #38;
	if (flash.indexOf("&") != -1) {
		flash = flash.replace("&", "InsertAmp")
	}

	widgetWin = open('/stage5/lessonSection/flashPopup.jsp?flashFile=' + flash, 'flashWindow', 'width=' + feedWidth + ',height=' + feedHeight + ',scrollbars=no,toolbar=no,location=0,directories=0,status=0,menuBar=0,resizable=yess,top='+ch+',left='+cw)
	widgetWin.focus();
}