
function ProjectsSlider(html_obj_id, p, thumb_overlay_style, speed) {
	this.$slider = $(html_obj_id);
	this.p = p || new Array();
	this.t = thumb_overlay_style || 1;
	this.s = speed || 300;
	
	var img_count = this.p.length - 1;
	var self = this;
	
	$('.thumb_overlay strong', this.$slider).text('Proszę czekać ...');
	
	for(var i in this.p) {
		if(!this.p[i].image) continue;
		this.p[i].image.onload = function() {
			$('.thumb_overlay span', self.$slider).append(' &curren; ');
			if(!--img_count) self.setProject(0);
		};
	
	}
}

ProjectsSlider.prototype.setProject = function(i) { 
	if (i<0 || i>=this.p.length-1) return;
	var self = this;

	this.thumbOverlayStyle(0);
	
	$('a:first img:first', this.$slider).fadeOut(this.s, function() {
		$(this).attr('src', self.p[i].image.src).attr('alt', self.p[i].title);
		$('.thumb_overlay strong',	this.$slider).html(self.p[i].title);
		$('.thumb_overlay span',	this.$slider).html(self.p[i].sdesc.substr(0, 85)+(self.p[i].sdesc.length > 85?' ...':''));
		$('.thumb_overlay',	this.$slider).attr('href', self.p[i].href);

		self.thumbOverlayStyle(100);
		
	}).next().attr('src', self.p[i].image.src).attr('alt', self.p[i].title).fadeIn(this.s, function() {
		$(this).hide().prev().show();
	});

	$('.slider_arrow:eq(0)', this.$slider).unbind('click').click(function(){ self.setProject(i-1); });
	$('.slider_arrow:eq(1)', this.$slider).unbind('click').click(function(){ self.setProject(i+1); });
}

ProjectsSlider.prototype.thumbOverlayStyle = function(i) {
	var $thov = $('.thumb_overlay',  this.$slider);
	var self = this;
	
	switch(this.t+i) {
		case 1: $thov.animate({height: "0px", top: "170px", paddingTop: "0px", paddingBottom: "0px"}, this.s); break;
		case 2:	$thov.fadeOut(this.s); break;
		case 3:	$('*', $thov).fadeOut(this.s); break;
		case 4: $thov.animate({width: "0px", left: "64px", paddingLeft: "0px", paddingRight: "0px"}, this.s); break;
		case 5: $thov.animate({height: "0px", top: "170px", paddingTop: "0px", paddingBottom: "0px"}, this.s); break;
		case 6:	$thov.hide(this.s); break;
		
		case 101: $thov.animate({height: "70px", top: "80px", paddingTop: "10px", paddingBottom: "10px"}, this.s);break;
		case 102: $thov.fadeIn(this.s);	break;
		case 103: $('*', $thov).fadeIn(this.s);	break;
		case 104: $thov.animate({width: "213px", left: "64px", paddingLeft: "10px", paddingRight: "10px"}, this.s);break;
		case 105: 
			$('a:first img:first', this.$slider).unbind('mouseover').mouseover(function(){
				$thov.animate({height: "70px", top: "80px", paddingTop: "10px",  paddingBottom: "10px"}, self.s);
			});
		break;
		case 106:
			$('a:first img:first', this.$slider).unbind('mouseover').mouseover(function(){ $thov.show(self.s); });
		break;
	}
}