$(document).ready(function(){

	
	
	var current_slide = 0;
	var slides = 0;
	var elmHeight = $(".slideshow > div").height();
	
	$(".slideshow").height(elmHeight + "px");
	        
	if ($(".slideshow > div").length > 1 && ! $("body").hasClass("mobile")) {
	        
		$(".slideshow").after('<div class="bullets"></div>');
		$(".slideshow > div").each(function(i,e) {
	              
			slides++;
			$(this).attr("rel", i);
			$(".bullets").append('<a href="#" rel="'+i+'" class="bullet"> </a>');
			$(".bullets .bullet:first").addClass("active");
			$(this).css("top", i*elmHeight + "px");
		});
		
		$(".bullets .bullet").click(function(e){
			e.preventDefault();
			showSlide(Number($(this).attr("rel")));
			clearInterval(inter);
			inter = setInterval(slideInterval, 6000);
		});
		
		function showSlide(num) {
			current_slide = num;
			$(".bullets .bullet").removeClass("active");
			$(".bullets .bullet[rel='"+num+"']").addClass("active");
			$(".slideshow > div").each(function(i,e) {
				var pos = Number($(this).attr("rel")) - num;
				$(this).animate({"top": pos*elmHeight + "px"}, {duration: 600, queue: false});
			});
		}
		
		function slideInterval(){
			if (current_slide < slides-1) {
				showSlide(current_slide + 1);
			} else {
				showSlide(0);
			}
		}
		var inter = setInterval(slideInterval, 6000);
		/*
		$(".mod_catalogfeatured a img").mouseenter(function(e){
			
			$(".mod_catalogfeatured a").animate({width: "872px", height: "314px", borderWidth: "4px" }, {duration: 100, queue: false});
			$(".mod_catalogfeatured a span").animate({marginLeft: "-4px", marginTop: "-4px"}, {duration: 100, queue: false});
		});
		
		$(".mod_catalogfeatured a img").mouseleave(function(e){
			
			$(".mod_catalogfeatured a").animate({width: "880px", height: "322px", borderWidth: "0px" }, {duration: 300, queue: false});
			$(".mod_catalogfeatured a span").animate({marginLeft: "0px", marginTop: "0px"}, {duration: 300, queue: false});
		});
		*/
	}
	
	//$(".mod_catalogfeatured a img").insetBorder({borderColor:"#A19A8C", inset: 10});
	
	
	$("a.slideLink").click(function(e){
		e.preventDefault();
		clearInterval(inter);
		inter = setInterval(slideInterval, 6000);
		showSlide(Number($('.slideshow img[src="'+$(this).attr("href")+'"]').closest("[rel]").attr("rel")));
	});
});
