/**
 * Bootstrap.js - JavaScript bootstrapper
 * 
 * @author Webstores <info at webstores dot nl>
 *         Copyright (c) Webstores internet totaalbureau <http://www.webstores.nl/>
 */
$(document).ready(function() {
	
	// Utilities
	WS.Util.externalLinks();
	WS.Util.rowClick();
	WS.Util.fixPlaceholders();
	
	// Messages
	MessageBar.init();
	
	// IE6 fixes
	if(/msie 6/i.test(navigator.userAgent)) {
		MessageBar.show('warning', '<h1>U gebruikt een zeer oude versie van Internet Explorer</h1><p>Voor een optimale ervaring is het aan te raden om de <a href="http://www.microsoft.com/netherlands/windows/internet-explorer/" title="De laatste versie van Internet Explorer downloaden" rel="external">laatste versie van Internet Explorer</a> te installeren, of te kiezen voor een alternatieve browser zoals <a href="http://www.mozilla.com/firefox/" title="Mozilla Firefox downloaden" rel="external">Firefox</a>, <a href="http://www.google.com/chrome" title="Google Chrome downloaden" rel="external">Chrome</a>, <a href="http://www.apple.com/nl/safari/" title="Apple Safari downloaden" rel="external">Safari</a> of <a href="http://www.opera.com/" title="Opera downloaden" rel="external">Opera</a>.</p>');
		WS.Util.fixIE6HoverList();
	}
	
	// AJAX loading
	$(document.body).ajaxStart(function() {
		$(this).addClass('loading');
	}).ajaxComplete(function() {
		$(this).removeClass('loading');
	});
	
	// Carousels
	var syc = new YouTubeCarousel('#spotlight-visuals');
	
	/*if($('#spotlight-visuals').length) {
		$('#spotlight-visuals').jcarousel({
			scroll: 1,
			animation: 'slow',
			auto: 7,
			wrap: 'both',
			initCallback: function(carousel) {
				$('#spotlight-controls li').each(function(i) {
					$(this).bind('click', function(e) {
						e.preventDefault();
						carousel.stopAuto();
						carousel.scroll(i + 1);
						carousel.startAuto();
					});
				});
				
				carousel.clip.hover(function() {
					carousel.stopAuto();
				}, function() {
					carousel.startAuto();
				});
			},
			itemVisibleInCallback: {
				onBeforeAnimation: function(carousel, slide, index, state) {
					$('#spotlight-controls li:nth-child(' + index + ')').addClass('selected');
				}
			},
			itemVisibleOutCallback: {
				onBeforeAnimation: function(carousel, slide, index, state) {
					$('#spotlight-controls li:nth-child(' + index + ')').removeClass('selected');
				}
			}
		});
	}*/
	
	// Galleries
	var referenceGallery = new Gallery('#reference-gallery', {
		onAfterItemChange: function(el, index) {
			$('.gallery .gallery-image-zoom').attr('href', $(el).attr('href').replace("/gallery/", "/max/"));
			Shadowbox.setup('.gallery .gallery-image-zoom');
		}
	}); 
	
	// Togglers
	$('.accordion').each(function() {
		switch(this.id) {
			/*case 'whatever-accordion':
				new Toggler(this).expand($(this).find('li:first-child'));
				break;*/
			default:
				new Toggler(this);
				break;
		}
	});
	
	// YouTube players
	$('.youtube:not(#spotlight .youtube)').each(function() {
		new YouTubePlayer(this);
	});
	
	// Validation
	$('form').each(function() {
		$(this).validate({
			highlight: function(el, errorClass, validClass) {
				var errorEl = null;
				
				switch(el.type) {
					case 'radio':
						errorEl = $(el).parents('.options');
						break;
					case 'checkbox':
						errorEl = $(el).parent();
						break;
					default:
						errorEl = $(el);
						break;
				}
				
				errorEl.removeClass(validClass).addClass(errorClass);
			},
			unhighlight: function(el, errorClass, validClass) {
				var errorEl = null;
				
				switch(el.type) {
					case 'radio':
						errorEl = $(el).parents('.options');
						break;
					case 'checkbox':
						errorEl = $(el).parent();
						break;
					default:
						errorEl = $(el);
						break;
				}
				
				errorEl.removeClass(errorClass).addClass(validClass);
			}
		});
	});
	
	// Checkout form
	var cf = new CheckoutForm('#checkout');
	
	// Shadowbox
	Shadowbox.init({
		overlayOpacity: 0.8,
		troubleElements: ['select']
	});
});
