/*
* Rich HTML Ticker- by JavaScript Kit (http://www.javascriptkit.com)
* Freeware. Created Sept 13th, 08'
* This credit must stay intact for use
*/

var richhtmlticker={
loadingtext: '<em>Fetching Ticker Contents. Please wait...</em>', //Loading text if content is being fetched via Ajax
loadingrss:  '<em>Fetching RSS Contents. Please wait...</em>', //Loading text if content is being fetched via Ajax

getajaxcontent:function($, config){
	config.$ticker.html(this.loadingtext)
	$.ajax({
		url: config.msgsource,
		error:function(ajaxrequest){
			config.$ticker.html('Error fetching content.<br />Server Response: '+ajaxrequest.responseText)
		},
		success:function(content){
			config.$ticker.html(content)
			richhtmlticker.setupticker(config)
		}
	})
},

loadXMLDoc:function($, config, url)
{
try {
  var xmlhttp;
  var txt;
  xmlhttp=null;
  if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp=new XMLHttpRequest();
  }
  else {// code for IE5, IE6
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
//  xmlhttp.onreadystatechange=richhtmlticker.onResponse;
  xmlhttp.open("GET",url,false);
  xmlhttp.send(null);
} 
catch(e) {
  alert("loadXMLDoc1 " + e.description);
}

txt="";
try{
x=xmlhttp.responseXML.documentElement.getElementsByTagName("item");
for (i=0;i<x.length;i++) {
  guid=x[i].getElementsByTagName("guid");
  title=x[i].getElementsByTagName("title");
  desc=x[i].getElementsByTagName("description");
  txt=txt+"<div class=\"messagediv\">";
  txt=txt+"<table width=\"95%\" border=\"1\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\" bordercolor=\"#CCCCFF\">\n";
  txt=txt+"<tr bgcolor=\"#CCCCFF\"><td height=\"7\"><table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n";
  txt=txt+"<tr>\n";
  txt=txt+"<td width=\"100%\" bgcolor=\"#E1E1FF\"><b><i><font size=\"-1\" face=\"Verdana, Arial, Helvetica, sans-serif\">\n";
  txt=txt+"<a name=\"" + guid[0].firstChild.nodeValue + "\"></a>" + title[0].firstChild.nodeValue + "</font></i></b>\n";
  txt=txt+"</tr></tr></table></td></tr>\n";
  txt=txt+"<tr valign=\"top\"><td height=\"20\"><p align=\"left\"><font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"-1\">\n";
  txt=txt+ desc[0].firstChild.nodeValue;
  txt=txt+"</font></p></td></tr></table>\n";
  txt=txt+"</div>\n\n";
}
}
catch(e) {
  alert("loadXMLDoc2 " + e.description);
}
return(txt);
},

getrsscontent:function($, config){
	config.$ticker.html(this.loadingrss)
        content = richhtmlticker.loadXMLDoc($, config, config.msgsource);
	config.$ticker.html(content)
	richhtmlticker.setupticker(config)
},

rotate:function(config){
      try {
	if (config.$ticker.get(0)._hoverstate=="over"){
		setTimeout(function(){richhtmlticker.rotate(config)}, config.rotatespeed)
	}
	else{
		config.$messages.eq(config.currentmsg).fadeOut(config.animateduration, 
               function(){
			config.currentmsg=(config.currentmsg<config.$messages.length-1)? config.currentmsg+1 : 0;
			config.$messages.eq(config.currentmsg).fadeIn(config.animateduration, 
                     function(){
				setTimeout(function(){richhtmlticker.rotate(config)}, config.rotatespeed);
			   }
                  )
		   }
            )
	}
      } catch(e) {
          alert("rotate" + e.description);
      }
},

getCookie:function(Name){ 
	var re=new RegExp(Name+"=[^;]+", "i") //construct RE to search for target name/value pair
	if (document.cookie.match(re)) //if cookie found
		return document.cookie.match(re)[0].split("=")[1] //return its value
	return null
},

setCookie:function(name, value){
	document.cookie = name+"="+value
},

setupticker:function(config){
	config.$messages=config.$ticker.find('div.'+config.msgclass).hide()
	config.currentmsg=Math.min(parseInt(richhtmlticker.getCookie(config.id) || 0), config.$messages.length-1);
      config.currentmsg=Math.max(0, config.currentmsg);
	config.$messages.hide().eq(config.currentmsg).fadeIn(config.animateduration);
	setTimeout(function(){richhtmlticker.rotate(config)}, config.rotatespeed)
	$(window).bind('unload', function(){richhtmlticker.cleanup(config)});
},

define:function(config){
  jQuery(document).ready(function($){
		config.$ticker=$('#'+config.id)
		if (config.$ticker.length==0)
			return
		config.$ticker.css({overflow:'hidden'}).hover(
			function(){this._hoverstate="over"},
			function(){this._hoverstate="out"}
		)
		if (config.msgtype=="inline"){
			richhtmlticker.setupticker(config);
		}
            else if (config.msgtype=="rss") {
			richhtmlticker.getrsscontent($,config);
            }		
            else if (config.msgtype=="html") {
			richhtmlticker.getajaxcontent($,config);
            }		
		else{
			alert("Illegal richhtmlticker msgtype. Must be inline, rss, or html");
		}
	})
},

cleanup:function(config){
	this.setCookie(config.id, config.currentmsg)
}

} //end richhtmlticker object




