
var Slideshow = {
	current: 1,
	activate: true,
	initialize: function() {
		var myself = this;
		if($('.home-slideshow').size()) {
			myself.animate();
			$('.home-slideshow .nav-ele li').click(function() {
				$('.home-slideshow').stopTime();
				myself.current = myself.showCurrentSlide(myself.current, parseInt($(this).text()));
				$('.home-slideshow').oneTime(10000, function() {
					myself.animate();
				});
			});
		}
	},
	animate: function() {
		var myself = this;
		$('.home-slideshow').everyTime(4000, function() {
			myself.current = myself.showCurrentSlide(myself.current, null);
		});
	},
	selectCurrent: function(currentItem) {
		$('.nav-ele li').each(function(index){
			if(currentItem == index + 1) {
				$(this).html('<strong>' + (index + 1) + '</strong>');
			} else {
				$(this).html('<a href="javascript:;">' + (index + 1) + '</a>');
			}
		});
	},
	showCurrentSlide: function(from, to) {
		var myself = this;
		if(myself.activate) {
			myself.activate = false;
			var maxItems = $(".home-slideshow div[id^='ele-']").size();
			if(from == maxItems) {
				to = 1;
			} else if(to == null) {
				to = from + 1;
			}
			$(".home-slideshow #ele-0" + from).fadeOut("slow", function(){
				myself.selectCurrent(to);
				$(".home-slideshow #ele-0" + to).fadeIn("slow", function(){
					myself.activate = true;
				});
			});
			return to;
		}
		return from;
	}
}

$(document).ready(function() {
	Slideshow.initialize();
});

