/*********************************
* Copyright 2010 Web Services Corp
* Written by: Richard Sharp
* Version 1.1
*********************************/

/******** Configuration *********/
// Change any of the values below

// how long the slide transitions shoud last, in milliseconds (1000=1 second)
var iWSCSlideTransitionSpeed=500;

// how long the menu fade in/out transition should last, in milliseconds
var iWSCMenuFadeSpeed=300;

// how long to wait before automatically advancing to the next slide, in milliseconds.
// if set to 0, slides will not automatically advance
var iWSCAutoAnimationSpeed=6000;

//whether or not to use the fade in/out animation
var bWSCUseFadeAnimation=false;

//whether or not to display a "next" button
var bWSCUseShowNextButton=false;


/******** Configuration *********/
// Don't change anything below this point


var iWSCCurrentSlide=0;
var iWSCSliderHeight;
var iWSCSliderWidth;
var iWSCTotalSlides;
var iWSCInterval;

//initialize everything
(function($) {
	$(function() { //on DOM ready
		
		//get the container dimentions
		iWSCSliderHeight=$("#SliderContainer").height();
		iWSCSliderWidth=$("#SliderContainer").width();
		
		//make sure all slides are the same dimentions as the container, and move them to the right of the container (out of view)
		$(".Slide").css({"left":iWSCSliderWidth + "px","width":iWSCSliderWidth + "px","height":iWSCSliderHeight + "px"});
		
		//get the total number of slides
		iWSCTotalSlides=$(".Slide").length;
		
		//set it on the first slide
		$(".Slide:first").css("left","0px");
		
		//create the navigation links
		$('<div id="SliderNav"></div>').appendTo($("#SliderContainer"));
		if(bWSCUseShowNextButton) {
			$("#SliderNav").append('<a href="#" onclick="nextSlide();stopAutoAnimation();return false;" class="SlideButton">&gt;</a>');
		}
		for(i=iWSCTotalSlides ; i >0 ; i--) {
			$("#SliderNav").append('<a href="#" onclick="goToSlide(' + (i-1) + ');stopAutoAnimation();return false;" class="SlideButton">' + (i) + '</a>');
		}
		
		//set up the navigation fade in/out for mouse enter and leave
		if(bWSCUseFadeAnimation) {
			$("#SliderContainer").bind("mouseenter",function() {
				$(".SlideButton").stop().animate({"-ms-filter":"progid:DXImageTransform.Microsoft.Alpha(Opacity=100)","filter":"alpha(opacity=100)","-moz-opacity":"1","opacity":"1"},iWSCMenuFadeSpeed,'swing');
			 }).bind("mouseleave",function() {
				$(".SlideButton").stop().animate({"-ms-filter":"progid:DXImageTransform.Microsoft.Alpha(Opacity=30)","filter":"alpha(opacity=30)","-moz-opacity":".30","opacity":".30"},iWSCMenuFadeSpeed,'swing'); 
			 });
		}
		
		 setNavigationSlide();
		
		//start auto-advancing the slides
		if(iWSCAutoAnimationSpeed>0) {
			iWSCInterval=setInterval(nextSlide,iWSCAutoAnimationSpeed);
		}
	});
})(jQuery);
function nextSlide() {
	//get a reference to the current slide, then increment the slide number
	var oCurrentSlide=$(".Slide:eq(" + iWSCCurrentSlide + ")");
	iWSCCurrentSlide++;
	
	//if the current slide was the last slide, then the "next" slide will be the first one
	if(iWSCCurrentSlide==iWSCTotalSlides) iWSCCurrentSlide=0;
	
	//make sure the next slide is in the correct position
	$(".Slide:eq(" + iWSCCurrentSlide + ")").stop().css("left",iWSCSliderWidth + "px")
	
	//slide out the current slide
	oCurrentSlide.stop().animate({"left":"-" + iWSCSliderWidth + "px"},iWSCSlideTransitionSpeed,'swing');
	
	//slide in the next slide
	$(".Slide:eq(" + iWSCCurrentSlide + ")").animate({"left":"0px"},iWSCSlideTransitionSpeed,'swing');
	
	setNavigationSlide()
	
	//remove the highlight on the link
	$(".SlideButton").blur();
}
function goToSlide(iNum) {
	if(iNum<0) iNum=0;
	if(iNum>=iWSCTotalSlides) iNum=iWSCTotalSlides-1;
	if(iNum==iWSCCurrentSlide) return null;
	if(iNum>iWSCCurrentSlide) { //if going forward, slide right to left
		$(".Slide:eq(" + iWSCCurrentSlide + ")").stop().animate({"left":"-" + iWSCSliderWidth + "px"},iWSCSlideTransitionSpeed,'swing');
		iWSCCurrentSlide=iNum;
		$(".Slide:eq(" + iWSCCurrentSlide + ")").stop().css("left",iWSCSliderWidth + "px").animate({"left":"0px"},iWSCSlideTransitionSpeed,'swing');
	}
	else { //if going backwards, slide left to right
		$(".Slide:eq(" + iWSCCurrentSlide + ")").stop().animate({"left":(parseInt(iWSCSliderWidth)+1) + "px"},iWSCSlideTransitionSpeed,'swing');
		iWSCCurrentSlide=iNum;
		$(".Slide:eq(" + iWSCCurrentSlide + ")").stop().css("left","-" + iWSCSliderWidth + "px").animate({"left":"0px"},iWSCSlideTransitionSpeed,'swing');
	
	}
	iWSCCurrentSlide=iNum;	
	
	setNavigationSlide()
	
	//remove the highlight on the link
	$(".SlideButton").blur();
}
function stopAutoAnimation() {
	if(iWSCInterval) {
		clearInterval(iWSCInterval);
		iWSCInterval=null;
	}
}
function setNavigationSlide() {
	$(".SlideButton").removeClass("Selected");
	$(".SlideButton:eq(" + (iWSCTotalSlides - iWSCCurrentSlide - 1) + ")").addClass("Selected");
	
}

