


var typewatch = (function(){
  var timer = 0;
  return function(callback, ms){
    clearTimeout (timer);
    timer = setTimeout(callback, ms);
  }  
})();


biuro_ = new Class({
	initialize:function(){
		
		if ($('button_my_account')) {
			$('button_my_account').addEvent('click',function(e){
				document.location.href = '?node_id=1606&lang=pl';
			});
			$('button_my_cart').addEvent('click',function(e){
				document.location.href = '?node_id=1601&lang=pl';
			});
		}
		
		this.sstring = 'Wpisz nazwę produktu którego szukasz';
		var search = $('node_shop_product_search_input');
		if (search.value=='') search.value=this.sstring;
		search.addEvent('focus',function(e){ if (search.value==this.sstring) search.value='';}.bind(this));
		search.addEvent('blur',function(e){	if (search.value=='') search.value=this.sstring;}.bind(this));
		
		var max =0;
		$$('td.pid_name').each(function(item){
			size = item.getSize();
			if (size.y>max) max = size.y;
		});
		$$('td.pid_name').each(function(item){
			item.setStyle('height',max);
		});
		
		
		var max =0;
		$$('div.front_category').each(function(item){
			size = item.getSize();
			if (size.y>max) max = size.y;
		});
		$$('div.front_category').each(function(item){
			item.setStyle('height',max);
		});
		
		
		$$('a.goback').each(function(item){
			item.addEvent('click',function(e){
				e.stop();
				history.back();
			});
		});
		
//		$$('.tab-group').each(function(it){ it.addClass('hi');});
//
//		$$('.tab-item').each(function(item){
//			item.addEvent('click',function(e){
//				e.stop();
//				$$('.tab-group').each(function(it){ it.addClass('hi');});
//				$$('.tab-item').each(function(it){ it.removeClass('active');});
//				var x = item.rel+'_content';
//				$(x).removeClass('hi');
//				item.addClass('active');
//			});
//		});
		
//		automatycznie inicjujemy bestsellery
//		if ($('tabA')) {
//			if ($$('.special-item').length>0) $('tips-cat-id').removeClass('hidden');
//			$('tabA').addClass('active');
//			$('tabA_content').removeClass('hi');
//		}
	},
	tab_click:function(id){
		
	}
});


