

/*
 ****************************************************
 *	Main content (onload, content switching, etc	*
 ****************************************************
 */
 
 
if(window.widget) {
	widget.onshow = onShow;
}

function onShow() {
    retrieveAssignments();
}

function retrieveAssignments()
{
    if (AssignmentPlannerWidgetPlugin) {
    
		var text = AssignmentPlannerWidgetPlugin.getAssignmentTable();
		document.getElementById("mainContent").innerHTML = text;

        scrollArea.reveal( document.getElementById("mainContent") );
        scrollArea.refresh();
	}
}

var scrollbar, scrollArea;
var glassDoneButton, whiteInfoButton;

function loaded() {

    // Scroll Bar
	scrollbar = new AppleVerticalScrollbar(document.getElementById("myScrollBar"));
	scrollArea = new AppleScrollArea(document.getElementById("parentDiv"), scrollbar);
	scrollArea.scrollsHorizontally = false;
	scrollArea.singlepressScrollPixels = 25;
	scrollArea.focus(); // for key control when first loading in Safari
	
	window.onfocus = function () { scrollArea.focus(); }
	window.onblur = function () { scrollArea.blur(); }
	
    // Flip Button
    glassDoneButton = new AppleGlassButton(document.getElementById("doneButton"), "Done", hidePrefs);
	whiteInfoButton = new AppleInfoButton(document.getElementById("infoButton"), document.getElementById("front"), "white", "white", showPrefs);
	
	retrieveAssignments();
}

// showPrefs() is called when the preferences flipper is clicked upon.  It freezes the front of the widget,
// hides the front div, unhides the back div, and then flips the widget over.

function showPrefs()
{
    AssignmentPlannerWidgetPlugin.showButtons();
		
	var front = document.getElementById("front");
	var back = document.getElementById("back");
	
	if (window.widget)
		widget.prepareForTransition("ToBack");		// freezes the widget so that you can change it without the user noticing
	
	front.style.display="none";		// hide the front
	back.style.display="block";		// show the back
	
	if (window.widget)
		setTimeout ('widget.performTransition();', 0);		// and flip the widget over	

}

// hidePrefs() is called by the done button on the back side of the widget.  It performs the opposite transition
// as showPrefs() does.

function hidePrefs()
{
	var front = document.getElementById("front");
	var back = document.getElementById("back");
	
	if (window.widget)
		widget.prepareForTransition("ToFront");		// freezes the widget and prepares it for the flip back to the front
	
	back.style.display="none";			// hide the back
	front.style.display="block";		// show the front
	
	if (window.widget)
		setTimeout ('widget.performTransition();', 0);		// and flip the widget back to the front
		
    AssignmentPlannerWidgetPlugin.hideButtons();
    
    retrieveAssignments();
}

function gotoWebsite()
{
	theResult = true;
	if (window.widget) {
		widget.openURL("http://www.assignmentplanner.com");
		theResult = false;
	}
	return theResult;
}

function openApplication()
{
	theResult = true;
	if (window.widget) {
		widget.openURL("assigmentplanner.rtf");
		
		widget.system('osascript -e \'delay 0.1\'', null);
		widget.system('osascript -e \'tell application "Assignment Planner" to activate\'', null);
		theResult = false;
	}
	return theResult;
}
