csm = {};
csm.photos = {};
csm.photostimer = {};
csm.settimer = function(){
	if(typeof(csm.photostimer) == "number"){
		clearInterval(csm.photostimer);
	}
	csm.photostimer = window.setInterval(function() {
		csm.photos.next();
	}, 6000);
};
csm.photos.next = function(){
	var from = $("#vignette .slides a.active");
	var toIndex = 0;
	if(parseInt(from.attr("pos"),10)+1 < $("#vignette .slides a").length){
		toIndex = parseInt(from.attr("pos"),10)+1;
	}
	var to = $("#vignette .slides a:eq("+toIndex+")");

	to.css("top","100%").show().animate({top: "0%"}, 500, "linear", function(){
		$(this).addClass("active");
	});
	from.animate({top:"-100%"}, 500, "linear", function(){
		$(this).hide().removeClass("active");
	});
};
csm.photos.back = function(){
	var from = $("#vignette .slides a.active");
	var toIndex = parseInt(from.attr("pos"),10)-1;
	if(toIndex == -1){
		toIndex = $("#vignette .slides a").length-1;
	}
	var to = $("#vignette .slides a:eq("+toIndex+")");

	to.css("top","-100%").show().animate({top: "0%"}, 500, "linear", function(){
		$(this).addClass("active");
	});
	from.animate({top:"100%"}, 500, "linear", function(){
		$(this).hide().removeClass("active");
	});
};
csm.photos.watch = function(){
	window.location.href = $("#vignette .slides a.active").attr("href");
};
$(document).ready(function(){
	/******************
		FMA Sliders
	*******************/
	$("#vignette .slides a")
		.each(function(i){
			$(this).attr("pos",i);
			if(i===0){
				$(this).show().addClass("active");
			} else {
				$(this).hide();
			}
		});


	/* Auto Advance FMA */
	csm.settimer();	
});