/* $Id$ 
 *
 *    2002-03-20  db@sv    created
 */
 
function btn_clicked( b, m ) {
	// b = button info from flash
	// m = current module
	
	//alert( "button: " + b + " | module: " + m );
    var re = /^([\w_-]+):?(\w*)$/;
    var re_match = re.exec(b);
    var cmd = re_match[1];
    var cmd_arg = re_match[2];
    
	//alert(cmd);
	
    var url = "";
    // they all go into frame mainFrame except for activities
    var target = "_parent.mainFrame";
    // now find the url
    switch ( cmd ) {
        case "module_main":
			url = "module_welcome.html";
		break;
        case "module_summary":
            url = "summary.html";
            break;
        case "vocabulary":
		case "glossary":
			url = "vocab.html";
			break;
        case "plant_and_animal_care":
			url = "plantanimal.html";
			break;
        case "home-school_connection":
			url = "home.html";
			break;
		case "photo_gallery":
			url = "gallery/index.html";
			break;
        case "ask-a-scientist":
			url = "ask.html";
			break;
        case "resources":
        case "tips":
        case "websites":
        case "movies":
		case "pictures":
		case "posters":
		case "media":
		case "teacher_resources":
        	url = cmd + ".html";
        	break;
		case "books":
			url = "books_resources.html";
			break;
		case "references":
			// MS uses "references" but its the same as "resources"
			url = "resources.html";
			break;
		case "course_notes":
			// MS uses "course_notes" which is "tips & tricks"
			url = "tips.html";
			break;
		case "lab_notebook":
			// added for MS modules...
			url = "notebook.html";
			break;
        case "ACTIVITY":
        	url = "activities/" + cmd_arg + ".html";
			opts = "width=620,height=440,resizable=yes";
			// special case for rock database, dagnabbit
			if(cmd_arg == "rockdatabase") {
				url = "activities/rockdatabase/index.html";
				opts = opts + ",scrollbars=1";
			}
			if (cmd_arg == "lunarcalendar") {
				opts = "width=695,height=540,resizable=no";
			}
			else if(cmd_arg == "pacificcoastsunsets") {
				opts = opts + ",scrollbars=1";
			}
			open_popup(url, "activityWindow", opts);
            //open_activity(url);
            return;
		case "multimedia":
			// only MS uses this (for now); opens the on-the-web module's online CD content
			url = "../kit_multimedia/" + m + "/";
			open( url, "_blank" );
			return;
		case "planetfoss":
			if (m == "HumanBrain") m = "HumanBrainandSenses";
			url = "../../planetfoss/"+m+"/";
			open( url, "_blank" );
			return;
        default:
            url = "unknown.html";
    } // end long switch statement
    //open(url, target);  
    frames['mainFrame'].location = url;
}

function top_bar_btn_pressed(b) {
	//alert(b);
	var url = "";
	var tgt = "";
	switch( b ) {
		case "search":
			// for now its a fake page...
			url = "search.html";
			tgt = "_top";
			break;
		case "welcome":
			// load the main FOSSWeb welcome page
			url = "../";
			tgt = "_top";
			break;
		case "fossweb":
			// do nothing?
			break;
		case "foss":
			// do nothing?
			break;
		case "another_module":
			// load the potato-main frameset for the current age range
			url = "index.html";
			tgt ="_top";
			break;
		case "calculator":
			open_calculator();
			return;
		default:
			//do nothing
	}
	if ( url != "" && tgt != "" ) {
		open( url, tgt );
	}
}

function open_popup(url, wname, options) {
	win = window.open(url, wname, options);
	// bring window to front if its already open
	//  timeout is workaround so IE will focus the window
	t = setTimeout("win.focus();",5);
}

function module_main( module ) {
	var url = module + "/index.html";
	open( url, "_top" );
}

function openGallery(url) {
	var wname = "gallery";
	var options = "toolbar=0,width=660,height=550,innerHeight=0,innerWidth=0,outerHeight=0,outerWidth=0,screenX=0,left=0,screenY=0,top=0,channelmode=0,dependent=0,directories=0,fullscreen=0,location=0,menubar=0,resizable=1,scrollbars=1,toolbar=0,status=0";
	open_popup(url,wname,options);
}

function open_calculator() {
	var url = "calculator.html";
	var options = "toolbar=0,width=200,height=230,menubar=0,scrollbars=0,status=0";
	open_popup(url, "calc", options);
}