Date.prototype.date = function(format)
{
	for (var i = 0, c = '', returner = '', formats = new Object(); i < format.length; i++)
	{
		c = format.charAt(i);
		if (c == '\\' && i + 1 < format.length) returner += format.charAt(++i);
		else if (typeof formats[c] != 'undefined') returner += formats[c];
		else
		{
			switch (c)
			{
				case 'a':
					formats[c] = this.getHours() < 12 ? 'przed południem' : 'po południu';
					break;
				case 'd':
					var day = this.getDate();
					formats[c] = (day < 10 ? '0' : '') + day;
					break;
				case 'D':
					var days = new Array('Nie', 'Pon', 'Wto', 'Śro', 'Czw', 'Pią', 'Sob');
					formats[c] = days[this.getDay()];
					break;
				case 'E':
					var month = new Array('stycznia', 'lutego', 'marca', 'kwietnia', 'maja', 'czerwca', 'lipca', 'sierpnia', 'września', 'października', 'listopada', 'grudnia');
					formats[c] = month[this.getMonth()];
					break;
				case 'F':
					var month = new Array('Styczeń', 'Luty', 'Marzec', 'Kwiecień', 'Maj', 'Czerwiec', 'Lipiec', 'Sierpień', 'Wrzesień', 'Październik', 'Listopad', 'Grudzień');
					formats[c] = month[this.getMonth()];
					break;
				case 'g':
					formats[c] = (this.getHours() - 1) % 12 + 1;
					break;
				case 'G':
					formats[c] = this.getHours();
					break;
				case 'h':
					var hour = (this.getHours() - 1) % 12 + 1;
					formats[c] = (hour < 10 ? '0' : '') + hour;
					break;
				case 'H':
					var hour = this.getHours();
					formats[c] = (hour < 10 ? '0' : '') + hour;
					break;
				case 'i':
					var minute = this.getMinutes();
					formats[c] = (minute < 10 ? '0' : '') + minute;
					break;
				case 'j':
					formats[c] = this.getDate();
					break;
				case 'l':
					var days = new Array('Niedziela', 'Poniedziałek', 'Wtorek', 'Środa', 'Czwartek', 'Piątek', 'Sobota');
					formats[c] = days[this.getDay()];
					break;
				case 'L':
					formats[c] = this.getFullYear() % 400 && (this.getFullYear() % 4 || !(this.getFullYear() % 100)) ? 0 : 1;
					break;
				case 'm':
					var month = this.getMonth() + 1;
					formats[c] = (month < 10 ? '0' : '') + month;
					break;
				case 'M':
					var month = new Array('Sty', 'Lut', 'Mar', 'Kwi', 'Maj', 'Cze', 'Lip', 'Sień', 'Wrz', 'Paź', 'Lis', 'Gru');
					formats[c] = month[this.getMonth()];
					break;
				case 'n':
					formats[c] = this.getMonth() + 1;
					break;
				case 'O':
					var O = -this.getTimezoneOffset() / 60;
					if (O < 0)
					{
						var sign = '-';
						O = -O;
					}
					else sign = '+';
					formats[c] = sign + (O < 10 ? '0' : '') + O + '00';
					break;
				case 'r':
					formats[c] = this.date('D, d M Y H:i:s O');
					break;
				case 's':
					var second = this.getSeconds();
					formats[c] = (second < 10 ? '0' : '') + second;
					break;
				case 'S':
					if (this.getDate().toString().search(/(^|[02-9])1$/) != -1) formats[c] = '-wszy';
					else if (this.getDate().toString().search(/(^|[02-9])2$/) != -1) formats[c] = '-gi';
					else if (this.getDate().toString().search(/(^|[02-9])3$/) != -1) formats[c] = '-ci';
					else if (this.getDate().toString().search(/(^|[02-9])[78]$/) != -1) formats[c] = '-my';
					else formats[c] = '-ty';
					break;
				case 't':
					var months = new Array(31, this.getFullYear() % 400 && (this.getFullYear() % 4 || !(this.getFullYear() % 100)) ? 28 : 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
					formats[c] = months[this.getMonth()];
					break;
				case 'U':
					formats[c] = Date.parse(this) / 1000;
					break;
				case 'w':
					formats[c] = this.getDay();
					break;
				case 'W':
					var day = this.getDay() - 1;
					if (day == -1) day = 6;
					formats[c] = Math.round((this.date('z') - day + 6) / 7);
					if (formats[c] == 0)
					{
						var date = new Date(this.getFullYear() - 1, 11, 31, 23, 59, 59);
						day = date.getDay() - 1;
						if (day == -1) day = 6;
						formats[c] = Math.round((date.date('z') - day + 6) / 7);
					}
					else
					{
						var date = new Date(this.getFullYear(), 11, 31, 23, 59, 59);
						day = date.getDay() - 1;
						if (day == -1) day = 6;
						if (day < 3 && this.date('z') >= date.date('z') - day) formats[c] = 1;
					}
					break;
				case 'Y':
					formats[c] = this.getFullYear();
					break;
				case 'y':
					formats[c] = this.getFullYear().toString().substring(2);
					break;
				case 'z':
					var months = new Array(31, this.getFullYear() % 400 && (this.getFullYear() % 4 || !(this.getFullYear() % 100)) ? 28 : 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
					formats[c] = this.getDate();
					for (var j = 0, month = this.getMonth(); j < month; j++) formats[c] += months[j];
					break;
				case 'Z':
					formats[c] = -this.getTimezoneOffset() * 60;
					break;
				default:
					formats[c] = c;
					break;
			}
			returner += formats[c];
		}
	}
	
	return returner;
}

var biuro = null;
window.addEvent('domready',function() { biuro = new biuro_();});


