//<![CDATA[ 

var ImgSizes = new Array();
var min_menu_height = 500;
// croc_h300A.jpg
/*
var slide_list = new Array ("http://raupplab.umd.edu/images/banner/toucan_342x220.jpg", "http://raupplab.umd.edu/images/banner/flower_h300.jpg", "http://raupplab.umd.edu/images/banner/croc_360x219.jpg", "http://raupplab.umd.edu/images/banner/scorpion_326x220.jpg", "http://raupplab.umd.edu/images/banner/group2_h300.jpg", "http://raupplab.umd.edu/images/banner/army-ant_319x220.jpg",
"http://raupplab.umd.edu/images/banner/belize1_335x220.jpg", "http://raupplab.umd.edu/images/banner/tarantula_330x230.jpg", "http://raupplab.umd.edu/images/banner/belize2_331x220.jpg",
"http://raupplab.umd.edu/images/banner/stingless_bee_350x238.jpg",
"http://raupplab.umd.edu/images/banner/stingless_bee_330x253.jpg"
);
*/

/*
var slide_list = [
["/images/banner/h1/h1-fall-cankerworm-adult.jpg",""],
["/images/banner/h1/h1-lacewing-larva.jpg","http://raupplab.umd.edu/bugweek/archive/BugOfWeek_15B.html"],
["/images/banner/h1/h1-mealybug.jpg","http://raupplab.umd.edu/bugweek/archive/BugOfWeek_22B.html"],
["/images/banner/h1/h1-patuxent-winter.jpg","http://raupplab.umd.edu/bugweek/archive/BugOfWeek_19.html"],
["/images/banner/h1/h1-stonefly-adult.jpg","http://raupplab.umd.edu/bugweek/archive/BugOfWeek_19.html"],
["/images/banner/h1/h1-tenebrionids-adult.jpg","http://raupplab.umd.edu/bugweek/archive/BugOfWeek_19.html"],
["/images/banner/h1/h1-ants-scale.jpg","http://raupplab.umd.edu/bugweek/archive/BugOfWeek_19.html"],
["/images/banner/h1/h1-eggs-1.jpg","http://raupplab.umd.edu/bugweek/archive/BugOfWeek_19.html"],
["/images/banner/h1/h1-eggs-2.jpg","http://raupplab.umd.edu/bugweek/archive/BugOfWeek_19.html"],
["/images/banner/h1/h1-holly-berries.jpg","http://raupplab.umd.edu/bugweek/archive/BugOfWeek_19.html"],
["/images/banner/h1/h1-leaf-tube.jpg","http://raupplab.umd.edu/bugweek/archive/BugOfWeek_19.html"],
["/images/banner/h1/h1-snow-scropion.jpg","http://raupplab.umd.edu/bugweek/archive/BugOfWeek_19.html"]
];
*/
var slide_list = [
["/images/banner/may-june/androm-lacebug.jpg",""],
["/images/banner/may-june/ant-guard-aphid.jpg",""],
["/images/banner/may-june/",""],
["/images/banner/may-june/boxwood-aphid.jpg",""],
["/images/banner/may-june/carpenter-bee.jpg",""],
["/images/banner/may-june/dragonfly-adult.jpg","http://raupplab.umd.edu/bugweek/archive/BugOfWeek_25B.html"],
["/images/banner/may-june/green-tiger-beetle.jpg",""],
["/images/banner/may-june/harmonia-eggs.jpg",""],
["/images/banner/may-june/honeyad.jpg",""],
["/images/banner/may-june/inch-worm.jpg",""],
["/images/banner/may-june/mosquito-larvae.jpg",""],
["/images/banner/may-june/stripped-larvae.jpg",""],
["/images/banner/may-june/tiger-mosquito.jpg",""],
["/images/banner/may-june/black-widow.jpg",""],
["/images/banner/may-june/royal-moth-adults.jpg",""],
["/images/banner/may-june/rsp-adult.jpg",""],
["/images/banner/may-june/rsp2.jpg",""],
["/images/banner/may-june/syrphid-adult.jpg",""],
["/images/banner/may-june/tipulid-adult.jpg",""]
];

function blockImgRCEvents(evt) {
    evt=(evt?evt:event);
    var blockit=false;
    var elem = (evt.target?evt.target:(evt.srcElement?evt.srcElement:null));
    if (elem && elem.tagName && elem.tagName.toLowerCase()=="img") {
        if (evt.cancelBubble)
            evt.cancelBubble=true;
        //alert
        return false;
    }
    return (blockit);
}
// document.oncontextmenu=blockImgRCEvents;

