$(document).ready(function () {
	
	window.setTimeout(function() {
		equalHeight();
		$('body').toggleClass('tickle');
	}, 500);
	
    languageNav();
    zIndexFix();
    locationLoader();
    setCorrectGridForTeaser();
	resizeSlider();

    jQuery('input').Placeholders();

    Shadowbox.init({
        overlayOpacity: 0.7,
        players: ["img", "flv", "mp4", "swf"],
		counterType: 'skip'
    });
	
    jQuery('div.googlemaps').StoreLocator({
        el: 'googlemaps',
        cssHeight: '370px',
        cssWidth: '660px',
        geolocation: false,
        getStreet: '.street-address',
        getPostal: '.postal-code',
        getCity: '.locality',
        getInput: '#starting-point',
        idDataHolder: '#data',
        idMapsHolder: '#maps',
        idRouteHolder: '#route',
        idRouteBtn: '#submitRoute',
        zoom: 15
    });
	
	$('a[class*=external]').bind({
		'click': function(e) {
			if(e.which > 1) return;
			e.preventDefault();
			window.open(this.href, '');			
		}
	});

	var slideshow = new Pushbox($('ul.slideshow li'), {
		'navigation': false
	});

	$('div.slideshow-nav a.prev').click(function() {
		slideshow.showSlide('prev');
	});

	$('div.slideshow-nav a.next').click(function() {
		slideshow.showSlide('next');
	});


});


function resizeSlider(){
	var elSlider =  $('.viewport-slideshow');
	var elSliderImage = $('img', elSlider)[0];
	var sliderImageWidth = $(elSliderImage).width();
	var sliderImageheight = $(elSliderImage).height();
	
	$(elSlider).css({
		width: sliderImageWidth,
		height: sliderImageheight 
	});
	$(elSlider).prev().css({
		width: '640'- sliderImageWidth
	});
	$('h3',elSlider).css({
		width: sliderImageWidth -90 //min 2 knoppen en de padding op h3
	});
	
	
}


(function(){
	/*
	 * jQuery placeholder
	 * place holder functionality for browsers which don't support placeholder attribute
	 * otherwise HTML5 will handle this
	 * needs placeholder attribute <input placeholder="Zoek...">
	 *
	 * @author Lee Boonstra, <lee.boonstra@efocus.nl>
	 * @since 21 jan 2011
	 * @version 1.0
	 * @copyright eFocus
	 *
	 * @uses jQuery 1.2.6, <http://www.jquery.com> or higher
	 */
	$.fn.InputPlaceHolder = function(){
		var e = $(this);
		var strSavedString = "";
		
		/*
		 * Does the browser support placeholder attribute?
		 * @return boolean
		 */
		function isBrowserSupport(){
			var i = document.createElement("input");
			return "placeholder" in i;
		}
		if(!isBrowserSupport()){
			return this.each(function(){	
				var strPlaceHolderText = $(this).attr("placeholder");
				
				if(e.val().length == 0){
					e.val(strPlaceHolderText);	
				}
				
				/*
				 * On field focus remove placeholder if there is no written text in it.
				 * @return void
				 */
				e.focus(function(){
					strSavedString = e.val();
					if (strSavedString === strPlaceHolderText) {
						e.val("");	
					}
				});
				
				/*
				 * Save the written text in a variable
				 * @return void
				 */
				e.change(function(){
					strSavedString = e.val();
				});
				
				/*
				 * While leaving the focus of the field, put the placeholder back
				 * or the written text.
				 * @return void
				 */
				e.blur(function(){
					if(strSavedString !== strPlaceHolderText && strSavedString !== ""){
						e.val(strSavedString);		
					} else {
						e.val(strPlaceHolderText);
					}
				});
			});
			
		}
	};
})(jQuery);

/*
 * Set the equal height per row.
 * @author Kristiaan Thivessen, <kristiaan.thivessen@efocus.nl>
 * @since 22 aug 2011
 * @copyright eFocus
 *
 * @uses jQuery 1.6.2, <http://www.jquery.com> or higher
 * @param els: optional jQuery object to look for .equal classes inside
 */
 
function equalHeight(els) {
	if (!els) els = $('.equalize');
    els.each(function () {
        var max = 0;
        var children = $('.equal', this);
		// determine the tallest child
        children.each(function () {
            var h = $(this).outerHeight();
            if (h > max) max = h;
        });
		// set all children to the tallest child
        children.each(function () {
            var a = $(this);
            var val = max - (a.outerHeight() - a.height());
            a.css({ minHeight: val + 'px' });
        });
    });
}


/*
 * SetCorrectGridForTeaser
 * @author Lee Boonstra, <lee.boonstra@efocus.nl>
 * @since 9 aug 2011
 * @version 1.0
 * @copyright eFocus
 *
 * @uses jQuery 1.6.2, <http://www.jquery.com> or higher
 */

function setCorrectGridForTeaser() {
    var arrTeasers = jQuery('.teaser');

    arrTeasers.each(function () {
        var parent = jQuery(this).parent('div');
        var parentOfParent = jQuery(parent).parent('div');

        if (jQuery(parentOfParent).hasClass('col-9')) {
            jQuery(parent).removeClass('col-4');
            jQuery(parent).addClass('col-3');
        }
    });
}
    
/*
 * Language nav animation
 * @author Martijn de Valk, <martijn.de.valk@efocus.nl>
 * @since 28 jul 2011
 * @version 1.0
 * @copyright eFocus
 *
 * @uses jQuery 1.6.2, <http://www.jquery.com> or higher
 */
 
function languageNav() {

    var startHeight = $('.language-nav').height();
    var endHeight = $('.language-nav ul').height();

    $('.language-nav').hover(function () {
        $(this).stop(true).animate({
            height: endHeight
        }, 100);

    }, function () {
        $(this).stop(true).animate({
            height: startHeight
        }, 100);
    });
}

/*
 * ie7 footer bug fix
 * @author Martijn de Valk, <martijn.de.valk@efocus.nl>
 * @since 11 aug 2011
 * @version 1.0
 * @copyright eFocus
 *
 * @uses jQuery 1.6.2, <http://www.jquery.com> or higher
 */

function zIndexFix() {

    if ($.browser.msie) {
        $(".groups ul li").hover(function () {
            $("#footer-container .wrapper").css("zIndex", "-1");
        }, function () {
            $("#footer-container .wrapper").css("zIndex", "0");
        });
    }
}

/*
 * add onchange event on location selectbox
 * @author Richard van Yperen, <richardvy@efocus.nl>
 * @since 11 aug 2011
 * @version 1.0
 * @copyright eFocus
 *
 * @uses jQuery 1.6.2, <http://www.jquery.com> or higher
 */

function locationLoader() {
    $('#location').change(function () {
        window.location.href = $(this).val();
    })
}

