var lista_obiektow = [];


jQuery(document).ready(function(){
	
	
	
	jQuery('#facebook_sliderek').each(function(key, val) {
		
		val = jQuery(val);
		val = new class_facebook_slid(val);
		
		lista_obiektow.push(val);
		});
	
	});



function class_facebook_slid(obiekt) {
	
	
	this.obiekt     = obiekt;
	this.animacja   = false;
	this.stan       = false;
	this.last_event = false;
	
	this.obiekt_animowany = this.obiekt.find('#facebook_sliderek_1');
	
	
	var self = this;
	
	this.obiekt_animowany.mouseover(function(){
	//this.obiekt.mouseover(function(){

		self.last_event = true;
											//ignorowanie zdarzeń jeśli trwa animacja
		if (self.animacja === true) {
			return;
			}
		
		self.show();
		
		return false;
		});
	
	
	this.obiekt_animowany.mouseout(function(){
	//this.obiekt.mouseout(function(){
		
		
		self.last_event = false;
		
											//ignorowanie zdarzeń jeśli trwa animacja
		if (self.animacja === true) {
			return;
			}
		
		self.hide();
		
		return false;
		});
	}



class_facebook_slid.prototype.check = function() {
	
	if (this.stan !== this.last_event) {
		
		
		if (this.last_event === true) {
			
			this.show();
			}
		
		else if (this.last_event === false) {
			
			this.hide();
			}
		
		else {
			console.log('nieprawidłowe odgałęzienie programu');
			}
		}
	}



class_facebook_slid.prototype.hide = function() {
	
	
	if (this.animacja === true) {
		
		console.info('błąd, ignoruje zdarzenie');
		return;
		}

	
	this.animacja = true;
	
	var self = this;	
	this.obiekt_animowany.animate({
		
		marginLeft: -190
		
		}, 1000, function() {
			
			self.animacja = false;
			self.stan     = false;
			
			self.check();		
			});
	}



class_facebook_slid.prototype.show = function() {
	
	
	if (this.animacja === true) {
		
		console.info('błąd, ignoruje zdarzenie');
		return;
		}
	
	
	this.animacja = true;
	
	var self = this;
	this.obiekt_animowany.animate({
		
		marginLeft: 0
		
		}, 1000, function() {
			
			self.animacja = false;
			self.stan     = true;
			
			self.check();		
			});
	}



