/* News ticker JavaScript file */
if(!window._DOMImplements){window._DOMImplements={Document:(window.Document)?1:0,Element:(window.Element)?1:0,Node:(window.Node)?1:0};}
if(!_DOMImplements.Document){Document=function(){};Document.prototype=document;Document.apply(Document.prototype);}
if(!_DOMImplements.Element){Element=function(){this.getAttribute=function(attr){if(attr=='class'&&this.className!=undefined){return this.className;}if(attr=='for'&&this.htmlFor!=undefined){return this.htmlFor;}return this[attr];};this.setAttribute=function(attr,val){if(attr=='class'&&this.className!=undefined){this.className=val;}else if(attr=='for'&&this.htmlFor!=undefined){this.htmlFor=val;}else{this[attr]=val;}};};}
if(!_DOMImplements.Node){Node=function(){};function __NodeType(){if(!this.ELEMENT_NODE){this.ELEMENT_NODE=1;this.ATTRIBUTE_NODE=2;this.TEXT_NODE=3;this.CDATA_SECTION_NODE=4;this.ENTITY_REFERENCE_NODE=5;this.ENTITY_NODE=6;this.PROCESSING_INSTRUCTION_NODE=7;this.COMMENT_NODE=8;this.DOCUMENT_NODE=9;this.DOCUMENT_TYPE_NODE=10;this.DOCUMENT_FRAGMENR_NODE=11;this.NOTATION_NODE=12;}}__NodeType.apply(Node);function NodeList(){var nodes=[];nodes.item=function(idx){return nodes[idx]?nodes[idx]:null;};return nodes;}}

