/**
 * Bootstrap.js - Bootstrap for all Javascript functionality
 * 
 * @author  Webstores <info at webstores dot nl>
 *           Copyright (c) Webstores internet totaalbureau <http://www.webstores.nl/>
 */

WS.Event.addEvent(window, 'load', function() {
		
	var introducee1 = false;
	var introducee2 = false;
	if($('agenda-formulier')) {
		var introduceeVal = new WS.Validation('agenda-formulier');
		introduceeVal.initialize();
		
		WS.hide('introducee1');
		WS.hide('introducee2-wrapper');
		WS.hide('introducee2');
		WS.Event.addEvent('introducee1-toevoegen', 'click', function() {
			WS.toggle('introducee1');
			WS.toggle('introducee2-wrapper');
			if(introducee1){
				$('introducee-1-naam').disable();			
				$('introducee-1-email').disable();
				$('introducee-1-bedrijf').disable();
				$('introducee-1-mobnr').disable();					
			}else{
				$('introducee-1-naam').enable();			
				$('introducee-1-email').enable();
				$('introducee-1-bedrijf').enable();
				$('introducee-1-mobnr').enable();					
			}
			introducee1 = !introducee1;	
		});
		WS.Event.addEvent('introducee2-toevoegen', 'click', function() {
			WS.toggle('introducee2');
			if(introducee2){
				$('introducee-2-naam').disable();			
				$('introducee-2-email').disable();
				$('introducee-2-bedrijf').disable();
				$('introducee-2-mobnr').disable();					
			}else{
				$('introducee-2-naam').enable();
				$('introducee-2-email').enable();
				$('introducee-2-bedrijf').enable();
				$('introducee-2-mobnr').enable();
			}
			introducee2 = !introducee2;
		});
	}	
	
	// Album
	if($('album-image')) {
		var images = $('album-thumbnails').getElementsByTagName('a');
		var album = new PhotoAlbum('album-image', images, { initial: 0 });
		WS.Event.addEvent('album-prev', 'click', function(e) { WS.Event.stopEvent(e); album.prev(); });
		WS.Event.addEvent('album-next', 'click', function(e) { WS.Event.stopEvent(e); album.next(); });
	}
	
	if($('contact-formulier')) {
		var contactVal = new WS.Validation('contact-formulier');
		contactVal.initialize();	
	}		
	
	if($('lidworden-formulier')) {
		var lidwordenVal = new WS.Validation('lidworden-formulier');
		lidwordenVal.initialize();	
	}
});

document.observe('dom:loaded', function() {
	// External links
	var a = document.getElementsByTagName('a');
	for(var i = 0; i < a.length; i++) {
		if(/external/.test(a[i].rel)) {
			a[i].target = '_blank';
		}
	}
	
	if($('ask-question')){
		$('ask-question').observe('click', function(){
			$('ask').submit();
		});
	}	
	
	if($('profile')){
		$('profile').observe('click', function(){
			document.location = "/contacts/profile/"
		});
	}
	
	//Carousel
	if($('visual')) {
		var homeCarousel = new Carousel('visual-wrap', $$('#visual-content img'), $$('a.carousel-control', 'a.carousel-jumper'), {
			auto: true,
			frequency: 7,
			circular: true,
			afterMove: function() {
				homeCarousel.controls.each(function (el) {
					el.removeClassName(homeCarousel.options.selectedClassName);
				});
				homeCarousel.controls.each(function (el) {
					if (el.rel == homeCarousel.current.id) {
						el.addClassName(homeCarousel.options.selectedClassName);
					}
				});
			}
		});
	}
});