// JavaScript Document

		// Script for handling goto's and prev and next
		var SlideDeckAssistant = {
			innerSlideCount: 0,
			/** prevSlide, nextSlide and goToSlide are all custom functions to control progress of the SlideDeck */
			prevSlide: function(theIndex){
				SlideDeckAssistant.goToSlide(theIndex - 1);
			},
			nextSlide: function(theIndex){
				SlideDeckAssistant.goToSlide(theIndex + 1);
			},
			goToSlide: function(theIndex){        
				$('ul.galleryNav li').removeClass('active');
				$('ul.galleryNav li:eq('+ theIndex +')').addClass('active');
				myDeck.goTo(theIndex+1);
				if((theIndex + 1) == SlideDeckAssistant.innerSlideCount){
					// disable the next button
					$('ul.galleryArrows .next').addClass('disabled');
					$('ul.galleryArrows .prev').removeClass('disabled');
				}else if((theIndex + 1) == 1){
					// disable the previous button
					$('ul.galleryArrows .next').removeClass('disabled');
					$('ul.galleryArrows .prev').addClass('disabled');
				}else{
					// enable both next/previous buttons
					$('ul.galleryArrows .next, ul.galleryArrows .prev').removeClass('disabled');
				}
			},
			init: function(){
				SlideDeckAssistant.innerSlideCount = $('.slidedeck_frame dl.slidedeck dd').length;
				/** Store number of slides in SlideDeck */
				$('.slidedeck').append('<ul class="galleryArrows"><li class="prev"><a href="#prev">&larr;<\/a><\/li><li class="next"><a href="#next">&rarr;<\/a><\/li><\/ul>');
				// create navigation element with next and previous buttons
				$('.slidedeck_frame').append('<ul class="galleryNav"><\/ul>');
				// create bullet navigation element
				for (i=0 ; i < SlideDeckAssistant.innerSlideCount ; i++ ) {
					$('ul.galleryNav').append('<li><a href="goto#' + (i+1) + '">' + (i+1) + '<\/a><\/li>');
				}
				// create navigation bullets based on number of slides
				var goToDots = $('ul.galleryNav li a');
				$('ul.galleryNav').css({marginLeft: '-' + (goToDots.outerWidth(true)*goToDots.length / 2) + 'px'});
				// position navigation bullets
				$('ul.galleryNav li:first').addClass('active');
				$('ul.galleryArrows li.prev').addClass('disabled');
				$('ul.galleryNav li a').click(function(e){
					e.preventDefault();
					var theIndex = $('ul.galleryNav li a').index($(this));
					SlideDeckAssistant.goToSlide(theIndex);
					return false;
				});
				// assign click function to navigation bullets
				$('ul.galleryArrows li.prev a').click(function(e){
					e.preventDefault();
					if($(this).parent('li').hasClass('disabled')){
						return false;
					}else{
						var theIndex = $('ul.galleryNav li').index($('ul.galleryNav li.active'));
						SlideDeckAssistant.prevSlide(theIndex);
					}
					return false;
				});
				// assign click function for previous button
				$('ul.galleryArrows li.next a').click(function(e){
					e.preventDefault();
					if($(this).parent('li').hasClass('disabled')){
						return false;
					}
					else{
						var theIndex = $('ul.galleryNav li').index($('ul.galleryNav li.active'));
						SlideDeckAssistant.nextSlide(theIndex);
					}
					return false;
				});
				//assign click function for next button
		}
		};
		
		$(document).ready(function(){
			SlideDeckAssistant.init();
		});
			
		/** Initiate the SlideDeck */
		var myDeck = $('.slidedeck_frame dl.slidedeck').slidedeck({
			hideSpines: true,
            autoPlay: true,
			autoPlayInterval: 5000,
            cycle: true,
			speed: 480,
            /**
             * The complete function is executed after each slide animation.
             * here we are using it to upate the navigation dots.
             */
            complete: function(deck){
				$('ul.galleryNav li').removeClass('active');
				$('ul.galleryNav li:eq('+ ( deck.current - 1 ) +')').addClass('active');
				/** Update current slide indicator after each slide animation completes */
            }
		})
			
			
