//$ = jQuery.noConflict(); 
$(document).ready(function() {
	quick_gallery.init();
	imprezy_carousel.init();
});

var quick_gallery = {
	current : 0,
	run : null, // interval
	speed : 5000,
	fade_speed : 800,
	
	init: function() {	
		this.next();
		this.run = setInterval('quick_gallery.next()', this.speed); 
	},
	
	next: function() {
		if (this.current > 3) {	
			this.current = 1;
		} else {
			this.current++;
		}	

		this.fadeAllOut(this.current);
		
		$('#quick_gall_'+this.current).fadeIn(this.fade_speed);
		if ($.browser.msie) {
			$('#quick_gall_'+this.current+' *').fadeIn(this.fade_speed);
		}

	},
	
	fadeAllOut: function(cid) {
		for (var i = 1; i <= 4; i++) {
			if (i != cid) {
				$('#quick_gall_'+i).fadeOut(this.fade_speed);
				if ($.browser.msie) {
					$('#quick_gall_'+i+' *').fadeOut(this.fade_speed);
				}
			}
		}				
	}
}

var imprezy_carousel = {
	elements_amount : 3, // ilość elementów
	current_element : 1,
	stoped : false,
	run : null, // interval
	speed_time : 5000,
	fade_speed : 800,
	timer_speed : 700,
	
	init: function() {	
		this.show(1);
		
		for (var i = 1; i <= this.elements_amount; i++)
		{
			$('#slider-nav-'+i).click(function() {
				var cid = this.id.slice(-1);
				imprezy_carousel.fadeAllOut(cid);
				if (cid != imprezy_carousel.current_element) { // pokaz jeśli nie jest aktualnym
					imprezy_carousel.show(parseInt(cid));
				} else {
					clearInterval(imprezy_carousel.timer);
				}
				
				if (imprezy_carousel.stoped == true && imprezy_carousel.current_element == cid) { // drugi raz kliknięto na ten sam link, uruchom pokaz slajdów	
					imprezy_carousel.stoped = false;
					imprezy_carousel.run = setInterval('imprezy_carousel.runSlider()', imprezy_carousel.speed_time);
				} else {
					imprezy_carousel.stoped = true;	
					clearInterval(imprezy_carousel.run);
				}
				imprezy_carousel.current_element = parseInt(cid);
				
				return false;
		    });
		}		
		this.run = setInterval('imprezy_carousel.runSlider()', this.speed_time); 		
	}, 
	
	fadeAllOut: function(cid) {
		for (var i = 1; i <= this.elements_amount; i++)
			if (i != cid) this.hide(i); 
	},
	
	stop: function() {
		this.stoped = true;
		clearInterval(this.run);	
	},
	
	runslideshow: function() {
		this.stoped = false;
		this.run = setInterval('imprezy_carousel.runSlider()', this.speed_time); 	
	},
	
	show: function(cid) {
		$('#slide_'+cid).fadeIn(this.fade_speed);
		
		if ($.browser.msie) {
			//$('#slider-'+cid+' *').fadeIn(this.fade_speed);
		}
			
		$('#slider-nav-'+cid).addClass('active');	
	},
	
	hide: function(cid) {
		$('#slide_'+cid).fadeOut(this.fade_speed);	
		if ($.browser.msie) {
		//	$('#slider-'+cid+' *').fadeOut(this.fade_speed);
		}		
		$('#slider-nav-'+cid).removeClass('active');
	},	
	
	runSlider: function() {
		if (this.stoped == true) {
			clearInterval(this.run);
			return;
		}
		
		this.hide(this.current_element);
		if (this.current_element == this.elements_amount) {
			this.show(1);
			this.current_element = 1; 
		} else {
			this.show(this.current_element + 1);
			this.current_element++; 
		}		
	}
}
