/**
 * Bootstrap.js - JavaScript bootstrapper
 * 
 * @author Webstores <info at webstores dot nl>
 *         Copyright (c) Webstores internet totaalbureau <http://www.webstores.nl/>
 */
$(document).ready(function() {
	
	$(document.body).addClass('js');
	
	// 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 svycCompactConfig = ($(document.body).hasClass('section-home') || $(document.body).hasClass('section-product')) ? {
		autoSize: false,
		width: 470,
		height: 360,
		auto: 4
	} : {
		auto: 4
	};
	
	var svyc = new YouTubeCarousel('#spotlight-visuals', svycCompactConfig);
	
	// Togglers
	$('.accordion').each(function() {
		switch(this.id) {
			case 'company-info-accordion':
				new Toggler(this, {
					allowMultiple: false
				}).expand($(this).find('div:first-child'));
				break;
			default:
				new Toggler(this);
				break;
		}
	});
	
	// YouTube
	$('.youtube:not(#spotlight .youtube)').each(function() {
		new YouTubePlayer(this);
	});
	
	// Validation
	$('form.generated').validate();
	
	// Network form
	$('#network-form select').change(function() {
		if($(this).val().indexOf('http://') != -1) {
			window.open($(this).val());
		}
	});
	
	// Shadowbox
	Shadowbox.init({
		overlayOpacity: 0.8,
		troubleElements: ['select']
	});
});
