/* gt:javascript */
$(function(){
	var slideAnimationTime = 600;
	var noteCounter = new Array();
	var defaultNoteHtml = '';
	var closeNoteHtml = '';
	var monitor = $('#NoteDisplay');
	$(document).ready(function(){ defaultNoteHtml = monitor.html();});
	$('#logo').bind('click',function(event){
		event.preventDefault(); $(this).blur(); 
		resetSlidesAndNotes();
	});
	/* handle note switching */
	$('a.SlideSwitch').bind('click', function(event){
		/* modify default behavior */
		event.preventDefault();
		$(this).blur();
		/* identify the slide to open */
		var slideId = $(this).attr('id').replace('Switch', '');
		var activeSlide = $("#" + slideId);
		if (!activeSlide.is(':visible'))
		{
			/* close all previous slides */
			$('.slide').hide();
			/* set event listener for the close button action */
			activeSlide.find('a.CloseSlideSwitch').bind('click', function(){ 
				activeSlide.slideUp(slideAnimationTime);
				monitor.html(closeNoteHtml.toString());
			});
			activeSlide.slideDown(slideAnimationTime);
			/* display the notes per slide */
			var noteContainer = $('#'+slideId).find('.notes');
			var notes = $("#"+slideId).find('.notes > div');
			if (typeof noteCounter[slideId] == 'undefined')
			{
			 	noteCounter[slideId] = 0;
			} else {
				if (noteCounter[slideId] == 0)
				{
					noteCounter[slideId] = 1;
				} else {
					if (noteCounter[slideId] < (notes.length - 1))
						noteCounter[slideId] += 1;
					else
						noteCounter[slideId] = 0;
				}
			}
			notes.hide();
			var child = noteCounter[slideId] + 1; 
			var thisNote = noteContainer.find('div:nth-child(' + child.toString() + ')');
			var html = (
				'<div class="note">' 
				+ thisNote.children('.note-message').html() 
				+ '</div>'
				);
		 	closeNoteHtml = (
				'<div class="note">' 
				+ thisNote.children('.note-close-message').html() 
				+ '</div>'
				);
		} else {
			
			activeSlide.slideUp(slideAnimationTime);
			html = closeNoteHtml.toString();
		}
		monitor.html(html);
	});
	function resetSlidesAndNotes()
	{
		$('.slide').hide();
		monitor.html(defaultNoteHtml.toString());
	}
});
