// $Id: mcal_scroll1.js,v 1.18 2011/09/06 23:32:38 yu Exp yu $

//messages: set your own; use as many as you'd like; set up Hyperlinks to
//URLs as you normally do: <a target=... href="... URL ...">..message..</a>;
var singletext=new Array();
singletext[0]='Upcoming seminars and colloquia......<p style="color: purple;font-size:x-small">move your mouse pointer here to pause, <br>or click to go to the calendar page.</p>';
//-- end Parameters and message -->

// ajax lib yu@math.duke.edu.
var xmlreq=false, xmlwait=false; // xmlwait to prevent http error 0 on repeated clicks.
function createXMLHttpRequest(){
	if(xmlreq) return;
	if(window.XMLHttpRequest){
		try{ xmlreq = new XMLHttpRequest(); }catch(e1){;}
	}else if(window.ActiveXObject){
		try{
			xmlreq = new ActiveXObject("Msxml2.XMLHTTP");
		}catch(e1){
			try{ xmlreq = new ActiveXObject("Microsoft.XMLHTTP"); }catch(e2){;}	
		}
	}
	xmlwait=false; // first use.
}
function sendXMLHttp(action,method,async,data){
	createXMLHttpRequest(); if(!xmlreq || xmlwait) return;
	try{ xmlwait=true;
	if(!method || method.match(/[Gg][Ee][Tt]/)){
		xmlreq.open('GET', /* document.location+ */action, async?true:false);
		xmlreq.onreadystatechange=handleXMLHttpResponse;
		xmlreq.send(null);
	} }catch(er){xmlwait=false;}
}
function handleXMLHttpResponse(){
    try{ if(xmlreq.readyState == 4){
    	if(xmlreq.status == 200){
        	var response = xmlreq.responseText; //alert(response);
        	var a=response.split('</B><ul>');
        	if(a[1]){ //alert(a[1]);
        		var b=a[1].split('</ul><hr>');
        		if(b[0]){ a=b[0].split('<p></li>');
        			for(var j=0; j<a.length; j++){ if(j>=5) break;
        				var c=a[j].split('<DL>&nbsp;<DT>');
        				singletext[j]=c[0]?c[0]:a[j]; //alert(singletext[j]);
        			}
        			start(); // not to take time to show the initial info.
        		}
        	}
   		}else{
    		//alert("HTTP error: "+xmlreq.status);
    	}
    	xmlwait=false;
    } }catch(er){xmlreq=xmlwait=false;}
}
sendXMLHttp('/mcal?listgroup-0','GET',true,'');

/**************************************
* http://vertical-scroller.vbarsan.com/
*    This notice may not be removed 
**************************************/
//-- Begin Scroller's Parameters and messages -->
//scroller's width
var swidth=380; // default
if(1){
	var w1=parseInt((window.innerWidth ? window.innerWidth : 
		document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth :
		document.body && document.body.clientWidth ? document.body.clientWidth : 0) * 0.85 * 0.49 - 80); //alert(w1);
	if(w1<200){
		swidth=200;
	}else if(w1>swidth*2){
		swidth*=2;
	}else{
		swidth=w1;
	}
}

//scroller's height
var sheight=100;

//scroller's speed 
var sspeed=3;
var restart=sspeed;
var rspeed=sspeed;

//scroller's pause 
var spause=1000;

//scroller's background
var sbcolor="#f4f2c1";

//-- begin: Scroller's Algorithm -->
var ii=0;
function goup(){if(sspeed!=rspeed*16){sspeed=sspeed*2;restart=sspeed;}}

function start(){
if(document.getElementById){ns6div=document.getElementById('iens6div');ns6div.style.top=sheight+"px";ns6div.innerHTML=singletext[0];sizeup=ns6div.offsetHeight;ns6scroll();}
else 
if(document.layers){ns4layer=document.ns4div.document.ns4div1;ns4layer.top=sheight;ns4layer.document.write(singletext[0]);ns4layer.document.close();sizeup=ns4layer.document.height;ns4scroll();}
else 
if(document.all){iediv=iens6div;iediv.style.pixelTop=sheight+"px";iediv.innerHTML=singletext[0];sizeup=iediv.offsetHeight;iescroll();}}
function iescroll(){if(iediv.style.pixelTop>0&&iediv.style.pixelTop<=sspeed){iediv.style.pixelTop=0;setTimeout("iescroll()",spause);}else 
if(iediv.style.pixelTop>=sizeup*-1){iediv.style.pixelTop-=sspeed+"px";setTimeout("iescroll()",100);}else{if(ii==singletext.length-1)ii=0;else ii++;iediv.style.pixelTop=sheight+"px";iediv.innerHTML=singletext[ii];sizeup=iediv.offsetHeight;iescroll();}}
function ns4scroll(){if(ns4layer.top>0&&ns4layer.top<=sspeed){ns4layer.top=0;setTimeout("ns4scroll()",spause);}else 
if(ns4layer.top>=sizeup*-1){ns4layer.top-=sspeed;setTimeout("ns4scroll()",100);}else{if(ii==singletext.length-1)ii=0;else ii++;ns4layer.top=sheight;ns4layer.document.write(singletext[ii]);ns4layer.document.close();sizeup=ns4layer.document.height;ns4scroll();}}
function ns6scroll(){if(parseInt(ns6div.style.top)>0&&parseInt(ns6div.style.top)<=sspeed){ns6div.style.top=0;setTimeout("ns6scroll()",spause);}else 
if(parseInt(ns6div.style.top)>=sizeup*-1){ns6div.style.top=parseInt(ns6div.style.top)-sspeed+"px";setTimeout("ns6scroll()",100);}
else{if(ii==singletext.length-1)ii=0;else ii++;
ns6div.style.top=sheight+"px";ns6div.innerHTML=singletext[ii];sizeup=ns6div.offsetHeight;ns6scroll();}}
//-- end Algorithm -->

document.write('<table border="1" style="margin-left:40px;" onclick="document.location=\'http://www.math.duke.edu/mcal?listgroup-0\'" title="click to go to the calendar page."><tr><td><b>Upcoming seminars and colloquia</b></td></tr><tr><td>');
if(document.layers){document.write('<ilayer id="ns4div" width="'+swidth+'" height="'+sheight+'" bgcolor='+sbcolor+'><layer id="ns4div1" width="'+swidth+'" height="'+sheight+'" onmouseover="sspeed=0;" onmouseout="sspeed=rspeed"></layer></ilayer>')}
if(document.getElementById||document.all){document.write('<div style="position:relative;overflow:hidden;width:'+swidth+'px;height:'+sheight+'px;clip:rect(0 '+swidth+'px '+sheight+'px 0);background-color:'+sbcolor+';" onmouseover="sspeed=0" onmouseout="sspeed=rspeed"><div id="iens6div" style="position:relative;width:'+swidth+'px;font-size:small;padding:2px;"></div></div>');}
document.write('</td></tr></table>');

//start();

