/* Author: 		Thom van den Hork :: Jaarsma de Boer
 * Customer:	DieZit
 * Date:		22-03-2011
 */
$(document).ready(function(){
	backgroundImages.init();
	
	if($('html').hasClass('ie7') !== true) {
		menu.init();
		
		$(window).resize(function(){
			menu.init();
		});
	}
});

var backgroundImages = {

	navigation : null,
	container : null,
	itemWidth : 2560,
	timeoutID : null,
	timeout : 10000,
	slideSpeed : 1500,
	
	/**
	 * Init functie van dit object
	 */
	init : function() {
		this.navigation = $('#background-images-navigation');
		if(this.navigation.size() > 0) {
			this.navigation.find('a:first').addClass('current');
			this.navigation.find('a').live('click',function(){
				backgroundImages.slideTo(this);
				return false;
			});
			this.container = $('#background-images-container');
			this.autoSlide();
		}
	},
	
	
	/** 
	 * Slide naar een bepaalde div toe
	 */
	slideTo : function(o,s,b) {
		
		// Clear timeout
		clearTimeout(backgroundImages.timeoutID);
		
		// Manual slide
		if(typeof(o) === 'object') { 
			o = $(o);
		}
		
		// Auto slide
		else {
			o = backgroundImages.navigation.find('a.current');
			if(o.next().size() > 0) o = o.next();
			else o = backgroundImages.navigation.find('a:first');
		}
		
		backgroundImages.navigation.find('a.current').removeClass('current');
		o.addClass('current');
		s = backgroundImages.container.find('> div:lt('+o.index()+')');
		b = backgroundImages.container.find('> div:gt('+o.index()+'), > div:eq('+o.index()+')');
		

		/** BOF : CSS Animatie **/
		if(Modernizr.csstransitions === true) {
			
			// Inklappen van alle slides die ervoor staan
			s.addClass('shut');
			
			// Uitklappen van alle overige slides
			b.removeClass('shut');
			backgroundImages.animationCallback();
		} 
		/** EOF : CSS Animatie **/
		
		/** BOF : Javascript animatie **/
		else {
			
			// Inklappen van alle slides die ervoor staan
			s.animate({
				'width' : 0
			},backgroundImages.slideSpeed,'easeOutQuint',backgroundImages.animationCallback);
			
			// Uitklappen van alle overige slides
			b.animate({
				'width' : backgroundImages.itemWidth
			},backgroundImages.slideSpeed,'swing',backgroundImages.animationCallback);

		}
		/** EOF : Javascript animatie **/
	},
	
	/**
	 * Zorgt voor de eerste keer autoSlide
	 * De rest wordt gedaan door de slideTo functie
	 */
	autoSlide : function() {
		backgroundImages.timeoutID = setTimeout(backgroundImages.slideTo,backgroundImages.timeout);
	},
	
	/**
	 * Callback voor na de animatie
	 * Zorgt ervoor dat er weer een nieuwe timeout wordt geset
	 */
	animationCallback : function() {
		clearTimeout(backgroundImages.timeoutID);
		backgroundImages.timeoutID = setTimeout(backgroundImages.slideTo,backgroundImages.timeout);
	}
}

/**
 * 	Zorgt ervoor dat het menu altijd bovenaan blijft staan
 */
var menu = {
	
	item : null,
	offsetLeft : 849,
	
	containerWidth : null,
	
	init : function() {
				
		this.item = $('#navigation');
		this.containerWidth = $('#container').attr('clientWidth');
		this.left = (((menu.containerWidth - 1000)/2) + menu.offsetLeft);
		
		this.item.css({
			'position' : 'fixed',
			'left' : menu.left
		});
		
	}
}
























