(function($) {
    String.implement({
        toElement: (function() {
            var div = document.createElement('div');
            return function() {
                div.innerHTML = this;
                return div.firstChild;
            }
        })()
    });


    var 
        searchOpts = $$('.searchOptions')[0],
        searchInput = $('siteSearch'),
        optsTimer = null
    ;
    
    function hideOpts(){
        optsTimer = searchOpts.fade.delay(500, searchOpts, 'out');
    }
    
    if(searchOpts){
        $$('.headerSearch')[0].setProperty('action',relativePath);
        searchOpts.getElements('input').addEvents({
            focus: function(){
                clearTimeout(optsTimer);
                if(this.id == "thisSite"){
                    $$('.headerSearch')[0].setProperty('action',relativePath);
                } else {
                    $$('.headerSearch')[0].setProperty('action','/search/'); 
                }  
            },
            blur: function(){
                hideOpts();
            }
        });
    }
    

	if(searchInput){
		searchInput.set('value','Enter search').addEvents({
			focus: function(){
				if(this.get('value') == 'Enter search'){
					this.set('value','');
				}
				clearTimeout(optsTimer);
				
				if(searchOpts){
					searchOpts.setStyle('minWidth',this.getSize().x).fade('in');
				}
			},
			blur: function(){
				if(this.get('value') == ''){
					this.set('value','Enter search');
				}
				if(searchOpts){
					hideOpts();
				}
			}
		});
	}
  
      
    var Scroller = new Class({
        initialize: function(e) {
            this._e = e;
            this._fx = new Fx.Tween(e.getFirst().getFirst(), {
                transition: 'back:in:out',
                duration: 900,
                link:'chain',
                property:'marginLeft'
            });
            this._insertNav();
            this._size();
            this._iScroll = 0;
        },
        _insertNav: function() {
            var $this = this,
                ePrev = new Element('button', {
                    'class': 'prev',
                    html: '&lt;',
                    disabled: 'disabled'
                }),
                eNext = new Element('button', {
                    'class': 'next',
                    html: '&gt;'
                });


            ePrev.addEvent('click', function(ev) {
                ev.stop();
                var i = $this._prev();

                if (i == 0) {
                    this.setProperty('disabled', 'disabled');
                }

                $this._fx.start(i);
                eNext.removeProperty('disabled');    
            }).inject(this._e, 'top');


            eNext.addEvent('click', function(ev) {
                ev.stop();
                var i = $this._next();

                if (i == $this._iPageEnd) {
                    this.setProperty('disabled', 'disabled');
                }

                $this._fx.start(i);
                ePrev.removeProperty('disabled');
            }).inject(this._e);
        },
        _size: function() {
            //contentBoxCount = .scroller>ul>li
            var iScrollerSize = 450,
                ecContentBox = this._e.getElements('.scroller>ul>li'),
                iContentBoxCount = ecContentBox.length,

                //contentBoxSize = width + marginLeft + borders
                iContentBoxSize = ecContentBox[0].getSize().x + ecContentBox[0].getStyle('marginLeft').toInt(),

                //boxesInPage = floor(scrollerWidth/contentBoxSize)
                iBoxesInPageCount = Math.floor(iScrollerSize / iContentBoxSize),

                //pageSize = contentBoxSize * boxesInPage
                iPageSize = iContentBoxSize * iBoxesInPageCount,
            

                //pageCount = contentBoxCount / boxesInpage
                iPageCount = Math.ceil(iContentBoxCount / iBoxesInPageCount),

                //pageEnd = (pageCount-1) * pageSize
                //1 less as the first page starts at 0
                iPageEnd = -((iPageCount - 1) * iPageSize);
            
            
            this._iPageSize = iPageSize;
            this._iPageEnd = iPageEnd;

            /*console.log('iScrollerSize: ', iScrollerSize, '\n',
            'iContentBoxCount: ', iContentBoxCount, '\n',
            'iContentBoxSize: ', iContentBoxSize, '\n',
            'iBoxesInPageCount: ', iBoxesInPageCount, '\n',
            'iPageSize: ', iPageSize, '\n',
            'iPageCount: ', iPageCount, '\n',
            'iPageEnd: ', iPageEnd, '\n');*/
        },
        _prev: function() {
            this._iScroll += this._iPageSize;
            return this._iScroll >= 0 ? this._iScroll = 0 : this._iScroll;
        },
        _next: function() {
            this._iScroll -= this._iPageSize;
            return this._iScroll <= this._iPageEnd ? this._iScroll = this._iPageEnd : this._iScroll;
        }
    });
    
    
    $$('div.ip10').each(function(e) {
        new Scroller(e);
    });
    

    var corners = (function() {
        //create our corners and box
        var eCorners = '<span class="cnrs"><b class="cnr top tl"></b><b class="cnr top tr"></b><b class="cnr btm bl"></b><b class="cnr btm br"></b></span>'.toElement(),
            //if IE6 apply fix for 1px error
            bIE6 = (Browser.ie6) ? true : false,
            eCornersNew,
            eLast;

        return function(sSelector) {
            //add corners to each element in collection
            $$(sSelector).each(function(e) {
                eCornersNew = eCorners.cloneNode(true);

                //if IE 6, fix 1px bug for heights with odd number
                if (bIE6) {
                    if (e.getSize().y % 2) {
                        (eLast = eCornersNew.lastChild).style.bottom = eLast.previousSibling.style.bottom = '-1px';
                    }
                }

                //setup element for corners by applying our class
                e.addClass('cnrBox').appendChild(eCornersNew);
            });
        }
    })();

    //corners("#box,#nav,#footer,#header,#globalNav li,#breadcrumb ul,#sj01,#sj02,.ip01,.tabNav li,.tabBox,#explore,#about,#searchSchool,#socialMedia,.fs11,.rh01,.rh05,.rh02,.fs03,.fs05");
    //corners("#box, #nav, #footer, #header, #globalNav li, #breadcrumb, #breadcrumb ul, .tabContentBox, .tabs li, .m, #main .searchBox, #main ul.sitemap, .fs03, #searchToggle li a, #siblingNav li a, .ip10,.ec02 .eventTableBox,.ec02,#p546546 #main,#p546546 .bgOff,#p644338 .searchResults ul li,.ec04,.ec04 .resourceTableBox,#aside .searchBox");
    corners("#box, #nav, #footer, #globalNav .f, #globalNav .l, .subBrand, #breadcrumb, #breadcrumb ul, .tabContentBox, .tabs li, .m, #main .searchBox, #main ul.sitemap, .fs03, #searchToggle li a, #siblingNav li a, .ip10,.ec02 .eventTableBox,.ec02,#p546546 #main,#p546546 .bgOff,#p644338 .searchResults ul li,.ec04,.ec04 .resourceTableBox,#aside .searchBox");


    //transition
    //http://www.ltscotland.org.uk/learningteachingandassessment/approaches/outdoorlearning/index.asp
    
    
    var Transitioner = new Class({
        Implements: [Options,Events],
        options: {
            direction: 1, //0 = reverse, 1 = forward
            index: 0,
            autoPlay: false,
            random: false,
            transitionSet: ['fade','fade','fade','fade'],
            period: 5000
            /*
            onLoad: $empty,
            onStartEach: $empty,
            onCompleteEach: $empty,
            onPlay: $empty,
            onPause: $empty,
            onReverse: $empty,
            onCancel: $empty
            */  
        },
        initialize: function(items, options){
            this.setOptions(options);
            this.direction = this.options.direction;
            this.index = this.options.index;
            this.transitionSet = this.options.transitionSet;
            this.random = this.options.random;
            this.affiliates = options.affiliates;
            this.name = this.options.name;
            this.period = this.options.period;
            this.transitioning = false;

        
            //add items and set the specified index to display on top
            this.addItems(items)
            this.previousItem = this.item = items[this.index].setStyle('z-index',3);

            //might want to set specific elements once initialized
            this.fireEvent('load');
            
            //autoplay
            if(this.options.autoPlay){
                this.play();
            }   
        },
        addItem: function(item,index){              
            if(index !== undefined){
                this.items.splice(index,0,item);
            } else {
                this.items.push(item);    
            } 
            
            this.finalIndex = this.items.length-1;
            return this;   
        },
        addItems: function(items){
            if(this.hasOwnProperty('items')){
                var i = items.length;
                
                while(i--){
                    this.addItem(items[i],0);
                }
            } else {
                this.items = $$(items);
                this.finalIndex = this.items.length-1;  
            } 
            return this;
        },
        resetItem: function(){
            this.previousItem.setStyles({
                    zIndex: 1,
                    visibility: 'visible',
                    opacity: 1
                });
            this.item.setStyle('zIndex', 3);
            return this; 
        },
        transition: function(index,transition){    
            if(index !== undefined){
                this.previousItem = this.items[this.index];
                this.item = this.items[this.index = index];
            } else {
                var
                    //x and y are the indexes for the next and previous items
                    //the direction will determine if x is the next or previous, and the same for y
                    x = (this.index+1 > this.finalIndex ? 0 : this.index+1),
                    y = (this.index-1 >= 0 ? this.index-1 : this.finalIndex)
                ;
                
                this.previousItem = this.items[this.index];
                this.item = this.items[this.index = this.random ? this._randomize(0,this.finalIndex) : (this.direction ? x : y)];  
            }

            this.transitions[transition || this.transitionSet[this.index]](this);
        },
        play: function(){
            //only start the transitioner if it isn't already running
            if(this.timer == undefined){
                var me = this;
            
                function tada(){
                    me.transition();    
                }
            
                this.timer = setInterval(tada,this.period); 
                
                //this.transition.periodical(this.period,this);
            }
            
            this.fireEvent('play');
            return this;  
        },
        pause: function(){
            clearInterval(this.timer);   
            this.timer = undefined;
            this.fireEvent('pause');
            return this;  
        },
        reverse: function(){
            this.direction = 1 - this.direction;
            this.fireEvent('reverse');
            return this; 
        },
        cancel: function(){
            if(this.transitioning == false){
                return this;
            }
        
            var fx = this.fx;
            
            if(fx){
                for(var i=0, lenI=fx.length; i<lenI; i++){
                    fx[i].cancel(); 
                }
                this.fx = undefined;
            }
            
            this.fireEvent('cancel'); 
            return this; 
        },
        _randomize: function(from,to){
            var randomIndex;
            
            //ensure the randomly generated number isn't the current index
            while((randomIndex = Math.floor(Math.random() * (1 + to - from)) + from) == this.index){}

            return randomIndex;
        },
        onStart: function(transition){
            this.transitioning = true;
            this.fireEvent('startEach');
            transition.onStart();
        },
        onComplete: function(transition){
            this.transitioning = false;
            transition.onComplete();
            this.fireEvent('completeEach'); 
        },
        transitionCache: {},
        addFx: function(transition){
            this.transitionCache[transition.name] = transition;
        
            /*
                a transition can contain one or more fx instances with different durations etc.
                a transition is only complete after each fx instance has completed.
                
                to determine when the overall transition has completed each transition will increment
                a count for the number of fx instances in that transition, once the count equals the number of fx instances
                we know all fx instances have completed and fired their onComplete event(s)
            */
            var 
                completeCount = 0,
                me = this
            ;
            
            this.onStart(transition);
            
            for(var i=0, lenI=transition.fx.length; i<lenI; i++){
                transition.fx[i].addEvent('chainComplete',function(){
                    if(++completeCount == lenI){
                        me.onComplete(transition);
                    }    
                }).fireEvent('transition');
            }
            
            this.fx = transition.fx;
        },
        transitions: {
            instant: function(instance){
                instance.item.setStyle('z-index',2);
                instance.previousItem.fade('hide');
                instance.resetItem();
            },
            instant2: function(instance){
                instance.item.getParent().setStyles({
                    height: instance.item.getScrollSize().y,
                    overflow: 'hidden' 
                });
                instance.item.setStyle('z-index',2);
                instance.previousItem.fade('hide');
                instance.resetItem();
            },
            fade: function(instance){
                instance.previousItem.get('tween').removeEvents();
                //instance.item.getParent().get('tween').removeEvents();
            
                instance.addFx({
                    name: 'fade',
                    onStart: function(){
                    },
                    onComplete: function(){
                    },
                    fx: [
                        instance.previousItem.set('tween',{
                            duration: 1700,
                            onComplete: function(){
                                instance.resetItem();    
                            },
                            onCancel: function(){
                                instance.resetItem();
                            },
                            onTransition: function(){
                                
                                //instance.item.setStyle('z-index',2);
                                if(Browser.ie){
                                    instance.item.setStyles({visibility:'hidden','z-index':2}).fade('in');
                                } else {
                                    instance.item.setStyles({'z-index':2});
                                }
                                this.element.fade('out')
                            }
                        }).get('tween')
                        
                        /*,
                        
                        instance.item.getParent().set('tween',{
                            duration: 1000,
                            onTransition: function(){
                                this.element.setStyle('overflow','hidden'); 
                                this.element.tween('height',instance.item.getScrollSize().y);    
                            }
                        }).get('tween')*/
                    ]
                });
            },
            fadeOutIn: function(instance){
            
                //var color = instance.affiliates.tabContent.items[0].getStyle('backgroundColor');
                instance.previousItem.get('morph').removeEvents();
                instance.item.get('morph').removeEvents();
            
                instance.addFx({
                    name: 'fadeOutIn',
                    onStart: function(){
                    },
                    onComplete: function(){
                    },
                    fx: [
                        //fade current tab background from #0CA8D5 to #FFF
                        //and current tab link colour from #FFF to #0CA8D5
                        instance.previousItem.set('morph',{
                            duration: 1700,
                            onComplete: function(){
                            },
                            onTransition: function(){
                                this.start('.js .tabs .off');
                            }
                        }).get('morph'),
                        
                        
                        //fade next tab background from #FFF to #0CA8D5
                        //and next tab link colour from #0CA8D5 to #FFF
                        instance.item.set('morph',{
                            duration: 1700,
                            onComplete: function(){
                            },
                            onTransition: function(){
                                this.element.morph('.js .tabs .on');

                                instance.affiliates.tabContent.transition(instance.index);
                            }
                        }).get('morph')
                    ]
                });
            }
        }    
    });
    
    
    if($('tabs1')){
        
        var tabContent = new Transitioner($$('#tabs1 .tabContent'),{
            transitionSet: ['fade','fade','fade','fade'],
            autoPlay: false,
            onStartEach: function(){
            },
            onCompleteEach: function(){
            }
        });
                
          
        var tabNav = new Transitioner($$('#tabs1 .tabs li a'),{
            transitionSet: ['fadeOutIn','fadeOutIn','fadeOutIn','fadeOutIn'],
            autoPlay: true,
            random: false,
            affiliates: {
                tabContent: tabContent
            },
            onLoad: function(){ 
                this.item.addClass('on');

                this.items.each(function(el,i){
                    el.addEvents({
                        mouseover: function(ev){
                            tabNav.pause();
                            tabNav.cancel();
                            tabContent.cancel();
                            tabNav.index = i;
                                
                            $$('#tabs1 .tabs li a').setStyles({
                                backgroundColor: '',
                                color: ''
                            }).removeClass('on');
                                                   
                            this.addClass('on').focus();

                            tabContent.transition(i,'instant');
                        },
                        focus: function(){
                            this.fireEvent('mouseover');
                        },
                        click: function(ev){
                            ev.stop();
                            this.fireEvent('mouseover');
                        }
                    }); 
                });  
            }, 
            onStartEach: function(){
            },
            onCompleteEach: function(){
            }
        });
        
        
        //if there is a tabs one there could also be a tabs2
        if($('tabs2')){ 
            var tabContent2 = new Transitioner($$('#tabs2 .tabContent'),{
                transitionSet: ['fade','fade','fade','fade'],
                autoPlay: false,
                onStartEach: function(){
                },
                onCompleteEach: function(){
                }
            });
                           
            var tabNav2 = new Transitioner($$('#tabs2 .tabs li a'),{
                transitionSet: ['fadeOutIn','fadeOutIn','fadeOutIn','fadeOutIn'],
                autoPlay: false,
                affiliates: {
                    tabContent: tabContent2
                },
                onLoad: function(){ 
                    this.item.addClass('on');
                    tabContent2.transition(0,'instant2');

                    this.items.each(function(el,i){
                        el.addEvents({
                            mouseover: function(ev){
                                tabNav2.pause();
                                tabNav2.cancel();
                                tabContent2.cancel();
                                tabNav2.index = i;
                                    
                                $$('#tabs2 .tabs li a').setStyles({
                                    backgroundColor: '',
                                    color: ''
                                }).removeClass('on');
                                this.addClass('on').focus();

                                tabContent2.transition(i,'instant2');
                            },
                            focus: function(){
                                this.fireEvent('mouseover');
                            },
                            click: function(ev){
                                ev.stop();
                                this.fireEvent('mouseover');
                            }
                        }); 
                    });  
                }, 
                onStartEach: function(){
                },
                onCompleteEach: function(){
                }
            });
        } 
    }
    
    
    /* siblingNav */
        function splitList(sSelector) {
            $$(sSelector).each(function(e) {
                var ecListItems = e.getChildren(),
                    iItemCount = ecListItems.length,
                    iLeftItemsCount = parseInt(iItemCount / 2, 10) + iItemCount % 2;


                for (var i = 0, iOffset = 0, _e; i < iItemCount; i++) {
                    _e = ecListItems[i];

                    if (i == iLeftItemsCount) {
                        _e.setStyle('marginTop', -iOffset);
                        e.setStyle('min-height', iOffset);
                    }
                    if (i >= iLeftItemsCount) {
                        _e.addClass('col2');
                    }

                    iOffset += parseInt(_e.getSize().y) + _e.getStyle('marginTop').toInt() + _e.getStyle('marginBottom').toInt();
                }
            });
        }
        
        splitList('#siblingNav ol');
    /* end siblingNav */
    
    
    
    /* zebra */
        $$('#aside .searchResults > ul li:nth-child(even), .rh02 .feedBox ul li:nth-child(even)').addClass('zebra');       
    /* end zebra */

    
/* fs04 default state */
    var ecFS04List = $$('.fs04 ul li a');
    
    if(ecFS04List.length > 0){
        ecFS04List.addEvents({
            mouseover: function(){
                ecFS04List.removeClass('on');
                this.addClass('on');
            },
            focus: function(){
                ecFS04List.removeClass('on');
                this.addClass('on');
            }        
        })[0].addClass('on');
    }
/* end fs04 default state */
    
  
         
    /*
	    Slimbox v1.71 - The ultimate lightweight Lightbox clone
	    (c) 2007-2009 Christophe Beyls <http://www.digitalia.be>
	    MIT-style license.
    */
    var Slimbox=(function(){var G=window,n=Browser.ie6,u,g,H=-1,o,x,F,v,z,N,s,m={},t=new Image(),L=new Image(),J,b,h,q,K,e,I,c,B,M,y,i,d,D,w=new Element("img",{id:"sharedImg"});G.addEvent("domready",function(){$(document.body).adopt($$(J=new Element("div",{id:"lbOverlay",events:{click:E}}),b=new Element("div",{id:"lbCenter"}),I=new Element("div",{id:"lbBottomContainer"})).setStyle("display","none"));h=new Element("div",{id:"lbImage"}).inject(b,'bottom').adopt(K=new Element("a",{id:"lbPrevLink",href:"#",events:{click:C}}),e=new Element("a",{id:"lbNextLink",href:"#",events:{click:f}}),q=new Element("div",{styles:{position:"relative"}}));c=new Element("div",{id:"lbBottom"}).inject(I,'bottom').adopt(new Element("a",{id:"lbCloseLink",href:"#",events:{click:E}}),B=new Element("div",{id:"lbCaption"}),M=new Element("div",{id:"lbNumber"}),new Element("div",{styles:{clear:"both"}}));h.addEvents({mouseover:function(){K.addClass("show");e.addClass("show")},mouseout:function(){K.removeClass("show");e.removeClass("show")}}).grab(w,"top")});function A(){var O=G.getScroll(),P=G.getSize();$$(b,I).setStyle("left",O.x+(P.x/2));if(v){J.setStyles({left:O.x,top:O.y,width:P.x,height:P.y})}}function l(O){["object",n?"select":"embed"].forEach(function(Q){Array.forEach(document.getElementsByTagName(Q),function(R){if(O){R._slimbox=R.style.visibility}R.style.visibility=O?"hidden":R._slimbox})});J.style.display=O?"":"none";var P=O?"addEvent":"removeEvent";G[P]("scroll",A)[P]("resize",A);document[P]("keydown",p)}function p(P){var O=P.code;return u.closeKeys.contains(O)?E():u.nextKeys.contains(O)?f():u.previousKeys.contains(O)?C():false}function C(){return a(x)}function f(){return a(F)}function a(O){if(O>=0){H=O;o=g[O][0];x=(H||(u.loop?g.length:0))-1;F=((H+1)%g.length)||(u.loop?0:-1);r();b.className="lbLoading";m=new Image();m.onload=k;m.src=o}return false}function k(){b.className="";d.set(0);h.setStyles({display:""});if(m.width>u.maxWidth){m.height=parseInt((u.maxWidth*(m.height/m.width)),10);m.width=u.maxWidth}w.setStyles({width:m.width,height:m.height}).setProperty("src",o);q.setStyles({width:m.width,height:m.height});B.set("html",g[H][1]||"");M.set("html",(((g.length>1)&&u.counterText)||"").replace(/{x}/,H+1).replace(/{y}/,g.length));if(x>=0){t.src=g[x][0]}if(F>=0){L.src=g[F][0]}N=h.offsetWidth;s=h.offsetHeight;var Q=Math.max(0,z-(s/2)),O=0,P;if(b.offsetHeight!=s){O=i.start({height:s,top:Q})}if(b.offsetWidth!=N){O=i.start({width:N,marginLeft:-N/2})}P=function(){I.setStyles({width:N,top:Q+s,marginLeft:-N/2,visibility:"hidden",display:""});d.start(1)};if(O){i.chain(P)}else{P()}}function j(){if(x>=0){K.style.display=""}if(F>=0){e.style.display=""}D.set(-c.offsetHeight).start(0);I.style.visibility=""}function r(){m.onload=Function.from;m.src=t.src=L.src=o;i.cancel();d.cancel();D.cancel();$$(K,e,h,I).setStyle("display","none")}function E(){if(H>=0){r();H=x=F=-1;b.style.display="none";y.cancel().chain(l).start(0)}return false}Element.implement({slimbox:function(O,P){$$(this).slimbox(O,P);return this}});Elements.implement({slimbox:function(O,R,Q){R=R||function(S){return[S.href,S.title]};Q=Q||function(){return true};var P=this;P.removeEvents("click").addEvent("click",function(){var S=P.filter(Q,this);return Slimbox.open(S.map(R),S.indexOf(this),O)});return P}});return{open:function(Q,P,O){u=Object.append({loop:false,overlayOpacity:0.8,overlayFadeDuration:400,resizeDuration:400,resizeTransition:false,initialWidth:250,initialHeight:250,imageFadeDuration:400,captionAnimationDuration:400,counterText:"Image {x} of {y}",closeKeys:[27,88,67],previousKeys:[37,80],nextKeys:[39,78]},O||{});y=new Fx.Tween(J,{property:"opacity",duration:u.overlayFadeDuration});i=new Fx.Morph(b,Object.append({duration:u.resizeDuration,link:"chain"},u.resizeTransition?{transition:u.resizeTransition}:{}));d=new Fx.Tween(h,{property:"opacity",duration:u.imageFadeDuration,onComplete:j});D=new Fx.Tween(c,{property:"margin-top",duration:u.captionAnimationDuration});if(typeof Q=="string"){Q=[[Q,P]];P=0}z=G.getScrollTop()+(G.getHeight()/2);N=u.initialWidth;s=u.initialHeight;b.setStyles({top:Math.max(0,z-(s/2)),width:N,height:s,marginLeft:-N/2,display:""});v=n||(J.currentStyle&&(J.currentStyle.position!="fixed"));if(v){J.style.position="absolute"}y.set(0).start(u.overlayOpacity);A();l(1);g=Q;u.loop=u.loop&&(g.length>1);return a(P)}}})();Slimbox.scanPage=function(){$$("a").filter(function(a){return a.rel&&a.rel.test(/^lightbox/i)}).slimbox({maxWidth:720},function(a){return[a.href,a.title.replace(/  +/g,"<br />")]},function(a){return(this==a)||((this.rel.length>8)&&(this.rel==a.rel))})};if(!/android|iphone|ipod|series60|symbian|windows ce|blackberry/i.test(navigator.userAgent)){window.addEvent("domready",Slimbox.scanPage)};



    /* promo banners */
        function startGalleryRotation(ec, delay) {
            if (ec.length > 0) {
                var i = 0, zIndex = 50;

                ec.each(function(e) {
                    e.setStyle('zIndex', zIndex -= 1).set('tween', { duration: 2000 });
                });

                delay = (delay == undefined) ? 6000 : delay;
                setInterval(function() {
                    ec[i].fade('out');
                    i = (i == ec.length - 1) ? 0 : i + 1;
                    ec[i].fade('in');
                }, delay);
            }
        }

        startGalleryRotation($$('.rh05s .rh05'), 6000);
        startGalleryRotation($$('.rh12s .rh12'), 6000);
    /* end promo banners */
    
    
    /* archive banner */
        if (location.host.indexOf('archive' + '-it' + '.org') > -1) {
            var path = ['http', '://', 'www', '.', 'ltscotland', '.', 'org.uk', '/a-it_banner', '.', 'js'],
                newScript = document.createElement('script');

            newScript.type = 'text/javascript';
            newScript.src = path.join('');
            document.getElementsByTagName("head")[0].appendChild(newScript);
        }
    /* end archive banner */


    /* firefox table margins don't collapse! */
	if(Browser.firefox && 1==1){
		$$('table').each(function(el){
			el.setStyle('margin',0);
			new Element('div',{'class':'ffTable'}).wraps(el);  
		});
	}


})(document.id);
        
