/**
 * Witveld Bloembinders
 * Copyright (c) 2007-2010
 * 
 * @author		Tim Kurvers <tim@moonsphere.net>
 * @copyright	2007-2010 Tim Kurvers
 * @link		http://www.witveld.nl
 */

/**
 * Witveld Class
 */
var Witveld = function() {

	/**
	 * Sloppy accessible singleton
	 */
	Witveld.instance = this;
	
	/**
	 * Animation speed
	 */
	this.SPEED = 750;
	
	/**
	 * Reference to this Witveld object
	 */
	var self = this;
	
	/**
	 * Witveld Constructor
	 */
	var _construct = function() {
		_blocker();
		_hovers();
		self.show(1, false);
	};
	
	/**
	 * Removes the blocker after a second of rendering time
	 */
	var _blocker = function() {
		$('#blocker').animate({opacity: 0}, {duration: self.SPEED + 500, queue: false, complete: function() {
			$(this).css('display', 'none');
		}});
	};
	
	/**
	 * Sets up hovers for the Witveld boxes
	 */
	var _hovers = function() {
		$('.box').hover(function() {
			self.show($(this).index() + 1);
		});
	};
	
	/**
	 * Forces the eyecatcher to disappear & enters the website in consequence
	 */
	this.enter = function() {
		$('#eyecatcher').animate({opacity: 0}, {duration: self.SPEED, queue: false, complete: function() {
			$(this).css('display', 'none');
		}});
	};
	
	/**
	 * Shows the box specified by index
	 */
	this.show = function(index, animate) {
		index = (index === undefined) ? 1 : index - 1;
		animate = (animate === undefined) ? true : animate;
		$('.box').each(function() {
			if(index === $(this).index()) {
				$(this).addClass('hover');
			}else{
				$(this).removeClass('hover');
			}
		});
		$('#visuals img').each(function() {
			var value = 0;
			if(index === $(this).index()) {
				value = 1;
			}
			if(animate) {
				$(this).animate({opacity: value}, {duration: self.SPEED, queue: false});
			}else{
				$(this).css('opacity', value);
			}	
		});
	};
	
	_construct();

};

