
// Automatically calls all functions in HOME.init
jQuery(document).ready(function() {
	HISTORY.global();
});

// Module pattern:
// http://yuiblog.com/blog/2007/06/12/module-pattern
var HISTORY = (function($) {
	return {
		// Start It
		global: function() {
			for (var i in HISTORY.init) {
				HISTORY.init[i]();
			}
		},



		
		init: {
		
		
			do_auto: function()
			{
				HISTORY.auto();
			},
		
		
		
		
		
		
			set_vars: function()
			{
					callout_positions = new Array();
					callout_positions = {
						'li#foot img.icon' : {
							'left'	: 1068,
							'top'	: 624,
						},
						'img#egg img.icon' : {
							'left'	: 1126,
							'top'	: 979,
						},
						'img#coffee img.icon' : {
							'left'	: 7,
							'top'	: 189,
						},
						'img#box img.icon' : {
/*
							'left'	: 6,
							'top'	: 262,
*/
						}
					};
						
					HISTORY.callout_positions = callout_positions;				
			},
		

			/* Triggers for the history icons */
			icon_trigger: function() 
			{				
				$('img.icon').hover(function(){
					HISTORY.icon_active($(this));
				}, function(){
					HISTORY.icon_inactive($(this));
					
				});

				$('img.icon').click(function(){
					HISTORY.callout_insert($(this));
				});




			}
			
		
		
		
		},	/*	End Init	*/
		



		callout_insert: function(el)
		{
		
		
			// Get id of current callout
			var id = el.parent('li').attr('id');
			var active = el.parent('li.active');
			var current_num = '';
				

			
			$('li div.callouts').stop().fadeOut(500);
			
			// Make triggered element active.
			$('li#' + id).addClass('active');


			$('li.active div.callouts').stop().fadeIn(1000, function(){
			
				// Do the auto	
				setTimeout(function(){		
				    HISTORY.auto();
				}, 10000);
			
			
			});
			
			
			
					
			
			
			
		
		},
		
		
		
		
		
		
		
		icon_active: function(el)
		{
			var parent = el.parent('li');	
			id = $(parent).attr('id');

/*
			var left 	= HISTORY.callout_positions[id]['left'];
			var top 	= HISTORY.callout_positions[id]['top'];
*/

			$(parent).children('img.icon').stop().animate({
				width: 	'67px',
				height: '67px',
				left: 	parseInt(left - 6) +'px',
				top: 	parseInt(top - 5) +'px'
			}, 100);
			
			
			
		},


		
		icon_inactive: function(el)
		{
			var parent = el.parent('li');	
			id = $(parent).attr('id');
			
			var left 	= HISTORY.callout_positions[id]['left'];
			var top 	= HISTORY.callout_positions[id]['top'];
					
			$(parent).children('img.icon').stop().animate({
				width: 	'60px',
				height: '60px',
				left: 	left +'px',
				top: 	top +'px'
			}, 100);	
			
			
			
				
		},
		
		
		
		
		
			auto: function()
			{
				var el = $('ul.slides');

				// Determine active one, move forward -- one iteration
				if ($(el).children('li.active').length > 0)
				{				
					var active = $(el).children('li.active');
					
					// Get the next one, 
					var next = $(active).next().attr('id');

					setTimeout(function(){
						// Remove Class
						$(active).removeClass('active');
						
						// Make next active
						HISTORY.callout_insert($('li#'+next).children('img.icon'));
					
					
					}, 1000);
					
				} else {
				
					var active = $('ul.slides li:first-child');
					
					// Show them.
					HISTORY.callout_insert($(active).children('img.icon'));
									
				
				
				
				
				}
				
				
			
			
			}
		
		
		
	
	
	
		
	
	
		
		
	};	
		
		
// Pass in jQuery ref.
})(jQuery, this);







