/*
	jQuery Mitko Slider Plugin
*/

(function($){
    $.MitkoSlideShow = function(selector, settings){
		// settings
		var config = {
			'delay': 2000,
			'fadeSpeed': 500,
			'language': 1
		};
					
		if ( settings ){$.extend(config, settings);}

		
		// variables
		
		var obj = $(selector); //#slideshow
		var img = obj.children('img');//a
		
		var count = img.length;//for now it's 5 
		var i = 0; //from 0 to count - 1
		//console.log(count);
		var before = 0;
		var current = 1;
		var id_dot = '';
		var status_stop = false;
		// show first image
		
		$.post('slider_callback.php',{name: i,lang: config.language }, function(data) {
			$('#slide_text_content').html(data);
		});
		img.eq(0).show();			
		// run slideshow
		function change(){
			img.eq(i).fadeOut(config.fadeSpeed); //fade out the current
			i = ( i+1 == count ) ? 0 : i+1; //if the next is the last the current is 0	
			if (!id_dot) { 
				img.eq(i).fadeIn(config.fadeSpeed); //fade in the next
				$.post('slider_callback.php',{name: i,lang: config.language }, function(data) {
					$('#slide_text_content').html(data);
				});
			}
			else { 
				img.eq(current).fadeIn(config.fadeSpeed); //fade in the next
				$.post('slider_callback.php',{name: current,lang: config.language }, function(data) {
					$('#slide_text_content').html(data);
				});//extract the text in relation to the current index
			}
			if (!id_dot) { //id_dot is set only if we have clicked button
				if (i == 0) {
					$('#full_dot').attr('id','empty_dot3');
					$('#empty_dot'+i).attr('id','full_dot'); 
					return;
				}
				else {
					$('#full_dot').attr('id','empty_dot'+(i-1));
					$('#empty_dot'+i).attr('id','full_dot');
					return;
				}
			}
			else {
				if (i == 0) {// if it is the last slide
					$('#full_dot').attr('id','empty_dot3');
					$('#'+id_dot).attr('id','full_dot');
					i = parseInt(id_dot.substr(9,1));
					//alert(i);
					id_dot = '';
					return;
				}	
				else {
					$('#full_dot').attr('id','empty_dot'+(i-1));
					$('#'+id_dot).attr('id','full_dot');
					i = parseInt(id_dot.substr(9,1));
					//alert(i);
					id_dot = '';
					return;
				}
			}
		}
		
		var si = setInterval(change, config.delay);
        $('.slider_dot').click(function() {
			var id = $(this).attr('id');//it takes the current id
			if (id != 'full_dot') {
				id_dot = id; //id_dot = current id
				current = parseInt(id_dot.substr(9,1));
				change();
			}
		});
		
		$('#slider').mouseover(function() {
			clearInterval(si);
			status_stop = true;
		});
		$('#slider').mouseout(function() {
			if (status_stop) {
				status_stop = false;
				si = window.setInterval(change, config.delay);
			}
		});
		return this;
	};
})(jQuery);

/*
(function($){
    $.MitkoSlideShow = function(selector, settings){
		// settings
		var config = {
			'delay': 2000,
			'fadeSpeed': 500,
			'language': 1
		};
		if ( settings ){$.extend(config, settings);}

		// variables
		var obj = $(selector);
		var img = obj.children('img');
		var count = img.length;
		
		var i = 0;
		var id_dot = '';
		var status_stop = false;
		// show first image
		$.post('slider_callback.php',{name: i,lang: config.language }, function(data) {
			$('#slide_text_content').html(data);
		});
		img.eq(0).show();			
		// run slideshow
		
		function change(){
			//alert(i);
			img.eq(i).fadeOut(config.fadeSpeed);
			i = ( i+1 == count ) ? 0 : i+1;
			img.eq(i).fadeIn(config.fadeSpeed);
			var currNo = 0;
			$.post('slider_callback.php',{name: i,lang: config.language }, function(data) {
				$('#slide_text_content').html(data);
			});
			if (!id_dot) {
				if (i != 0) {
					$('#full_dot').attr('id','empty_dot'+(i-1));
					$('#empty_dot'+i).attr('id','full_dot');
				}
				else {
					$('#full_dot').attr('id','empty_dot3');
					$('#empty_dot'+i).attr('id','full_dot');
				}
			}
			else {
				$('#full_dot').attr('id','empty_dot'+(i-1));
				$('#'+id_dot).attr('id','full_dot');
				id_dot = '';
			}
			//alert(i);
		}
		var si = setInterval(change, config.delay);
        //Doesn't work perfect
		$('.slider_dot').click(function() {
			var id = $(this).attr('id');
			if (id != 'full_dot') {
				id_dot = id;
			//clearInterval(si);
				change();
				//alert("tuka kvo staa:"+i);
			}
		});
		
		$('#slider').mouseover(function() {
			clearInterval(si);
			status_stop = true;
		});
		$('#slider').mouseout(function() {
			if (status_stop) {
				status_stop = false;
				si = setInterval(change, config.delay);
			}
		});
		return this;
	};
})(jQuery);*/
