/**
 * file default.js
 *
 * contains javascript for MontClair website
 *
 * @require MooTools version 1.2.2
 */


window.addEvents({
	'domready': function() {
		startCarrousel();
		closeLightbox();
		initMainnav();
	},
	'load': function() {
		fitBlocksInColumn();
		clickableTestimonial();
		makeEqualHeight($$('ul.vacancy > li'));
		makeEqualHeight($$('div.contentbox'));
		makeEqualHeight($$('div.contactorcall div.contactblock').extend($$('div.contactorcall div.callmeback')));
		makeEqualHeight($$('ul.footercolumns > li'));
		
	}
});



/**
 * fitBlocksInColumn
 *
 * removes right margin from every rightmost floating contentbox
 * in order to make them fit in their column
 *
 * @author Klaas Dieleman <klaas{AT}efocus.nl>
 * @return void
 */
function fitBlocksInColumn() {
	var rightContentBoxes = $$('div.col3of4 div.contentbox').filter(function(el, index) {
		if((index + 1) % 3 == 0) return el
	});
	
	rightContentBoxes.extend(
		$$('div.col4of4 div.contentbox').filter(function(el, index) {
			if((index + 1) % 4 == 0) return el
		})
	);
	
	rightContentBoxes.setStyle('margin-right', 0);
}


/**
 * clickableTestimonial
 *
 * make testimonial div clickable
 *
 * @author Phison Do <phison.do{AT}efocus.nl>
 * @return void
 */
function clickableTestimonial() {
	if (!document.getElement('.testimonial')) return;
	
	var arrTestimonialDiv = $$('.testimonial');
	
	arrTestimonialDiv.each(function(elTestimonialDiv){
		elTestimonialDiv.setStyle('cursor', 'pointer');		
		elTestimonialDiv.addEvent('click', function (){
			var goTo = elTestimonialDiv.getElement('h2 a');
			if(goTo && goTo!=''){
				window.location = goTo;
			};
		});
	});
}



/**
 * starts carrousel
 *
 * @author Klaas Dieleman <klaas@efocus.nl>
 * @return void
 */

function startCarrousel() {
	if (!$('carrousel')) return;
	
	var pbox = new Pushbox({
		'viewport': $('carrousel').getElement('div.viewport'),
		'slides': $('carrousel').getElement('ul.slides').getElements('li'),
		'navigation': $('carrousel').getElement('ul.pushbox_nav').getElements('li'),
		'transition': 'slide',
		'duration': 1,
		'delay': carrouselDelay
	});
	
	$$('ul.pushbox_nav li')[0].addClass('active');
}

/**
* close lightbox
*
* @author Rou-hun Fan <lowen@efocus.nl>
* @return void
*/

function closeLightbox() {
	if (!$('lightbox_close')) return;

	$('lightbox_close').addEvent('click', function(event) {
		event.stop();
		window.parent.Shadowbox.close();

	});
	
}


/**
* hover interaction of main navigation
*
* @author Klaas Dieleman <klaas@efocus.nl>
* @return void
*/

function initMainnav() {
	$$('ul.main_nav > li').each(function(el) {
		el.addEvents({
			'mouseenter' : function() {
				el.addClass('hover');
			},
			'mouseleave' : function() {
				el.removeClass('hover');
			}
		});
	});
}
