
function Licznik() {
this.liczba=0;
this.obrazek='licznikAbialy/licznikA';
this.format='.png';
this.szerokosc_obrazka=20;
this.timer_on=0;
};

Licznik.prototype.ustal = function (litera_id, wartosc)
{
 for(var i=0; i<wartosc.length; i++){
 var jqnazwa='#'+litera_id+i;
  var aktualny_img= $(jqnazwa + ' > img').attr('src');
  var img = 'http://voyagerwineclub.pl/images/'+this.obrazek+wartosc[i]+this.format;
  var wstawiany_img = '<img style=" position:inherit; top:0px; width:inherit; height:inherit;" src="http://voyagerwineclub.pl/images/'+this.obrazek+wartosc[i]+this.format+'">';
  if(aktualny_img != img)
  {
	  this.animuj_licznik(jqnazwa, wstawiany_img);
	  }
}
}

Licznik.prototype.animuj_licznik = function (jqnazwa, wstawiany_img)
{
var $f = $(jqnazwa);
var $img=$(jqnazwa+' > img');

 $f.fadeOut(100);
 $f.html(wstawiany_img);
 $f.fadeIn(150); /*
 $f.slideToggle(150, 'linear', function() {$f.html(wstawiany_img);});
 $f.slideToggle(150);*/
}

Licznik.prototype.ustalDni = function ()
{
var dd = this.days(this.countDownUntil(data));
 this.ustal('d', dd); 
}
Licznik.prototype.ustalGodz = function ()
{
 var dd= this.hours(this.countDownUntil(data));
 if(dd==23)
  this.ustalDni();
 this.ustal('h', dd);
}
Licznik.prototype.ustalMin = function ()
{
 var dd= this.minutes(this.countDownUntil(data));
 if(dd==59)
  this.ustalGodz();
 this.ustal('m', dd);
}
Licznik.prototype.ustalSec = function ()
{
 var dd= this.seconds(this.countDownUntil(data));
 this.ustal('s', dd);
 if(dd==59)
  this.ustalMin();
}

Licznik.prototype.addzeros = function (d, length_wanted)
{
var ds=d;
 while(ds.length<length_wanted)
  ds = '0' + ds;
 return ds;
}

Licznik.prototype.days = function (d)
{
 var ds = Math.floor(d/(1000*3600*24));
 var dstr = ds.toString();
 return this.addzeros(dstr, 3);
}
Licznik.prototype.hours = function (d)
{
 var ds = (Math.floor(d/(1000*3600))).toString();
 return this.addzeros(ds, 3);
}

Licznik.prototype.__hours = function (d)
{
 var ds=(Math.floor((d%(60*60*1000*24))/(60*60*1000))).toString();
 return this.addzeros(ds, 2);
}
Licznik.prototype.minutes = function (d)
{
var ds = (Math.floor(((d%(60*60*1000*24))%(60*60*1000))/(60*1000))).toString();
 return this.addzeros(ds, 2);
}
Licznik.prototype.seconds = function (d)
{
var ds = (Math.floor((((d%(60*60*1000*24))%(60*60*1000))%(60*1000))/1000*1)).toString();
 return this.addzeros(ds, 2);
}
Licznik.prototype.countDownUntil = function (datado)
{
 var today=new Date();
 var odlicz = Date.parse(datado) - today;
 if(odlicz<=0)
  {
	this.reachedDate();
  }
 return odlicz;
}

Licznik.prototype.reachedDate = function ()
{
 if(this.timer_on) 
 {
	 this.timer_on=0;
	 $('#oferta_tygodnia').fadeOut(150);
	 $('#oferta_tygodnia').html('<img src="http://voyagerwineclub.pl/images/oferta_tygodnia/oferta_tygodnia_tylko_dzis.png"/>');
	 $('#oferta_tygodnia').fadeIn(250);
 }
 }