// accessibility toolbar
var textSwitch, colourSwitch;
(function() {
    //check that the access toolbar exists
    if (document.getElementById('userPref')) {
        function createCookie(name, value, days) {
            if (days) {
                var date = new Date();
                date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
                var expires = "; expires=" + date.toGMTString();
            }
            else var expires = "";
            document.cookie = name + "=" + value + expires + "; path=/";
        }

        function readCookie(name) {
            var nameEQ = name + "=";
            var ca = document.cookie.split(';');
            for (var i = 0; i < ca.length; i++) {
                var c = ca[i];
                while (c.charAt(0) == ' ') c = c.substring(1, c.length);
                if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
            }
            return null;
        }

        var body = document.body;

        textSwitch = function(myTextPreference) {
            var sClass = body.className;

            if (myTextPreference == 'textnormal') {
                body.className = sClass.replace('large', '').replace('xlarge');
            }
            else if (myTextPreference == 'textlarge') {
                body.className = sClass.replace('xlarge', '') + ' large';
            }
            else {
                body.className = sClass.replace('large', '') + ' xlarge';
            }
            createCookie('text-preference', myTextPreference, 1);
        };

        colourSwitch = function(myColourPreference) {
            var sClass = body.className;

            if (myColourPreference == 'colournormal') {
                body.className = sClass.replace('high', '').replace('highvisibility');
            }
            else if (myColourPreference == 'colourhighcontrast') {
                body.className = sClass.replace('highvisibility', '') + ' high';
            }
            else {
                body.className = sClass.replace('high', '') + ' highvisibility';
            }
            createCookie('colour-preference', myColourPreference, 1);
        };

        //load previous selections
        //load previous selections or default to normal
        textSwitch(readCookie('text-preference') || 'textnormal');
        colourSwitch(readCookie('colour-preference') || 'colournormal');

        //insert text switch buttons
        document.getElementById('textSwitcher').innerHTML = '<p id="accessibility">Text size:</p>' +
                    '<a href="#" id="textnormal" onclick="textSwitch(\'textnormal\');" /><img src="http://www.ltscotland.org.uk/global/graphics/iconTextNormal.png" alt="Adjust text size: normal" /></a>' +
                    '<a href="#" id="textbig" onclick="textSwitch(\'textlarge\');" /><img src="http://www.ltscotland.org.uk/global/graphics/iconTextBig.png" alt="Adjust text size: normal" /></a>' +
                    '<a href="#" id="textbigger" onclick="textSwitch(\'textxlarge\');" /><img src="http://www.ltscotland.org.uk/global/graphics/iconTextBigger.png" alt="Adjust text size: bigger" /></a>';

        //insert colour switcher buttons
        document.getElementById('colourSwitcher').innerHTML = '<p id="accessibilitycolour">Contrast options:</p>' +
            '<a href="#" id="colournormal" onclick="colourSwitch(\'colournormal\');" /><img src="http://www.ltscotland.org.uk/global/graphics/iconNormalContrast.png" alt="Adjust colour contrast: normal" /></a>' +
            '<a href="#" id="colourhighcontrast" onclick="colourSwitch(\'colourhighcontrast\');" /><img src="http://www.ltscotland.org.uk/global/graphics/iconHighContrast.png" alt="Adjust colour contrast: high contrast" /></a>' +
            '<a href="#" id="colourhighvisibility" onclick="colourSwitch(\'colourhighvisibility\');" /><img src="http://www.ltscotland.org.uk/global/graphics/iconHighVisibility.png" alt="Adjust colour contrast: high visibility" /></a>';
    }
})();

dE.id = 'post';
