function $A (iterable) {
	return Array.prototype.slice.apply(iterable);
}
Function.prototype.bind = function () {
	var method = this, args = $A(arguments), object = args.shift();
	return function () {
		return method.apply(object, args);
	};
};

var grs = {};
	grs.Counter = function() {
		this.interval;
		this.element = arguments[0];
		this.options = jQuery.extend({
			'digits': 1,
			'initial': 0,
			'offset': 1000,
			'delta': 1,
			'callback': function() {}
		}, arguments[1] || {});
		this.value = this.options.initial;

		this.generate = function() {
			var returnStr = '';
			var valueStr = (arguments[0] || this.value).toString();
			var deltaInt = this.options.digits - valueStr.length;

			for (var i = this.options.digits; i > 0; i--) {
				var j = i - deltaInt;
				var k = valueStr.length - j;
				var cls = [];
				if (i == 1)
					cls.push('first');
				if (i == this.options.digits)
					cls.push('last');
				if (i > 1 && i < this.options.digits)
					cls.push('odd');
				if ((k-2) % 3 == 1)
					cls.push('predot');

				if (valueStr.charAt(j - 1)) {
					if ((k-2) % 3 == 1)
						returnStr	= '<span class="digit digit-dot value-dot">.</span>' + returnStr;
					returnStr		= '<span class="digit digit-' + i + ' value-' + valueStr.charAt(j - 1) + ' ' + cls.join(' ') + '">'
									+ valueStr.charAt(j - 1)
									+ '</span>'
									+ returnStr;
				} else {
					if ((k-2) % 3 == 1)
						returnStr	= '<span class="digit digit-dot dot">.</span>' + returnStr;
					returnStr		= '<span class="digit digit-' + i + ' value-null ' + cls.join(' ') + '">0</span>' + returnStr;
				}
			}

			this.element.html(returnStr);
		}
		this.increase = function() {
			this.value = this.value + this.options.delta;
			return this.value;
		}
		this.decrease = function() {
			this.value = this.value - this.options.delta;
			return this.value;
		}
		this.start = function() {
			var i = 0;
			this.options.callback(i++);
			this.generate(this.increase());
			this.interval = window.setInterval(
				(function() {
					this.options.callback(i++);
					this.generate(this.increase());
				}).bind(this),
				this.options.offset
			);
		}
		this.pause = function() {
			if (this.interval)
				window.clearInterval(this.interval);
		}
		this.stop = function() {
			if (this.interval)
				window.clearInterval(this.interval);
			this.value = this.options.initial;
			this.generate();
		}

		return this;
	}
	grs.Accordion = function() {
		var options = jQuery.extend({
			'handleClass': '.handle',
			'toggleClass': '.toggle',
			'speed': 'slow'
		}, arguments[1] || {});

		var element = arguments[0];
			element.find(options.handleClass).each(function(i) {
				this.related = element.find(options.toggleClass)[i];
				$(this).click(function() {
					element.find('.active ' + options.toggleClass).slideUp(options.speed).parent().removeClass('active');
					$(this.related).slideDown(options.speed).parent().addClass('active');
				});
			});
	}
	grs.ImageLoader = function() {
		var imgs = arguments[0] || [];
		this.options = jQuery.extend({
			'onready': function() {},
			'onpercentage': function() {}
		}, arguments[1]);

		this.queueAdd = function() {
			this.queue.push({ src: arguments[0], ready: false });
		}
		this.queueStart = function() {
			for (i in this.queue)
				this._load(this.queue[i]);
		}
		this.checkStatus = function() {
			var allready = true;
			for (i in this.queue) {
				if (!this.queue[i].ready) allready = false;
				this.options.onpercentage();
			}
			if (allready)
				this.options.onready();
		}
		this.getPercentage = function() {
			return this.queue.findAll(function(q) { return q.ready; }).size() / this.queue.size() * 100;
		}
		this._load = function() {
			var inQueue = arguments[0];
				inQueue.cache = new Image();
				inQueue.cache.onload = (function() {
					inQueue.ready = true;
					this.checkStatus();
				}).bind(this);
				inQueue.cache.src = inQueue.src;
		}

		if (imgs.length) {
			this.queue = [];
			for (i in imgs)
				this.queueAdd(imgs[i]);
			this.queueStart();
		} else this.options.onready();
	}
	grs.Slideshow = function() {
		var self = this;
		var options = jQuery.extend({
			'images': '',
			'thumbs': '',
			'arrowright': '',
			'arrowleft': '',
			'autohide': false,
			'autoplay': false,
			'speed': 500,
			'active': 0,
			'contents': []
		}, arguments[1] || {});
		var element = arguments[0];
		var working = false;
		var interval = 0;
		var current = options.active;
		var previous = options.active;
		var rightarrow = element.find(options.arrowright).fadeTo(0, 0);
		var leftarrow = element.find(options.arrowleft).fadeTo(0, 0);
		var images = element.find(options.images + ' .inner');
		var thumbs = element.find(options.thumbs + ' .inner');

		if (options.autohide) {
			element.mouseover(function() {
				rightarrow.fadeTo(200, 1);
				leftarrow.fadeTo(200, 1);
			});
			element.mouseleave(function() {
				rightarrow.fadeTo(200, 0);
				leftarrow.fadeTo(200, 0);
			});
		}

		this.autoplay = function() {
			if (interval)
				window.clearInterval(interval);

			interval = window.setInterval(
				(function() {
					var next = current + 1;
					if (!options.contents[next])
						next = 0;
					this.goto(next);
				}).bind(this),
				options.autoplay
			);
		}
		this.generateImage = function(src, xtr) {
			var loadImg = new Image();
				loadImg.src = src;
			return '<div class="img" style="width: 0;" ' + (xtr || '') + '><div style="background: url(' + loadImg.src + ') no-repeat;"></div></div>';
		}
		this.swapImages = function(index, position, callback) {
			var imgObj = options.contents[index];
			var linked = imgObj.link;
			var thbInt = index;
			switch (position) {
				case 'left':
					// generate big image
					images.html(this.generateImage(imgObj.image) + images.html());
					var img = images.find('.img:first-child');
						img.css({ 'background-position': 'right' });
						img.animate({ 'width': 610 }, options.speed, 'linear', function() {
							images.find('.img:last-child').remove();
						});
					if (linked)
						img.addClass('linked').click(function() {
							location.href = linked;
						});
					// generate thumbnails
					var p = options.contents.length - 1 - (options.contents.length - 1 + 2 - index) % options.contents.length;
					thumbs.html(this.generateImage(options.contents[p].thumb, 'rel="' + p + '"') + thumbs.html());
					thumbs.find('.img.active').removeClass('active');
					thumbs.find('.img:first-child').animate({ 'width': 130 }, options.speed, 'linear', function() {
						thumbs.find('.img:last-child').remove();
						thumbs.find('.img:nth-child(3)').addClass('active');
						thumbs.find('.img').each(function() {
							//$(this).find('div').html($(this).attr('rel'));
							$(this).click(function() {
								self.gotoImage(2 - thumbs.find('.img').index($(this)));
							});
						});
						working = false;
						if (callback)
							callback(index);
					});
					break;
				case 'right':
					// generate big image
					images.html(images.html() + this.generateImage(imgObj.image));
					var img = images.find('.img:last-child').width(610);
					if (linked)
						img.addClass('linked').click(function() {
							location.href = linked;
						});
					images.find('.img:first-child').css({ 'background-position': 'right' }).animate({ 'width': 0 }, options.speed, 'linear', function() {
						images.find('.img:first-child').remove();
					});
					// generate thumbnails
					var n	= (index + 2) % options.contents.length;
					thumbs.html(thumbs.html() + this.generateImage(options.contents[n].thumb, 'rel="' + n + '"'));
					thumbs.find('.img:last-child').width(130);
					thumbs.find('.img.active').removeClass('active');
					thumbs.find('.img:first-child').css({ 'background-position': 'right' }).animate({ 'width': 0 }, options.speed, 'linear', function() {
						thumbs.find('.img:first-child').remove();
						thumbs.find('.img:nth-child(3)').addClass('active');
						thumbs.find('.img').each(function() {
							//$(this).find('div').html($(this).attr('rel'));
							$(this).click(function() {
								self.gotoImage(2 - thumbs.find('.img').index($(this)));
							});
						});
						working = false;
						if (callback)
							callback(index);
					});
					break;
				default:
					// generate big image
					images.html(this.generateImage(options.contents[index].image));
					var img = images.find('.img').width(610);
					if (linked)
						img.addClass('linked').click(function() {
							location.href = linked;
						});
					// generate thumbnails
					thumbs.html(this.generateImage(options.contents[index].thumb, 'rel="' + index + '"'));
					thumbs.find('.img').width(130).addClass('active');
					for (var i = 1; i < 3; i++) {
						var p	= options.contents.length - 1 - (options.contents.length - 1 + i - index) % options.contents.length;
						var n	= (index + i) % options.contents.length;
						thumbs.html(this.generateImage(options.contents[p].thumb, 'rel="' + p + '"') + thumbs.html() + this.generateImage(options.contents[n].thumb, 'rel="' + n + '"'));
					}
					thumbs.find('.img').each(function() {
						//$(this).find('div').html($(this).attr('rel'));
						$(this).width(130).click(function() {
							self.gotoImage(2 - thumbs.find('.img').index($(this)));
						});
					});
					break;
			}
		}
		this.nextImage = function() {
			if (!working) {
				var clbk = arguments[0] || function() {}
				var next = current + 1;
				if (!options.contents[next])
					next = 0;
				if (current != next) {
					working = true;
					self.swapImages(next, 'right', clbk);
					previous = current;
					current = next;
					if (options.autoplay)
						self.autoplay();
				}
			}
		}
		this.prevImage = function() {
			if (!working) {
				var clbk = arguments[0] || function() {}
				var prev = current - 1;
				if (!options.contents[prev])
					prev = options.contents.length-1;
				if (current != prev) {
					working = true;
					self.swapImages(prev, 'left', clbk);
					previous = current;
					current = prev;
					if (options.autoplay)
						self.autoplay();
				}
				return false;
			}
		}
		this.gotoImage = function(offset) {
			if (offset > 0)
				self.prevImage(function() {
					self.gotoImage(offset-1);
				});
			else if (offset < 0)
				self.nextImage(function() {
					self.gotoImage(offset+1);
				});
			else return false;
		}
		this.build = function() {
			this.swapImages(options.active);
			this.load();
		}
		this.load = function() {
			var loader = new Image();
			for (var i = 0; i < options.contents.length; i++)
				loader.src = options.contents[i].image;
		}

		rightarrow.click(function(e) {
			e.preventDefault();
			self.nextImage();
		});
		leftarrow.click(function(e) {
			e.preventDefault();
			self.prevImage();
		});
		if (options.autoplay)
			this.autoplay();
	}
	grs.Slider = function() {
		this.options = jQuery.extend({
			'handleUp': '.up',
			'handleDown': '.down',
			'scrollClass': '.scroll',
			'itemClass': '.item',
			'offset': 1,
			'speed': 500
		}, arguments[1]);
		var self = this;
		var current = 0;
		var element = arguments[0];
		var elements = element.find(this.options.itemClass).map(function(i, e) {
			return $(e).offset().top - element.offset().top;
		});

		this.scrollUp = function(e) {
			e.preventDefault();
			if (!$(this).hasClass('active')) {
				current = elements[current - self.options.offset] ? current - self.options.offset : 0;
				element.animate({
					'scrollTop': elements[current]
				}, self.options.speed);
			}
		}
		this.scrollDown = function(e) {
			e.preventDefault();
			if (!$(this).hasClass('active')) {
				current = elements[current + self.options.offset] ? current + self.options.offset : elements.length - 1;
				element.animate({
					'scrollTop': elements[current]
				}, self.options.speed, 0, function() {
					/*alert(''
						+ (element.height() + element.scrollTop()) + "\n"
						+ (element.innerHeight() + element.scrollTop()) + "\n"
						+ (element.outerHeight() + element.scrollTop()) + "\n"
						+ $(self.options.scrollClass).height() + "\n"
						+ $(self.options.scrollClass).innerHeight() + "\n"
						+ $(self.options.scrollClass).outerHeight()
					)*/
				});
			}
		}
		this.updateControls = function() {
			if (element.scrollTop() == 0)
				$(self.options.handleUp).addClass('active');
			else if (element.height() + element.scrollTop() == $(self.options.scrollClass).height() ||
					 element.height() + element.scrollTop() == $(self.options.scrollClass).height() - 2)
				$(self.options.handleDown).addClass('active');
			else $(self.options.handleUp + ',' + self.options.handleDown).removeClass('active');
		}

		$(self.options.handleUp).click(self.scrollUp);
		$(self.options.handleDown).click(self.scrollDown);
		element.scroll(this.updateControls);
		element.scroll();
	}
	
$(document).ready(function(){
	$('.tx-indexedsearch-res:odd').addClass('keks');
	$('.tx-indexedsearch-browsebox strong:even').addClass('keks');
	
	jQuery(".tafiframe").removeClass("unhidethis"); 
	jQuery(".tafiframe").addClass("hidethis"); 
	
	jQuery(".toolbar .recommend").click(function(){
				jQuery(".tafiframe").addClass("unhidethis"); 
				jQuery(".tafiframe").removeClass("hidethis");
             });
	jQuery(".toolbar .print").click(function(){
				window.print ();
             });

	
	try{
		// language selector 
		$('#catmenu').find('div').bind('mousedown', function(event){
			var el = $(event.currentTarget);
			if (el.hasClass('open')) {
				el.removeClass('open');
				$('#catmenu').find('ul').removeClass('over');
			} else {
				el.addClass('open');
				$('#catmenu').find('ul').addClass('over');
			}
/*  			if(Event.element(event).className=='') {
  				event.currentTarget.addClass('open');
  				$('top-company-selector').down('ul').addClassName('over');
  			} else {
  				Event.element(event).removeClassName('open');
  				$('top-company-selector').down('ul').removeClassName('over');
  			}
  */
 		});

	}catch(e){}
});



