window.addEvent('load', function() {
		try{
			var list = $('tweets-here');
						items = list.getElements('li');
			showDuration = 8000;
			scrollDuration = 500;
			index = 0;
			height = items[0].getSize().y;
			move.periodical(showDuration);
			var move = function() {
				list.set('tween',{
					duration: scrollDuration,
					onComplete: function() {
						if(index == items.length - 1) {
							index = 0 - 1;
							list.scrollTo(0,7);
						}
					}
				}).tween('top',0 - (++index * height)+7);
			};

		}
		catch(err){
		}
		
currentchap='';


function AjaxContent(chap, page){		
		var req = new Request.HTML({
            	method: 'get',
           		url: 'lib/ajaxcontent.php',
           		data: { 'chap' : chap }, 
           		update: $('innercontent'),
                onComplete:  function(responseHTML) { 
                	myFx.start(0,1);
                	initButs();
  					chch = $('logos').getChildren();
  					cnum=0;
  					maxc = chch.length;
  					chch1 = chch[cnum];
  					var idd =chch1.getProperty('id');
  					$('rondje2').position({relativeTo: chch1});
					$('rondje2').setStyle('display', 'block');
					var page = idd.substring(4);
                   	AjaxInnerContent(chap, page);
                   	if (chap == 'tain' || chap == 'brain' || chap == 'pain'){
                   	AjaxOverlay(chap, 'services');}
                }
    		});
    	
    	if (chap != currentchap){
    	$('rondje').setStyle('display', 'none');
		var myFx = new Fx.Tween('innercontent', {property: 'opacity'});
		myFx.start(1,0).chain( function(){ req.send(); } );
		currentchap = chap;
		}
}
AjaxContent('home', 0);	

function AjaxInnerContent(chap, page){		
		var req = new Request.HTML({
            	method: 'get',
           		url: 'lib/ajaxinnercontent.php',
           		data: { 'chap' : chap , 'page': page}, 
           		update: $('slidecontent'),
                onComplete:  function(responseHTML) { 
                  	txtc2 = new Fx.Slide('textcontent2', {
    					duration: 1000
 					});
 					toggleaan=0;
 					
 					$('textcontent').setStyle('display','block');
 					
 					$('textcontent3').addEvent('click', function(){
 						txtc2.toggle();
 						if (toggleaan ==0){
 							$('textcontent3').set('text', 'show');
 							toggleaan =1;
 						}
 						else{
 							$('textcontent3').set('text', 'hide');
 							toggleaan =0;
 						}
					});
					
 					if ($('textcontent2').get('text') == ''){
						$('textcontent2').setStyle('display','none');
						$('textcontent3').setStyle('display','none');
					}else{
						$('textcontent2').setStyle('display','block');
						$('textcontent3').setStyle('display','block');
					}

    			}
    	});		
    	req.send();
}


function AjaxOverlay(chap, page){		
		var req = new Request.HTML({
            	method: 'get',
           		url: 'lib/ajaxoverlay.php',
           		data: { 'chap' : chap, "item": page }, 
           		update: $('overlaycontent'),
                onComplete:  function(responseHTML) { 
					$('overlaywindow').setStyle('display', 'block');
					overlayon=1;
                }
    		});
    	req.send(); 

}
function AjaxContact(){		
		var req = new Request.HTML({
            	method: 'get',
           		url: 'lib/ajaxcontact.php',
           		update: $('overlaycontent'),
                onComplete:  function(responseHTML) { 
					$('overlaywindow').setStyle('display', 'block');
					overlayon=1;
                }
    		});
    	req.send(); 

}
	
	function ScaleSize(){
		var size = window.getSize();
		if ( (size.x/size.y) > 14/9 ){
			$('background').getElement('img').setStyle('width', size.x);
			$('background').getElement('img').setStyle('height', (size.x/14*9));
		}else{
			$('background').getElement('img').setStyle('height', size.y);
			$('background').getElement('img').setStyle('width', (size.y/9*14));
		}
	}
	ScaleSize();
	window.addEvent('resize', function(){
			ScaleSize();
	});
	
	
	
	
	
	var fotoview=0;
	var overlayon=0;
	var agendaon=0;
	
	$("fotoview").addEvent('click', function(){
			if (fotoview ==0){
				fotoview=1;
				myFx1 = new Fx.Tween('twitterbar', {property: 'opacity' });
				myFx1a = new Fx.Tween('twitimgs', {property: 'opacity' });
				myFx2 = new Fx.Tween('rondje', {property: 'opacity' });
				myFx2a = new Fx.Tween('rondje2', {property: 'opacity' });
				myFx3 = new Fx.Tween('socialmedia', {property: 'opacity' });
				myFx4 = new Fx.Tween('innercontent', {property: 'opacity' ,
        			onComplete: function(){myFx6.start(1);}
				});
				myFx5 = new Fx.Tween('socialwhiteline', {property: 'opacity' });
				myFx6 = new Fx.Tween('contentwindow', {property: 'height'});
				myFx1.start(1,0);
				myFx1a.start(1,0);
				myFx2.start(1,0);
				myFx2a.start(1,0);
				myFx3.start(1,0);
				myFx5.start(1,0);
				myFx4.start(1,0);
				if (overlayon==1){$('overlaywindow').setStyle('display', 'none');}
				if (agendaon==1){$('agendawindow').setStyle('display', 'none');}
			}
			else{
				fotoview=0;
				myFx1 = new Fx.Tween('twitterbar', {property: 'opacity' });
				myFx1a = new Fx.Tween('twitimgs', {property: 'opacity' });
				myFx2 = new Fx.Tween('rondje', {property: 'opacity' });
				myFx2a = new Fx.Tween('rondje2', {property: 'opacity' });
				myFx3 = new Fx.Tween('socialmedia', {property: 'opacity' });
				myFx4 = new Fx.Tween('innercontent', {property: 'opacity' });
				myFx5 = new Fx.Tween('socialwhiteline', {property: 'opacity',
        			onComplete: function(){myFx4.start(1);}
				});
				myFx6 = new Fx.Tween('contentwindow', {property: 'height',
        			onComplete: function(){
						myFx1.start(0,1);
						myFx1a.start(0,1);
						myFx2.start(0,1);
						myFx2a.start(0,1);
						myFx3.start(0,1);
						myFx5.start(0,1);}	
				});
				myFx6.start(470);				
				if (overlayon==1){$('overlaywindow').setStyle('display', 'block');}
				if (agendaon==1){$('agendawindow').setStyle('display', 'block');}
			}
		});
	
		$('kontact').addEvent('click', function(){
			AjaxContact();
			$('overlaywindow').setStyle('display', 'block');
			overlayon=1;
		});	
		
		$("agendabut").addEvent('click', function(){
			$('agendawindow').setStyle('display', 'none');
		});	

		$("shop").addEvent('click', function(){
			URL1= 'http://www.truus-shop.com';
			winRef = window.open( URL1, 'truus shop'  );

		});	
	

	
	function initButs(){
		Element.Events.click = { 
			base:'click',
			onAdd: function() {
				if(this.setStyle) {
					this.store('original-cursor',this.getStyle('cursor'));
					this.setStyle('cursor','pointer');
				}
			},
			onRemove: function() {
				if(this.setStyle) {
					this.setStyle('cursor',this.retrieve('original-cursor'));
				}
			}
		};
		
		$$('.navbut').each(function(cont, c){
			cont.addEvent('click', function(){
				$$('.navbut img').each(function(cont1, c){
						cont1.setStyle('display', 'block');
					});
				var firstDiv = cont.getElement('img');
				firstDiv.setStyle('display', 'none');
				var idd =cont.getProperty('id');
				AjaxContent(idd,0);
				
			});	
				
		});
		
		
		$$('.dnabut').each(function(cont, c){
			cont.addEvent('click', function(){
			var idd =cont.getProperty('id');
			AjaxOverlay('dna',idd);
			});	
				
		});
		 


		$("overlaybut").addEvent('click', function(){
			$('overlaywindow').setStyle('display', 'none');
			overlayon=0;
		});	
		 
		$$('.logo').each(function(cont, c){
			cont.addEvent('click', function(){
				var idd =cont.getProperty('id');
				$('rondje2').position({relativeTo: cont});
				$('rondje2').setStyle('display', 'block');
				var page = idd.substring(4);
				AjaxInnerContent(currentchap, page);
				
			});	
			
		});
		
		$$('.underbut1').each(function(cont, c){
			cont.addEvent('mouseenter', function(){
				cont.setStyle('color', '#9d7e2c');
			});
			cont.addEvent('mouseleave', function(){
				cont.setStyle('color', 'black');
			});	
		});	
		
		$$('.underbut').each(function(cont, c){
			cont.addEvent('mouseenter', function(){
				cont.setStyle('color', '#9d7e2c');
			});
			cont.addEvent('mouseleave', function(){
				cont.setStyle('color', 'black');
			});	
			cont.addEvent('click', function(){
				if (cont.getProperty('id') == 'services'){AjaxOverlay(currentchap, 'services');}
				cont.setStyle('color', '#9d7e2c');
				$('rondje').position({relativeTo: cont});
				$('rondje').setStyle('display', 'block');
			});	
		
		
		});
		if ($('nextbut') != null){
		  			chch = $('logos').getChildren();
  					cnum=0;
  					maxc = chch.length;
  					chch1 = chch[cnum];
  					var idd =chch1.getProperty('id');
  					$('rondje2').position({relativeTo: chch1});
					$('rondje2').setStyle('display', 'block');
		$('nextbut').addEvent('click', function(){
  					if (cnum ==(maxc-1)){cnum=0;}else{cnum+=1;}
  					chch1 = chch[cnum];
  					var idd =chch1.getProperty('id');
  					$('rondje2').position({relativeTo: chch1});
					$('rondje2').setStyle('display', 'block');
					var page = idd.substring(4)
                   	AjaxInnerContent('', page);
			});
			$('prevbut').addEvent('click', function(){
					if (cnum ==0){cnum=(maxc-1);}else{cnum-=1;}
  					chch1 = chch[cnum];
  					var idd =chch1.getProperty('id');
  					$('rondje2').position({relativeTo: chch1});
					$('rondje2').setStyle('display', 'block');
					var page = idd.substring(4)
                   	AjaxInnerContent('', page);
			});	
		}	
		if ($('agendah') != null){
		$("agendah").addEvent('click', function(){
			$('agendawindow').setStyle('display', 'block');
		});	
		}
	 	

	

	}	
	initButs();
	
	
var currentTime = new Date();
var month = currentTime.getMonth() + 1;
var day = currentTime.getDate();
var year = currentTime.getFullYear();
ctime = month + "/" + day + "/" + year;

	
	
	
	var req = new Request({
		method: 'get',
		url: './eventFeed2.php',
		onComplete: function(response) {
			new Calendar({
			calContainer:'agendacontent',
			newDate:ctime,
			cEvents: JSON.decode(response)
			});
			
			$$('.fullevent1').each(function(cont, c){
			cont.getParent().addClass('full');
		});	
		}
	}).send();
	
	
});

window.addEvent('domready', function() {

	

	if($('tweets-here')){
		$('tweets-here').set('html','');
		//get information
		var myTwitterGitter = new TwitterGitter('TRUUSMULTILAB',{
			count: 8,
			onComplete: function(tweets_b,user) {
				tweets_b.each(function(tweet,i) {
					new Element('li',{
						html: '<div class=\'tweettext\'>'+tweet.text + '&nbsp;&nbsp;&nbsp;&nbsp;<a href="http://twitter.com/TRUUSMULTILAB" target="_blank">Follow TRuus</a></div>',
						'class': 'tweet clear'
					}).inject('tweets-here');
				});
			}
		}).retrieve();

	}

});




function setTheDate(tweetdate){
	
	Date.defineFormat('tweettime', '%I:%M %p %B %d%o');
	var tweettime = new Date(tweetdate).format('tweettime');
	return tweettime;

}

