/**
 * 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');
	});
	
	// 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;
		}
	});
	
	// Validation
	$('form.generated').validate();
	
	// Shadowbox
	Shadowbox.init({
		overlayOpacity: 0.8,
		troubleElements: ['select']
	});
	
	// Carousel
	jQuery(document).ready(function() {
	    jQuery('#spotlight-items').jcarousel({
			scroll: 1,
    		animation: 'slow',
    		auto: 5,
    		wrap: 'both',
    		buttonNextHTML: null,
    		buttonPrevHTML: null,
    		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: function(carousel, slide, index, state) {
    			$('#spotlight-controls li:nth-child(' + index + ')').addClass('selected');
    		},
    		itemVisibleOutCallback:function(carousel, slide, index, state) {
    			$('#spotlight-controls li:nth-child(' + index + ')').removeClass('selected');
    		}
		});
	});
	
	// Tabs
	if($("#homepage-tabs").length > 0) {
		$(function() {
			$("#homepage-tabs").tabs();
		});
	}
});
