$(document).ready(function(){
	var homeSlideShow = new clsSlideshowSimple({"elmsItems": $(".homenews .itemcontent"), "pause":6000});
});

function clsSlideshowSimple(arguments){
		this.elmsItems = (arguments.elmsItems)?arguments.elmsItems:null;
		this.currentClass = (arguments.currentClass)?arguments.currentClass:"selected";
		this.pause = (arguments.pause)?arguments.pause:3000;
		this.duration = (arguments.duration)?arguments.duration:500;

		this.elmCurrent = this.elmsItems.filter("."+this.currentClass);
		this.indexCurrent = this.getItemIndex(this.elmCurrent);
		
		this.start();
	}
	clsSlideshowSimple.prototype.start = function(){
		var fncThis = this;
		var callback = function(){
			fncThis.changeItemNext();
		}
		if(this.elmsItems.length > 1)
			setInterval(callback, fncThis.pause);
	}
	clsSlideshowSimple.prototype.changeItemNext = function(){
		if(this.elmsItems[this.indexCurrent + 1])
			this.changeItemByIndex(this.indexCurrent + 1);
		else
			this.changeItemByIndex(0);
	}
	clsSlideshowSimple.prototype.changeItemByIndex = function(argIndex){
		var fncThis = this;
		var elmNew = fncThis.elmsItems.eq(argIndex);
		fncThis.elmCurrent.fadeOut(fncThis.duration, function(){
			elmNew.fadeIn(fncThis.duration, function(){
				fncThis.elmCurrent.removeClass(fncThis.currentClass);
				elmNew.addClass(fncThis.currentClass);
				fncThis.elmCurrent = elmNew;
				fncThis.indexCurrent = fncThis.getItemIndex(elmNew);
			});
		});
	}
	clsSlideshowSimple.prototype.getItemIndex = function(argElement){
		var arrayLength = this.elmsItems.length;
		for(var i=0;i<arrayLength;++i){
			if(this.elmsItems[i] == argElement[0]){
				return i;
			}
		}
	}

