﻿jQuery.noConflict();
var $j = jQuery;

//  initialize the slideshow when the DOM is ready 
jQuery(document).ready( function(){ //alert('DOM is Ready');
	//setTimeout('GoogleMaps()', 500)

});

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

}



