/* 

	nitec 
	MooTools enabled javascript
	
	Created by Ryan Mitchell of RTNetworks (www.rtnetworks.net)

*/

MooTools.More={version:"rc01"};(function(){var A={language:"usENG",languages:{usENG:{}},cascades:["usENG"]};var B;MooTools.lang=new new Class({Implements:Events,setLanguage:function(C){if(!A.languages[C]){return ;
}A.language=C;this.load();this.fireEvent("langChange",C);return this;},load:function(){var C=this.cascade(this.getCurrentLanguage());B={};$each(C,function(E,D){B[D]=this.lambda(E);
},this);},getCurrentLanguage:function(){return A.language;},addLanguage:function(C){A.languages[C]=A.languages[C]||{};return this;},cascade:function(E){var C=(A.languages[E]||{}).cascades||[];
C.combine(A.cascades);C.erase(E).push(E);var D=C.map(function(F){return A.languages[F];},this);return $merge.apply(this,D);},lambda:function(C){(C||{}).get=function(E,D){var E=arguments[0];
return $lambda(C[E]).apply(this,$splat(D));};return C;},get:function(E,D,C){if(B[E]){return(D?B[E].get(D,C):B[E]);}},set:function(D,E,C){this.addLanguage(D);
langData=A.languages[D];if(!langData[E]){langData[E]={};}$extend(langData[E],C);if(D==this.getCurrentLanguage()){this.load();this.fireEvent("langChange",D);
}return this;},list:function(){return $A(A.languages);}});})();Fx.Scroll=new Class({Extends:Fx,options:{offset:{x:0,y:0},wheelStops:true},initialize:function(B,A){this.element=this.subject=$(B);
this.parent(A);var D=this.cancel.bind(this,false);if($type(this.element)!="element"){this.element=$(this.element.getDocument().body);}var C=this.element;
if(this.options.wheelStops){this.addEvent("start",function(){C.addEvent("mousewheel",D);},true);this.addEvent("complete",function(){C.removeEvent("mousewheel",D);
},true);}},set:function(){var A=Array.flatten(arguments);this.element.scrollTo(A[0],A[1]);},compute:function(C,B,A){return[0,1].map(function(D){return Fx.compute(C[D],B[D],A);
});},start:function(C,H){if(!this.check(arguments.callee,C,H)){return this;}var E=this.element.getSize(),F=this.element.getScrollSize();var B=this.element.getScroll(),D={x:C,y:H};
for(var G in D){var A=F[G]-E[G];if($chk(D[G])){D[G]=($type(D[G])=="number")?D[G].limit(0,A):A;}else{D[G]=B[G];}D[G]+=this.options.offset[G];}return this.parent([B.x,B.y],[D.x,D.y]);
},toTop:function(){return this.start(false,0);},toLeft:function(){return this.start(0,false);},toRight:function(){return this.start("right",false);},toBottom:function(){return this.start(false,"bottom");
},toElement:function(B){var A=$(B).getPosition(this.element);return this.start(A.x,A.y);}});var Drag=new Class({Implements:[Events,Options],options:{snap:6,unit:"px",grid:false,style:true,limit:false,handle:false,invert:false,preventDefault:false,modifiers:{x:"left",y:"top"}},initialize:function(){var B=Array.link(arguments,{options:Object.type,element:$defined});
this.element=$(B.element);this.document=this.element.getDocument();this.setOptions(B.options||{});var A=$type(this.options.handle);this.handles=((A=="array"||A=="collection")?$$(this.options.handle):$(this.options.handle))||this.element;
this.mouse={now:{},pos:{}};this.value={start:{},now:{}};this.selection=(Browser.Engine.trident)?"selectstart":"mousedown";this.bound={start:this.start.bind(this),check:this.check.bind(this),drag:this.drag.bind(this),stop:this.stop.bind(this),cancel:this.cancel.bind(this),eventStop:$lambda(false)};
this.attach();},attach:function(){this.handles.addEvent("mousedown",this.bound.start);return this;},detach:function(){this.handles.removeEvent("mousedown",this.bound.start);
return this;},start:function(C){if(this.options.preventDefault){C.preventDefault();}this.mouse.start=C.page;this.fireEvent("beforeStart",this.element);
var A=this.options.limit;this.limit={x:[],y:[]};for(var D in this.options.modifiers){if(!this.options.modifiers[D]){continue;}if(this.options.style){this.value.now[D]=this.element.getStyle(this.options.modifiers[D]).toInt();
}else{this.value.now[D]=this.element[this.options.modifiers[D]];}if(this.options.invert){this.value.now[D]*=-1;}this.mouse.pos[D]=C.page[D]-this.value.now[D];
if(A&&A[D]){for(var B=2;B--;B){if($chk(A[D][B])){this.limit[D][B]=$lambda(A[D][B])();}}}}if($type(this.options.grid)=="number"){this.options.grid={x:this.options.grid,y:this.options.grid};
}this.document.addEvents({mousemove:this.bound.check,mouseup:this.bound.cancel});this.document.addEvent(this.selection,this.bound.eventStop);},check:function(A){if(this.options.preventDefault){A.preventDefault();
}var B=Math.round(Math.sqrt(Math.pow(A.page.x-this.mouse.start.x,2)+Math.pow(A.page.y-this.mouse.start.y,2)));if(B>this.options.snap){this.cancel();this.document.addEvents({mousemove:this.bound.drag,mouseup:this.bound.stop});
this.fireEvent("start",[this.element,A]).fireEvent("snap",this.element);}},drag:function(A){if(this.options.preventDefault){A.preventDefault();}this.mouse.now=A.page;
for(var B in this.options.modifiers){if(!this.options.modifiers[B]){continue;}this.value.now[B]=this.mouse.now[B]-this.mouse.pos[B];if(this.options.invert){this.value.now[B]*=-1;
}if(this.options.limit&&this.limit[B]){if($chk(this.limit[B][1])&&(this.value.now[B]>this.limit[B][1])){this.value.now[B]=this.limit[B][1];}else{if($chk(this.limit[B][0])&&(this.value.now[B]<this.limit[B][0])){this.value.now[B]=this.limit[B][0];
}}}if(this.options.grid[B]){this.value.now[B]-=(this.value.now[B]%this.options.grid[B]);}if(this.options.style){this.element.setStyle(this.options.modifiers[B],this.value.now[B]+this.options.unit);
}else{this.element[this.options.modifiers[B]]=this.value.now[B];}}this.fireEvent("drag",[this.element,A]);},cancel:function(A){this.document.removeEvent("mousemove",this.bound.check);
this.document.removeEvent("mouseup",this.bound.cancel);if(A){this.document.removeEvent(this.selection,this.bound.eventStop);this.fireEvent("cancel",this.element);
}},stop:function(A){this.document.removeEvent(this.selection,this.bound.eventStop);this.document.removeEvent("mousemove",this.bound.drag);this.document.removeEvent("mouseup",this.bound.stop);
if(A){this.fireEvent("complete",[this.element,A]);}}});Element.implement({makeResizable:function(A){return new Drag(this,$merge({modifiers:{x:"width",y:"height"}},A));
}});var Slider=new Class({Implements:[Events,Options],options:{onTick:function(A){if(this.options.snap){A=this.toPosition(this.step);}this.knob.setStyle(this.property,A);
},snap:false,offset:0,range:false,wheel:false,steps:100,mode:"horizontal"},initialize:function(E,A,D){this.setOptions(D);this.element=$(E);this.knob=$(A);
this.previousChange=this.previousEnd=this.step=-1;this.element.addEvent("mousedown",this.clickedElement.bind(this));if(this.options.wheel){this.element.addEvent("mousewheel",this.scrolledElement.bindWithEvent(this));
}var F,B={},C={x:false,y:false};switch(this.options.mode){case"vertical":this.axis="y";this.property="top";F="offsetHeight";break;case"horizontal":this.axis="x";
this.property="left";F="offsetWidth";}this.half=this.knob[F]/2;this.full=this.element[F]-this.knob[F]+(this.options.offset*2);this.min=$chk(this.options.range[0])?this.options.range[0]:0;
this.max=$chk(this.options.range[1])?this.options.range[1]:this.options.steps;this.range=this.max-this.min;this.steps=this.options.steps||this.full;this.stepSize=Math.abs(this.range)/this.steps;
this.stepWidth=this.stepSize*this.full/Math.abs(this.range);this.knob.setStyle("position","relative").setStyle(this.property,-this.options.offset);C[this.axis]=this.property;
B[this.axis]=[-this.options.offset,this.full-this.options.offset];this.drag=new Drag(this.knob,{snap:0,limit:B,modifiers:C,onDrag:this.draggedKnob.bind(this),onBeforeStart:(function(){this.isDragging=true;
}).bind(this),onStart:this.draggedKnob.bind(this),onComplete:function(){this.isDragging=false;this.draggedKnob();this.end();}.bind(this)});if(this.options.snap){this.drag.options.grid=Math.ceil(this.stepWidth);
this.drag.options.limit[this.axis][1]=this.full;}},set:function(A){if(!((this.range>0)^(A<this.min))){A=this.min;}if(!((this.range>0)^(A>this.max))){A=this.max;
}this.step=Math.round(A);this.checkStep();this.end();this.fireEvent("tick",this.toPosition(this.step));return this;},clickedElement:function(C){if(this.isDragging){return ;
}var B=this.range<0?-1:1;var A=C.page[this.axis]-this.element.getPosition()[this.axis]-this.half;A=A.limit(-this.options.offset,this.full-this.options.offset);
this.step=Math.round(this.min+B*this.toStep(A));this.checkStep();this.end();this.fireEvent("tick",A);},scrolledElement:function(A){var B=(this.options.mode=="horizontal")?(A.wheel<0):(A.wheel>0);
this.set(B?this.step-this.stepSize:this.step+this.stepSize);A.stop();},draggedKnob:function(){var B=this.range<0?-1:1;var A=this.drag.value.now[this.axis];
A=A.limit(-this.options.offset,this.full-this.options.offset);this.step=Math.round(this.min+B*this.toStep(A));this.checkStep();},checkStep:function(){if(this.previousChange!=this.step){this.previousChange=this.step;
this.fireEvent("change",this.step);}},end:function(){if(this.previousEnd!==this.step){this.previousEnd=this.step;this.fireEvent("complete",this.step+"");
}},toStep:function(A){var B=(A+this.options.offset)*this.stepSize/this.full*this.steps;return this.options.steps?Math.round(B-=B%this.stepSize):B;},toPosition:function(A){return(this.full*Math.abs(this.min-A))/(this.steps*this.stepSize)-this.options.offset;
}});var Asset={javascript:function(f,d){d=$extend({onload:$empty,document:document,check:$lambda(true)},d);var b=new Element("script",{src:f,type:"text/javascript"});
var e=d.onload.bind(b),a=d.check,g=d.document;delete d.onload;delete d.check;delete d.document;b.addEvents({load:e,readystatechange:function(){if(["loaded","complete"].contains(this.readyState)){e();
}}}).set(d);if(Browser.Engine.webkit419){var c=(function(){if(!$try(a)){return;}$clear(c);e();}).periodical(50);}return b.inject(g.head);},css:function(b,a){return new Element("link",$merge({rel:"stylesheet",media:"screen",type:"text/css",href:b},a)).inject(document.head);
},image:function(c,b){b=$merge({onload:$empty,onabort:$empty,onerror:$empty},b);var d=new Image();var a=$(d)||new Element("img");["load","abort","error"].each(function(e){var f="on"+e;
var g=b[f];delete b[f];d[f]=function(){if(!d){return;}if(!a.parentNode){a.width=d.width;a.height=d.height;}d=d.onload=d.onabort=d.onerror=null;g.delay(1,a,a);
a.fireEvent(e,a,1);};});d.src=a.src=c;if(d&&d.complete){d.onload.delay(1);}return a.set(b);},images:function(d,c){c=$merge({onComplete:$empty,onProgress:$empty,onError:$empty},c);
d=$splat(d);var a=[];var b=0;return new Elements(d.map(function(e){return Asset.image(e,{onload:function(){c.onProgress.call(this,b,d.indexOf(e));b++;if(b==d.length){c.onComplete();
}},onerror:function(){c.onError.call(this,b,d.indexOf(e));b++;if(b==d.length){c.onComplete();}}});}));}};

