// JavaScript Document

// NOTICE:
// This code is copyrighted and may not be used without the express written consent of
// of the author. For details contact: http://www.steeltre.com
//
// ST SLIDER FUNCTIONS
//
// These functions are used to control the st_slider feature
// the slider feature is used to display a series of divs as individual slides.
// A control bar is created that displays the number of slides. clicking on the number goes directly to the slide
// The slides also rotate automatically.

// v1.00
//Copyright 2008 by steeltree
//
//
// Usage:
//
// Add the following lines to the document ready function
// divs must be named <div class="st_slider"> some content </div>
//
//	//set the max number of slides
//	st_slider_max=$(".st_slider").length;
//
//	//add the control bar 
//	st_slider_build_controls();
//	
//	//show the first slide
//	st_slider_display();
//	
//	//start the slide show
//	st_slider_interval=setInterval("st_slider_display()", st_slider_setinterval );
//
	var st_slider_setinterval=6000;
	var st_slider_count=0;
	var st_slider_max=0;

function st_slider_display(slider_num){
//This function handles loading and displaying a slide
	if ( slider_num === undefined ) {} else { st_slider_count = slider_num - 1; }

	if(st_slider_count>st_slider_max-1){st_slider_count=0;}
	
	$("#st_slider_controls a").removeClass("current");
	$("#st_slider_controls a").eq(st_slider_count).addClass("current");

	$("#st_slider_show").fadeOut(1000,function () { 
		$("#st_slider_show").html($(".st_slider").eq(st_slider_count++).html());
	});
		
	$("#st_slider_show").fadeIn(1000);
		
	};
	
function st_slider_build_controls(){
//This function displays the control bar under the slide area. Clicking the numbers goes to that slide.
	var a="";
	$(".st_slider").each(function(i){
		a+="<a href='#' id='"+ (i+1) + "'>" + (i+1) + "</a>";
	});
	
	//add the controls for prev, pause & next
	a+='<a href="#" id="<" class="prev" >' + '&nbsp;' + '</a>';
	a+='<a href="#" id=".." class="pause" >' + '&nbsp;' + '</a>';
	a+='<a href="#" id=">" class="next" >' + '&nbsp;' + '</a>';
	
	//insert the controls in a div with id=#st_slider_controls
	$("#st_slider_controls").html(a);
	
	//make the controls clickable
	$('#st_slider_controls a').click(function () {
		var slider_num=$(this).eq(0).attr("id"); //get the slide number		
		
		if (isNumeric(slider_num)){ //if slide_num is a number display the slide
			st_slider_display(slider_num);
			clearInterval(st_slider_interval); //reset the timer so it displays the normal length
			st_slider_interval=setInterval("st_slider_display()", st_slider_setinterval );
			
		} else { // slide_num must be prev, next or pause
		
			switch (slider_num) {
			
			case ('<'):
				st_slider_count = st_slider_count-2;
				
				if (st_slider_count<0){ st_slider_count=st_slider_max-1;}
				
				st_slider_display();
				clearInterval(st_slider_interval); //reset the timer so it displays the normal length
				st_slider_interval=setInterval("st_slider_display()", st_slider_setinterval );					
				break;
				
			case ('>'):			
				st_slider_display();
				clearInterval(st_slider_interval); //reset the timer so it displays the normal length
				st_slider_interval=setInterval("st_slider_display()", st_slider_setinterval );
				break;
			
			case ('..'):
				clearInterval(st_slider_interval); //stop the show
				break;			
			}		
		}		
		return false; //disable the hyperlink function
	});
}

function isNumeric(value) {
	if (value == null || !value.toString().match(/^[-]?\d*\.?\d*$/)) return false;
	return true;
}