(function(){
if(!Function.method){
	Function.prototype.method=function(name,func){this.prototype[name]=func;return this;};
	Function.method('selfName',function(){var s;return(s=/function (\w+)/.exec(this.toString()))?s[1]:'(anonymous)';});
	if(typeof Function.apply!='function'){Function.method('apply',function(o,a){var r,x='____apply';if(!Is.obj(o)){o={};}o[x]=this;switch((a&&a.length)||0){case 0:r=o[x]();break;case 1:r=o[x](a[0]);break;case 2:r=o[x](a[0],a[1]);break;case 3:r=o[x](a[0],a[1],a[2]);break;case 4:r=o[x](a[0],a[1],a[2],a[3]);break;case 5:r=o[x](a[0],a[1],a[2],a[3],a[4]);break;case 6:r=o[x](a[0],a[1],a[2],a[3],a[4],a[5]);break;default:alert('Too many arguments to apply.');}delete o[x];return r;});}
	Function.method('inherits',function(parent){var d=0,p=(this.prototype=new parent());this.uber=function uber(name){var f,r,t=d,v=parent.prototype;if(t){while(t){v=v.constructor.prototype;--t;}f=v[name];}else{f=p[name];if(f==this[name]){f=v[name];}}++d;r=f.apply(this,Array.prototype.slice.apply(arguments,[1]));--d;return r;};return this;});
	Function.method('swiss',function(parent){for(var i=1,name;i<arguments.length;++i){name=arguments[i];this.prototype[name]=parent.prototype[name];}return this;});
}
if(!''.toTitleCase){String.method('toTitleCase',function(separator){if(!separator||!separator.length){separator=' ';}var a=this.split(separator),s=[];for(var i=0;i<a.length;++i){s.push(a[i].charAt(0).toUpperCase()+a[i].substr(1));}return s.join(separator);});}
if(!window.Is){window.Is={};Is.func=function(a){return typeof a=='function';};Is.obj=function(a){return(a&&typeof a=='object')||Is.func(a);};Is.alien=function(a){return Is.obj(a)&&typeof a.constructor!='function';};Is.array=function(a){return Is.obj(a)&&a.constructor==Array;};Is.bool=function(a){return typeof a=='boolean';};Is.def=function(){for(var i=0,r=true;i<arguments.length&&r;++i){r=(typeof arguments[i]!='undefined');}return r;};Is.empty=function(o){var i,v;if(Is.obj(o)){for(i in o){v=o[i];if(!Is.def(v)&&Is.func(v)){return false;}}}return true;};Is.nul=function(a){return typeof a=='object'&&!a;};Is.num=function(a){for(var i=0,r=true;i<arguments.length&&r;++i){r=(typeof arguments[i]=='number'||isFinite(arguments[i]));}return r;};Is.str=function(){for(var i=0,r=true;i<arguments.length&&r;++i){r=(typeof arguments[i]=='string');}return r;};Is.all=document.all?1:0;Is.w3c=document.getElementById?1:0;Is.lay=Is.w3c?false:document.layers?1:0;Is.Ice=navigator.__ice_version?navigator.__ice_version:0;Is.NS4=Is.lay;Is.IE4=(!Is.w3c&&Is.all);Is.IE5=(Is.w3c&&Is.all);Is.IE55=(Is.IE5&&(document.body&&document.body.contentEditable));Is.IE6=(Is.IE5&&(typeof document.compatMode!='undefined'));Is.Mac=((Is.IE4||Is.IE5)&&(/mac/i.test(navigator.appVersion)));Is.NS6=(Is.w3c&&!Is.all);Is.Opera=((Is.w3c||Is.all)&&window.opera);Is.OperaVer=Is.Opera&&(/opera/i.test(navigator.appName))?parseFloat(navigator.userAgent.substring(navigator.userAgent.search(/opera.[^ ]+/i)+6)):0;Is.Safari=(/safari/i.test(navigator.appVersion));}
window.__TimerQueue=function(){
	// call with window.__TimerQueue(function reference);
	// keeping the function running depends on the return of the function; true if needed, false when done
	var base,timer,interval=42,newFncs=null;
	function addFnc(next,f){function t(){next=next&&next();if(f()){return t;}else{f=null;return next;}}t.addItem=function(d){if(next){next.addItem(d);}else{next=d;}return this;};return t;}
	function tmQueue(fc){if(newFncs){newFncs=newFncs.addItem(addFnc(null,fc));}else{newFncs=addFnc(null,fc);}if(!timer){timer=window.setTimeout(tmQueue.act,interval);}}
	tmQueue.act=function(){var st=(new Date()).getTime();if(newFncs){if(base){base.addItem(newFncs);}else{base=newFncs;}newFncs=null;}base=base&&base();if(base||newFncs){var t=interval-((new Date()).getTime()-st);timer=window.setTimeout(tmQueue.act,((t>0)?t:1));}else{timer=null;}};
	tmQueue.act.toString=function(){return 'window.__TimerQueue.act();';};return tmQueue;
}; 
})();
/* Cross-browser XMLHttpRequest() */
(function(){
if(!window.XMLHttpRequest){
	//	originally from Cross-Browser XMLHttpRequest v1.2 (Andrew Gregory, http://www.scss.com.au/family/andrew/webdesign/xmlhttprequest/)
	//	reworked and extended to provide:
	//		inheritance for common methods and properties
	//		more DOM methods: responseXML for IE/Mac 5.2. Possible extensions to be from the Sarissa project (http://sourceforge.net/projects/sarissa/)
	//		a cleaner IE object detection
	//		IE/Mac 5.2 support (includes Opera without Java) using hidden iframe and timeouts
	//		Cachebusting querystring appended in case of cacheing. 
	//
	//	Known bugs / shortfalls:
	//		Opera without Java / IE/Mac 5.2: no headers returned. Some are faked. Workaround: none possible
	//		Opera with Java: responseXML is not a document. Workaround: disable Java.
	//
	//	code linted by JSLint (http://www.jslint.com/) and encapsulated in closure
	// IE Win only.
	if(!Is.ice&&!Is.Mac&&window.ActiveXObject){window.XMLHttpRequest=function(){function progID(){if(this.progID){return this.progID;}var o,p,pL=6;while((--pL)&&!this.progID){try{p=(pL>1?'MSXML2':'Microsoft')+'.XMLHTTP'+(pL>2?'.'+pL+'.0':'');o=new window.ActiveXObject(p);this.progID=p;return this.progID;}catch(ex){}}throw new Error('Could not find an installed XML parser. Ensure you have enabled ActiveX objects for this site');}try{return new window.ActiveXObject(progID());}catch(ex){}throw new Error('Your browser does not support XMLHTTP objects');};}
	else{
		window.__XMLHttpRequest=function(){ // base class to inherit from
			this._aborted=false;this._async=true;this._defaultCharset='iso-8859-1';this._headers=[]; // Note: "async" is pseudo-async, which is as close as we can get
			this.readyState=0;this.responseText=this.responseXML='';this.status=0;this.statusText='';// readyState: 0==uninitialised, 1==loading, 2==loaded, 3==interactive, 4==complete
			this.abort=function(){this._aborted=true;return this;};
			this.getAllResponseHeaders=function(){var ret=[];for(var header in this._headers){ret.push(header+': '+this._headers[header]);}return ret.length?ret.sort().join('\n'):'';};
			this.getResponseHeader=function(header){header=header.toTitleCase('-');return this._headers[header]?header+': '+this._headers[header]:'';};
			this.open=function(method,url,async,user,pass){this.method=method.toUpperCase();this.url=url+(url.indexOf('?')!=-1?'&amp;':'?')+(new Date()).getTime();this._async=true;this._aborted=false;this._headers={};if(arguments.length>2){this._async=async;}if(arguments.length>3){var err='XMLHttpRequest.open() - user / password not supported';if(window.opera){window.opera.postError(err);}else{window.alert(err);}}this.readyState=1;if(this.onreadystatechange){this.onreadystatechange();}return this;};
			this.send=function(data){};this.setRequestHeader=function(header,value){this._headers[header.toTitleCase('-')]=value;return this;};
			this._getCharset=function(){var contentType=this.getResponseHeader('Content-Type').toLowerCase(),p=new RegExp('.*?charset=(.*)','i');return contentType.search(p)!=-1?p.replace(contentType,'$1').replace(/[;,]$/,''):this._defaultCharset;};
			this._sendasync=function(req,data){if(!req._aborted){req._sendsync(data);}return this;};
			this._sendsync=function(data){};this._setReadyState=function(readyState){this.readyState=readyState;if(this.onreadystatechange){this.onreadystatechange();}return this;};
		};
		if(window.opera&&navigator.javaEnabled()){ // Opera < 7.6 requires Java plugin installed and enabled (which is similar to IE requiring ActiveX enabled before you complain)
			window.XMLHttpRequest=function(){
				this._sendsync=function(data){
					this._setReadyState(2);var headerFields=['Cache-Control','ETag','Server','Transfer-Encoding','Vary'],hName,hValue,i=-1,reqdata=[],url=new window.java.net.URL(new window.java.net.URL(window.location.href),this.url),conn=url.openConnection();
					for(var header in this._headers){conn.setRequestProperty(header,this._headers[header]);}
					// POST data, fallback to adding header in case it hasn't been set explicitly
					if(this.method=='POST'){if(!this._headers['Content-Type']){conn.setRequestProperty('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');}conn.setDoOutput(true);var wr=new window.java.io.OutputStreamWriter(conn.getOutputStream(),this._getCharset());wr.write(data);wr.flush();wr.close();delete wr;}
					while((hName=conn.getHeaderFieldKey(++i))){this.setRequestHeader(hName,conn.getHeaderField(i));} // read response headers, probably won't work even though it should...
					// try to fill in any missing header information
					while((hName=headerFields.shift())){if(!this._headers[hName]){hValue=conn.getHeaderField(hName);if(!Is.nul(hValue)){this.setRequestHeader(hName,hValue);}}}
					if(!this._headers['Content-Encoding']){hValue=conn.getContentEncoding();if(!Is.nul(hValue)){this.setRequestHeader('Content-Encoding',hValue);}}
					if(!this._headers['Content-Length']){hValue=conn.getContentLength();if(!Is.nul(hValue)){this.setRequestHeader('Content-Length',hValue);}}
					if(!this._headers['Content-Type']){hValue=conn.getContentType();if(!Is.nul(hValue)){this.setRequestHeader('Content-Type',hValue);}}
					if(!this._headers['Date']){hValue=conn.getDate();if(!Is.nul(hValue)){this.setRequestHeader('Date',(new Date(hValue)).toUTCString());}}
					if(!this._headers['Expires']){hValue=conn.getExpiration();if(!Is.nul(hValue)){this.setRequestHeader('Expires',-1/*(new Date(hValue)).toUTCString()*/);}}
					if(!this._headers['Last-Modified']){hValue=conn.getLastModified();if(!Is.nul(hValue)){this.setRequestHeader('Last-Modified',(new Date(hValue)).toUTCString());}}
					// read response data
					var stream=conn.getInputStream();delete conn;window.java.lang.System.err.println(stream);if(stream){var reader=new window.java.io.BufferedReader(new window.java.io.InputStreamReader(stream,this._getCharset())),line;while((line=reader.readLine())){if(this.readyState==2){this._setReadyState(3);}reqdata.push(new String(line));}reader.close();delete reader;this.responseText=reqdata.length?reqdata.join('\n'):'';}
					this.status=stream?200:404;this.statusText=this.status==200?'OK':'Not Found';this._setReadyState(4);
					if(this.status==200){if(this.onload){this.onload();}}else{if(this.onerror){this.onerror();}}return this;
				};
				this.send=function(data){if(this._async){setTimeout(this._sendasync,0,this,data);}else{this._sendsync(data);}return this;}; // async won't execute until the current execution context ends
			};
		}
		else if(document.createElement&&document.childNodes){ // the slowest way...
			window.__XMLSerialize=function(id){var req=window.__XMLHttpRequests[id],url=req.url.substring(0,req.url.indexOf('?'));req.status=200;req.statusText='OK';req.responseXML=window.frames['XML_Loader_'+id].window.document;req.responseText=window.__XMLSerializeNode(req.responseXML);req.setRequestHeader('Content-Length',req.responseText.length);req.setRequestHeader('Content-Type','text/xml');req.setRequestHeader('Date',(new Date()).toUTCString());req._setReadyState(4);if(!req.responseText.length){req.status=404;req.statusText='Not Found';if(req.onerror){req.onerror();}}else{if(req.onload){req.onload();}}return this;};
			window.__XMLSerializeNode=function(node){
				var a,childNode,i=-1,j,s=[],tag,attrs;
				if(Is.Mac){
					if((childNode=(node.nodeType==Node.DOCUMENT_NODE)?node.all.item(1):node)){
						delete childNode.attributes;switch(childNode.nodeType){
							case Node.ELEMENT_NODE:
								tag=childNode.outerHTML.substring(0,childNode.outerHTML.indexOf('>')+1);s.push(tag);
								if(tag.indexOf(' ')!=-1){attrs=tag.substring(tag.indexOf(' ')+1,tag.length-1).split(/\x22\s?/);for(j=0;j<attrs.length;j+=2){childNode.setAttribute(attrs[j].substring(0,attrs[j].length-1),attrs[j+1]);}}
								while((a=childNode.childNodes.item(++i))){s.push(window.__XMLSerializeNode(a));}s.push('</'+childNode.nodeName+'>\n');break;
							case Node.TEXT_NODE:s.push(childNode.nodeValue);break;
						}
					}
				}
				else{
					while((childNode=node.childNodes.item(++i))){
						switch(childNode.nodeType){
							case Node.ELEMENT_NODE:s.push('<'+childNode.nodeName);if(childNode.attributes.length){j=-1;while((a=childNode.attributes.item(++j))){if(a.name){s.push(' '+a.name.toLowerCase()+'="'+a.value+'"');}}}if(childNode.childNodes.length){s.push('>'+window.__XMLSerializeNode(childNode)+'</'+childNode.nodeName+'>');}else{s.push('/>');}break;
							case Node.TEXT_NODE:s.push(childNode.nodeValue);break;
						}
					}
				}
				return s.length?s.join(''):'';
			};
			window.__XMLLoadCheck=function(){
				while(window.__XMLHttpRequests.length&&!window.__XMLHttpRequests[0]){window.__XMLHttpRequests.shift();} // auto-clear completed requests from pool
				if(!window.__XMLHttpRequests.length){document.body.removeChild(document.getElementById('XML_Loader'));} // remove container from DOM tree (but inner document is still referenced until parent is detroyed)
				else{
					for(var i=0,n;i<window.__XMLHttpRequests.length;++i){
						n='XML_Loader_'+i;
						if(window.__XMLHttpRequests[i]&&window.frames[n]&&(window.frames[n].window.document.readyState=='interactive')&&(/^http/.test(window.frames[n].window.document.location.href))){
							window.__XMLSerialize(i);window.__XMLHttpRequests[i]=false;
						}
					}
				}return window.__XMLHttpRequests.length;
			};
			window.XMLHttpRequest=function(){
				var _self=this;this.responseText='';window.__XMLHttpRequests=window.__XMLHttpRequests||[];
				this._sendsync=function(data){
					delete this.$;
					var div=document.createElement('div');div.id='XML_Loader';div.style.position='absolute';div.style.top=div.style.left='-1000em;';div.style.visibility='hidden';
					var ifr=document.createElement('iframe');ifr.height=ifr.width=0;ifr.name='XML_Loader_'+window.__XMLHttpRequests.length;ifr.src=this.url;div.appendChild(ifr);document.body.appendChild(div);
					window.__XMLHttpRequests.push(this);window.__TimerQueue(window.__XMLLoadCheck);this._setReadyState(2);return this;
				};
				this.send=function(data){if(arguments.length){this.$=data;}if(!document.body){window.__TimerQueue(this.send);}else{_self._sendasync(_self,_self.$);}return (!document.body);};
			};
		}
		if(window.XMLHttpRequest){window.XMLHttpRequest.inherits(window.__XMLHttpRequest);} // inherit from the base class
	}
}
else{
	if(Node&&Node.prototype.__defineGetter__&&!Node.xml){
		Node.method=Function.prototype.method;
		Node.prototype.__defineGetter__('xml',function(){return new window.XMLSerializer().serializeToString(this);});
	}
}
})();