/*
function blockAllRCEvents(evt) {
    evt=(evt?evt:event);
    var blockit=false;
    var elem = (evt.target?evt.target:(evt.srcElement?evt.srcElement:null));
    //if (elem && elem.tagName && elem.tagName.toLowerCase()=="img") {
        if (evt.cancelBubble)
            evt.cancelBubble=true;
        //alert
        return false;
    //}
}
//document.oncontextmenu=blockAllRCEvents;
*/

//*********************IMAGES.JS **************************

           
function preloadImages (img_list){
     if (document.images) {
        var obj_list = new Array();
        for (var x=0; x<img_list.length; x++) {
            var i = new Image();
            i.src = img_list[x][0];
            if (img_list[x][1].length<2)
                i.img_link = "";
            else
                i.img_link = img_list[x][1];
            obj_list.push(i);
        }
        return (obj_list);
    }
    return null;
}
            
function onImageClick () {
    if (onImageClick.img_link)
        newWindow2(onImageClick.img_link,50,50,80);
}

function rotateSlides (img_obj_list, img_name) {
    rotateImages (img_obj_list, img_name,"slide_showx");
}

function rotateImages (img_obj_list, img_name, img_div) {
    if (!rotateImages.last_ndx)
        rotateImages.last_ndx = -1;
    var img_el = document.getElementById(img_div);
    var max = img_obj_list.length;
    var n = Math.round(Math.random()*10);
    var prefix = "http://www.raupplab.umd.edu/";

    while (n >= max || n == rotateImages.last_ndx) {
        n = Math.round(Math.random()*10);
    }
    
    rotateImages.last_ndx = n;
    var img_link = img_obj_list[n].img_link;
    
    if (n>=0 && n < max && document.images[img_name]) {
        document.images[img_name].src = img_obj_list[n].src;
        if (img_el && document.images[img_name].src=="") {
            //img_el.style.cursor="normal";
            //img_el.style.visibility="hidden";
            onImageClick.img_link=null;
        }
        else if (img_el) {
            img_el.style.visiblity="visible";
            if (img_link && img_link.length>1) {
                onImageClick.img_link=img_link;
                img_el.style.cursor="pointer";
                img_el.onclick=onImageClick;
            }
            else {
                //img_el.style.cursor="arrow";
                img_el.onclick="";
            }
        }
    }
}

function clearWindow (div_id, method, delay) {
    if (!clearWindow.d)
	clearWindow.d = document.getElementById(div_id);
    if (!clearWindow.method)
	clearWindow.method=method;
    if (!clearWindow.delay)
	clearWindow.delay=delay;
    if (!clearWindow.x)
	clearWindow.x = 0;
    if (!clearWindow.s) {
	clearWindow.s = clearWindow.d.innerHTML;
	clearWindow.s_len = clearWindow.s.length;
    }
    if (!clearWindow.method || clearWindow.method==1) {
	try {
	    if (clearWindow.x<clearWindow.s_len) {
		clearWindow.d.innerHTML=clearWindow.s.slice(clearWindow.x);
		clearWindow.x = clearWindow.x+4;
		window.setTimeout("clearWindow();", clearWindow.delay);
	    }
	    else
		return (true);
	}
	catch (ex) {
	    return (false);
	}
    }
    else if (clearWindow.method==2) {
	clearWindow.used_nums_list = null;
	if (clearWindow.x < clearWindow.s_len-1) {
	    var n = getPseudoRandom(clearWindow.s.length-1, clearWindow.used_nums_list); 
	    clearWindow.s = clearWindow.s.slice(0,n)+" "+clearWindow.s.slice(n+10);
	    clearWindow.d.innerHTML = clearWindow.s; //clearWindow.s.slice(0,n)+"&nbsp;"+clearWindow.s.slice(n);
	    //clearWindow.d.innerHTML=clearWindow.s;
	    clearWindow.x = clearWindow.x + 10;
	    window.setTimeout("clearWindow();", clearWindow.delay);
	}
	else
	    return(true);
    }
    else if (clearWindow.method==3) {
	alert (clearWindow.d.style.zIndex);
    }
    return (false);
}


var LinkXFileNdx=0;

