/////////////////////////////////////////// BASIC FUNCTIONS, DON'T EDIT ///////////////////////////////////////////

/**
 * Starts executing the initializing functions when either the DOM structure of the page has been loaded ('domready'), or the entire page ('load').
 * 
 * @author CSD (clientsidedevelopers{AT}efocus.nl)
 * @uses Mootools 1.2.2 JavaScript Library
 */
window.addEvents({
	'domready': function() {
		initDebugger();
		initExternalLinks();
		initFormSubmitButtons();
		initCarDetailGallery();
		initEqualHeightFixTeasers();
		initCarsOfTheWeekCarousel();
	},
	'load': function() {
		
	}
});



/**
 * initDebugger
 * In case the Firebug add-on is present in Firefox, it's console is used (only when enabled), else an alert is shown instead.
 * 
 * @author Ralph.Meeuws (ralph.meeuws{AT}efocus.nl)
 * @usage log(my_variable);
 * @return void
 */
function initDebugger() {
	log = (Browser.Engine.gecko && window.console) ? function(msg){console.log(msg)} : function(msg){alert(msg)};
}


/**
 * initExternalLinks
 * Opens external links valid in a new window without the target attribute.
 * 
 * @author CSD (clientsidedevelopers{AT}efocus.nl)
 * @uses <a href="http://www.efocus.nl/" class="external">eFocus</a>
 */
function initExternalLinks() {
	var arrExternalLinks = $$('a.external');
	if (arrExternalLinks.length == 0) return;
	
	arrExternalLinks.each(function(elExternalLink) {
		elExternalLink.addEvent('click', function(event) {
			event.stop();
			window.open(this.get('href'));   
		});
	});
}


/**
 * initFormSubmitButtons
 * 
 * @author Ralph.Meeuws (ralph.meeuws{AT}efocus.nl)
 * @return void
 */
function initFormSubmitButtons() {
	var arrForms = $$('form');
	if (arrForms.length == 0) return;
		
	arrForms.each(function(elForm){
		elForm.getElement('.button').addEvent('click', function(event){
			event.stop();
			elForm.submit();
		});
	});
}



/**
 * initCarDetailGallery
 *
 * shows visual in large container
 *
 * @author phison Do <phison.do{AT}efocus.nl>
 * @return void
 */

function initCarDetailGallery() {
	if(!document.getElement('div.photogallery')) return false;
	
	var drop = document.getElement('.container');
	var arrThumbLists = document.getElement('ul.item_container').getElements('li');
	var arrThumbImages = document.getElement('ul.item_container').getElements('li img');	
	
	arrThumbImages.each(function(elThumbImage){
		elThumbImage.addEvent('click', function() {
			drop.removeEvents();
			drop.empty();
			var cloneThumb = elThumbImage.clone();
			cloneThumb.inject(drop);
		});
	});
	
	arrThumbImages[0].clone().inject(drop);	
}


/**
 * initEqualHeightFixTeasers
 * Fix equal height for teaserblock
 * 
 * @author CSD (phison.do{AT}efocus.nl)
 */
function initEqualHeightFixTeasers() {
	if (!document.getElement('.col_teaser')) return;
	
	var arrTeaserBlocks = $$('.col_teaser');
	var intTeaserBlockHeightMax = 0;
	
	arrTeaserBlocks.each(function(elTeaserBlock){
		if (elTeaserBlock.getHeight() > intTeaserBlockHeightMax) {
			intTeaserBlockHeightMax = elTeaserBlock.getHeight();
		}
	});	
	
	arrTeaserBlocks.each(function(elTeaserBlock){
		elTeaserBlock.setStyle('height', intTeaserBlockHeightMax);
	});		

}



/**
 * CarsOfTheWeekCarousel
 * Animates the header slideshow on the homepage and defines the interaction.
 *
 * @author Ralph Meeuws (ralph.meeuws[AT]efocus.nl)
 * @editor Phi Son do <phison.do{AT}efocus.nl>
 * @param arrSlides, intStartSlide, blnLoop, intInterval, blnAutoPlay, blnPlaying
 * @param strOutEffectProperty, intOutEffectStartValue, intOutEffectEndValue, intOutEffectDuration
 * @param strInEffectProperty, intInEffectStartValue, intInEffectEndValue, intInEffectDuration
 * @param elNav, strLabelPrev, strLabelNext, strLabelFirst, strLabelLast, strLabelPlay, strLabelPause
 * @return EfxNavSlideShow Class instance
 */
function initCarsOfTheWeekCarousel(){
	arrCarousel = $$('.cars_of_the_week');
	if (arrCarousel.length == 0) return;
	
	var elMySs = arrCarousel[0];
	var arrMySlides = elMySs.getElements('.slide');
	
	var elMyNav = elMySs.getElement('.slideshow_nav');

	var objSlideShow = new EfxNavSlideShow({
		arrSlides: arrMySlides,
		elNav: elMyNav,
		intInterval: 4000
	});
}



///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
