var swSlider = {
	target: "",
	interval: "",
	intTime: 8000,
	animateTime: 1000,
	menu: "",
	init: function() {
		//
		this.viewport = this.target.find(".sliderViewport");
		//viewport width / height
		this.slideWidth	= this.target.find(".singleSlide").width();
		this.slideHeight= this.target.find(".singleSlide").height();
		//count elements
		this.slideCount	= this.target.find(".singleSlide").length;
		//
		this.viewport.width(this.slideWidth * this.slideCount);
		//start interval
		this.initInterval();
		//create menu
		this.createMenu();
		//bind menu
		this.bind();
	},
	initInterval: function() {
		this.interval = window.setInterval("swSlider.next()", this.intTime);
	},
	createMenu: function() {
		this.target.append("<div class='sliderMenu'></div>");
		this.menu = this.target.find(".sliderMenu");
		this.target.find(".singleSlide").each(function(){
			if(typeof(a) == "undefined") a = 0;
			a++;
			swSlider.menu.append("<span class='singleMenu'>"+a+"</span>");
		})
		this.menu.find("span:first").addClass("activeSlide");
	},
	bind: function() {
		this.target.find(".sliderMenu span").live("click", function(){
			swSlider.next($(this).index());
		})
		this.target.hover(
			function () {
				clearInterval(swSlider.interval);
			}, 
			function () {
				swSlider.initInterval();
			}
		);
	},
	next: function(index) {
		var allSlides = this.target.find(".singleSlide").length;
		if(typeof(index) == "undefined") {
			var index = this.menu.find(".activeSlide").index() + 1;
		}
		if(index == allSlides) var index = 0;
		this.menu.find(".activeSlide").removeClass("activeSlide");
		this.menu.find("span:eq("+index+")").addClass("activeSlide");
		this.target.find(".sliderBox").animate({
			scrollLeft: index * this.slideWidth
			}, this.animateTime); 
	}
}
$(document).ready(function(){	
	swSlider.target = $(".swSlider");
	swSlider.init();
})


