
(function() {

	// global flag
	var isIE = false;
	var DETAILS = "agsCOE_details";
	var monthAbbArray = new Array("Jan.", "Feb.", "Mar.", "Apr.", "May", "June", "July", "Aug.", "Sep.", "Oct.", "Nov.", "Dec.");

	var _load = function() {
	if(document.getElementById) {
			if ( document.getElementById('template') ) {
				DETAILS = 'details';
			}
			var strXML = "<?xml version=\"1.0\" encoding=\"utf-8\"?>    <rss version=\"2.0\">     <channel>      <title>Alabama's Gulf Coast: Calendar of Events</title>      <link>http://www.gulfshores.com/things-to-do/calendar-events/</link>      <description>Events in Alabama's Gulf Coast</description>      <language>en-us</language>      <ttl>60</ttl>      <copyright>&#169; 2008 Alabama Gulf Coast CVB</copyright>      <pubDate>Wed, 20 Aug 2008 02:27:55 GMT</pubDate>      <lastBuildDate>Wed, 20 Aug 2008 02:27:55 GMT</lastBuildDate>               <item>          <title>58th Annual Galilean Beach Worship Service    </title>             <link>http://www.gulfshores.com/things-to-do/calendar-events/?coe_id=13228</link>             <description>             <![CDATA[           <p>Celebrate your spiritual beliefs during the 58th season of Galilean Beach Worship Service, which kicks off on Mother’s Day (Sunday, May 11) and runs through Labor Day weekend (Sunday, August 31). Conducted by the Foley United Methodist Church (FUMC), these outdoor ecumenical services will begin  ...</p>             ]]>             </description>             <pubDate>Sun, 11 May 2008 00:00:00 GMT</pubDate>             <dateDisplay>5/11/2008 - 8/31/2008</dateDisplay>         </item>                   <item>          <title>The Orange Beach Running Club is looking for you!</title>             <link>http://www.gulfshores.com/things-to-do/calendar-events/?coe_id=13229</link>             <description>             <![CDATA[           <p>5:45 p.m. Every Monday night in Orange Beach. Run or walk 3 miles and then meet back at the restaraunt for discounted beer and free food.  After a runner or walker participates 10 times, they are eligible to receive a free member t-shirt.  All ages and running/walking levels are welcomed.  Tell  ...</p>             ]]>             </description>             <pubDate>Tue, 03 Jun 2008 00:00:00 GMT</pubDate>             <dateDisplay>6/3/2008 - 12/31/2008</dateDisplay>         </item>                   <item>          <title>FROGS! Beyond Green hops to Mobile's Exploreum   </title>             <link>http://www.gulfshores.com/things-to-do/calendar-events/?coe_id=13268</link>             <description>             <![CDATA[           <p>A medley of croaks, a chorus of calls welcomes you to the Gulf Coast Exploreum Science Center's latest exhibition, FROGS! Beyond Green, which is set to open Friday June 13. FROGS! is an interactive element of the Exploreum's summer line-up that includes live animals, earth-science programming, c ...</p>             ]]>             </description>             <pubDate>Fri, 13 Jun 2008 00:00:00 GMT</pubDate>             <dateDisplay>6/13/2008 - 11/2/2008</dateDisplay>         </item>                   <item>          <title>LA Fleet Feet Run Club Gulf Shores</title>             <link>http://www.gulfshores.com/things-to-do/calendar-events/?coe_id=13304</link>             <description>             <![CDATA[           <p>Join us every Tuesday night in Gulf Shores!  We meet at the end of Hwy. 59 next to The Hangout. Choose to run or walk one of several courses including a 5k or 10k along West Beach, a 5k going east, or a 5 mile jog through the Gulf State Park. Enjoy the beach and hang out with friends before and ...</p>             ]]>             </description>             <pubDate>Wed, 25 Jun 2008 00:00:00 GMT</pubDate>             <dateDisplay>6/25/2008 - 12/31/2008</dateDisplay>         </item>                   <item>          <title>Tigers of India at the AL Gulf Coast Zoo </title>             <link>http://www.gulfshores.com/things-to-do/calendar-events/?coe_id=13306</link>             <description>             <![CDATA[           <p>Two shows will be presented daily, Monday through Friday at 10:30 am and 7:00 pm. Skip the hassle of making dinner, and arrive at the zoo early for \"Feast with the Beasts.\" A $25.00 adult ticket or a $15.00 children’s ticket will include a gourmet meal provided by Villaggio Grille and Ginny Lane ...</p>             ]]>             </description>             <pubDate>Mon, 30 Jun 2008 00:00:00 GMT</pubDate>             <dateDisplay>6/30/2008 - 9/23/2008</dateDisplay>         </item>                   <item>          <title>The Nature of the Beach Guided Beach Tours</title>             <link>http://www.gulfshores.com/things-to-do/calendar-events/?coe_id=13332</link>             <description>             <![CDATA[           <p>On this 1 1/2 hour beach walk, Capt. Skip will explain where the sand, water and salt came from. The first half of the trip, we'll do some experiments to prove bouyancy and salinity. The second half, we'll identify dune plants, birds, shells and whatever else we can find on the beach.  You will ...</p>             ]]>             </description>             <pubDate>Sat, 19 Jul 2008 00:00:00 GMT</pubDate>             <dateDisplay>7/19/2008 - 11/30/2008</dateDisplay>         </item>                   <item>          <title>Pottery, Hand building, Slumps and Slabs </title>             <link>http://www.gulfshores.com/things-to-do/calendar-events/?coe_id=13349</link>             <description>             <![CDATA[           <p>Eight Weeks, Wednesday Nights 6:00pm - 8:30pm. includes one 25lb. bag of clay, glazes and firings. This class is excellent for beginners as well as those who are coming back into the love of clay. You will learn the basic hand-building techniques such as coil, pinch and slab work, glazing and el ...</p>             ]]>             </description>             <pubDate>Wed, 06 Aug 2008 00:00:00 GMT</pubDate>             <dateDisplay>8/6/2008 - 9/24/2008</dateDisplay>         </item>                   <item>          <title>6th Annual One Hundred Points of Light  </title>             <link>http://www.gulfshores.com/things-to-do/calendar-events/?coe_id=13353</link>             <description>             <![CDATA[           <p>10:30 a.m. An afternoon of fun  will be had by the attendees with local celebrity waiters. This yearly event benefits The Lighthouse, a home for abused women and children. There will also be a raffle, silent auction and guests may bring a slightly used item to be given to the Lighthouse for wome ...</p>             ]]>             </description>             <pubDate>Thu, 21 Aug 2008 00:00:00 GMT</pubDate>             <dateDisplay>8/21/2008</dateDisplay>         </item>                   <item>          <title>Waterville proudly presents &quot;2008 Alabama Slamma&quot; Flowrider Competition</title>             <link>http://www.gulfshores.com/things-to-do/calendar-events/?coe_id=13339</link>             <description>             <![CDATA[           <p>9:00 a.m.-6:00 p.m. nearly 200 of the best riders will be expected to come in and compete. </p>             ]]>             </description>             <pubDate>Sat, 23 Aug 2008 00:00:00 GMT</pubDate>             <dateDisplay>8/23/2008 - 8/24/2008</dateDisplay>         </item>                   <item>          <title>2008 Gulf Shores Out &amp; In Concert Series presents Brent Burns</title>             <link>http://www.gulfshores.com/things-to-do/calendar-events/?coe_id=13149</link>             <description>             <![CDATA[           <p>Indoor. An Island favorite returns with his beach-flavored witty compositions. This philanthropist songwriter supports many causes. Build A House benefits Habitat for Humanity.</p>             ]]>             </description>             <pubDate>Thu, 28 Aug 2008 00:00:00 GMT</pubDate>             <dateDisplay>8/28/2008</dateDisplay>         </item>                   <item>          <title>42nd Annual Labor Day Tournament</title>             <link>http://www.gulfshores.com/things-to-do/calendar-events/?coe_id=12732</link>             <description>             <![CDATA[           <p>There is a $1 million prize to anyone who sets a new Alabama state record for Blue Marlin in this tournament.  See website for complete details.</p>             ]]>             </description>             <pubDate>Fri, 29 Aug 2008 00:00:00 GMT</pubDate>             <dateDisplay>8/29/2008 - 9/1/2008</dateDisplay>         </item>                   <item>          <title>SanRoc Arts &amp; Crafts Festival </title>             <link>http://www.gulfshores.com/things-to-do/calendar-events/?coe_id=13354</link>             <description>             <![CDATA[           <p>Sat. August 30, 12:00-9:00 and Sun. August 31, 12:00-6:00. There will be over 30 artists, live music and wine tasting, as well as our restaurants, spa, shops, dolphin cruises, fishing charters, parasailing and scuba diving. Join us for this huge event! </p>             ]]>             </description>             <pubDate>Sat, 30 Aug 2008 00:00:00 GMT</pubDate>             <dateDisplay>8/30/2008 - 8/31/2008</dateDisplay>         </item>                   <item>          <title>Odyssey's Shipwreck! Treasures from the SS Republic at the Baldwin County Heritage Museum</title>             <link>http://www.gulfshores.com/things-to-do/calendar-events/?coe_id=13323</link>             <description>             <![CDATA[           <p>Set sail for a one-of-a-kind adventure. Shipwreck! Treasures from the SS Republic will take you on an amazing journey 1700 feet below the surface of the Atlantic to the wreck site of the SS Republic, the greatest shipwreck treasure of the Civil War era. En route from New York to New Orleans in O ...</p>             ]]>             </description>             <pubDate>Sun, 31 Aug 2008 00:00:00 GMT</pubDate>             <dateDisplay>8/31/2008 - 12/21/2009</dateDisplay>         </item>                   <item>          <title>22nd Annual Mullet Festival</title>             <link>http://www.gulfshores.com/things-to-do/calendar-events/?coe_id=13330</link>             <description>             <![CDATA[           <p>Activities for this big indoor and outdoor one-day event on Labor Day begin with a breakfast at 6:30 a.m., traditional “Run for the Mullet 5-K Race” at 7:30 a.m. followed by A Mullet Toss and other activities at 10:00 a.m.  Other events scheduled include a silent auction, bake sale, bands provid ...</p>             ]]>             </description>             <pubDate>Mon, 01 Sep 2008 00:00:00 GMT</pubDate>             <dateDisplay>9/1/2008</dateDisplay>         </item>               </channel> </rss> ";
			loadXMLDoc(strXML);
			
		}
	};
	//don't overwrite exsisting onload handlers
	if (window.addEventListener) {
		window.addEventListener('load', _load, false);
	}
	else if (window.attachEvent) {
		window.attachEvent('onload', _load );
	}
	// global request and XML document objects
	var doc;

	//MAIN TICKER FUNCTION
	//SET PREFERENCE VARIABLES
	var myTimer;
	var theCharacterTimeout = 15;
	var theStoryTimeout = 2500;
	// Ticker startup function
	function startTicker() {
		//clear the ticker timer
		window.clearTimeout(myTimer);
		// Define run time values
		//Get the Items array
		items = doc.getElementsByTagName("item");
		theItemCount = items.length;
		theCurrentStory = -1;
		theCurrentLength = 0;
		// Locate base objects
		if (document.getElementById) {
				//Write the anchor text for the ticker
				/*
				*/
				runTheTicker();
			} else {
				return true;
		}
	}

	// Ticker main run loop function
	function runTheTicker() {
		var myTimeout;
		
		var objDetails = document.getElementById(DETAILS)
		// Go for the next story data block
		if(theCurrentLength == 0 && theItemCount != 0) {
			theCurrentStory++;

			theCurrentStory = theCurrentStory % theItemCount;
			
			if(theCurrentStory == 0)
			{
			    for(i = document.getElementsByName("tickerAnchor").length - 1; document.getElementsByName("tickerAnchor").length > 0; i = document.getElementsByName("tickerAnchor").length - 1)
			    {
			        document.getElementsByName("tickerAnchor")[i].parentNode.parentNode.removeChild(document.getElementsByName("tickerAnchor")[i].parentNode);
			    }
			        
			    objDetails.scrollTop = 0;
			}
			
			objDetails.innerHTML += '<span name="itemSpanWrapper"><a class="tickerAnchor" name="tickerAnchor" href="#"><\/a><br><span id="tickerStory" name="tickerStory" ><\/span><br><br><\/span>';
			theAnchorObject = document.getElementsByName("tickerAnchor")[theCurrentStory];
			theStoryObject = document.getElementsByName("tickerStory")[theCurrentStory];
			
			theStoryHeader = getElementTextNS("", "title", items[theCurrentStory], 0);
			theStorySummary = getElementTextNS("", "dateDisplay", items[theCurrentStory], 0);
			theTargetLink = getElementTextNS("", "link", items[theCurrentStory], 0);

			theAnchorObject.innerHTML = theStoryHeader;
			theAnchorObject.href = theTargetLink;

		}
		// Stuff the current ticker text into the anchor
		theStoryObject.innerHTML = theStorySummary.substring(0,theCurrentLength);
		// Modify the length for the substring and define the timer
		if(theCurrentLength < theStorySummary.length) {
			theCurrentLength++;
			myTimeout = theCharacterTimeout;
		} else {
			theCurrentLength = 0;
			myTimeout = theStoryTimeout;
			
		}
		if(objDetails.scrollHeight > objDetails.clientHeight)
		{
			objDetails.scrollTop = objDetails.scrollHeight - objDetails.clientHeight;
		}

		// Call up the next cycle of the ticker
		myTimer = window.setTimeout(runTheTicker, myTimeout);
	}

	function loadXMLDoc(strXML) {
		if (window.ActiveXObject) {
			doc=new ActiveXObject("Microsoft.XMLDOM")
			doc.loadXML(strXML);   
		}
		else if (document.implementation && document.implementation.createDocument) {
			var objDOMParser = new DOMParser();
			doc = objDOMParser.parseFromString(strXML, "text/xml");
		}
		startTicker() ;
	}
	// DISPLAY LOADING ANIMATION
	function startLoadFlag() {
		document.getElementById(DETAILS).innerHTML = '<p id="LoadMsg"><\/p>';
	}

	// HIDE LOADING ANIMATION
	function stopLoadFlag() {
		document.getElementById(DETAILS).innerHTML = "";
	}

	// retrieve text of an XML document element, including
	// elements using namespaces
	function getElementTextNS(prefix, local, parentElem, index) {
		var result = "";
		if (prefix && isIE) {
			// IE/Windows way of handling namespaces
			result = parentElem.getElementsByTagName(prefix + ":" + local)[index];
		} else {
			// the namespace versions of this method
			// (getElementsByTagNameNS()) operate
			// differently in Safari and Mozilla, but both
			// return value with just local name, provided
			// there aren't conflicts with non-namespace element names
			result = parentElem.getElementsByTagName(local)[index];
		}
		if (result) {
			// get text, accounting for possible
			// whitespace (carriage return) text nodes
			if (result.childNodes.length > 1) {
				return result.childNodes[1].nodeValue;
			} else {
				return result.firstChild.nodeValue;
			}
		} else {
			return "n/a";
		}
	}
})();