var Slideshow = {
	init: function(options,images){
		this.options = $extend({
			isImage: false,
			hasText: false,
			imageContainer: $('g_window'),
			slide: $('g_slide'),
			load: false
		}, options || {});
		this.images = this.options.load ? this.setup(images) : images;
		//this.links = links; //need to integrate with Slimbox
		this.options.imageContainer.style.left = 0;
		this.options.imageContainer.style.width = this.images.length*846+'px'; //ширина контейнера для фото
		this.count = 0; //loaded backgroung if javascript enabled
		this.options.slide.style.opacity = 0;
		this.fx = new Fx.Style(this.options.imageContainer,'left', {'duration' : 1000, 'fps' : 300});
		this.slide = new Fx.Style(this.options.slide,'opacity', {'duration' : 600, 'fps': 100});
		this.timer = true;
		return this.slideon();
	},
	setup: function(images){
		var images_array = [];
		images.each(function(img){
			images_array.push( new Element('img', {'src': '/main/i/slideshow/'+img}).injectInside(this.options.imageContainer) );
		},this);
		return images_array;
	},
	slideon:function(){
		if(this.timer) { timer = setTimeout('Slideshow.slideshow()', 4000);}
	},
	slideshow: function(){
		this.slide.set(1);
		this.count++;
		if(this.count>=this.images.length) this.count = 0;
		this.options.imageContainer.style.left = -(this.count)*846+'px';
		this.slide.start(0);
		return this.slideon();
	},
	changeImage: function(i){
		if ((i<0)||(i>=this.images.length)) return false;
		sub = (i>this.count)?-1:1;
		this.fx.start(parseInt(this.options.imageContainer.style.left)+(sub)*846);
		this.count = i;
		return false;
	},
	show: function() {
		if(this.options.isImage) this.options.imageContainer.src = this.images[this.count][0];
		else this.options.imageContainer.style.backgroundImage = 'url('+this.images[this.count][0]+')';
		
		if(this.options.hasText) this.options.textContainer.innerHTML = this.images[this.count][1];
		if(this.options.showCounter) this.options.counter.innerHTML = this.count+1;
		this.fx.start(1);
		return false;
	}
}
window.addEvent('domready',function(){
options = {
	isText: false,
	isImage: false, // default container
	load:true
}
images = ['stol2.jpg','stol3.jpg','corp2.jpg','corp3.jpg','corp4.jpg','corp5.jpg','atclean2.jpg','atclean1.jpg','bar1.jpg','bar2.jpg','clean1.jpg','clean2.jpg','tech5.jpg','tech1.jpg','tech2.jpg','tech3.jpg'];
Slideshow.init(options,images);
});
