// OsXs JavaScript



$(document).ready(function(){
	$("#photoGal, #thumbDots, #thumbArrows").show();
	
	var nImages = $("#photoGal ul li").length;
	var nCount = 0;
	var nCurrent = 0;
	var nImageW = 166;
	
	/*var interval = setInterval(animateImg, 10000);
		
	function animateImg()
	{	
		//var nRanMargin = -Math.floor(Math.random() * nImages) * nImageW;
		if (nCount <= nImages) {
			$("#photoGal ul").animate({
				marginLeft: -(nCount * nImageW)
			}, 1500, "linear", function(){nCount += 1;});
		} else {
			nCount = 0;
			$("#photoGal ul").animate({
				marginLeft: 0
			}, 0, "linear");
		}
	}*/
	
	$("#thumbNext").click(function(event) {
		if ((nCurrent + 1) != nImages) {
			nCurrent += 1;
			animateImages();
		}
		
		event.preventDefault();
	});
	
	$("#thumbPrev").click(function(event) {
		if ((nCurrent) != 0) {
			nCurrent -= 1;
			animateImages();
		}
		
		event.preventDefault();
	});
	
	$("#thumbDots li a:first").addClass("activeDot");
	
	$("#thumbDots li a").click(function(event){
		nCurrent = Number($(this).attr("id").substring($(this).attr("id").lastIndexOf("_")+1));;
		animateImages();	
		
		event.preventDefault();
	});
	
	function animateImages() {
		$("#photoGal ul").animate({
				marginLeft: -(nCurrent * nImageW)
			}, 500);
		
		$("#thumbDots li a.activeDot").removeClass("activeDot");
		$("#thumbDot_" + nCurrent).addClass("activeDot");
	}
		
});
