// JavaScript Document
function slideSwitch($navSel) {
	if($navSel) {
		$NextPlace=$navSel;
	}
	$("#Sliderwrapper div:nth-child("+$CurrentPlace+")").animate({marginLeft:"-"+$ContentWidth},$sliderSpeed);
	$(".sliderNavButton").removeClass("sliderNavButtonActive");
	$("#sliderNavButtonId"+$NextPlace).addClass("sliderNavButtonActive");
	$("#Sliderwrapper div:nth-child("+$NextPlace+")").animate({marginLeft:"0"},$sliderSpeed,											  
		function(){$("#Sliderwrapper div:nth-child("+$CurrentPlace+")").animate({marginLeft:$ContentWidth},1,loopy() )}
	);
	if($navSel) {
		//$("#Sliderwrapper div:nth-child("+$CurrentPlace+")").css("margin-left:"+$ContentWidth);
	}
}
function loopy(){
	$CurrentPlace++;
	$NextPlace++;
	if($CurrentPlace==($NoOfItems+1)){
		$CurrentPlace=1;
	}
	if($NextPlace==($NoOfItems+1)){
		$NextPlace=1;
	}
}
$(document).ready(function(){
	
$AllItems=$("#Sliderwrapper .sliderContent") // Set Array of elements
$NoOfItems=$($AllItems).length; // Get Length of elements
$ContentWidth=$("#Sliderwrapper").width(); // Get width of element
$CurrentPlace=1;
$NextPlace=2;
$sliderInterval=5000;
$sliderSpeed=500;

// Set Slider Buttons
var x = 1; // Counter
var NavHTMLButtons =  ''; // Empty String for building HTML
// Create Buttons dependant on nuber of items
while (x!=$NoOfItems+1) {
	// Write HTML
	if(x==1){
		//NavHTMLButtons = ('<span class="sliderNavButton sliderNavButtonActive" id="sliderNavButtonId'+x+'" onclick="slideSwitch('+x+')">&nbsp;</span>');
		NavHTMLButtons = ('<span class="sliderNavButton sliderNavButtonActive" id="sliderNavButtonId'+x+'">&nbsp;</span>');
	}else{
		//NavHTMLButtons = NavHTMLButtons+('<span class="sliderNavButton" id="sliderNavButtonId'+x+'" onclick="slideSwitch('+x+')">&nbsp;</span>');
		NavHTMLButtons = NavHTMLButtons+('<span class="sliderNavButton" id="sliderNavButtonId'+x+'">&nbsp;</span>');
	}
	x++;
}

// Write out the Navigation Buttons
document.getElementById("sliderNav").innerHTML = NavHTMLButtons;

//Navigation Pause
$("#Sliderwrapper").mouseenter(function(){
	clearInterval($setInv)
});
//Navigation Start
$("#Sliderwrapper").mouseleave(function(){
	myInterval();
});

// Set Interval Timer Function
function myInterval() {
	$setInv = setInterval( "slideSwitch()", $sliderInterval );
}
myInterval(); // Run the Interval Function
});
