var icon = '/LIB/css/css_default_icon.gif';
var defsep = '__';
var spacer = '-';
var menwidth = 180;
var hilite = '#ffdf00';

var goog,_gaq = _gaq || [],gfolder = '',gRan = [],gTick = [],tmr,g_js = [];
var rsp = new RegExp(spacer,'g');
var durl = document.URL.replace(/^http:\/\//,'');
var ura = durl.replace(/\\/g,'/').split('/'),urc = ura[0];uri = unescape( ura.pop() ).replace(rsp,' ');
var urp = ura.join('/');

var curl = 'http://';
if( durl.test(/^(.*?)\.thatsthat\.co\.uk/) ){
var stt = RegExp.$1;
curl = 'http://'+stt+'.thatsthat.co.uk/cgi-bin/'+stt+'/';
gfolder = ura[2]+'/';
} else if( durl.test(/^(.*?)\.parknet\-hosting\.co\.uk/) ){
curl = 'http://demo.parknet-hosting.co.uk/cgi-bin/'+stt+'/';
} else {
curl = 'http://'+urc+'/cgi-bin/';
}
var burl = 'http://'+urp;
var uu = durl.test(/\?$/)?true:false;

var analyseMe = function(){
$$('meta').each(function(z,i){ goog = z.getProperty('name') == 'gref'?z.getProperty('content'):null; });
if(goog){
_gaq.push(['_setAccount',goog]);
_gaq.push(['_trackPageview']);
var ga = document.createElement('script');
ga.type = 'text/javascript';
ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(ga);
}
};
//$$('a[target*="_blank"]').addEvent('click', function(){ try { if(_gaq){ _gaq.push(['_trackPageview', '/outgoing/'+ this.getProperty('href');]); } } catch (err) {}; });

var debugMe = function(){ var c = 'not detected';if(navigator.oscpu){c = navigator.oscpu;} else { if(navigator.cpuClass){c = navigator.cpuClass;} }if( $('debug') ){ $('debug').setProperty('target','_blank').setProperty('href','../cgi-bin/debug.pl?path='+durl.replace(urc+'/','')+'&js=yes&cpu='+c+'&platform='+navigator.platform+'&flash='+Browser.Plugins.Flash.version+'&screen-x='+screen.width+'&screen-y='+screen.height); } };
var accordMe = function(){ $$('dl.accordion').each(function(z,i){if( z.getElement('dd.togr') ){new Fx.Accordion(z.getElements('dd.togr'),z.getElements('dd.toge'),{ 'hilite':hilite,onActive:function(t,e){if(t.getElement('span.icon')){t.getElement('span.icon').set('html','&#45;');}},onBackground:function(t,e){if(t.getElement('span.icon')){t.getElement('span.icon').set('html','&#43;');}} }); } }); };//,{display:-1}
var tabMe = function(){ $$('li.column').each(function(z,i){ if( z.getElement('dl.is-tab') ){ var t = new doTab(z,{'corners':1}); } }); };
var iframeMe = function(){ $$('dd.iframe').each(function(z,i){ var d,e,f,w = z.getStyle('width'),h = z.getStyle('height');d = z.getElement('a');if( d && !z.getElement('iframe') ){ var y = d.clone().set('text','').setStyles({'position':'absolute','width':w,'height':h,'padding-top':0,'border':0,'z-index':50}).inject(z,'top');new IFrame({src:d.getProperty('href'),scrolling:'no',styles:{'width':w,'height':h,'border':0,'overflow':'hidden'},events:{} }).replaces(d); } }); };
var tickMe = function(){ $$('ul.ticked').each(function(z,i){ if( z.getElement('li.plain') ){new Ticker( z.getElements('li.plain'),{'frq':500,'ifreq':250,'chf':100} );} }); };
var libraryMe = function(){ $$('dd.library','dd.newsticker').each(function(z,i){ var a,b,d = z.getElement('a');if(d){if(d.get('class').test(/^news/) ){ a = d.getProperty('href');b = d.get('class');c = z; } else { a = d.getProperty('href');b = z.get('class');c = d; }var aH = new Hash({'news':a,'list':b});sendER(b,aH.toQueryString(),false,z,c); } }); };
var rssMe = function(){ $$('dd.rss').each(function(z,i){ var b = 'rss';if( z.get('class').test(/(wordpress|twitter|blogger|facebook)/) ){b = RegExp.$1;}var c = z.getElement('a').getProperty('title').replace(/[^0-9]/g,'').toInt();if( isNaN(c) ){c = 1;}if( z.getElement('a') ){var a = new Rss(z,z.getElement('a').getProperty('href'),{'type':b,'count':c,'char':60});} }); };

var imgboxMe = function(){ $$('dd.imagebox a').slimbox({},null,function(z){return [z.href,z.getFirst('img').alt];});}

var swfMe = function(){
if(Browser.Plugins.Flash.build){ 
$$('dd.flash').each(function(z,i){
var j,k,m = [z.retrieve('bg'),z.getStyle('width'),z.getStyle('height'),z.getStyle('background-color')];

if( !z.getElement('object[id^=swf]') ){
k = z.getStyle('background-image');if( k && k != 'none'){m[0] = k.unurl();}z.store('bg',m[0]);
var f = m[0].split('.');if( !f[f.length-1].test(/swf/i) ){ f[f.length-1] = f[f.length-1].replace(/[a-z]+/,'swf').replace(/[A-Z]+/,'SWF'); }m[0] = f.join('.');
m[3] == 'transparent'?j = m[3]:j = 'opaque';
if(m[0]){ var s = new Swiff(m[0],{ 'id':'swf_'+i,'width':m[1],'height':m[2],'container':z,'params':{'wmode':j,'bgcolor':m[3]} });z.setStyle('background-image','none'); }
}
});
}
};

var doRotate = function(a,b,c,d,e){ return new Rotator({'outer':a,'inner':b,'items':c,'controls':d,'dir':e}); };

var rotateMe = function(){
$$('li.rotator').each(function(z,i){
var g = 'west',h = 0;if( z.get('class').test(/(north|south|east|west)/) ){g = RegExp.$1;if( g.test(/north/) ){h = 1;} else { if(g.test(/south/) ){h = 2;}}}g == 'east'?g = -1:g = 1;
var f = z.getElements('dl.cs');var rh = z.getFirst('dl.cs').getSize().y;
if(f.length > 1){
var rt = f[0].clone().empty().removeClass('cs').setStyles({'border':0,'width':'100%','height':(rh+2)+'px','overflow':'hidden'}).addClass('rotator').inject(z,'top');
var nw = new Element('dd',{'class':'cs-inner','style':'position:relative; height:'+(rh+2)+'px; margin:0; float:left;'}).inject(rt);
for(var j=0;j<f.length;j++){ nw.grab( f[j] ); }nw.getElements('dl.cs').each(function(zz,ii){ zz.setStyles({'float':'left','min-height':rh+'px','clear':'none'}); });z.removeClass('rotator');
var p = doRotate(nw,nw,'dl.cs',h,g);}
});
};

var doPromo = function(a,b){ var l = a.getProperty('href'),t = a.getProperty('title'),k = a.getProperty('html');a.getParent('dd.promo').setProperty('html',b).setStyles({'height':'auto','background':'transparent none'}).store('link',l).store('item',t).store('cont',k); };

var promoMe = function(){
$$('dd.promo').each(function(z,i){
if( z.getElement('a.promolink') ){
var a = z.getElement('a.promolink');var b = a.getProperty('href'),c = a.getProperty('title').split(',');
if( z.get('class').test(/(north|south|east|west)/) ){z.addClass(RegExp.$1);}
if(b.length){ sendER('latest','promo='+b+'&target='+c,false,'',a); }
}
});
};

var randomMe = function(){
$$('dd.random img').each(function(z,i){
var a = z.getProperty('alt'),s = z.getProperty('src').replace(/\\/g,'/').split('/'),c= '';var f = s.pop().split('_');var d = a.replace(/[^0-9]/g,'').toInt();
var j = Math.floor((Math.random()*d)+1).toString().nil();f[(f.length-1)] = f[(f.length-1)].replace(/[0-9]+/,j);
if($type(s) == 'array'){c = s.join('/')+'/';}c+= f.join('_');if(c){ var n = new Asset.image(c,{alt:a,onload:function(){ n.replaces(z); } }); }
});
};

var boardMe = function(){
$$('dl.newsboard').each(function(z,i){
if(!gE.ie6){

z.setStyles({'border-style':'solid','background-color':'','background-image':'url('+cbk.src+')','background-repeat':'repeat'}).set('morph',{duration:200});
var ry = 10,ov = 60,tw = (z.getComputedSize().width - 200).toInt(),w = $(z).getChildren('dd')[0].getDimensions(true).width.toInt(),h = 12,q = 20,u = 5,v = 5;
var wh = 1+(tw / (w-ov)).toInt();
var rem = ((w * wh) - tw).toInt();
var n = w - (rem / wh).toInt();
$(z).getChildren('dd').each(function(zz,ii){
zz.addClass('paper');
if((h+n) < (tw-w) ){ if(ii > 0){h = h+n.toInt();} } else { var k = z.getComputedSize().height+ry;z.morph({'height':k});h = q;v+= (20+ry);q = (q == 5?20:5); }
zz.setStyles({'z-index':800+ii,'top':(v+u)+'px','left':h+'px'}).addEvents({
'click': function(){ var r = [];this.getParent().getChildren().each(function(zzz,iii){r.push(zzz.getStyle('z-index'));});r.sort( function(a,b){return (a - b);} );this.setStyle( 'z-index',1+r.getLast().toInt() ); },
'mouseenter': function(){ this.setStyles({'cursor':'pointer','border-color':'#cc6600'}); },
'mouseleave': function(){ this.setStyle('border-color','#666'); }
});
if(u == 5){u = 20;} else if(u == 20){u = 35;} else {u = 5;} 
zz.setStyle('display','block').makeDock(z);
});

} else {
z.setStyles({'background-color':'#fff','background-image':''});
z.getElements('dd.notice').setStyles({'display':'block','margin':'0 0 1em 0'});
}
});
};

//
var endY = function(a,b){
switch(a){
case 'news':
case 'newsresult':
case 'newsresults':
case 'newssection':
case 'newslist': if( !gE.ie6 ){ accordMe(); } break;
case 'newstag': break;
case 'newsboard': boardMe(); break;
case 'newsticker': tickMe(); break;
case 'mail': if($('question_result') ){$('question_result').setStyle('background-color','#fff');} break;
case 'search': if($('textonly') && uu){urlSwap();}b.setStyles({'overflow':'hidden','overflow-y':'scroll','scroll':'scroll','background-color':'#fff','background-image':'none'});break;
}
};

var failY = function(a,b){
b.setStyles({'background':'transparent none top left no-repeat'});
switch(a){
case 'latest': break;
default: b.set('html','<span class="s-fail">Sorry, the request to the remote server failed: unable to connect..</span>');
}
};

var sendER = function(a,b,c,d,e){
var g = a.test(/^news/)?'news':a;
var hh = 'auto';if(a == 'search'){hh = '22em';} else if(a == 'newsticker'){hh = d.getStyle('height');}
if(d && e){ d.store({ 'hrf':e.getProperty('href'),'cls':a,'wt':d.getStyle('width'),'ht':d.getStyle('height') }); }
var snk = new Request.HTML({url:curl+g+'.pl?'+b,evalScripts:c,update:d,noCache:true,
onRequest: function(){ if(e && a != 'latest'){e.setStyles({'height':hh,'background':'transparent url('+tmr.src+') center center no-repeat'});e.set('html','<span class="s-req"></span>');} },
onSuccess: function(tree,xml,htm,js){ if(a == 'latest'){if(htm){doPromo(e,htm);} else {failY(a,e);}} else { if(d && a != 'newsticker'){d.setStyles({'height':hh,'background-color':'transparent','background-image':'none','background-position':'top left','background-repeat':'repeat-x'});}endY(a,e);} },
onFailure: function(){ failY(a,e) ;}
});
snk.get();
};

var validF = function(a,b){
var eA = a.elements;
var dA = [];
var rA = [];
var q = 0;
var s = '';

for(var i=0;i<eA.length;i++){
var d;
var c = eA[i];
var f = eA[i].type;

if( c.name && c.name.test(/^pre_/) ){
var pA = c.name.split('_');
var r1 = /^(email)|(e-mail)$/i;
var r2 = /^(tel)|(telephone)|(phone)$/i;
var r3 = /^([0-9 ]+)$/i;
var r5 = /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;
if(f == 'text' || f == 'textarea'){ if(!(c.value) || c.value == "" || c.value == ' '){dA.push('Please complete the '+pA[1]+' field.');} else {
if( r1.test(pA[1]) ){ if(c.value.indexOf('@') < 0 || c.value.indexOf('.') < 0 ){dA.push('Please enter a valid email address.');} }
if( r2.test(pA[1]) ){ if( r3.test(c.value) == false ){dA.push('Please enter a valid phone number.');} }
} }
if(f == 'select-one'){if(c.selectedIndex < 1 || c.options[c.selectedIndex].text == ""){dA.push('Please select from the '+pA[1]+' dropdown.');}}
if(f == 'select-multiple' && a.selectedIndex < 1){dA.push('Please choose from the '+pA[1]+' options.');}
if(f == 'checkbox' && !(c.checked) ){dA.push('Please check the '+pA[1]+' box.');}
if(f == 'radio'){ if(c.name != s){s = c.name;q++;}if(c.checked){rA[q] = '';}if(rA[q] == ''){} else {rA[q] = pA[1];} }
} else {
if(f == 'checkbox'){c.checked?c.value = 'checked':c.value = "";}
}

}

for(var k=1;k<rA.length;k++){if(rA[k] != ''){dA.push('Please choose from the '+rA[k]+' group');}}

if( b.test(/(register)|(library)/) ){ if(a.elements[0].value.indexOf('@') < 0 || a.elements[0].value.indexOf('.') < 0){dA.push('Please enter a valid email address.');} }
if(dA && dA.length > 0){alert( dA.join('\n') );return false;} else {return true;}
};

var crY = function(a,b,c){ for(var i = a;i < c.length;i++){b[i]+= defsep+c[a].replace(/ /g,'-');}return b; };

var upCrumb = function(a){
if( a && $$('.crumb') ){
a = a.replace(/\?$/,'').replace(/\.html$/,'');
var c = a.split(defsep);
//if(c.length > 1){
var nA = [];
for(var i = 0;i < c.length;i++){ nA[i] = c[0].replace(/ /g,'-'); }
for(var d = 1;d < c.length;d++){ if( c[d] ){nA = crY(d,nA,c);} }
for(var w = 0;w < c.length;w++){c[w] = '<strong><a href="'+nA[w]+'.html">'+c[w]+'</a></strong>';}
$$('.crumb').set( 'html',c.join('<span class="join"> &#187; </span>') ); 
} else {
$$('.crumb').set( 'html','&nbsp;');
//}
} 
};

var upLink = function(){var b = (uri == '')?'index.html':uri;
$$('ul.hori','ul.vert').each(function(z,i){
z.getElements('li.nav').each(function(zz,ii){
if( zz.getElement('a') && zz.getElement('a').getProperty('href') ){
var s = 0,d = unescape(zz.getElement('a').getProperty('href'));d = d.replace(/\-/g,' ').replace(/^\//,'').replace(/^(.*?)\//,'');
var c = b.split(defsep);if(c[0] && c[0] == d){s++;} else {if(uri == '' && ii == 0){s++;}}
if(d == b || s > 0){zz.getElement('a').addClass('navoff');}
}
});
});
upCrumb(b);
};

var rollMe = function(){ 
var s = '';
$$('.sprite1','.sprite2','.sprite3','.sprite4').each(function(z,i){
var n;if( z.get('class').test(/sprite([0-9])/) ){n = RegExp.$1;}
z.store('sprite',n);
z.removeEvents().addEvents({ 
'mouseenter': function(){var a = this.retrieve('sprite');this.setStyle('background-position',gE.rollA[a]);},
'mouseleave': function(){this.setStyle('background-position',gE.rollA[1]);} 
}); 
});
};

var sendY = function(a,b){
if( validF(a,b) ){
var c = $(a).get('id')+'_result';if( !$(c) ){c = $(a).getParent('dd');}
var oH = new Hash();
$(a).getElements('input,textarea,radio,select').each(function(z,i){
if(z.name && z.type != 'submit'){if( z.type.test('select') ){oH.set(z.name,z.options[z.selectedIndex].value);} else if( z.type.test('radio') ){if(z.get('checked') ){oH.set(z.name,z.value);}} else {oH.set(z.name,z.value);}
}
});
sendER(b,oH.toQueryString(),'',$(c),$(c));
}
};

var formOut = function(a){
var c = "search";
var f = a.getElement('.form-sg')
if(f){

if(f.get('name').test(/^pre_search/) ){ if( f.get('value').test(/[a-zA-Z]/) ){sendY(a,c);} } else 
if(f.get('name').test(/^pre_email/)){c = "mail";sendY(a,c);} else 
if(f.get('name').test(/^pre_quickfind/) ){var m = f.selectedIndex;if(m > 0){window.location = f.options[m].value;}}

} else {
sendY(a,'mail');
}
};

var sendMe = function(){
$$('form').each(function(z,i){
z.getElements('input[name^=submit]').each(function(zz,ii){ zz.addEvent('click',function(){ formOut(z); }); });
z.getElements('input[id^=search]').addEvents({'focus':function(){ this.store('val',this.value);this.set('value',''); },'blur':function(){ if( !this.value.test(/[a-zA-Z]/) ){this.set('value',this.retrieve('val'));} }});
});
};

var urlSwap = function(){ $$('a').each(function(z,i){ if( z.getProperty('id') && z.getProperty('id') == 'textonly'){z.setProperty('href',document.URL.replace(/\?$/,'')); } else { var a = z.getProperty('href');if( a.test(/\.html$/) && !a.test(/www\./) ){z.setProperty('href',a+'?');} } }); }

var ie6Me = function(){
if(gE.ie6){
$$('dd.navigation').each(function(z,i){ z.getParent('ul.area').setStyle('z-index','1000'); });
$$('div','ul','dl').each(function(z,i){ var a = z.getStyle('background-image');if( a.test(/\.PNG\)$/i) ){a = a.replace('PNG','GIF');a = a.replace('png','gif');z.setStyle('background-image',a);} });
}
};

var css3Me = function(){
if(!Browser.Engine.trident){ $$('dd.navigation ul.hori li','dd.navigation ul.vert li').setStyle('opacity','1'); }
$$('a.blank').setProperty('target','_blank');
$$('a[class^=popup]').each(function(z,i){var a = z.get('class').replace(/^popup/,'').split('_');var p = z.getProperty('href');z.setProperty('href','javascript:popMe("'+ p +'", "", '+ a[0] + ',' + a[1] +')');});};

var growMe = function(){
$$('span.grow1,span.grow2,span.grow3').addEvents({
'select': function(){$$('span.grow1,span.grow2,span.grow3').setStyle('text-decoration','none');this.setStyle('text-decoration','underline');},
'click': function(){
if( this.get('class').test('1') ){$('body0').setStyle('font-size','76%');}
if( this.get('class').test('2') ){$('body0').setStyle('font-size','90%');}
if( this.get('class').test('3') ){$('body0').setStyle('font-size','104%');}
this.fireEvent('select');
}
});
};

var quoteMe = function(){
$$('dl.quoter').each(function(z,i){ 
if( z.getElement('span.quoteup') ){
var c = z.getElement('span.quoteup').get('html');
var m = new Element('div',{'id':'quoter_'+i,'class':'floater','html':c}).inject(document.body);
z.addEvents({ 'mouseenter':function(){$('quoter_'+i).setStyles({'top':this.getCoordinates().top,'left':this.getCoordinates().left+100}).setStyle('display','block');},'mouseleave':function(){ $('quoter_'+i).setStyle('display','none'); } });
} 
});
if( $('qtarget') ){
var qh = new Element('dl',{ id:'qholder',html:$('qtarget').get('html'),styles:{'position':'absolute','display':'none'} }).inject(document.body);
$$('dl.quoter2').each(function(z,i){ if( z.getElement('span.quoteup') ){
z.addEvents({ 'mouseenter':function(){ var c = '<dl class="text"><dd>'+this.getElement('span.quoteup').get('html')+'</dd></dl>';$('qtarget').set('html',c); },'mouseleave':function(){ var c = $('qholder').get('html');$('qtarget').set('html',c); } });
} });
}
}

var getXML = function(a,b){ if(a.length > 0){ var parser = new DOMParser(); return parser.parseFromString(b,"text/xml");} else {return;} };

var noText = function(){
navMe( $$('dl.pagenav,dd.navigation,dd.side') );
quoteMe();
upLink();
rollMe();
ie6Me();
if( !$('swapdiv') ){ 
rssMe();libraryMe();iframeMe();swfMe();randomMe();tabMe();rotateMe();promoMe();imgboxMe();
if(!gE.ie6){ var g = $$('dd.library');g.each(function(z,i){ if( z.getElement('a') && z.getElement('a').hasClass('newstag') ){g.erase(z);} });accordMe(); } //if(g.length){  }
}
$$('.hori','.vert').setStyle('visibility','visible');
css3Me();
};

var dateMe = function(){ $$('dd.fulldate').set('text',setDate(0));};

var textMe = function(){
if(uu){
$('textonly').set('text','Non-Text Version').set('title','non-text version of this page');
new Asset.css('text.css', {id:'text'});
$$('div','ul','li','a','dl','dd','img','form').each(function(z,i){z.erase('style');});
urlSwap();
} else {
if( $('textonly') ){ $('textonly').setProperty( 'href',document.URL+'?' ); }
noText();
}

sendMe();
growMe();
};

Slimbox.scanPage = function() {
	$$("dd.imagebox a").slimbox({ //.filter(function(el) {return el.rel && el.rel.test(/^lightbox/i);}).slimbox({
		loop: true,
				initialWidth: 1024,
				initialHeight: 768,
				overlayOpacity: 0.6,
				overlayFadeDuration: 200,
				resizeDuration: 500,
				resizeTransition: Fx.Transitions.Elastic.easeOut,
				counterText: "This is image <strong>{x}</strong> out of a total of <strong>{y}</strong>",
				previousKeys: [37, 80, 16],
				nextKeys: [39, 78, 17]		
		}, null, function(el) {
		return (this == el) || ((this.rel.length > 8) && (this.rel == el.rel));
	});
};

if (!/android|iphone|ipod|series60|symbian|windows ce|blackberry/i.test(navigator.userAgent)) {
	window.addEvent("domready", Slimbox.scanPage);
}

window.addEvent('domready',function(){
cbk = new Asset.image(burl+'/LIB/css/css_noticeboard.jpg',{});
tmr = new Asset.image(burl+'/LIB/css/css_timer.gif',{});
if(!gfolder){analyseMe();debugMe();}
textMe();
dateMe();
});

