/////////////////////////////////////////// BASIC FUNCTIONS, DON'T EDIT ///////////////////////////////////////////
var photoGalleryHtml;

/**
 * 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 arrThumbLists;
	var arrThumbImages;
	
	var drop = document.getElement('.container');
	if($chk(document.getElement('ul.item_container'))) {
		arrThumbLists = document.getElement('ul.item_container').getElements('li');
		arrThumbImages = document.getElement('ul.item_container').getElements('li img');	
	}

	if($chk(arrThumbImages) && $chk(arrThumbImages[0])) {
		arrThumbImages.each(function(elThumbImage){
			elThumbImage.addEvent('click', function() {
				drop.removeEvents();
				drop.empty();
				var cloneThumb = elThumbImage.clone();
				cloneThumb.inject(drop);
			});
		});
		
		arrThumbImages[0].clone().inject(drop);	
	}
	var photoGallery = $$('div.photogallery');
	if($chk(photoGallery) && $chk(photoGallery[0])) {
		photoGalleryHtml = photoGallery[0].innerHTML;
	}
}


/**
 * 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');

	if(elMyNav == null) {
		var objSlideShow = new EfxNavSlideShow({
			arrSlides: arrMySlides,
			elNav: elMyNav,
			intInterval: 0
		});	
	} else {
		var objSlideShow = new EfxNavSlideShow({
			arrSlides: arrMySlides,
			elNav: elMyNav,
			intInterval: 4000
		});
	}
}



///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
