//** Featured Content Slider script- (c) Dynamic Drive DHTML code library: http://www.dynamicdrive.com.
//** May 2nd, 08'- Script rewritten and updated to 2.0.
//** June 12th, 08'- Script updated to v 2.3, which adds the following features:
//1) Changed behavior of script to actually collapse the previous content when the active one is shown, instead of just tucking it underneath the later.
//2) Added setting to reveal a content either via "click" or "mouseover" of pagination links (default is former).
//3) Added public function for jumping to a particular slide within a Featured Content instance using an arbitrary link, for example.

//** July 11th, 08'- Script updated to v 2.4:
//1) Added ability to select a particular slide when the page first loads using a URL parameter (ie: mypage.htm?myslider=4 to select 4th slide in "myslider")
//2) Fixed bug where the first slide disappears when the mouse clicks or mouses over it when page first loads.

//** Dec 20th, 12'- v 2.41: Fixed bug with slider failing to load if the same script is used on different pages with different # of contents

//** Jan 23rd, 13'- v2.5: Modified onChange event handler behaviour for more robustness , plus added section on embedding YouTube videos inside the Slider.
//Important: onChange(previndex, curindex, contentdivs) now uses a 0 based index system, where 0=1st slide, 1=2nd slide etc. Previously the count started at 1.

