/* $Id$ 
 *
 *    2002-03-20  db@sv    created
 */
 
function btn_clicked( b, m ) {
	// b = button info from flash
	// m = current module
    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 "teacher_resources":
			url = "resources.html";
			break;

        case "tips":
        case "websites":
        case "movies":
		case "pictures":
		case "posters":
		case "student_resources":
        	url = cmd + ".html";
        	break;
      
		case "books":
			url = "book_resources.html";
			break;
      
/*		case "books":
			url = "books.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 == "pacificcoastsunsets") {
				opts = opts + ",scrollbars=1";
			}
			if (cmd_arg == "foodwebs") {
				opts = "width=750,height=550,resizable=yes";
			}
			if (cmd_arg == "lunarcalendar") {
				opts = "width=695,height=540,resizable=no";
			}
			if ((cmd_arg == "wheredoesitlive") || (cmd_arg == "habitatgallery") ||
				(cmd_arg == "vascular") || (cmd_arg == "circulation") ||
				(cmd_arg == "whatdoesntbelong") || (cmd_arg == "pollinators")) {
				opts = "width=750,height=560,resizable=yes";
			}
			if (cmd_arg == "periodictable") {
				opts = "width=750,height=560,resizable=yes";
			}
			if (cmd_arg == "electromagnet") {
				opts = "width=832,height=656,resizable=yes";
			}
			if (cmd_arg == "resourceid") {
				opts = "width=832,height=656,resizable=yes";
			}			
			open_popup(url, "activityWindow", opts);
			
            //open_activity(url);
            return;
        default:
            url = "unknown.html";
    }
    //open(url, target);  
    frames['mainFrame'].location = url;
}

function habitatgallery() {
	url = "habitatgallery.html";
	opts = "width=750,height=560,resizable=yes";
	open_popup(url, "activityWindow2", opts);
}

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
			//which will be (once its really on fossweb.com):
			//url = "/index.html";
			// but for now we can use:
			url = "../index.html";
			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=650,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 openStandards(url) {
	var url = "../" + url;
	var wname = "standards";
	var options = "toolbar=0,width=800,height=600,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 openTG(url) {
	var url = url;
	var wname = "teacherguide";
	var options = "toolbar=0,width=800,height=600,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);
}

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

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

function openStarMap(url) {
	var wname = "starmap";
	var options = "toolbar=0,width=660,height=550,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);
}
