var accStartId = 0;
var interval;
window.addEvent('domready', function(){

	new SlideItMoo({itemsVisible:1,
					currentElement: 0,
					thumbsContainer: 'thumbs',
					elementScrolled: 'thumb_container',
					overallContainer: 'container'});
	
	$('thumbs').getElements('img').setStyle('opacity', '0.3');
	
	if(Cookie.read('popup') == 1){
		if ($('MovieElementBg99') != null) {
			
			$('MovieElementBg99').setStyle('display', 'none');
			$('MovieElement99').setStyle('display', 'none');
			
		}
	} 
	else {
		if ($('MovieElementBg99') != null) {
			
			$('MovieElementBg99').setStyle('display', 'block');
			$('MovieElement99').setStyle('display', 'block');
			
		}
	}

	
//	var initMultiBox = new multiBox({
//		mbClass: '.mb',//class you need to add links that you want to trigger multiBox with (remember and update CSS files)
//		container: $(document.body),//where to inject multiBox
//		descClassName: 'multiBoxDesc',//the class name of the description divs
//		path: './Files/',//path to mp3 and flv players
//		useOverlay: true,//use a semi-transparent background. default: false;
//		maxSize: null,//max dimensions (width,height) - set to null to disable resizing
//		addDownload: true,//do you want the files to be downloadable?
//		addRollover: true,//add rollover fade to each multibox link
//		addOverlayIcon: true,//adds overlay icons to images within multibox links
//		addChain: true,//cycle through all images fading them out then in
//		recalcTop: true,//subtract the height of controls panel from top position
//		addTips: true,//adds MooTools built in 'Tips' class to each element (see: http://mootools.net/docs/Plugins/Tips)
//		autoOpen: Timeopen//to auto open a multiBox element on page load change to (1, 2, or 3 etc)
//	}); 
	
	var accordion = new Accordion('a.toggler', 'div.element', {
		opacity: 0,
		display: false,
		onActive: function(toggler, element){
			//Cookie.write('AccOpen',toggler.get('id'));
			toggler.setStyle('color', '#4d4d4d');
			toggler.removeEvents('mouseenter');
	        toggler.removeEvents('mouseleave');
	        toggler.addEvent('mouseenter',function() {
	
	        });
		},
		onBackground: function(toggler, element){
			toggler.setStyle('color', '#000000');
			toggler.setStyle('background', 'transparent');
			toggler.removeEvents('mouseenter');
	        toggler.removeEvents('mouseleave');
	        toggler.addEvent('mouseenter',function() {
	   
		        this.setStyle('color','#4d4d4d');
		
		        toggler.addEvent('mouseleave',function() {
		
			        this.setStyle('background','transparent');        
			        this.setStyle('color', '#000000');
		
		        });
	        });
		}
		}, $('mymenu'));
		var defaultAcc = $('mymenu').getFirst().id;

		if(accStartId > 0) {
			$(accStartId.toString()).fireEvent('click');
		}
	
		
	Dofader(0, 1)	
	DoOmschrijving(0);
	
	$$('div.thumbnail a').addEvent('click', false);
	
	var myCookie  = Cookie.write('popup', '1', {duration: 1});
	
//	var index = 0;
//    var ele = $('maketekst');
//    var txt = ele.get('text');
//    ele.set('text', '');
//    var typewriter = (function() {
//        ele.set('text', ele.get('text') + txt[index]);
//        if(index++ == txt.length - 1) { $clear(typewriter); }
//    }).periodical(1);

	
});
function doMovie(vidId, id, pid)
{
	if(hasFlash == 1) {
		jQuery('#player' + vidId).youTubeEmbed({
			video			: movieHtmlContent[vidId][0],
			progressBar	: true
		});
	}
	else {
		$('player' + vidId).innerHTML = movieHtmlContent[vidId][1];
	}
	
	document.getElementById(id).style.display = "block";
	document.getElementById(pid).style.display = "block";

}
function dontMovie(vidId, id, pid)
{

	window.clearInterval(interval);
	document.getElementById(id).style.display = "none";
	document.getElementById(pid).style.display = "none";
	$('player' + vidId).innerHTML = '';
	
}
function DoOmschrijving(id)
{
	if($('titletodo_' + id)) {
		var titleToDo = $('titletodo_' + id).get('text');
		
		if(typeof(titleToDo) != 'undefined') {
			$('titleHome').set('text', titleToDo);
		}
	}
	if($('texttodo_' + id)) {
		var textToDo = $('texttodo_' + id).get('text');
		
		if(typeof(textToDo) != 'undefined') {
			$('omschrijvingHome').set('text', textToDo);
		}
	}
	if($('clienttodo_' + id)) {
		var clientToDo = $('clienttodo_' + id).get('text');
		
		if(typeof(clientToDo) != 'undefined') {
			$('clientHome').set('text', clientToDo);
		}
	}
	if($('yeartodo_' + id)) {
		var yearToDo = $('yeartodo_' + id).get('text');
		
		if(typeof(yearToDo) != 'undefined') {
			$('yearHome').set('text', yearToDo);
		}
	}
	if($('linktodo_' + id)) {
		var linkToDo = $('linktodo_' + id).get('text');
		
		if(typeof(linkToDo) != 'undefined') {
			$('linkHome').set('href', linkToDo);
		}
	}
	if($('linknametodo_' + id)) {
		var linknameToDo = $('linknametodo_' + id).get('text');
		
		if(typeof(linknameToDo) != 'undefined') {
			$('linkHome').set('text', linknameToDo);
		}
	}
	
}
function Dofader(id, type) 
{
	$$('div.thumbnail img.image').setStyle('opacity', '0.3');
	if(type == 1) {
		$('img' + id).setStyle('opacity', '1');
	}
	else {
		$('img' + id).setStyle('opacity', '0.3');
	}
}
function loadPre() {
	
	
	showImages('thumb_container', 'loading');
	
	var dims = windowDims();
	var w = dims[0];
	var h = dims[1];
	var he = dims[1] - 146;
	
	$('footer').setStyle('display', 'block');
	
	$('container').setStyle('width', w + 'px');
	$('container').setStyle('height', he + 'px');

	$$('#container div.left').setStyle('height', he + 'px');
	$$('#container div.right').setStyle('height', he + 'px');
	
	$('thumb_container').setStyle('width', w + 'px');
	$('thumb_container').setStyle('height', he + 'px');
	
	$('thumbs').getElements('img').setStyle('height', he + 'px');

};
function saymyid(id){
	var mypopmenuid = id;	
}
function showImages(divId, loadId){
	document.getElementById(divId).style.display = "block";
	document.getElementById(loadId).style.display = "none";
} 