function writeLLink (LinkName,PromptName) {
   var cmd;
   var fixed_link = LinkName;

   var replace_targets=[["\n",""],["<br />",""],["<br>",""]];
   for (var x=0; x<replace_targets.length; x++) {
       fixed_link=replaceStringAll(fixed_link,String(replace_targets[x][0]),String(replace_targets[x][1]));
   }
    var n = fixed_link.toLowerCase().indexOf("http:");
    var click_link = fixed_link;
    if (n>0) 
    click_link=fixed_link.substring(n);
   if ((navigator.appName=="Netscape" && parseInt(navigator.appVersion)<5) || (navigator.appName=="Microsoft Internet Explorer" && parseInt(navigator.appVersion)<8)) {
      cmd = "<a href=\""+click_link+"\">"+PromptName+"</a>";
      document.write(cmd);
   }
   else {
      var rname = "writelink"+(LinkXFileNdx++);
      cmd = '<a href="#'+rname+'" name="'+rname+'" onclick=\'javascript:newWindow2(\"'+click_link+'\",50,50,80);\'>'+PromptName+'</a>';
      document.write(cmd);
   }
   return(cmd);
}


function eggQuiz(rollover_id,quiz_id,action,side) {
    var rid = document.getElementById(rollover_id);
    var qid = document.getElementById(quiz_id);
    var mess_id;
    if (quiz_id == "EggQuiz1") {
        mess_id = document.getElementById("quiz1_mess");
    }
    else if (quiz_id == "EggQuiz2") {
        mess_id = document.getElementById("quiz2_mess");
    }
    else if (quiz_id == "EggQuiz3") {
        mess_id = document.getElementById("quiz3_mess");
    }
    else if (quiz_id == "EggQuiz4") {
        mess_id = document.getElementById("quiz4_mess");
    }
    if (mess_id) {
        setText(mess_id,"");
    }
    if (rid && qid) {
        var rid_pos = getElementPosition(rollover_id);
        if (rid_pos) {
            qid.style.top=(parseInt(rid_pos.top)-60)+"px";
            if (side == "left") {
                qid.style.left=(parseInt(rid_pos.left)+parseInt(rid.style.width)-80)+"px";
            }
            else if (side == "RIGHT") {
                qid.style.left=(parseInt(rid_pos.left)-parseInt(qid.style.width)+80)+"px";
            }
            if (action==1) {
                qid.style.visibility="visible";        
            }
            else {
                ; //qid.style.visibility="hidden";
            }
        }
    }
}

// old stuff****************************************

displayVideo.video_list = new Array();
	
function restartApplet (applet_name) {
    //window.location.href=window.location.href+"#"+applet_name;
    window.location.href=window.location.href;
    var d = document.applet_name;
    if (d) {
	//d.start();
    }
}

