

 var search;

 function init()
 {
	if (bm('newsbox')) bm('newsbox').script= new newsbox();
	if (bm('calendarbox')) bm('calendarbox').script= new calendarbox();
	if (bm('knowledgebox')) bm('knowledgebox').script= new knowledgebox();
	if (bm('team')) bm('team').script= new team();
	
	search= new search();
 }



 function search()
 {
 	var that= this;
 	this.opened= false;
 	this.clickclose= false;
 	this.searchlink= bm(bm('head', 'p', 'search', true), 'a', null, true);
 	this.searchdiv= bm('search');
 	
 	//this.searchlink.addevent('mouseover', function() { search.open(); });
 	//this.searchlink.addevent('click', function() { if (!search.opened) search.open(); else if (search.clickclose) search.close(); });
	this.searchdiv.style.minHeight= (window.innerHeight-35)+'px';
	bm(this.searchdiv, 'div', 'main', true).addevent('mouseout', function(ev) { if (that.searchlink.parentNode.nochild(ev) && bm('search').nochild(ev)) search.close(); });
	
	this.search_object= new ajax('', function(a) { search.sendreturn(a); });
	
	this.init= function()
	{
		//bm(this.searchdiv, 'form', null, true).addevent('submit', search.send);
		bm(this.searchdiv, 'input', null, true).addevent('keyup', function(ev) { if (ev.target.value.length > 1) search.send(); });
	}
	
	this.init();
	
	this.open= function()
	{
		if (this.opened) return;
		this.opened= true;
		setTimeout(function() { that.clickclose= true; }, 300);
		this.searchdiv.fadein();
		setTimeout(function() { bm('search', 'input', null, true).focus() }, 100);
	}
	
	this.close= function()
	{
		if (!this.opened) return;
		this.opened= false;
		this.clickclose= false;
		this.searchdiv.fadeout();
	}
	
	this.send= function(ev)
	{
		this.search_object.query= bm('search', 'input', null, true).value;
		this.search_object.send('');
		return false;
	}
	
	this.sendreturn= function(response)
	{
		var htmlText= '';alert(30%12);
		
		for (var i= 0; i < response.length%30; i++)
		{
			htmlText+= '<div onclick="document.location.href=\''+base+'news/'+response[i][0]+'\';"><h2>'+response[i][2]+'</h2><p class="topic"><a href="'+base+'news">News</a> '+response[i][1]+'</p></div>';
		}
		
		bm('search', 'div', 'hits', true).innerHTML= htmlText;
	}
 }


 
 function newsbox()
 {
 	var that= this;
 	var timer;
 	var messages= bm('newsbox', 'div');
 	
	messages.execute(function(e) { e.addevent('click', function() { that.openMessage(e); }); e.addevent('mouseover', function() { that.clearTimer(); }); e.addevent('mouseout', function() { that.setTimer(); }); });
	
	this.setTimer= function()
	{
		if (this.timer == undefined) this.timer= setInterval(function() { that.nextMessage(); }, 8000);
	}
 	this.setTimer();
	
	this.clearTimer= function()
	{
		clearInterval(this.timer);
		this.timer= undefined;
	}
	
	this.resetTimer= function()
	{
		this.clearTimer();
		this.setTimer();
	}
	
	this.nextMessage= function()
	{
		var opened= 0;
		
		messages.execute(function(e, x) { if (e.className == 'active') opened= x; });
		
		opened++;
		if (opened > 4) opened= 0;
		
		that.openMessage(messages[opened]);
	}
	
	this.openMessage= function(e)
	{
		if (e.className == 'active')
		{
			document.location.href= bm(e, 'a')[1].href;
			return;
		}
		//that.resetTimer();
		messages.execute(function(f)
		{
			//  if (f.className != '') f.fadein();
			f.className= '';
			global_timer.removework(bm(f, 'p', 'topic')[0]);
			global_timer.removework(bm(f, 'section')[0]);
			global_timer.removework(bm(f, 'img')[0]);
			bm(f, 'img')[0].style.display= 'none';
		});
		e.className='active';
		//e.moveto('height', 250, 0, 0);
		//e.fadein();
		bm(e, 'p', 'topic')[0].style.top= '-80px';
		bm(e, 'p', 'topic')[0].moveto('top', 10, -80, -80);
		bm(e, 'section')[0].style.left= '-260px';
		bm(e, 'section')[0].moveto('left', 0, -260, -260);
		bm(e, 'img')[0].style.right= '-280px';
		bm(e, 'img')[0].moveto('right', 0, -280, -280);
	}
 }



 function calendarbox()
 {
	var that= this;
	
	bm('calendarbox', 'div', 'container').execute(function(e) { e.scrollable(); });
	bm('calendarbox', 'h2').execute(function(e) { e.addevent('click', function(ev)
	{
		bm('calendarbox', 'h2').execute(function(i) { i.className= ''; });
		e.className= 'active';
		bm('calendarbox', 'div', 'container').execute(function(i) { i.style.display= 'none'; });
		e.nextSibling.nextSibling.style.display= 'block';
		bm(e.nextSibling.nextSibling, 'div', 'slider', true).style.left= '0px';
	}); });
 }



 function knowledgebox()
 {
	var that= this;
	
	bm('knowledgebox').scrollable();
 }
 
 
 
 
 function team()
 {
 	var that= this;
 	var container= bm('team');
 	
 	bm(container, 'img').execute(function(e) { bm(e).addevent('mouseover', function(ev) { that.highlight(ev.target); }); bm(e).addevent('mouseout', function(ev) { that.highlight(null); }); });
 	
 	this.highlight= function(el)
 	{
 		bm(container, 'img').execute(function(e)
 		{
 			if (e == el || el == null) bm(e).fadeto(100, 100);
 			else bm(e).fadeto(10, 100);
 			
 			if (e == el)
 			{
 				bm(e.parentNode, 'div', null, true).fadeto(100, 0);
 				bm(e.parentNode, 'div', null, true).moveto('top', 100, 0, 0);
 			}
 			else
 			{
 				timer.removework(bm(e.parentNode, 'div', null, true));
 				bm(e.parentNode, 'div', null, true).style.display= 'none';
 			}
 		});
 	}
 }
 
 
 
 
 
 
 function mail(tl, sl, nm)
 {
 	document.location.href= 'mailto:'+nm+'@'+sl+'.'+tl;
 }