function popup(url) 
{
 params  = 'width='+screen.width;
 params += ', height='+screen.height;
 params += ', top=0, left=0'
 params += ', fullscreen=yes';

 newwin=window.open(url,'windowname4', params);
 if (window.focus) {newwin.focus()}
 return false;
}

function OnResizeDocument() {
	
	var dims = windowDims();
	var w = dims[0];
	var h = dims[1];
	var he = dims[1] - 146;
	
	$('container').setStyle('width', w + 'px');
	$('container').setStyle('height', he + 'px');
	
	$$('#container div.left').setStyle('height', he + 'px');
	$$('#container div.right').setStyle('height', he + 'px');
	
	$('thumb_container').setStyle('width', w + 'px');
	$('thumb_container').setStyle('height', he + 'px');
	$('thumbs').getElements('img').setStyle('height', he + 'px');
	
}

function windowDims() {
  
	var dims = [];
	if(typeof(window.innerWidth) == 'number' ) {
		dims[0] = window.innerWidth;
		dims[1] = window.innerHeight;
	} 
	else if(document.documentElement 
			&& (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
   
		dims[0] = document.documentElement.clientWidth;
		dims[1] = document.documentElement.clientHeight;
	} 
	else if(document.body 
			&& (document.body.clientWidth || document.body.clientHeight)) {
   
		dims[0] = document.body.clientWidth;
		dims[1] = document.body.clientHeight;
	}
	return dims;
	
}
var gblSlideState = false;
var SlideItMoo = new Class({
	
	currentStep: 0,
	
	initialize: function(options){
		this.options = $extend({
			itemsVisible: 2,
			showControls: 1,
			autoSlide: 0,
			transition: Fx.Transitions.Sine.easeIn,
			currentElement: 0,
			thumbsContainer: 'thumbs',
			elementScrolled: 'thumb_container',
			overallContainer: 'container'
		},options || {});	
		
		this.images = $(this.options.thumbsContainer).getElements('img');
		
		var imgcount = Object.keys($('thumbs').getElements('img'));
		
		var imgcounter = imgcount.length - 1;

		for(i = 0; i < imgcounter; i++){
			
			if(this.images[i].id == 'img' + this.options.currentElement){
				$('img' + [this.options.currentElement]).set('opacity',1.00);
			}
			
			else {
				$('img' + [i]).set('opacity',0.30);	
			}
			
		}	

		this.setContainersSize();
		
		this.myFx = new Fx.Scroll(this.options.elementScrolled,{duration: 500, transition: this.options.transition });		
		this.myFx2 = new Fx.Scroll(this.options.elementScrolled,{duration: 10, transition: this.options.transition });		
		
		if(this.images) {

			this.fwd = this.addControlers('right');
			this.bkwd = this.addControlers('left');
			this.forward();
			this.backward();
			
			$('thumbs').set('tween', {transition: Fx.Transitions.Sine.easeInOut});		
			
			this.bkwd.addEvent('mouseover',function() {
				if(gblSlideState == false) {
					$('thumbs').tween('left', '50px');
				}
			}.bind(this));
			
			this.bkwd.addEvent('mouseout',function() {
				if(gblSlideState == false) {
					$('thumbs').tween('left', '0px');
				}
			}.bind(this));

			this.fwd.addEvent('mouseover',function() {
				if(gblSlideState == false) {
					$('thumbs').tween('left', '-50px');
				}
			}.bind(this));
			
			this.fwd.addEvent('mouseout',function() {
				if(gblSlideState == false) {
					$('thumbs').tween('left', '0px');
				}
			}.bind(this));
		}
			
		if( this.options.currentElement!==0 ){
			this.options.currentElement-=1;
			this.slide(1);
		}

		$('leftScrollButton').setStyle('display', 'block');
		$('rightScrollButton').setStyle('display', 'block');
		
		if(this.options.currentElement == 0) {
			$('leftScrollButton').setStyle('display', 'none');
		}
		if(this.options.currentElement == (imgcounter-1) ) {
			$('rightScrollButton').setStyle('display', 'none');
		}
	},
	
	setContainersSize: function(){
		$(this.options.overallContainer).set({

		});
		$(this.options.elementScrolled).set({

		});
	},
	
	forward: function(){
		this.fwd.addEvent('click',function() {
			this.slide(5);
			
			this.currentStep = (this.currentStep + 1);
			$('thumbs').tween('left', '0px');
		}.bind(this));		
	},
	
	backward: function(){			
		this.bkwd.addEvent('click',function(){	
			this.slide(-5);	
			
			this.currentStep = (this.currentStep - 1);
			$('thumbs').tween('left', '0px');

		}.bind(this))	
	},
	
	addControlers: function(cssClass){
		element = new Element('div',{
			'class': cssClass,
			'id': cssClass + 'ScrollButton',
			styles:{
				'display': this.options.showControls ? '' : 'none'
			}
		}).injectInside($(this.options.overallContainer));
		return element;
	},

	slide: function(step){
		gblSlideState = true;
		//$('thumbs').setStyle('left', '0px');
		if(this.options.autoSlide && this.options.currentElement >= this.images.length-this.options.itemsVisible ){
			this.options.currentElement = -1;
		}
		
		if ( ( this.options.currentElement < this.images.length-this.options.itemsVisible && step>0 ) || ( step < 0 && this.options.currentElement !== 0 ) ){
			this.myFx.cancel();
			this.options.currentElement += step;	
			
			var aaaa = this.myFx2;
			var bbbb = this.options.currentElement;
			var iiii = this.images;
			this.myFx.toElement( this.images[this.options.currentElement] ).chain(function() {
				$('thumbs').tween('left', '0px');
				aaaa.cancel();
				aaaa.toElement( iiii[bbbb] );
				
			});
		}
		
		var imgcount = Object.keys($('thumbs').getElements('img'));
		var imgcounter = imgcount.length - 1;
		
		for(i = 0; i < imgcounter; i++){
			
			if(this.images[i].id == 'img' + this.options.currentElement){
				$('img' + [this.options.currentElement]).fade('in');
				$('img' + [this.options.currentElement]).fade(1.00);
			} 
			else {
				$('img' + [i]).fade('out');
				$('img' + [i]).fade(0.30);
			}
		}
		
		/* on off buttons */
		$('leftScrollButton').setStyle('display', 'block');
		$('rightScrollButton').setStyle('display', 'block');
		
		if(this.options.currentElement == 0) {
			$('leftScrollButton').setStyle('display', 'none');
		}

		if(this.options.currentElement == (imgcounter-1) || 
		   this.options.currentElement == (imgcounter-2) || 
		   this.options.currentElement == (imgcounter-3) || 
		   this.options.currentElement == (imgcounter-4) || 
		   this.options.currentElement == (imgcounter-5) ) {
			$('rightScrollButton').setStyle('display', 'none');
		}
		setTimeout('gblSlideState = false;', 750);
	}
})


var DDSPEED = 5;
var DDTIMER = 5;

// main function to handle the mouse events //
function ddMenu(id,d){
  var h = document.getElementById(id + '-ddheader');
  var c = document.getElementById(id + '-ddcontent');
  clearInterval(c.timer);
  if(d == 1){
    clearTimeout(h.timer);
    if(c.maxh && c.maxh <= c.offsetHeight){return}
    else if(!c.maxh){
      c.style.top = '-' + 0 + 'px';
      c.style.cursor = 'default';
      c.style.display = 'block';
      c.style.height = 'auto';
      c.maxh = c.offsetHeight;
      c.style.height = '0px';
    }
    c.timer = setInterval(function(){ddSlide(c,1)},DDTIMER);
  }else if(d == 2){
	h.timer = setTimeout(function(){ddCollapse(c)},50);

  }else{
    h.timer = setTimeout(function(){ddCollapse(c)},100);
  }
}

// collapse the menu //
function ddCollapse(c){
  c.timer = setInterval(function(){ddSlide(c,-1)},DDTIMER);
}

// cancel the collapse if a user rolls over the dropdown cent //
function cancelHide(id){
  var h = document.getElementById(id + '-ddheader');
  var c = document.getElementById(id + '-ddcontent');
  clearTimeout(h.timer);
  clearInterval(c.timer);
  if(c.offsetHeight < c.maxh){
    c.timer = setInterval(function(){ddSlide(c,1)},DDTIMER);
  }
}

// incrementally expand/contract the dropdown and change the opacity //
function ddSlide(c,d){
  var currh = c.offsetHeight;
  var dist;
  if(d == 1){
    dist = (Math.round((c.maxh - currh) / DDSPEED));
  }else{
    dist = (Math.round(currh / DDSPEED));
  }
  if(dist <= 1 && d == 1){
    dist = 1;
  }
  c.style.top = parseInt(c.style.top.replace('px','')) - parseInt(dist * d) + 'px';
  c.style.height = currh + (dist * d) + 'px';
  c.style.opacity = currh / c.maxh;
  c.style.filter = 'alpha(opacity=' + (currh * 100 / c.maxh) + ')';
  if((currh < 2 && d != 1) || (currh > (c.maxh - 2) && d == 1)){
    clearInterval(c.timer);
  }
  if(currh < 10 && d == -1) {
	  c.style.top = '0px';
	  c.style.height = '0px';
	  c.style.opacity = 0;
	  c.style.filter = 'alpha(opacity=0)';
  }
}