function displayVideo (format, audio_enabled, filename, java_archive, float_pos, caption, width, height, vid_id) {
	var archive = java_archive;
	var video_id = "format"+video_list.length;
	if (vid_id)
		video_id = vid_id;
	var applet_name = video_id+"_applet";
	video_list.push(video_id);
	var w=336;
	if (typeof width != "undefined")
		w=width;
	var h=230;
	if (typeof height != "undefined")
		h=height;
	if (1==1) {
		var cmd = '\
			<a name="'+applet_name+'"></a> \
			<div id="'+video_id+'" style="position:relative; float:'+float_pos+'; \
			width:'+(w)+'px; padding:5px;margin:5px;border:3px ridge \
				rgb(0,128,0); z-index:1000;"> \
				<div id="mpg_player" style="position:static;">';
					if (format=="MPEG4" || format=="MP4") {
						if (archive==null)
							archive="mediaframe-mpeg4.jar,mediaframe-aac.jar";

							cmd = cmd+'<applet name="'+applet_name+'" code="mediaframe.mpeg4.MPEG4.class" archive="'+archive+'" width="'+width+'" height="'+height+'" mayscript="true"> \
							<param name="id" value="ID: "'+filename+'" /> \
							<param name="default_media"		value="'+filename+'" /> \
							<param name="pre_buffer"	value="50%" /> \
							<param name="playback"	value="auto_start" /> \
							<param name="loop"	value="true" /> \
							<param name="control_location" value="http://raupplab.umd.edu/video/icons" />';
							//<param name="pre_screen"		value="posters/pre.gif" /> \
							cmd = cmd + '<param name="pre_screen_loop"	value="false" />';
							cmd = cmd + '<param name="post_screen"		value="false" /> ';
							cmd = cmd + '<param name="post_screen_loop"	value="false" /> \
							<param name="audio"	  		value="'+(audio_enabled?"true":"false")+'" /> \
							<param name="smooth_video"		value="true" /> \
							<param name="video_license"		value="false" /> \
							<param name="allow_save"		value="false" /> \
						</applet>';
					}
					else if (format=="MPG" || format=="MPEG") {
						if (archive==null)
							archive = "mediaframe-mpeg1.jar";
						cmd = cmd+'<applet name="'+video_id+'_applet" code="mediaframe.mpeg1.MPEG1.class" archive="'+archive+'" width="'+(w)+'" height="'+(h)+'" mayscript="true">';
							cmd = cmd+'<param name="id" value="ID: '+filename+'" />';
							cmd = cmd + '<param name="video_license"		value="false" /> ';
							cmd = cmd + '<param name="allow_save"		value="false" /> ';
							cmd = cmd + '<param name="pre_buffer"  		value="25%" /> ';
							cmd = cmd + '<param name="audio"	  		value="'+(audio_enabled?"true":"false")+'" /> ';
							cmd = cmd + '<param name="default_media"		value="'+filename+'" /> ';
							cmd = cmd + '<param name="startup_volume"	value="100%" /> ';
							cmd = cmd + '<param name="loop"	 		value="true" /> ';
							cmd = cmd+'<param name="controls"	  		value="true" /> ';
							cmd = cmd + '<param name="playback"	  		value="AUTO_START" /> ';
							cmd = cmd + '<param name="feedback_agent"	value="true" /> ';
							cmd = cmd + '<param name="cache"	 		value="true" /> ';
							cmd = cmd + '<param name="target" 		value="_blank" /> ';
						cmd = cmd + '</applet>';
					}
				cmd = cmd + '</div>';
				cmd = cmd + '<div style="position:static; padding-top:3px; padding-left:1px; width:98%; font-weight:normal; font-size:0.8em; font-style:oblique; color:rgb(0,64,64);"> '+caption+' <a href="#" onclick=\'javascript:restartApplet("'+applet_name+'");\'>(if video fails to start, click *here*)</a></div>';
			cmd = cmd + '</div> <!-- video -->';
			document.writeln (cmd);
	} // if format=="MPG"
	return video_id;
}

function displayImage (ximg_src, align, width, caption, img_name, xsecond_img_src, second_img_width, link_text, top_adjust, hide_div) {
    var img_src=ximg_src;
    if (img_src.indexOf("/bugweek")==0)
	img_src="http://raupplab.umd.edu"+img_src;
    var second_img_src=xsecond_img_src;
    if (second_img_src.indexOf("/bugweek")==0)
	second_img_src="http://raupplab.umd.edu"+second_img_src;
    var top_offset = 0;
    if (top_adjust && top_adjust!=null)
	top_offset = top_adjust;
    var l_text="click *here* to see a larger image.";
    if (link_text) {
        l_text=link_text;
    }
    var hd=null;
    if (hide_div && hide_div!=null)
	hd=document.getElementById(hide_div);
    var second_img_name = img_name+"_lg";
    var caption2;
     //second_img_src.substring(0,second_img_src.lastIndexOf("."));
    if (navigator.appName.toUpperCase().indexOf("MICROSOFT")>=0) {
        caption2 = caption+'  <span style="color:rgb(0,0,211); cursor:pointer;" onclick = \'  javascript:newWindow2("'+second_img_src+'",50,50,80);\'>'+l_text+'</span>';
    }
    else {
        caption2 = caption+'  <span style="color:rgb(0,0,211); cursor:pointer;" onclick = \'  document.getElementById("'+second_img_name+'").style.display = "block";\'>'+l_text+'</span>';
    }
    var cmd='<div id="'+img_name+'" class=\"caption\" style="position:relative; margin:5px; float:'+align+'; width:'+width+'px;">';
    cmd += '<div><img src="'+img_src+'" name="'+img_name+'" usemap="#'+img_name+'" border="0" width="'+width+'" /></div>';
    if (second_img_src) {
	if (hd)
	    hd.style.display="none";
        cmd += '<div id="'+second_img_name+'" style="position:absolute; cursor:pointer;';
        if (align.toUpperCase() == "RIGHT") {
            var nleft = -400;
            var ntop = -100 + top_offset;
            cmd += ' left:'+(nleft)+'px; top:'+(ntop)+'px; ';
        }
        else if (align.toUpperCase() == "LEFT") {
            var ntop = -200 + top_offset;
            var nleft = 50;
            cmd += ' left:'+(nleft)+'px; top:'+(ntop)+'px; ';
        }
        
        cmd += ' display:none; z-index:600;" onclick=\'';
	if (hd)
	    cmd += 'document.getElementById("'+hide_div+'").style.display="block";';
	cmd += 'this.style.display="none";\'>';
            cmd += '<img name="'+second_img_name+'" src="'+second_img_src+'" width="'+second_img_width+'" border="0" />';
        cmd += '</div>';
        cmd += '<span class="Caption">'+caption2+'</span>';
    }
    else {
        cmd += '<span class="Caption">'+caption+'</span>';
    }
    cmd += '</div>';
    document.writeln(cmd);
}

