//$ = jQuery.noConflict(); 
// author: Michał Daniel, www.icube.pl
$(document).ready(function() {
	evip_carousel.init();
	evip_news.init();
});

var evip_carousel = {
	elements_amount : 3, 
	current_element : 1,
	stoped : false,
	run : null, // interval
	speed_time : 5000,
	fade_speed : 800,
	timer_speed : 700,
	
	init: function() {	
		this.elements_amount = $('.banner-main').size();
		this.show(1);
		
		for (var i = 1; i <= this.elements_amount; i++)
		{
			$('#slider-nav-'+i).click(function() {
				var cid = this.id.slice(-1);
				evip_carousel.fadeAllOut(cid);
				if (cid != evip_carousel.current_element) { // pokaz jeśli nie jest aktualnym
					evip_carousel.show(parseInt(cid));
				} else {
					clearInterval(evip_carousel.timer);
				}
				
				if (evip_carousel.stoped == true && evip_carousel.current_element == cid) { // drugi raz kliknięto na ten sam link, uruchom pokaz slajdów	
					evip_carousel.stoped = false;
					evip_carousel.run = setInterval('evip_carousel.runSlider()', evip_carousel.speed_time);
				} else {
					evip_carousel.stoped = true;	
					clearInterval(evip_carousel.run);
				}
				evip_carousel.current_element = parseInt(cid);
				
				return false;
		    });
		}		
		this.run = setInterval('evip_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('evip_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++; 
		}		
	}
}

var evip_news = {
	run : null, 
	speed_time : 6000,
	fade_speed : 800,
	timer_speed : 700,
	elements_amount : 5, 
	current_element : 1,
	stoped : false,
		
	fadeAllOut: function(cid) {
		for (var i = 1; i <= this.elements_amount; i++) if (i != cid) this.hide(i); 
	},
	
	show: function(cid) {
		$('#slajd_'+cid).fadeIn(this.fade_speed);
		$('#slajd_nav_'+cid).addClass('marked');	
	},
	
	hide: function(cid) {
		$('#slajd_'+cid).fadeOut(this.fade_speed);		
		$('#slajd_nav_'+cid).removeClass('marked');
	},	
	
	stop: function() {
		this.stoped = true;
		clearInterval(this.run);	
	},
	
	runslideshow: function() {
		this.stoped = false;
		this.run = setInterval('evip_news.runSlider()', this.speed_time); 	
	},
		
	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++; }		
	},
	
	init: function() {	
		this.elements_amount = $('.slajd').size();
		if (this.elements_amount < 1) return;
		this.show(1);
		
		for (var i = 1; i <= this.elements_amount; i++)
		{
			$('#slajd_nav_'+i).click(function() {
				var cid = this.id.slice(-1);
				evip_news.fadeAllOut(cid);
				if (cid != evip_news.current_element) evip_news.show(parseInt(cid));
				else clearInterval(evip_news.timer);

				if (evip_news.stoped == true && evip_news.current_element == cid) { 	
					evip_news.stoped = false;
					evip_news.run = setInterval('evip_news.runSlider()', evip_news.speed_time);
				} else {
					evip_news.stoped = true;	
					clearInterval(evip_news.run);
				}
				evip_news.current_element = parseInt(cid);
				
				return false;
		    });
		}		
		this.run = setInterval('evip_news.runSlider()', this.speed_time); 		
	}	
}

