function init() {
	//Write a stylesheet link into the document head
	var style = document.createElement('link');
	style.type = "text/css";
	style.rel = "stylesheet";
	style.href = "http://www.scls.info/resources/databasewidget.css"; 
	document.getElementsByTagName("head")[0].appendChild(style);

	//Make the widget 
	if (document.getElementById('widget')) {
		writeWidget('widget');
		var databaseWidget = new SlideShow(widgetList, 'widget', 12000, 'databaseWidget', buttonList[0]);
	}
	else if (document.getElementById('miniWidget')) { 
		writeWidget('miniWidget');
		var databaseWidget = new SlideShow(widgetList, 'miniWidget', 5000, 'databaseMiniWidget', buttonList[1]); 
	}
	
	var playPauseButton = document.getElementById('control');
	playPauseButton.onclick = function() {databaseWidget.start_stop(databaseWidget.current)};
	
	var nextButton = document.getElementById('next')
	nextButton.onclick = function() {databaseWidget.nxt(databaseWidget.current)};
	
	var previousButton = document.getElementById('previous');
	previousButton.onclick = function() {databaseWidget.prev(databaseWidget.current)};
	
	//Make the widget play
	databaseWidget.start();
	
	function writeWidget(widgetType) {
		widgetContent = '';
		if (widgetType === 'widget') {
			widgetContent = '<h2><a id="topicLink" href="http://www.scls.info/resources/wellness/">Looking for<br /> <span id="subject">Health Information</span>?</a></h2><p id="controls">Q <span id="currentQ">1</span> of <span id="totalQ">6</span> &nbsp; &nbsp;<a href="#" id="previous"><img src="http://www.scls.info/resources/graphics/control_rewind.gif" alt="Previous Topic" width="16" height="16" /></a> 	<a href="#" id="control"><img id="playPause" src="http://www.scls.info/resources/graphics/control_pause.gif" alt="Pause" width="16" height="16" /></a> 		<a href="#" id="next"><img src="http://www.scls.info/resources/graphics/control_fastforward.gif" alt="Next Topic" width="16" height="16" /></a></p> 	<p><strong>Q:</strong> <span id="question">I need current information on fibromyalgia -- specifically causes and promising treatment.</span></p> <p><strong>A:</strong> <span id="answer"><a href="http://www.scls.lib.wi.us/cgi-bin/auth.cgi?connectto=EHHXH">EBSCOHost</a> will help you find the latest information on fibromyalgia and other conditions. If you need more help, contact an <a href="http://www.questionpoint.org/crs/servlet/org.oclc.home.TFSRedirect?virtcategory=10989">AskAway</a> librarian for links to authoritative online medical sites.</span></p> <p class="lastline"><a href="./">Get help finding information on other topics...</a></p>';
		}
		else widgetContent = '<h2 class="mini"><a id="topicLink" href="http://www.scls.info/resources/wellness/">Looking for<br /> <span id="subject">Health Information</span>?</a><br><span id="controls"><a href="#" id="previous"><img src="http://www.scls.info/resources/graphics/mini_control_rewind.gif" alt="Previous Topic" width="16" height="16" /></a> 	<a href="#" id="control"><img id="playPause" src="http://www.scls.info/resources/graphics/mini_control_pause.gif" alt="Pause" width="16" height="16" /></a> 		<a href="#" id="next"><img src="http://www.scls.info/resources/graphics/mini_control_fastforward.gif" alt="Next Topic" width="16" height="16" /></a></span></h2>';
		document.getElementById(widgetType).innerHTML = widgetContent;
	}

	function SlideShow(slideList, hostElement, speed, name, buttonList) {
	//Here this is referring to databaseWidget
	
		this.slideList = slideList;	
		this.hostElement = hostElement;		
		this.speed = speed;		
		this.name = name;		
		this.current = 0;		
		this.timer = 0;		
		this.start = SlideShow_start;			
		this.start_stop = pause;		
		this.nxt = next;		
		this.prev = previous;
		this.buttonList = buttonList;
		
		function SlideShow_start() {
		//Here this is referring to the element defined in SlideShow
		
			with(this) {	
		
				clearTimeout(timer);
				timer = setTimeout(function() {loop()}, speed); 
				
				//if (hostElement === "widget") {
					if (document.images) {	    
						document.getElementById('playPause').src = buttonList[1];
						document.getElementById('playPause').alt = 'Pause Button';
					}
					else { document.getElementById('control').innerHTML="Pause"; }
				//}
			}
		}
		
		function pause() {
    // This method stops or starts the slideshow		
			with(databaseWidget) {
				
				//to pause the slideshow
				if (timer != 0) {
					clearTimeout(timer);
					timer = 0;
				
					//switch the button to a play button
					//if (hostElement === "widget") {
						if ( document.images) {	  
							document.getElementById('playPause').src = buttonList[0];			  
							document.getElementById('playPause').alt = 'Play Button';
						}					
						else { document.getElementById('control').innerHTML="Play"; }
					//}
				}
				//to resume the slideshow again
				else start();
			}
		}

		
		function loop() {
			with(databaseWidget) {

				next();
		
			// Keep playing the slideshow
				start();
		  	}
		}
		
		function next() {
			// This method advances to the next slide.
			with(databaseWidget) {
				// Increment the image number
				if (current < slideList.length - 1) {
				  current++;
				} else { current = 0; }
				
				switchImage(hostElement, slideList[current], current);
				
			  }
		}
		
		function previous() {
			// This method advances to the next slide.
			with(databaseWidget) {
				// Increment the image number
				if (current > 0) {
				  current--;
				} else { current = slideList.length - 1; }
				
				switchImage(hostElement, slideList[current], current);
				
			  }
		}
		
		function switchImage(hostElementName, slideData, slideNumber) {
		// This function just writes info to the page -- it doesn't actually advance the slides
			if (document.hostElementName != "none")  {
		
				if (slideData != "none") {
		
					document.getElementById('subject').innerHTML= slideData[0];
					document.getElementById(hostElementName).className = slideData[3];
					document.getElementById('topicLink').setAttribute("href", slideData[4]);
					
					if (hostElementName === 'widget') {
						document.getElementById('question').innerHTML= slideData[1];
						document.getElementById('answer').innerHTML= slideData[2];
					//write the slide count			
						if ( document.getElementById('currentQ') ) {
							document.getElementById('currentQ').innerHTML= slideNumber +1;
							document.getElementById('totalQ').innerHTML=slideList.length;
						}
					}

				}
		
			}
		
		}
	  
	} //closes SlideShow
	
} //closes init

