function class_timer(czas, func) {
	
	this.czas = czas;
	this.func = func;
	
	//this.start();
	}

class_timer.prototype.start = function() {
	
	this.time = setInterval(this.func, this.czas);
	};

class_timer.prototype.reset = function() {
	
	this.stop();
	this.start();
	};

class_timer.prototype.stop = function() {
	
	clearInterval(this.time);
};


var SLIDESHOW = (function()
{
	var n_timer = false;
	var p_timer = false;
	var stop_control = true;
	var slideshow,count,prev,next,stop;
	var left_timer,right_timer;
	
	function extend()
	{
		FSite2.extendForm(document, {
        	slideShowCurrent       : 0,
        	slideShowTransTime     : 150,
	       	slideShowClass         : 'slideshow2',
	      	slideShowSlideClass    : 'slideshow_slide2',
	        slideShowWaitTime	   : 5000,
	        slideShowLoop: true
		});
	}
	
	function prev_slide()
	{
		if(parseInt(slideshow._slideShow.currentSlide) == 0)
		{
			slideshow._slideShow.showSlide(count-1);
		}
		else
 		{
			slideshow._slideShow.showSlide(parseInt(slideshow._slideShow.currentSlide)-1);
		}
	}
	
	function prev_click()
	{
		if(stop_control)
		{
			if(n_timer)
				right_timer.stop();
			p_timer= true;
			prev_slide();
			left_timer.reset();		
		}
		else
			prev_slide();
	}
	
	function next_click()
	{
		if(stop_control)
		{
			if(p_timer)
				left_timer.stop();
			n_timer = true;
			next_slide();
			right_timer.reset();	
		}
		else
			next_slide();
	}
	
	function stop_click()
	{
		if(stop_control)
		{
			p_timer = false;
			n_timer = false;
			right_timer.stop();
			left_timer.stop();
			stop_control = false;
			this.className = 'start';
		}
		else
		{
			stop_control = true;
			this.className = 'stop';
			n_timer = true;
			right_timer.reset();
		}
	}

	
	function next_slide()
	{
		if(parseInt(slideshow._slideShow.currentSlide) == count - 1)
		{
			slideshow._slideShow.showSlide(0);
		}
		else
		{
			slideshow._slideShow.showSlide(parseInt(slideshow._slideShow.currentSlide)+1);
		}
	}
	
	return {
		init:function()
		{
			prev = $('top_slide_prev');
			next = $('top_slide_next');
			stop = $('top_slide_stop');
			extend();
			slideshow = FSite2.getElementsByClassName('slideshow2')[0];
			count = parseInt(slideshow._slideShow.getCount());
			prev.onclick = prev_click;
			next.onclick = next_click;
			stop.onclick = stop_click;
			
			left_timer = new class_timer(3000, function(){
				prev_slide();		
			});
			
			right_timer = new class_timer(3000, function(){
				next_slide();		
			});
			
			next_click();
			
		}
	};
}());

/*
if($('top_slideshow') != undefined)
		    {
		    
		    FSite2.extendForm(document, {
        	slideShowCurrent       : 0,
        	slideShowTransTime     : 150,
	       	slideShowClass         : 'slideshow2',
	      	slideShowSlideClass    : 'slideshow_slide2',
	        slideShowWaitTime	   : 5000,
	        slideShowLoop: true});
		    
		    
		    	var prev = $('top_slide_prev');
		    	var next = $('top_slide_next');
		    	var slideshow = FSite2.getElementsByClassName('slideshow2')[0];
		    	var count = parseInt(slideshow._slideShow.getCount());
		    	
		    	window.setTimeout(function(){
						slideshow._slideShow.play();
				},5000);
		    	
		    	
		    	prev.onclick = function()
		    	{
		    		console.log(slideshow._slideShow.currentSlide);
		    		if(parseInt(slideshow._slideShow.currentSlide) == 0)
		    		{
		    			slideshow._slideShow.stop();
		    			slideshow._slideShow.play(count-1);
		    		}
		    		else
		    		{
		    			slideshow._slideShow.stop();
		    			slideshow._slideShow.play(parseInt(slideshow._slideShow.currentSlide)-1);
		    		}
		    	}
		    	
		    	next.onclick = function()
		    	{
		    		console.log(slideshow._slideShow.currentSlide);
		    		if(parseInt(slideshow._slideShow.currentSlide) == count - 1)
		    		{
		    			slideshow._slideShow.stop();
		    			slideshow._slideShow.play(0);
		    		}
		    		else
		    		{
		    			slideshow._slideShow.stop();
		    			slideshow._slideShow.play(parseInt(slideshow._slideShow.currentSlide)+1);
		    		}
		    	}
		    	
		    	
		    }

*/
