/**
 * 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.fixExternal();
	WS.Util.rowClick();
	WS.Util.fixPlaceholders();
	
	// AJAX loading
	$(document.body).ajaxStart(function() {
		$(this).addClass('loading');
	}).ajaxComplete(function() {
		$(this).removeClass('loading');
	});
	
	// Carousels
	var syc = new YouTubeCarousel('#spotlight-items');
	
	/*if($('#spotlight-items').length) {
		$('#spotlight-items').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');
				}
			}
		});
	}*/
	
	// 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;
		}
	});
	*/
	$('.accordion').accordion();
	
	// YouTube players
	$('.youtube:not(#spotlight .youtube, .spotlight .youtube)').each(function() {
		new YouTubePlayer(this);
	});
	
	// Spotlight youtube player
	$('.spotlight .youtube').each(function() {
		new YouTubePlayer(this, {height: 330, aspectRatio:16/10});
	});
	
	// Tickers
	$('.ticker').each(function() {
		new Ticker(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);
			}
		});
	});
	
	// Shadowbox
	Shadowbox.init({
		overlayOpacity: 0.8,
		troubleElements: ['select']
	});
	
	// Analytics
	$('a.banner').each(function() {
		try {
			_gaq.push('_trackEvent', 'Banners', 'display', this.title);
		} catch(error) {}
		
		$(this).click(function(e) {
			e.preventDefault();
			
			try {
				_gaq.push('_trackEvent', 'Banners', 'click', this.title);
				
				setTimeout(function() {
					window.location = this.href;
				}, 100);
			} catch(error) {}
		});
	});
		
	$('.post').hover(
		function(){
			$('.body img', this).animate({
				opacity: 0.8
			},300);
			
			$('.body .info', this).animate({
				bottom: '0px'
			},300);
		},
		function(){
			
			$('.body img', this).animate({
				opacity: 1
			},300);
			
			$('.body .info', this).animate({
				bottom: '-30px'
			},300);
		}
	);
});