// A spot of ActiveX emulation for IE-centric scripts
if(!window.ActiveXObject){window.ActiveXObject=function(type){if(/\.xml/i.test(type)){return new window.XMLHttpRequest();}else{return null;}};}

var Scroller=function(id,width,height,pause,step,duration,dir){
	// id: id of div to populate
	// width: width in px
	// height: height in px
	// pause: how long to keep current item in view before displaying new one (ms)
	// step: distance to travel per "cycle". Used in conjunction with duration to set the interval between "cycles"
	// duration: how long the whole process should take to slide one item into position
	// dir: direction ("vert"=btt, "horiz"=rtl)
	var self=this;this.id=id||'canvas';this.width=width?parseInt(width,10):100;this.height=height?parseInt(height,10):100;
	this.pause=pause?parseInt(pause,10):3000;this.step=step?parseInt(step,10):10;this.duration=duration?parseInt(duration,10):1000;
	this.dir=dir||'vert';this.content=[];this.curCanvas=this.id+'0';this.curIndex=0;this.speed=Math.max(this.duration*(this.step/(this.dir=='vert'?this.height:this.width)),10);
	this.add=function(){for(var i=0;i<arguments.length;++i){self.content.push(arguments[i]);}};
	this.move=function(){if(self.curPos>0){self.curPos=Math.max(self.curPos-self.step,0);if(self.dir=='vert'){self.obj.style.top=self.curPos+'px';}else{self.obj.style.left=self.curPos+'px';}}else{window.clearInterval(self.interval);self.interval=null;self.setOpacity(100,self.obj);self.curCanvas=self.swapID(self.curCanvas);self.obj=self.object(self.curCanvas);self.setOpacity(0,self.obj);self.curIndex+=(self.curIndex<self.content.length-1)?1:-self.curIndex;window.setTimeout(function(){self.rotate();},self.pause);}};
	this.object=function(obj){if(Is.obj(obj)){return obj;}else if(Is.str(obj)){return document.all?document.all[obj]:document.getElementById?document.getElementById(obj):null;}else{return null;}};
	this.rotate=function(){
		if(!self.content.length){return;}
		if(Is.all||Is.w3c){
			self.obj=self.object(self.curCanvas);
			if(self.obj){
				self.curPos=parseInt(self.dir=='vert'?self.height:self.width,10);
				if(self.dir=='vert'){self.obj.style.top=self.curPos+'px';}else{self.obj.style.left=self.curPos+'px';}
				self.setOpacity(20,self.curCanvas,self.swapID(self.curCanvas));
				self.obj.innerHTML=self.content[self.curIndex];
				self.swapZIndex(self.curCanvas,self.swapID(self.curCanvas));
				self.interval=window.setInterval(function(){self.move();},self.speed);
			}
		}
	};
	this.setOpacity=function(opacity){if(arguments.length>1){opacity=Math.min(Math.max(0,opacity),100);for(var i=1,obj;i<arguments.length;++i){obj=self.object(arguments[i]);if(obj){if(obj.filters){obj.filters.alpha.opacity=opacity;}else if(Is.str(obj.style.MozOpacity)){obj.style.MozOpacity=(opacity/100);}}}}};
	this.swapID=function(id){return String(id).replace(/\d$/,function(s){return s=='0'?'1':'0';});};
	this.swapZIndex=function(e1,e2){if(arguments.length<2||!self.object(e1)||!self.object(e2)){return;}var o={f:self.object(e1),s:self.object(e2)};o.f.style.zIndex+=0;o.s.style.zIndex+=0;if(o.f.style.zIndex==o.s.style.zIndex){o.f.style.zIndex+=1;}else{var z=o.f.style.zIndex;o.f.style.zIndex=o.s.style.zIndex;o.s.style.zIndex=z;}};
};

