//$ = jQuery.noConflict(); 
// author: Michał Daniel, www.icube.pl
$(document).ready(function() {
	evip_carousel.init();
	evip_news.init();
	evip_main.init();
	icube_logos.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); 		
	}	
}


var evip_main = {
	run : null, speed_time : 6000, fade_speed : 800, timer_speed : 700, elements_amount : 5, current_element : 1, stoped : false,
		init: function() {	
		this.elements_amount = $('.product_carousel').size();
		if (this.elements_amount < 1) return;
		this.show(1);
		
		for (var i = 1; i <= this.elements_amount; i++)
		{
			$('#pc_nav_'+i).click(function() {
				var cid = this.id.slice(-1);
				evip_main.fadeAllOut(cid);
				if (cid != evip_main.current_element) evip_main.show(parseInt(cid));
				else clearInterval(evip_main.timer);

				if (evip_main.stoped == true && evip_main.current_element == cid) { 	
					evip_main.stoped = false;
					evip_main.run = setInterval('evip_main.runSlider()', evip_main.speed_time);
				} else {
					evip_main.stoped = true;	
					clearInterval(evip_main.run);
				}
				evip_main.current_element = parseInt(cid);
				
				return false;
		    });
		}		
		this.run = setInterval('evip_main.runSlider()', this.speed_time); 		
	},
		runslideshow: function() {
		this.stoped = false;
		this.run = setInterval('evip_main.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++; }		
	},	
		
	fadeAllOut: function(cid) {
		for (var i = 1; i <= this.elements_amount; i++) if (i != cid) this.hide(i); 
	},
	
	show: function(cid) {
		$('#pc_'+cid).fadeIn(this.fade_speed);
		$('#pc_nav_'+cid).addClass('marked');	
	},
	
	hide: function(cid) {
		$('#pc_'+cid).fadeOut(this.fade_speed);		
		$('#pc_nav_'+cid).removeClass('marked');
	},	
	
	stop: function() {
		this.stoped = true;
		clearInterval(this.run);	
	}
}

var icube_logos = {

	right_elements_amount : 4, 
	right_current_element : 1,	
	right_run : null,
	right_speed_time : 7000,
	
	init: function() {	
		
		this.right_elements_amount = Math.ceil($('#right-moving-logos div').size() / 4 );
		if (this.right_elements_amount > 1) this.right_run = setInterval('icube_logos.runRightSlider()', this.right_speed_time); 
				
	}, 

	runRightSlider: function() {
		if (this.right_current_element == this.right_elements_amount) {
			this.showRight(1);
			this.right_current_element = 1; 
		} else {
			this.showRight(this.right_current_element + 1);
			this.right_current_element++; 
		}		
	},
	
	showRight: function(cid) {
		if (cid == 1) var tmp = 0;
		else var tmp = ((cid-1)*160)*-1;
		
		$("#right-moving-logos").animate({ 
		    top: tmp+"px"
		  }, 900);
	}		
}