//////////// Declare instance of Rich HTML Ticker (invoked when page has loaded): ///////////////////////////

richhtmlticker.define({
	id: "sundayticker", //main ticker DIV id
	msgclass: "messagediv", //CSS class of DIVs containing each ticker message
	msgsource: "http://www.unityofwimberley.com/Content/RSS/blog.ashx?pageId=490110",
	msgtype: "rss", // "inline", "rss", or "html"
	rotatespeed: 3000, //pause in milliseconds between rotation
	animateduration: 500 //duration of fade animation in milliseconds 
})

richhtmlticker.define({
	id: "leftmenuticker", //main ticker DIV id
	msgclass: "messagediv", //CSS class of DIVs containing each ticker message
	msgtype: "html", // "inline", "rss", or "html"
	msgsource: "http://www.unityofwimberley.com/resources/JavaScript/Tickers/LeftMenuTicker.htm",
	rotatespeed: 3000, //pause in milliseconds between rotation
	animateduration: 500 //duration of fade animation in milliseconds 
})

richhtmlticker.define({
	id: "pictureticker", //main ticker DIV id
	msgclass: "messagediv", //CSS class of DIVs containing each ticker message
	msgtype: "html", // "inline", "rss", or "html"
	msgsource: "http://www.unityofwimberley.com/resources/JavaScript/Tickers/HomePagePics.htm",
	rotatespeed: 3000, //pause in milliseconds between rotation
	animateduration: 500 //duration of fade animation in milliseconds 
})

richhtmlticker.define({
	id: "cookoffticker", //main ticker DIV id
	msgclass: "messagediv", //CSS class of DIVs containing each ticker message
	msgtype: "html", // "inline", "rss", or "html"
	msgsource: "http://www.unityofwimberley.com/resources/JavaScript/Tickers/Cookoff.htm",
	rotatespeed: 3000, //pause in milliseconds between rotation
	animateduration: 500 //duration of fade animation in milliseconds 
})

richhtmlticker.define({
	id: "basicticker", //main ticker DIV id
	msgclass: "messagediv", //CSS class of DIVs containing each ticker message
	msgtype: "inline", // "inline", "rss", or "html"
	msgsource: "", 
	rotatespeed: 3000, //pause in milliseconds between rotation
	animateduration: 500 //duration of fade animation in milliseconds 
})