//** July 18th, 15'- v2.51: Set revealtype to always "click" in mobile browsers (instead of "mouseover")
var featuredcontentslider={ajaxloadingmsg:'<div style="margin: 20px 0 0 20px"><img src="loading.gif" /> Fetching slider Contents. Please wait...</div>',bustajaxcache:!0,enablepersist:!0,settingcaches:{},ismobile:null!=navigator.userAgent.match(/(iPad)|(iPhone)|(iPod)|(android)|(webOS)/i),jumpTo:function(e,t){this.turnpage(this.settingcaches[e],t)},ajaxconnect:function(e){var t=!1;if(window.ActiveXObject)try{t=new ActiveXObject("Msxml2.XMLHTTP")}catch(e){try{t=new ActiveXObject("Microsoft.XMLHTTP")}catch(e){}}else{if(!window.XMLHttpRequest)return!1;t=new XMLHttpRequest}var n=e.contentsource[1];t.onreadystatechange=function(){featuredcontentslider.ajaxpopulate(t,e)},document.getElementById(e.id).innerHTML=this.ajaxloadingmsg;var i=this.bustajaxcache?-1!=n.indexOf("?")?"&"+(new Date).getTime():"?"+(new Date).getTime():"";t.open("GET",n+i,!0),t.send(null)},ajaxpopulate:function(e,t){4!=e.readyState||200!=e.status&&-1!=window.location.href.indexOf("http")||(document.getElementById(t.id).innerHTML=e.responseText,this.buildpaginate(t))},buildcontentdivs:function(e){for(var t=document.getElementById(e.id).getElementsByTagName("div"),n=0;n<t.length;n++)this.css(t[n],"contentdiv","check")&&(e.contentdivs.push(t[n]),t[n].style.display="none");e.currentpage>e.contentdivs.length&&(e.currentpage=1,e.prevpage=1)},buildpaginate:function(e){this.buildcontentdivs(e);var t=document.getElementById(e.id),n=document.getElementById("paginate-"+e.id),i="",a=e.toc,c=e.nextprev;if("string"==typeof a&&"markup"!=a||"object"==typeof a){for(var s=1;s<=e.contentdivs.length;s++)i+='<a href="#'+s+'" class="toc">'+("string"==typeof a?a.replace(/#increment/,s):a[s-1])+"</a> ";i=(""!=c[0]?'<a href="#prev" class="prev">'+c[0]+"</a> ":"")+i+(""!=c[1]?'<a href="#next" class="next">'+c[1]+"</a>":""),n.innerHTML=i}var o=n.getElementsByTagName("a"),r=0;for(s=0;s<o.length;s++)if(this.css(o[s],"toc","check")){if(r>e.contentdivs.length-1){o[s].style.display="none";continue}o[s].setAttribute("rel",++r),o[s][e.revealtype]=function(){return featuredcontentslider.turnpage(e,this.getAttribute("rel")),!1},e.toclinks.push(o[s])}else(this.css(o[s],"prev","check")||this.css(o[s],"next","check"))&&(o[s].onclick=function(){return featuredcontentslider.turnpage(e,this.className),!1});this.turnpage(e,e.currentpage,!0),e.autorotate[0]&&(n[e.revealtype]=function(){featuredcontentslider.cleartimer(e,window["fcsautorun"+e.id])},t.onclick=function(){featuredcontentslider.cleartimer(e,window["fcsautorun"+e.id])},e.autorotate[1]=e.autorotate[1]+1/e.enablefade[1]*50,this.autorotate(e))},urlparamselect:function(e){return null==window.location.search.match(new RegExp(e+"=(\\d+)","i"))?null:parseInt(RegExp.$1)},turnpage:function(e,t,n){var i=e.currentpage,a=e.contentdivs.length,c=/prev/i.test(t)?i-1:/next/i.test(t)?i+1:parseInt(t);if((c=c<1?a:c>a?1:c)!=e.currentpage||void 0!==n){if(e.currentpage=c,e.contentdivs[c-1].style.zIndex=++e.topzindex,this.cleartimer(e,window["fcsfade"+e.id]),e.cacheprevpage=e.prevpage,1==e.enablefade[0]&&(e.curopacity=0,this.fadeup(e)),0==e.enablefade[0]){e.contentdivs[e.prevpage-1].style.display="none";try{e.onChange(e.prevpage-1,e.currentpage-1,e.contentdivs)}catch(e){}}e.contentdivs[c-1].style.visibility="visible",e.contentdivs[c-1].style.display="block",e.prevpage<=e.toclinks.length&&this.css(e.toclinks[e.prevpage-1],"selected","remove"),c<=e.toclinks.length&&this.css(e.toclinks[c-1],"selected","add"),e.prevpage=c,this.enablepersist&&this.setCookie("fcspersist"+e.id,c)}},setopacity:function(e,t){var n=e.contentdivs[e.currentpage-1];n.filters&&n.filters[0]?"number"==typeof n.filters[0].opacity?n.filters[0].opacity=100*t:n.style.filter="alpha(opacity="+100*t+")":void 0!==n.style.MozOpacity?n.style.MozOpacity=t:void 0!==n.style.opacity&&(n.style.opacity=t),e.curopacity=t},fadeup:function(e){if(e.curopacity<1)this.setopacity(e,e.curopacity+e.enablefade[1]),window["fcsfade"+e.id]=setTimeout((function(){featuredcontentslider.fadeup(e)}),50);else{e.cacheprevpage!=e.currentpage&&(e.contentdivs[e.cacheprevpage-1].style.display="none");try{e.onChange(e.cacheprevpage-1,e.currentpage-1,e.contentdivs)}catch(e){}}},cleartimer:function(e,t){void 0!==t&&(clearTimeout(t),clearInterval(t),e.cacheprevpage!=e.currentpage&&(e.contentdivs[e.cacheprevpage-1].style.display="none"))},css:function(e,t,n){var i=new RegExp("(^|\\s+)"+t+"($|\\s+)","ig");if("check"==n)return i.test(e.className);"remove"==n?e.className=e.className.replace(i,""):"add"==n&&(e.className+=" "+t)},autorotate:function(e){window["fcsautorun"+e.id]=setInterval((function(){featuredcontentslider.turnpage(e,"next")}),e.autorotate[1])},getCookie:function(e){var t=new RegExp(e+"=[^;]+","i");return document.cookie.match(t)?document.cookie.match(t)[0].split("=")[1]:null},setCookie:function(e,t){document.cookie=e+"="+t},init:function(e){var t=this.getCookie("fcspersist"+e.id)||1,n=this.urlparamselect(e.id);this.settingcaches[e.id]=e,e.contentdivs=[],e.toclinks=[],e.topzindex=0,e.currentpage=n||(this.enablepersist?t:1),e.prevpage=e.currentpage,this.ismobile&&(e.revealtype="click"),e.revealtype="on"+(e.revealtype||"click"),e.curopacity=0,e.onChange=e.onChange||function(){},"inline"==e.contentsource[0]&&this.buildpaginate(e),"ajax"==e.contentsource[0]&&this.ajaxconnect(e)}};