window.addEvent('domready',function(){
							
	myhash = '';
	
	firefoxhandler = false;
									
	// firefox needs a stylesheet
	if(Browser.Engine.gecko){
		var offset = navigator.userAgent.indexOf('Firefox');
		var version = parseFloat(navigator.userAgent.substring(offset+8));
		if(version < 3.5){
			new Asset.css('css/firefox.css');
		}
	}
	
	// back/forward doesnt want to work in firefox
	if(!Browser.Engine.gecko){
		(function(){
			if(myhash != location.hash){
				if(myhash != ''){
					myhash = location.hash;
					gotopage(location.hash);
				}
			}
		}.periodical(200,this));
	}
	
	applyExpand = function(l){
		if(l.getProperty('href') == '#close'){
			l.addEvent('click',function(e){ 
				var el = $(e.target);
				if(el.getParent('div.child') || el.getParent('div.child2')){
					e.stop();	
					// this means we are a submenu	
					var p = el.getParent('div.child') || el.getParent('div.child2');
					p.setStyle('display','none');
					$$('#middle div.link div.content li.nav a').each(function(a){
						if(a.getProperty('href') == '#'+p.getProperty('data-rel')){
							a.removeClass('selected');
							if(a.getProperty('href').split('/').length > 2){
								a.getParent('ul').setStyle('display','none');
								a.getParent('ul').getPrevious('a').removeClass('lastclick');
							} else {
								a.removeClass('lastclick');	
								if(a.getNext('ul')) a.getNext('ul').setStyle('display','none');
							}
						}
					},this);
					// all div child2s should be gone
					$$('div.child2').setStyle('display','none');
					// scroll height
					var t = new Fx.Tween(p.getParent('div.content'), {duration: 400, transition: Fx.Transitions.Sine.easeOut});
					t.start('height',calculate(p.getParent('div.content')));
					// scroll to?
					var sc = el.getParent('div.child') ? $('middle').getElement('div.content') : p.getPrevious('div.child');
					scrollToEl(sc);
				} else {
					// this means we are the root el
					gotopage('#home');
				}
			}.bindWithEvent(this));
		} else {
			l.addEvent('click',function(e){ 
				e.stop();
				var p = $(e.target).getParent('div.expand');
				var x = p.getNext('div.expanded');
				x.setStyle('display','block');
				p.setStyle('display','none');
				p.getElements('img.imgcorner').setStyle('display','block');
				var t = new Fx.Morph(p.getParent('div.content'), {duration: 400, transition: Fx.Transitions.Sine.easeOut});
				t.start({height:calculate(p.getParent('div.content'))});
				scrollToEl(x);
			}.bindWithEvent(this));
		}
	}
	
	applyCloseExpand = function(l){
		if(l.getProperty('href') == '#close'){
			l.addEvent('click',function(e){ 
				var el = $(e.target);
				var p = $(e.target).getParent('div.expanded');
				var x = p.getPrevious('div.expand');
				x.setStyle('display','block');
				p.setStyle('display','none');
				if(el.getParent('div.child') || el.getParent('div.child2')){
					e.stop();	
					// this means we are a submenu	
					var p = el.getParent('div.child') || el.getParent('div.child2');
					p.setStyle('display','none');
					$$('#middle div.link div.content li.nav a').each(function(a){
						if(a.getProperty('href') == '#'+p.getProperty('data-rel')){
							a.removeClass('selected');
							if(a.getProperty('href').split('/').length > 2){
								a.getParent('ul').setStyle('display','none');
								a.getParent('ul').getPrevious('a').removeClass('lastclick');
							} else {
								a.removeClass('lastclick');	
								if(a.getNext('ul')) a.getNext('ul').setStyle('display','none');
							}
						}
					},this);
					var t = new Fx.Tween(p.getParent('div.content'), {duration: 400, transition: Fx.Transitions.Sine.easeOut});
					t.start('height',calculate(p.getParent('div.content')));
					// scroll to?
					var sc = el.getParent('div.child') ? $('middle').getElement('div.content') : p.getPrevious('div.child');
					scrollToEl(sc);
				} else {
					// this means we are the root el
					gotopage('#home');
				}
			}.bindWithEvent(this));
		} else {
			l.addEvent('click',function(e){ 
				e.stop();
				var p = $(e.target).getParent('div.expanded');
				var x = p.getPrevious('div.expand');
				var c = (p.getParent('div.child2') != null) ? p.getParent('div.child2') : p.getParent('div.child');
				if(c == null) c = p.getPrevious('h1');
				x.setStyle('display','block');
				p.setStyle('display','none');
				var t = new Fx.Morph(p.getParent('div.content'), {duration: 400, transition: Fx.Transitions.Sine.easeOut});
				t.start({height:calculate(p.getParent('div.content'))});
				scrollToEl(c);
			}.bindWithEvent(this));
		}	
	}
	
	// make links clickable
	handleLinks = function(a){
		if(a.getProperty('href').indexOf('#') == 0){
			if((a.getProperty('href') != '#close') && (a.getProperty('href') != '#close-expanded') && (a.getProperty('href') != '#expand')){				
				a.addEvent('click',function(e){
					gotopage($(e.target).getProperty('href'));							
				});				
			}
		}  // is it a pdf link?
		else if(a.getProperty('href').substr(a.getProperty('href').length-3) == 'pdf'){
			a.addEvent('click',function(e){
				loadFeature($(e.target).getProperty('href'));	
				openFeature();
				e.stop();
			});
		}
	};
	
	// load latest news
	var n = new Request.JSON({url:'news.php?q=latest'});
	n.addEvent('success',function(j){
		if(j){
			var latestel = null;
			$$('div.child').each(function(e){ if($(e).getProperty('data-rel') == 'news/latest') latestel = e; },this);
			if(latestel){
				latestel.empty();
				latestel.adopt(new Element('p',{html:'&nbsp;'}));
				var count = 0;
				$each(j,function(i){
					var it = new Element('div',{'id':'newsitem'+i.id,'class':'child2news'}).setStyle('display','block');
					it.adopt(new Element('h1',{html:i.title}));
					it.adopt(new Element('div',{'class':"expand",html:'<span style="float:left; font-size:14px;">'+i.date+'</span><a href="#expand"><img src="images/down-arrow.png" width="16" height="10" alt="down" />Detail</a>'}));
					var ex = new Element('div',{'class':"expanded",html:i.content});
					ex.adopt(new Element('div',{'class':'close-expanded',html:'<a href="#close-expanded"><img src="images/up-arrow.png" alt="up" width="16" height="10" />Summary</a>'}));
					ex.adopt(new Element('p',{'class':'breaker',html:'&nbsp;'}).setStyles({'font-size':'0px','padding':'0px 0px 24px 0px'}));
					it.adopt(ex);
					it.getElements('div.expand a').each(function(l){ applyExpand($(l)); });
					it.getElements('div.close-expanded a').each(function(l){ applyCloseExpand($(l)); });
					it.getElements('div.expanded a').each(function(l){ handleLinks($(l)); });
					latestel.adopt(it);
					count++;
				},this);
				if(count == 0){
					latestel.adopt(new Element('p',{html:'We could not find any news items.'}));	
				}
				if(get('#') == 'news/latest') gotopage('#news/latest');
				if(get('#') == 'news') gotopage('#news/latest');
			}
		}
	});
	n.send();
	
	// load archived news
	loadArchive = function(year){
		var div = null;
		$$('div.child2').each(function(a){ 
			if($(a).getProperty('data-rel') == 'news/archive/'+year) div = a;
		},this);
		$$('div.child').each(function(a){ 
			if($(a).getProperty('data-rel') == 'news/archive') a.empty();
		},this);
		if(div && !div.getElement('div.child2news')){ // only do this once!
			var n = new Request.JSON({url:'news.php?q='+year});
			n.addEvent('success',function(j){
				if(j){
					var el = null;
					$$('div.child2').each(function(e){ if($(e).getProperty('data-rel') == 'news/archive/'+year) el = e; },this);
					if(el){
						el.empty();
						el.adopt(new Element('h6',{html:year}));
						var count = 0;
						$each(j,function(i){
							var it = new Element('div',{'id':'newsitem'+i.id,'class':'child2news'}).setStyle('display','block');
							it.adopt(new Element('h1',{html:i.title}));
							it.adopt(new Element('div',{'class':"expand",html:'<span style="float:left; font-size:14px;">'+i.date+'</span><a href="#expand"><img src="images/down-arrow.png" width="16" height="10" alt="down" />Detail</a>'}));
							var ex = new Element('div',{'class':"expanded",html:i.content});
							ex.adopt(new Element('div',{'class':'close-expanded',html:'<a href="#close-expanded"><img src="images/up-arrow.png" alt="up" width="16" height="10" />Summary</a>'}));
							ex.adopt(new Element('p',{'class':'breaker',html:'&nbsp;'}).setStyles({'font-size':'0px','padding':'0px 0px 24px 0px'}));
							it.adopt(ex);
							it.getElements('div.expand a').each(function(l){ applyExpand($(l)); });
							it.getElements('div.close-expanded a').each(function(l){ applyCloseExpand($(l)); });
								it.getElements('div.expanded a').each(function(l){ handleLinks($(l)); });
							el.adopt(it);
							count++;
						},this);
						if(count == 0){
							latestel.adopt(new Element('p',{html:'We could not find any news items for this year.'}));	
						}
						if(get('#').indexOf('news/archive') != -1) gotopage('#news/archive/'+year);
					}
				}
			});
			n.send();
		}
	};
	
	/*
	Function: get
	This function provides access to the “get” variable scope + the element anchor
	Function by Jens Anders Bakke, webfreak.no
	*/
	get = function(key,url){
		if(arguments.length < 2) url = location.href;
		if(arguments.length > 0 && key != ""){
			if(key == "#"){
				var regex = new RegExp("[#]([^$]*)");
			} else if(key == "?"){
				var regex = new RegExp("[?]([^#$]*)");
			} else {
				var regex = new RegExp("[?&]"+key+"=([^&#]*)");
			}
			var results = regex.exec(url);
			return (results == null )? "" : results[1];
		} else {
			url = url.split("?");
			var results = {};
			if(url.length > 1){
				url = url[1].split("#");
			if(url.length > 1) results["hash"] = url[1];
				url[0].split("&").each(function(item,index){
					item = item.split("=");
					results[item[0]] = item[1];
				});
			}	
			return results;
		}
	};
	
	cancelme = [];
	
	// gotopage function
	gotopage = function(where,kill){
		
        if (typeof(pageTracker) == "object") pageTracker._trackPageview('http://www.nitec.com/' + where);
        else if(typeof(_gaq) == "object") _gaq.push(['_trackPageview', 'http://www.nitec.com/' + where]);
	
		myhash = where;
		if(!kill) kill = false;
		var where = where.replace('#','');
		if(where == 'news'){
			$$('#middle div.link>h1 a').each(function(a){
				if($(a).getProperty('href') == '#news'){
					if(!$(a).hasClass('selected')){
						where = 'news/latest';
					}
				}
			});
		}
		if(where == 'news/archive') {
			$$('#middle div.link div.content li.nav a').each(function(a){
				if($(a).getProperty('href') == '#news/archive'){
					var el = a.getNext('ul').getElement('li a');
					where = el.getProperty('href').replace('#','');
				}
			});
		}
		if(where.indexOf('news/latest/') != -1){
			where = 'news/latest';	
		}
		where = where.split('/');
		if(where[0] != get('#').split('/')[0]){
			scroller.set(0,0);	
		}
		if(where.length > 0){
			// cancel any running events
			cancelme.each(function(e){ e.cancel(); });
			cancelme = [];
			if(!kill){ 
				$$('#middle div.link div.content li.nav a').removeClass('selected');
				$$('#middle div.link div.content li.text div.child').setStyle('display','none');
				$$('#middle div.link div.content li.text div.child2').setStyle('display','none');
				$$('#middle div.link div.content li.nav ul li ul').setStyle('display','none');	
				//$$('img.imgcorner').setStyle('display','none');
				$$('div.expanded').setStyle('display','none');
				$$('div.expand').setStyle('display','block');
				$('padding-p').setStyle('display','none');
				if($('event-banner')) $('event-banner').setStyle('display','none');
			}
			var addheight = 0;
			if(where.length > 1){
								
				if(where.length > 2){
					if((where[0] == 'news') && (where[1] == 'archive')) loadArchive(where[2]);		
					$$('#middle div.link div.content li.nav a').each(function(a){ 
						if($(a).getProperty('href') == '#'+where[0]+'/'+where[1]+'/'+where[2]){
							a.addClass('selected');
							ul = a.getParent('ul');
							ul.setStyle('display','block');
							ul.getPrevious('a').addClass('lastclick');
						}
					},this);
				} else {
					$$('#middle div.link div.content li.nav a').each(function(a){ 
						if($(a).getProperty('href') == '#'+where[0]+'/'+where[1]) {
							a.addClass('selected'); 
							$$('li.nav a.lastclick').each(function(e){ if(e!=a) e.removeClass('lastclick'); },this);
							if(!a.hasClass('lastclick')){
								a.addClass('lastclick');
								if(a.getNext('ul')){
									a.getNext('ul').setStyle('display','block');
								}
							} else {
 								if(a.getNext('ul')){
									a.getNext('ul').setStyle('display','none');
								}	
								a.removeClass('lastclick');
							}
						}
					},this);
				}
				
				$$('#middle div.link div.content li.text div.child').each(function(e){ 
					if($(e).getProperty('data-rel') == where[0]+'/'+where[1]){
						e.setStyle('display','block');
					}
				},this);
				$$('#middle div.link div.content li.text div.child2').each(function(e){ 
					//if($(e).getProperty('data-rel').indexOf(where[0]+'/'+where[1]) != -1){
					if($(e).getProperty('data-rel') == where[0]+'/'+where[1]+'/'+where[2]){
						e.setStyle('display','block');
					}
				},this);	
				
			} else {
				$$('li.nav a.lastclick').removeClass('lastclick');	
				//$$('div.child2 .expanded').setStyle('display','none');
				//$$('div.child2 .expand').setStyle('display','block');
			}
			$$('#middle div.link>h1 a').each(function(a){ 
				var parent = a.getParent('div.link');
				if((!a.hasClass('selected') || (where.length > 1)) && (a.getProperty('href') == '#'+where[0])){ 
					a.addClass('selected'); 
					if(parent.getElement('div.content')) {
						parent.getElement('div.content').removeClass('hide');
						var t = new Fx.Morph(parent.getElement('div.content'), {duration: 400, transition: Fx.Transitions.Sine.easeOut});
						t.addEvent('complete',function(){ 
							if(where.length == 1) scroller.start(0,parent.getElement('div.content').getPosition().y - 140); 
							else {
								if(where.length > 2){
									$$('div.child2').each(function(e) { if(e.getProperty('data-rel') == where[0]+'/'+where[1]+'/'+where[2]) el = e },this);
								}
								else{
									$$('div.child').each(function(e) { if(e.getProperty('data-rel') == where[0]+'/'+where[1]) el = e },this);
								}
								if(el) scrollToEl(el);
							}
							//if($("middle").getElement('div.scrollme').getScrollSize().y <= $("middle").getSize().y) $("middle").getElement('div.scrollarea').setStyle('display','none');
							//else $("middle").getElement('div.scrollarea').setStyle('display','block');
						}.bind(this));
						parent.getElement('div.content').setStyles({
							'border-top' : '1px solid #ffffff',
							'border-bottom' : '1px solid #ffffff',
							'display' : 'block'
						});
						t.start({ 
							'margin-top' : '-40px',
							'height' : calculate(parent.getElement('div.content')) + 'px'
						});
						$('padding-p').setStyles({'display':'block','height':parseInt($("middle").getStyle('height'))});
					}
				} else {
					a.removeClass('selected');
					if(parent.getElement('div.content')) {
						var t = new Fx.Morph(parent.getElement('div.content'), {duration: 300, transition: Fx.Transitions.Sine.easeOut});
						t.addEvent('complete',function(){ parent.getElement('div.content').setStyle('display','none'); }.bind(this));
						parent.getElement('div.content').setStyles({
							'border-top' : 'none',
							'border-bottom' : 'none',
							'overflow' : 'hidden'
						});
						if(Browser.Engine.trident) parent.getElement('div.content').setStyle('margin-top','0px');
						t.start({
							height:'0px',
							'margin-top':0
						});
					}
				}
			},this);
		}
		if($$('#middle div.link>h1 a.selected').length == 0){
			if($('event-banner')) $('event-banner').setStyle('display','block');
		}

	};
	
	// calculate height of element
	calculate = function(el){
		var height = 0;
		// get the height of the h1
		if(el.getElement('h1')) height += el.getElement('h1').getSize().y;
		if(el.getElement('div.caption')) height += el.getElement('div.caption').getSize().y + 24;
		//if(el.getElement('p.imageblock')) height += el.getElement('p.imageblock').getSize().y;
		
		// h1's expand/expanded
		if(el.getElement('div.expand') || el.getElement('div.expanded')){
			if(el.getElement('div.expand').getStyle('display') == 'block') height += el.getElement('div.expand').getSize().y + 50;
			else height += el.getElement('div.expanded').getSize().y + 50;
		}
		
		// children
		el.getElements('div.child').each(function(c){
			if(c.getStyle('display') == 'block'){
				
				// news section?
				if(c.getElement('div.child2news')){
					
					if(c.getElement('p')) height += c.getElement('p').getSize().y;
					if(c.getElement('form')) height += c.getElement('form').getSize().y;
					if(c.getElement('h6')) height += c.getElement('h6').getSize().y;
					
					c.getElements('div.child2news').each(function(d){
						if(d.getStyle('display') == 'block'){
							height += 20;
							if(d.getElement('h1')) height += d.getElement('h1').getSize().y;
							//if(d.getElement('div.caption')) height += d.getElement('div.caption').getSize().y + 24;
							
							// expand/expanded
							if(d.getElement('div.expand') || d.getElement('div.expanded')){
								if(d.getElement('div.expand').getStyle('display') == 'block') height += d.getElement('div.expand').getSize().y;
								else height += d.getElement('div.expanded').getSize().y;
							}
							
						}
					},this);
					
				} else {
				
					height += 24;
					if(c.getElement('h1')) height += c.getElement('h1').getSize().y;
					if(c.getElement('h2')) height += c.getElement('h2').getSize().y;
					if(c.getElement('div.caption')) height += c.getElement('div.caption').getSize().y + 24;
				
					// expand/expanded
					if(c.getElement('div.expand') || c.getElement('div.expanded')){
						if(c.getElement('div.expand').getStyle('display') == 'block') height += c.getElement('div.expand').getSize().y + 50;
						else height += c.getElement('div.expanded').getSize().y + 50;
					}
				
				}
				
			}
		},this);
		
		// children
		el.getElements('div.child2').each(function(c){
			if(c.getStyle('display') == 'block'){

				// news section?
				if(c.getElement('div.child2news')){
					
					if(c.getElement('p')) height += c.getElement('p').getSize().y;
					if(c.getElement('h6')) height += c.getElement('h6').getSize().y;
					
					c.getElements('div.child2news').each(function(d){
						if(d.getStyle('display') == 'block'){
							height += 20;
							if(d.getElement('h1')) height += d.getElement('h1').getSize().y;
							//if(d.getElement('div.caption')) height += d.getElement('div.caption').getSize().y + 24;
							
							// expand/expanded
							if(d.getElement('div.expand') || d.getElement('div.expanded')){
								if(d.getElement('div.expand').getStyle('display') == 'block') height += d.getElement('div.expand').getSize().y;
								else height += d.getElement('div.expanded').getSize().y;
							}
							
						}
					},this);
					
				} else {
					
					height += 24;
					if(c.getElement('h1')) height += c.getElement('h1').getSize().y;
					if(c.getElement('h2')) height += c.getElement('h2').getSize().y;
					if(c.getElement('div.caption')) height += c.getElement('div.caption').getSize().y + 24;
				
					// expand/expanded
					if(c.getElement('div.expand') || c.getElement('div.expanded')){
						if(c.getElement('div.expand').getStyle('display') == 'block') height += c.getElement('div.expand').getSize().y + 50;
						else height += c.getElement('div.expanded').getSize().y + 50;
					}
					
				}
				
			}
		},this);
		return height;
	};
	
	// work out the height of #middle
	middleHeight = function(){
		var middle = $("middle");
		var height = $(document.body).getSize().y;
		height -= $("top").getSize().y;
		height -= $("bottom").getSize().y;
		height -= 11;
		middle.setStyle('height',height);
		middle.getElement('div.scrollarea').setStyle('height',height);
		featureHeight = ($("middle").getSize().y < 640) ? $("middle").getSize().y - 80 : 560;
	};
	
	$(document.body).setStyle('overflow','hidden');
	middleHeight();
	window.addEvent('resize',function(){
		middleHeight();
		if(parseInt($('feature').getStyle('height')) > 0){
			var t = new Fx.Tween($("feature"));
			t.start('height',featureHeight);
			$('feature-window').setStyle('height',featureHeight - 30);
		}
	}.bind(this));
	window.fireEvent('resize');
	scrolling = false;
	
	moveNavs = function(){
		$$('li.nav').each(function(el){ 
			if($(el).getParent('div.content').getPrevious('h1').getElement('a').hasClass('selected')){
				var to = scrollerEl.getScroll().y;
				if(!Browser.Engine.trident){
					to -= $($(el).getParent('div.content')).getPosition(scrollerEl).y;
					to = ((to + 100) > 20) ? to + 100 : 20;
				} else {
					to = $(scrollerEl).getPosition($(el).getParent('div.content')).y;
					to = ((to + 100) > 20) ? to + 100 : 20;
				}
				var t = new Fx.Tween($(el),{duration:500});
				var parent = $(el).getParent('div.content');
				if((to + parseInt($(el).getStyle('height'))) >= calculate(parent)){
					parent.setStyle('height',calculate(parent)+parseInt($(el).getStyle('height'))-100);
					if(to > (calculate(parent) - 100)) to = calculate(parent) - 100;
				}
				t.start('padding-top',to);
				cancelme.push(t);
			}
		},this);
	};
	
	scrollCount = lastScrollCount = 0;
	
	// scrolling divs
	scrollerEl = $("middle").getElement('div.scrollme');
	scrollerEl.addEvent('scroll',function(){ if(!scrolling) scrollCount++; }.bind(this));
			
	// set up the scroller
	scroller = new Fx.Scroll(scrollerEl);
	scroller.addEvent('start',function(e){ scrolling = true; }.bind(this));
	scroller.addEvent('complete',function(e){ 
		moveNavs();
		scrolling = false;
	}.bind(this));
	
	window.addEvent('keydown',function(ev){
		if(ev.key == 'down' || ev.key == 'up'){
			var percent = scrollerEl.scrollTop / scrollerEl.getScrollSize().y;
			if(ev.key == 'down'){
				percent = percent + 0.05;
			} else if(ev.key == 'up'){
				percent = percent - 0.05;
			}
			scroller.set(0,percent * scrollerEl.getScrollSize().y);	
		}
	});
	
	(function(){
		if(!scrolling){
			if(scrollCount == lastScrollCount){
				moveNavs();	
			}
			else {
				lastScrollCount = scrollCount;	
			}
		}
	}.periodical(400,this));
	
	// scroller to element
	scrollToEl = function(el){
		// scroller.toElement(el); always bounces from the top
		if(el){
			var to = $(el).getPosition(scrollerEl);
			if(Browser.Engine.trident) to.y = to.y + $(scrollerEl).getScroll().y;
			scroller.start(0,to.y-80);
		}
	};
	
	// imageblock images
	$$('div.caption img').each(function(img){
										
		var rand = new Date().getTime();
	
		//img.addEvent('load',function(e){
			//try{
				// size them
				if(img.getProperty('width') < 190) img.setProperty('width',190).setProperty('height',95);
				else {
					if(img.getProperty('width') < 406) img.setProperty('width',406);
					else {
						if(img.getProperty('width') != 611) { img.setProperty('width',611); }
						if(img.getProperty('height') > 95) img.setProperty('height',180);
						else if(img.getProperty('height') < 95) img.setProperty('height',95);
					}
					if(img.getProperty('height') != 180) img.setProperty('height',180);
				}
			//} catch(e) { }
		//}.bind(img));
		
		// add captionability
		if(img.getProperty('title') && (img.getProperty('title') != '')){
		
			img.getParent('div.caption').addEvent('mouseenter',function(e){
				var target = $(e.target);
				if($(e.target).get('tag') == 'img'){ 
					target = $(e.target).getParent('div.caption')
					img = target.getElement('img:last-child');	
				} else {
					img = target.getElement('img:last-child');	
				}
				var capt = new Element('div',{'class':'imgcaption',html:img.getProperty('alt')});	
				capt.inject(target,'top');
				capt.setStyles({
					width:target.getSize().x - 10
				});
				if(target.getElement('img.imgcorner')) target.getElement('img.imgcorner').setStyle('display','none');
			});
			
			img.getParent('div.caption').addEvent('mouseleave',function(e){
				$$('.imgcaption').destroy();
				$$('img.imgcorner').setStyle('display','block');
			});
			
			if((navigator.userAgent.indexOf('MSIE 7') == -1) && (navigator.userAgent.indexOf('MSIE 6') == -1)){
				var corn = new Element('img',{src:'images/imagecorner.png','class':'imgcorner'}).setStyle('display','block');
				corn.inject(img.getParent('div.caption'),'top');
			}
		
		}
	},this);
	
	// onload gotopage the hash passed
	if(get('#') != '') { 
		if(get('#').indexOf('news/latest/') != -1){
			(function() { gotopage('#news');	}).delay(2000);
		} else {
			gotopage('#'+get('#'));	
		}
	}
	
	// make all of the main links clickable
	$$('#middle div.link>h1 a').each(function(l){
		l.addEvent('click',function(e){ gotopage(l.getProperty('href').replace('http://www.nitec.com/','')); }.bindWithEvent(this));
	},this);
	
	// make all of the sub links clickable
	$$('#middle div.link div.content li.nav a').each(function(l){
		l.addEvent('click',function(e){ gotopage(l.getProperty('href').replace('http://www.nitec.com/','')); }.bindWithEvent(this));
	},this);
	
	// make all tip links into links
	$$('a[href=tip]').each(function(e){
		e.addEvent('mouseover',function(e){ 
			var c = $(e.target).getCoordinates(); 
			$('tip').setStyles({ display:'block', top:c.top - 50, left:c.right + 24 }); 
			$('tip').getElement('p').set('html',$(e.target).getProperty('title'));
		}.bindWithEvent(this));
		e.addEvent('mouseout',function(e){ $('tip').setStyle('display','none'); }.bindWithEvent(this));	
		e.addEvent('click',function(e){ e.stop(); });
	});
		
	// make all of the expand links work
	$$('#middle div.link div.content li.text div.expand a').each(function(l){ applyExpand(l); },this);
			
	// make all of the close expand links work
	$$('#middle div.link div.content li.text div.expanded div.close-expanded a').each(function(l){ applyCloseExpand(l); },this);
	
	// clicking on home takes you nowhere
	$$('p.logo a.home').addEvent('click',function(e){
		gotopage('#home');								  
	});
	
	// news ticker
	(function(){
		
		// work out which element to show
		var els = $("top").getElements("ul.news li");
		var show = 0;
		var counter = 0;
		els.each(function(el){
			counter++;
			if(el.getStyle('display') != 'none') show = counter;
		},this);
		if(show >= els.length) show = 0;
		els.setStyles({'display':'none',width:'0px'});
		els[show].setStyles({'display':'block','overflow':'hidden'});
		// grow it
		var tw = new Fx.Tween(els[show],{duration:2400});
		tw.start('width',0,300);
	}.periodical(8000));
	
	// feature link at the top
	//if(featureHeight != 560){
	//	$('feature').setStyle('overflow-y','scroll');	
	//}
	
	openFeature = function(){
		var t = new Fx.Tween($("feature"));
		if($("feature").getStyle('display') == 'block'){
			t.addEvent('complete',function(e){ $("feature").setStyles({'height':'0px','display':'none'}); });
			t.start('height',0);
		} else {
			$("feature").setStyles({'height':'0px','display':'block'});
			t.start('height',0,featureHeight);
			var t = new Fx.Tween($("b-overlay"));
			t.addEvent('complete',function(e){ $("b-overlay").setStyles({'height':'0px','display':'none'}); $$("#bottom ul li a").removeClass('selected'); });
			t.start('height',0);
		}
	};
	
	$("top").getElement('a.feature-link').addEvent('click',function(e){
		if(e) e.stop();
		$('feature').getElement('div.feature-div').setStyle('display','none');
		$('feature').getElement('div.flash-div').setStyle('display','block');
		$('feature').getElement('div.flash-div ul li a').fireEvent('click',{target:$('feature').getElement('div.flash-div ul li a')});
		openFeature();
	});
	
	$('feature').getElements('a.close-link').addEvent('click',function(e){
		e.stop();
		var t = new Fx.Tween($("feature"));
		t.addEvent('complete',function(e){ $("feature").setStyles({'height':'0px','display':'none'}); });
		t.start('height',featureHeight,0);
	});
	
	// bottom links
	$$("#bottom ul li a").each(function(a){
		a.addEvent('click',function(e){
			
			if(a.getProperty('href') != '#home'){
				
				e.stop();
				
				$$("#bottom ul li a").removeClass('selected');
				
				if(($('b-overlay').getStyle('display') == 'block') && ($('b-overlay').getElement('div.'+$(e.target).getProperty('href').replace('#','')).getStyle('display') == 'block')){
					var t = new Fx.Tween($("b-overlay"));
					t.addEvent('complete',function(e){ $("b-overlay").setStyles({'height':'0px','display':'none'}); });
					t.start('height',0);
				} else {
				
					a.addClass('selected');
					$("b-overlay").setStyles({'height':'0px','display':'block'});
					var t = new Fx.Tween($("b-overlay"));
					
					$$('#b-overlay div.section').setStyle('display','none');
					$$('#b-overlay div.'+$(e.target).getProperty('href').replace('#','')).setStyle('display','block');
					
					// log me in has a smaller height
					var height = ($(e.target).getProperty('href') == '#logmein') ? 198 : 398;
					
					t.start('height',0,height);
					
					var t = new Fx.Tween($('feature'));
					t.addEvent('complete',function(e){ $('feature').setStyles({'height':'0px','display':'none'}); });
					t.start('height',0);
					
				}
			
			} else {
				gotopage('#home');	
				var t = new Fx.Tween($("b-overlay"));
				t.addEvent('complete',function(e){ $("b-overlay").setStyles({'height':'0px','display':'none'}); });
				t.start('height',0);
			}
		});
	},this);
				
	$("b-overlay").getElements('a.close-link').addEvent('click',function(e){
		e.stop();
		var t = new Fx.Tween($("b-overlay"));
		t.addEvent('complete',function(e){ $("b-overlay").setStyles({'height':'0px','display':'none'}); $$("#bottom ul li a").removeClass('selected'); });
		t.start('height',0);
	});
	
	// search form
	$('search-form').addEvent('submit',function(e){
		e.stop();
		var req = new Request.JSON({url:'search.php',method:'get'});
		req.addEvent('success',function(e){
			$('search-form').getParent().getNext('.searchresults').empty();
			if(e.querycount > 0){
				$each(e,function(i){
					if(i.title){
						var p = new Element('p',{html:'<strong><a href="'+i.link+'">'+i.title+'</a></strong><br />'+i.content});
						$('search-form').getParent().getNext('.searchresults').adopt(p);
					}
				},this);
				$('search-form').getParent().getNext('.searchresults').getElements('a').each(function(a){
					a.addEvent('click',function(l){
						gotopage(a.getProperty('href').replace('http://www.nitec.com/',''));
						var t = new Fx.Tween($("b-overlay"));
						t.addEvent('complete',function(e){ $("b-overlay").setStyles({'height':'0px','display':'none'}); $$("#bottom ul li a").removeClass('selected'); });
						t.start('height',0);
					});
				},this);
				$('search-form').getParent().getElement('span.results').setStyle('display','inline');
				$('search-form').getParent().getElement('div.prevnext').setStyle('display','block');
				$('search-form').getParent().getElement('div.prevnext').getElement('img.prev').setProperty('src','images/prev'+(e.page > 1 ? '-on' : '')+'.png');
				$('search-form').getParent().getElement('div.prevnext').getElement('img.prev').removeEvents('click');
				$('search-form').getParent().getElement('div.prevnext').getElement('img.prev').addEvent('click',function(ev){ 
					if(e.page > 1) { $('search-form').getElement('input.page').set('value',parseInt($('search-form').getElement('input.page').get('value'))-1); req.send({data:{q:$('search-form').getElement('input.ss').get('value'),page:$('search-form').getElement('input.page').get('value')}}); }																							 
				}.bind(this));
				$('search-form').getParent().getElement('div.prevnext').getElement('img.next').setProperty('src','images/next'+(e.page < (Math.ceil(e.querycount/6)) ? '-on' : '')+'.png');
				$('search-form').getParent().getElement('div.prevnext').getElement('img.next').removeEvents('click');
				$('search-form').getParent().getElement('div.prevnext').getElement('img.next').addEvent('click',function(ev){ 
					if(e.page < (Math.ceil(e.querycount/6))) { $('search-form').getElement('input.page').set('value',parseInt($('search-form').getElement('input.page').get('value'))+1); req.send({data:{q:$('search-form').getElement('input.ss').get('value'),page:$('search-form').getElement('input.page').get('value')}}); }																							 
				}.bind(this));
				$('search-form').getParent().getElement('span.querycount').set('html',e.querycount);
				$('search-form').getParent().getElement('span.searchvalues').set('html',(((e.page-1)*6)+1) + ' to ' + (((e.page*6) < e.querycount) ? (e.page*6) : e.querycount ));
			} else {
				var p = new Element('p',{html:'Sorry, we couldn\'t find any results to match that search.'});
				$('search-form').getParent().getNext('.searchresults').adopt(p);
				$('search-form').getParent().getElement('span.results').setStyle('display','none');
				$('search-form').getParent().getElement('div.prevnext').setStyle('display','none');
			}
		}.bind(this));
		req.send({data:{q:$('search-form').getElement('input.ss').get('value'),page:$('search-form').getElement('input.page').get('value')}});
	},this);
	
	// animate our maps
	(function(){ 
		var li = $('b-overlay').getElements('ul.antrim li');
		var count = 0;
		var show = 0;
		li.each(function(l){
			count++;
			if(l.getStyle('display')=='block') show = count;
		},this);
		if(show >= li.length) show = 0;
		li.setStyle('display','none');
		li[show].setStyle('display','block');
		
		var li = $('b-overlay').getElements('ul.tech li');
		var count = 0;
		var show = 0;
		li.each(function(l){
			count++;
			if(l.getStyle('display')=='block') show = count;
		},this);
		if(show >= li.length) show = 0;
		li.setStyle('display','none');
		li[show].setStyle('display','block');
	}.periodical(180));
	
	// map links
	$('antrim-map').addEvent('click',function(e){
		e.stop();
		$('antrim-map').addClass('selected');
		$('tech-map').removeClass('selected');
		$('b-overlay').getElement('ul.antrim').setStyle('display','block');
		$('b-overlay').getElement('ul.tech').setStyle('display','none');
	});
	
	$('tech-map').addEvent('click',function(e){
		e.stop();
		$('antrim-map').removeClass('selected');
		$('tech-map').addClass('selected');
		$('b-overlay').getElement('ul.antrim').setStyle('display','none');
		$('b-overlay').getElement('ul.tech').setStyle('display','block');
	});
	
	$('print-map').addEvent('click',function(e){
		e.stop();
		window.open('map.php','_blank');
	});
	
	$('google-map').addEvent('click',function(e){
		e.stop();
		window.open('http://maps.google.co.uk/maps?f=q&source=s_q&hl=en&geocode=&q=nitec,+antrim+business+park,+BT41+1QS&sll=53.800651,-4.064941&sspn=15.059141,45.571289&ie=UTF8&ll=54.702904,-6.189165&spn=0.028715,0.089006&z=14','_blank');	
	});

	// sitemap
	$('b-overlay').getElements('div.sitemap a').addEvent('click',function(e){
		if(!$(e.target).hasClass('close-link') && $(e.target).getProperty('href')){
			$$('div.sitemap a').removeClass('selected');
			$$('div.sitemap ul.sublink').setStyle('display','none');
			var found = false;
			$$('div.sitemap ul.sublink').each(function(u){
				if(u.getProperty('data-rel') == $(e.target).getProperty('href').replace('#','')){
					found = true;
					u.setStyle('display','block');
				}
			},this);
			if(found){
				e.stop();
				$(e.target).addClass('selected');
			} else {
				gotopage($(e.target).getProperty('href'));	
				var t = new Fx.Tween($("b-overlay"));
				t.addEvent('complete',function(e){ $("b-overlay").setStyles({'height':'0px','display':'none'}); $$("#bottom ul li a").removeClass('selected'); });
				t.start('height',0);
			}
		}
	});
	
	// make flash work
	$('feature').getElements('div.flash-div ul li a').addEvent('click',function(e){
		//e = new Event(e);
		//if(e){ e = new Event(e); e.stop(); }
		if($defined(e.stop)) e.stop();
		$('flash-window').empty();
		$('flash-window').adopt(new Element('div',{id:'flashbox'}));
		swfobject.embedSWF($(this).getProperty('href'),'flashbox','740','370','9.0.0');
		$(this).getParent('ul').getElements('li a').removeClass('selected');
		$(this).addClass('selected');
	});
	
	// flash timeouts
	timeout = 0;
	tScrollCount = 0;
	mouseCount = 0;
	/*(function(){
		if(mouseCount == tScrollCount){
			if($('middle').getElements('div.link>h1 a.selected').length == 0){
				if(timeout >= 10){
					if(parseInt($('feature').getStyle('height')) == 0){
						$("top").getElement('a.feature-link').fireEvent('click');
					}						
					timeout = 0;	
				} else {
					timeout += 2;	
				}
			} else {
				if(timeout >= 90){
					if(parseInt($('feature').getStyle('height')) == 0){
						$("top").getElement('a.feature-link').fireEvent('click');
					}						
					timeout = 0;	
				} else {
					timeout += 2;	
				}
			}

		} else {
			timeout = 0;
			tScrollCount = mouseCount;
		}
	}.periodical(2000));
	
	$(document).addEvent('mousemove',function(){ mouseCount++; }.bind(this));*/
	
	// pdf viewer
    vuzit.Base.apiKeySet("a26af495-8109-1758-b63a-8e7f8d842824");
	
	loadFeature = function(url,page){
	
		if(url.indexOf('http://') == -1){
			url = 'http://www.nitec.com/' + url;
		}
		
		$('feature').getElement('div.feature-div').setStyle('display','block');
		$('feature').getElement('div.flash-div').setStyle('display','none');
		
		loaded = function(){
			//$('feature-window').setStyles({
			//	width: viewer.getDocument().getWidth(viewerZoom),
			//	'margin-left': 300 - parseInt(viewer.getDocument().getWidth(viewerZoom)) + 250,
			//	height: viewer.getDocument().getHeight(viewerZoom)
			//});	
			
			//if((parseInt(viewer.getDocument().getHeight(viewerZoom)) + 40) != parseInt($('feature').getStyle('height'))){
			//	featureHeight = parseInt(viewer.getDocument().getHeight(viewerZoom)) + 40;
			//	if(featureHeight < 460) featureHeight = 460;
			//}
						
			imgext = (Browser.Engine.trident4) ? 'gif' : 'png';
			
			// do we have enough pages
			if(viewer.getDocument().getPageCount() > 1){
				
				// prev button
				$('feature').getElement('a.prev').addEvent('click',function(e){
					if(viewerPage > 1){
						viewerPage = viewerPage - 1;
						viewer.setPageNumber(viewerPage);
						thumbs();
					}
					
					if(viewerPage <= 1) $('feature').getElement('a.prev').getElement('img').setProperty('src','images/prev.'+ imgext);
					if(viewerPage < viewer.getDocument().getPageCount()) 	$('feature').getElement('a.next').getElement('img').setProperty('src','images/next-on.'+ imgext);
					
				}.bind(this));
				
				// next button
				$('feature').getElement('a.next').addEvent('click',function(e){
					if(viewerPage < viewer.getDocument().getPageCount()){
						viewerPage = viewerPage + 1;
						viewer.setPageNumber(viewerPage);
						thumbs();
					}
					
					if(viewerPage > 1) 	$('feature').getElement('a.prev').getElement('img').setProperty('src','images/prev-on.'+ imgext);
					if(viewerPage >= viewer.getDocument().getPageCount()) 	$('feature').getElement('a.next').getElement('img').setProperty('src','images/next.'+ imgext);
					
				}.bind(this));
				
				// show that this can be on
				$('feature').getElement('a.next').getElement('img').setProperty('src','images/next-on.'+ imgext);
				$('feature').getElement('a.prev').getElement('img').setProperty('src','images/prev.'+ imgext);
			
			} else {
				$('feature').getElement('a.prev').getElement('img').setProperty('src','images/prev.'+ imgext);
				$('feature').getElement('a.next').getElement('img').setProperty('src','images/next.'+ imgext);
			}
			
			// do we have enough zoom
			if(viewer.getDocument().getZoomCount() > 1){
			
				// enlarge button
				$('feature').getElement('a.enlarge').addEvent('click',function(e){
					if((viewerZoom + 1) < viewer.getDocument().getZoomCount()){
						viewerZoom = viewerZoom + 1;
						viewer.setZoom(viewerZoom);
					}
					
					if(viewerZoom > 0) 	$('feature').getElement('a.reduce').getElement('img').setProperty('src','images/reduce-on.'+ imgext);
					if((viewerZoom + 1) >= viewer.getDocument().getZoomCount()) 	$('feature').getElement('a.enlarge').getElement('img').setProperty('src','images/enlarge.'+ imgext);
					
				}.bind(this));
				
				// reduce button
				$('feature').getElement('a.reduce').addEvent('click',function(e){
					if((viewerZoom + 1) > 1){
						viewerZoom = viewerZoom - 1;
						viewer.setZoom(viewerZoom);
					}
					
					if(viewerZoom <= 0) $('feature').getElement('a.reduce').getElement('img').setProperty('src','images/reduce.'+ imgext);
					if((viewerZoom + 1) < viewer.getDocument().getZoomCount()) 	$('feature').getElement('a.enlarge').getElement('img').setProperty('src','images/enlarge-on.'+ imgext);
					
				}.bind(this));
				
				// show that this can be on
				$('feature').getElement('a.enlarge').getElement('img').setProperty('src','images/enlarge-on.'+ imgext);
				$('feature').getElement('a.reduce').getElement('img').setProperty('src','images/reduce.'+ imgext);
			
			} else {
				$('feature').getElement('a.enlarge').getElement('img').setProperty('src','images/enlarge.'+ imgext);
				$('feature').getElement('a.reduce').getElement('img').setProperty('src','images/reduce.'+ imgext);
			}
			
			thumbs();
			
			(function(){
				$('feature').getElement('div.vuzit_view').setStyles({width:600});
			}).delay(1000);
			
		};
		
		thumbs = function(){
			// page thumbs
			var start = viewerPage;
			var macx = start;
			if((viewer.getDocument().getPageCount() - start) >= 2) macx = start + 2;
			if((viewer.getDocument().getPageCount() - start) < 2){
				if((viewer.getDocument().getPageCount() - start) == 0) start = start - 2; // start == end
				else { start = start - 1; macx = macx + 1; }
			}
			
			$('feature').getElement('p.pagethumbs').empty();
			for(i=start;i<=macx;i++){
				var img = new Element('img',{src:viewer.getDocument().getUrlImageThumb(i-1)}).setProperty('data-rel',i);
				img.addEvent('click',function(e){ 
					viewerPage = parseInt($(e.target).getProperty('data-rel'));
					viewer.setPageNumber(viewerPage);
					if(viewerPage > 1) 	$('feature').getElement('a.prev').getElement('img').setProperty('src','images/prev-on.png');
					if(viewerPage >= viewer.getDocument().getPageCount()) 	$('feature').getElement('a.next').getElement('img').setProperty('src','images/next.png');
					if(viewerPage <= 1) $('feature').getElement('a.prev').getElement('img').setProperty('src','images/prev.png');
					if(viewerPage < viewer.getDocument().getPageCount()) 	$('feature').getElement('a.next').getElement('img').setProperty('src','images/next-on.png');
				}.bind(this));
				if(i==macx) img.addClass('lastchild');
				$('feature').getElement('p.pagethumbs').adopt(img);	
			}
		}
		
		$('feature-window').empty();
		
		viewerPage = (page) ? page : 1;
		viewerZoom = 0;
		viewer = vuzit.Viewer.fromUrl(url,{});
   		viewer.display(document.getElementById("feature-window"), { zoom: viewerZoom, page: viewerPage, onComplete: loaded });
		
		// remove clicking
		$('feature').getElement('a.prev').removeEvents('click');
		$('feature').getElement('a.next').removeEvents('click');
		$('feature').getElement('a.enlarge').removeEvents('click');
		$('feature').getElement('a.reduce').removeEvents('click');
		$('feature').getElement('a.download').removeEvents('click');
					
		// download button
		$('feature').getElement('a.download').addEvent('click',function(e){
			window.open(url,'_blank');
			e.stop();
		}.bindWithEvent(this));
				
	}
		
	// virus advisory rss
	// means the page doesn't hang while these load
	var j = new Request.JSON({url:'loadrss.php?feed=virusadvisory'});
	j.addEvent('success',function(j){
		if(j){
			if(j.threats) $('va-latest-threats').set('html',j.threats);
			if(j.risks) $('va-risks').set('html',j.risks);	
			if(j.advisory) $('va-advisory').set('html',j.advisory);	
		}
	});
	j.send();
	
	// make latest news clickable
	$("top").getElements('ul.news li a').addEvent('click',function(e){
		$$('div.child2news').each(function(el){
			if($(el).get('id') == 	'newsitem'+$(e.target).getProperty('href').replace('#news/latest/','')){
				$(el).getElement('div.expand').setStyle('display','none');
				$(el).getElement('div.expanded').setStyle('display','block');
				$(el).getElement('div.close-expanded').setStyle('display','block');
			} else {
				$(el).getElement('div.expand').setStyle('display','block');
				$(el).getElement('div.expanded').setStyle('display','none');
				$(el).getElement('div.close-expanded').setStyle('display','none');
			}
		},this);
		gotopage($(e.target).getProperty('href'),true);	
	});
		
	// make text links clickable
	$$('#middle div.link div.content ul.fc li.text a').each(function(l){ handleLinks($(l)); });
	
	$('top-tips-link').addEvent('click',function(e){
		loadFeature('http://win01.rtnetworks.net/niteccom/cmsfiles/pdf/VirusAlertTopTips.pdf'); 
		openFeature();
		e.stop();
	});
	
	$('privacy-link').addEvent('click',function(e){
		loadFeature('http://win01.rtnetworks.net/niteccom/cmsfiles/pdf/Privacy.pdf'); 
		openFeature();
		e.stop();
	});
	
	if($('event-banner')){
		var ref = $$('div.link>h1')[3].getPosition();
		$('event-banner').setStyles({
			'top': ref.y - 80,
			'left': ref.x + 500
		});
		$('event-banner').getElement('a').addEvent('click',function(e){ 
			if($('event-banner').getElement('a').getProperty('href').indexOf('#') == 0){
				gotopage('#news/events'); 
			} else if($('event-banner').getElement('a').getProperty('href').substr($('event-banner').getElement('a').getProperty('href').length-3) == 'pdf'){
				loadFeature($('event-banner').getElement('a').getProperty('href'));	
				openFeature();
				e.stop();
			} else {
				window.open($('event-banner').getElement('a').getProperty('href'));
				e.stop();
			}		
		});
		$$('event-banner a').each(function(l){ handleLinks(l); });
	}
	
	if($('event-signup-form')){
		$('event-signup-form').addEvent('submit',function(ev){ 
			ev.stop();
			$('event-signup-form').send(); 
			$('event-signup-form-div').setStyle('display','none'); 
			$('event-signup-message').setStyle('display','block');
		});
		
	}
	
});