
// When the DOM is ready
$('document').ready(function(){

	/* -- Fancybox -- */

	// Set Fancybox defaults
	$.fn.fancybox.defaults.overlayColor = '#000';
	$.fn.fancybox.defaults.overlayOpacity = 0.7;
	$.fn.fancybox.defaults.hideOnContentClick = false;
	$.fn.fancybox.defaults.padding = 0;
	$.fn.fancybox.defaults.titlePosition = "inside";
	$.fn.fancybox.defaults.centerOnScroll = true;
	
	// Activate Fancybox links
	$('a.fancybox').fancybox();
	
	// Links to privacy policy
	$('a.fancybox-iframe').each(function() {
		$(this).fancybox({
			type   : 'iframe',
			href   : $(this).attr('href') + '?viewmode=iframe',
			width  : 650,
			height : 650
		});
	});
	
	/* -- Thumbnails -- */

	// Fade in thumbnail images
	$('.tile a, .fancybox, .thumbnail').children('img').FadeInImageOnLoad();
	
	// Input hints
	$('#search-input').inputHint();
	
	/* -- Password fields (strength indicator) -- */

	// Password fields:
	$('.field-password-strength').keyup(function() {
		console.log('ts');
		// get a reference to the field:
		var $t = $(this);

		// If the password is not empty:
		if(jQuery.trim($t.val()) != '') {
			// Get the password's strength:
			$.ajax({
				url : jQueryBaseHref + '/account/password-strength',
				data : {
					password : $t.val()
				},
				success : function(data) {
					$('.password-strength', $t.parent()).remove();
					$t.after(data);
				}
			});
		}
	});

	/* -- Footer slider -- */
	
	 $('#footer-slider').cycle({
		 fx: 'scrollDown',
		 speed: 400,
		 timeout: 6000
	 });
});

/**
 * Toggle a html-element
 * 
 * This function will show or hide (animated) a element
 *
 * @param element jQuery element
 * @param bool TRUE to show, FALSE to hide
 * @return void
 */
function toggleElement(element, displayFlag, speed) {
	if (!$(element).is(':animated')) {
		(displayFlag) ? $(element).stop().slideDown(speed) : $(element).stop().slideUp(speed);
	}
}