//****************************** OGG video ********************************************

	function videoOGG (url, audio, float_dir, width, height, caption, applet_id, auto_play, loop) {
		this.url = url;
		this.audio = audio;
		this.float_dir = float_dir;
		this.width = width;
		this.height = height;
		this.caption = caption;
		this.applet_id = applet_id;
		this.wrapper_div_id = this.applet_id+"_wrapper";
		
		this.codebase = "/js/";
		this.code = "com.fluendo.player.Cortado.class";
		this.archive = "cortado-ovt-stripped-0.2.2-umd.jar";
		this.buff_size = "800";
		this.auto_play = true;
		if (auto_play)
			this.auto_play = auto_play;
		this.loop = true;
		if (loop)
			this.loop = loop;
		
		this.init = initVideoOGG;
		this.setBuffer = setVideoOGGBuffer;
		this.getWrapperID = getVideoOGGWrapperID;
	}
	function setVideoOGGBuffer (new_buff_size) {
	    this.buff_size = new_buff_size;
	}
	function getVideoOGGWrapperID () {
		return (this.wrapper_div_id);
	}
	function initVideoOGG () {
		var cmd = '<div id="'+this.wrapper_div_id+'" style="position:relative; width:'+this.width+'px; float:'+this.float_dir+'; border:2px ridge rgb(0,64,0);">';
			cmd = cmd + '<applet id="'+this.applet_id+'" codebase="'+this.codebase+'" code="'+this.code+'" archive="'+this.archive+'" width="'+this.width+'" height="'+this.height+'">';
			cmd = cmd + '<param name="url" value="'+this.url+'" />';
			cmd = cmd + '<param name="live" value="false" />';
			 cmd = cmd + '<param name="local" value="true"  />';
			 cmd = cmd + '<param name="keepAspect" value="true" />';
			 cmd = cmd + '<param name="video" value="true" />';
			 cmd = cmd + '<param name="audio" value="'+(this.audio?"true":"false")+'" />';
			 cmd = cmd + '<param name="bufferSize" value="'+this.buff_size+'" />';
			 cmd = cmd + '<param name="seekable" value="auto" />';
			 cmd = cmd + '<param name="autoPlay" value="'+(this.auto_play?"true":"false")+'" />';
			 cmd = cmd + '<param name="loop" value="'+(this.loop?"true":"false")+'" />';
			 cmd = cmd + '</applet>';
			cmd = cmd+'<div style="position:relative; font-size:0.8em; font-family:times,serif; width:98%; margin-left:1%; margin-top:1mm; line-height:0.9; color:rgb(0,0,0); ">';
			cmd = cmd + '<table style="width:100%;"><tr><td>'+this.caption+'</td>';
			cmd = cmd + '<td><div style="position:relative; float:right; border-left:1px ridge navy; font-size:0.9em; padding:1mm; line-height:1.1;">';
			cmd = cmd + '<div><a href="#" style="float:right;" onclick=\'var d = document.getElementById("'+this.applet_id+'"); d.doSeek(0.0);d.doPlay();\'>Play</a></div>';
			cmd = cmd + '<div><a href="#" style="float:right;" onclick=\'var d = document.getElementById("'+this.applet_id+'"); d.doStop();\'>Stop</a></div>';
			cmd = cmd + '</div>\n</td></table>\n</div>\n</div>';
		document.writeln(cmd);
	}


//]]>

