jQuery.support.placeholder = (function(){
    var i = document.createElement('input');
    return 'placeholder' in i;
})();

$(document).ready(function(){
	
	// Show login box on login-button click
	$('a#account-button-login').click(function(event) { 
		event.preventDefault();
		$('#account-login').toggle();$(this).toggleClass('active');
	});
	
	// Apply Fancybox to links with Fancybox class
	$("a.fancybox_gallery").attr('rel','fancybox_gallery').fancybox({
		transitionIn	: 'elastic',
		transitionOut	: 'elastic',
		easingIn      	: 'swing',
		easingOut     	: 'swing',
		autoScale		: true,
		titlePosition	: 'inside'
	});
	
	// Apply Fancybox to links with Fancybox class
	$("a.fancybox").fancybox({
		transitionIn	: 'elastic',
		transitionOut	: 'elastic',
		easingIn      	: 'swing',
		easingOut     	: 'swing',
		height			: '75%',
		width			: 600,
		autoDimensions	: false
	});
	
	// Apply Fancybox to links with Fancybox class
	$("a.fancybox_iframe").fancybox({
		type			: 'iframe',
		transitionIn	: 'elastic',
		transitionOut	: 'elastic',
		easingIn      	: 'swing',
		easingOut     	: 'swing',
		height			: '95%',
		width			: 880,
		autoDimensions	: false
	});
	
	// Style images from CMS content
	$("div#content img[align=right]").addClass('image-align-right');	
	$("div#content img[align=left]").addClass('image-align-left');
	
	// Make both columns same height to show dotted border correctly
	if ($('div#content-left')) {
		contentHeight = $('div#content').height();
		contentLeftHeight = $('div#content-left').height();
		
		if (contentHeight > contentLeftHeight) {
			$('div#content-left').css('min-height', contentHeight + 'px');
		};
	};
	
	// Validate forms
	$(".validate").each(function(){
		$(this).validate();
	});
	
	// jCarousel on home page
	$('#home-gallery').jcarousel({wrap: 'circular', scroll: 1});
	
	// Quotes in footer on home page
	$('#footer-quotes').jcarousel({vertical : true, auto:5, scroll: 1, wrap: 'circular', buttonNextHTML: 'NULL', buttonPrevHTML: 'NULL'});
	
	//Gallery category links
	$('a.gallery-change-category').click(function(event){
		// Prevent navigating to href
		event.preventDefault();
		if($(this).hasClass('not-active')){
			$('div#content').append('<div id="gallery-loading"></div><div id="gallery-loading-image"></div>');
			// Load new category
			$('div#content').load('/dsp_homepage.cfm' + $(this).attr('href') + '&ajaxRequest=1', function(){
				$('#home-gallery').jcarousel({wrap: 'circular', scroll: 1});
				$('#gallery-loading, #gallery-loading-image').remove();
				$("#home-gallery a.fancybox").fancybox({
					transitionIn	: 'elastic',
					transitionOut	: 'elastic',
					easingIn      	: 'swing',
					easingOut     	: 'swing',
					height			: '75%',
					width			: 600,
					autoDimensions	: false
				});
				
				$("#home-gallery a.fancybox_iframe").fancybox({
					type			: 'iframe',
					transitionIn	: 'elastic',
					transitionOut	: 'elastic',
					easingIn      	: 'swing',
					easingOut     	: 'swing',
					height			: '95%',
					width			: 880,
					autoDimensions	: false
				});
				if($('li.home-gallery-item').size() < 6){
					$('.jcarousel-prev').hide();
					$('.jcarousel-next').hide();
				};
			});
			// Add active class to indicate active category
			$('a.gallery-change-category').removeClass('active').addClass('not-active');
			$(this).addClass('active').removeClass('not-active');
			$('.language_nl .moreinfolink').hide();
			$('#div_'+$(this).attr('id').replace('cat_','')).show();
		};
	});
});