window.onload = init;

var widgetList = [['Health Information', 'I need current information on fibromyalgia -- specifically causes and promising treatment.', '<a href="http://www.scls.lib.wi.us/cgi-bin/auth.cgi?connectto=EHHXH">EBSCOHost</a> will help you find the latest information on fibromyalgia and other conditions. If you need more help, contact an <a href="http://www.questionpoint.org/crs/servlet/org.oclc.home.TFSRedirect?virtcategory=10989">AskAway</a> librarian for links to authoritative online medical sites.', "wellness","http://www.scls.info/resources/wellness/" ],
				   ["Business Information","I need to take the real estate appraisal examination. What resource should I use to help me prepare?", '<a href="http://www.scls.lib.wi.us/cgi-bin/auth.cgi?connectto=LE">LearningExpress Library</a> is a test preparation website that offers workplace skills enrichment and more than 300 online practice tests for students and adults of all ages.', "business", "http://www.scls.info/resources/business/" ],
				   ['Consumer Information', 'I\'m buying a new washing machine and want to know more about these front-loading types, and see which one has the best repair record. All your Consumer Reports magazines are checked out. Where else can I look?',  'Access <a href="http://www.scls.lib.wi.us/cgi-bin/auth.cgi?connectto=TIEH&db=f5h&jid=CRP&scope=site">Consumer Reports</a> online through <a href="http://www.scls.lib.wi.us/cgi-bin/auth.cgi?connectto=EHGEN">EBSCOHost</a>. Print the same articles you\'d see in the print copy, complete with rankings and graphs.',"consumer","http://www.scls.info/resources/consumers/" ],
				   ['Study/Teaching Info', 'Do you have an online encyclopedia?', 'EBSCOHost includes the <a href="http://www.scls.lib.wi.us/cgi-bin/auth.cgi?connectto=EHFUNK">Funk & Wagnalls New World Encyclopedia</a> as one of its many databases.', "student","http://www.scls.info/resources/education/" ],
				   ['Genealogy Information', 'My great-great-uncle was drafted into WWI. I heard there is a way to view the original draft registration form. Is this true? If so, where can I find it?', 'Search the Military Records on <a href="http://www.scls.lib.wi.us/cgi-bin/auth.cgi?connectto=AL">AncestryLibrary</a> (available in-library only) for images of these unique, original documents.',"genealogy", "http://www.scls.info/resources/genealogy/" ],
				   ['a Good Read', 'I\'ve read everything written by W.E.B. Griffin and I need more to read! What other authors write like him?', '<a href="http://www.scls.lib.wi.us/cgi-bin/auth.cgi?connectto=EHNOV">NoveList</a> offers ways to search for books similar to ones you\'ve already read and enjoyed.',"reader","http://www.scls.info/resources/readers/" ]
				  ];

var buttonList = [['http://www.scls.info/resources/graphics/control_play.gif', 'http://www.scls.info/resources/graphics/control_pause.gif'],
				   ['http://www.scls.info/resources/graphics/mini_control_play.gif', 'http://www.scls.info/resources/graphics/mini_control_pause.gif']];