function enableTargetPseudoClass() {
	if(window.attachEvent){
		window.attachEvent('onload',function(){
			var showTarget=function(yes){
				if(location.hash.length){
					var e=document.getElementById(location.hash.substring(1));
					if(e){e.className=yes?e.className+' sftarget':e.className.replace(/ sftarget\b/,'');}
				}
			};
			document.body.attachEvent('onclick',function(){showTarget(false);window.setTimeout(function(){showTarget(true);},0);});
			document.body.click();
		});
	}
}

function xmlParse(xml){
	var obj=xml.responseXML,newsitem,attrs,i=-1,now=Date.parse((new Date()).toUTCString());
	if(obj){
		while((newsitem=obj.getElementsByTagName('NewsItem')[++i])){
			var date=newsitem.getAttribute("date");if(!date||!date.length||date=='-'){date='&nbsp;';}
			var expiry,scrollitem;
			expiry=Date.parse(newsitem.getAttribute("expiry"));
			if(isNaN(expiry)){expiry=Date.UTC(2100);}else{expiry+=86400000;}
			if(expiry>now){
				scrollitem=[];//scrollitem=['<span class="NewsTickerDate">',date,'</span>'];
				scrollitem.push('<span>');
				if(newsitem.getAttribute('urn')){scrollitem.push('<a href="',newsitem.getAttribute('urn'),'">',newsitem.childNodes[0].nodeValue,'</a>');}
				else{scrollitem.push(newsitem.childNodes[0].nodeValue);}
				scrollitem.push('</span>');
				scroller.add(scrollitem.join(''));
			}
		}
	}
}

function xmlSend(url,verb,fn,async,content){
	url+=(url.indexOf('?')!=-1?'&':'?')+'xCB='+Math.random()*Date.parse(new Date());
	verb=(/(get|post|head)/i.test(verb))?verb.toUpperCase():'GET';if(!Is.bool(async)){async=new Boolean(false);}
	if(xml){
		xml.onreadystatechange=function(){
			if(xml.readyState==4&&verb.length){// Opera 7.6 has a bug doubling readyState 4, so we squash "verb" after first use...
				var s='',ok=(xml.status==200);if(!ok){window.alert('Error loading '+url+': '+xml.status+' '+xml.statusText);}
				else{switch(verb){
					case 'HEAD':s=xml.getAllResponseHeaders();break;
					case 'GET':
					case 'POST':s=xml.responseText;break;
				}}
				verb='';if(fn&&ok){fn(xml);}
			}return this;};
		xml.open(verb,url,async);
		xml.send(verb=='POST'?content:null);
	}return this;
}

var xml=new XMLHttpRequest();
var scroller=new Scroller('canvas',540,30,8000,5,100,'horiz');
xmlSend('/includes/NewsTicker.xml','get',xmlParse);

Events.Add(window,'load',scroller.rotate);
