/*pushoptions*/
/*cleearoptions*/
/*jslint white:false*/
/*jslint strict:false*/
/*jslint browser:true*/
/*jslint devel:true*/
/*jslint widget:true*/
/*jslint onevar:false*/
/*jslint undef:false*/
/*jslint nomen:true*/
/*jslint eqeqeq:true*/
/*jslint plusplus:false*/
/*jslint bitwise:true*/
/*jslint regexp:false*/
/*jslint maxerr: 200*/



/*
Script: Fx.Scroll.js
	Effect to smoothly scroll any element, including the window.

	License:
		MIT-style license.

	Authors:
		Valerio Proietti
*/

Fx.Scroll = new Class({

	Extends: Fx,

	options: {
		offset: {x: 0, y: 0},
		wheelStops: true
	},

	initialize: function(element, options){
		this.element = this.subject = document.id(element);
		this.parent(options);
		var cancel = this.cancel.bind(this, false);

		if ($type(this.element) != 'element') this.element = document.id(this.element.getDocument().body);

		var stopper = this.element;

		if (this.options.wheelStops){
			this.addEvent('start', function(){
				stopper.addEvent('mousewheel', cancel);
			}, true);
			this.addEvent('complete', function(){
				stopper.removeEvent('mousewheel', cancel);
			}, true);
		}
	},

	set: function(){
		var now = Array.flatten(arguments);
		this.element.scrollTo(now[0], now[1]);
	},

	compute: function(from, to, delta){
		return [0, 1].map(function(i){
			return Fx.compute(from[i], to[i], delta);
		});
	},

	start: function(x, y){
		if (!this.check(x, y)) return this;
		var offsetSize = this.element.getSize(), scrollSize = this.element.getScrollSize();
		var scroll = this.element.getScroll(), values = {x: x, y: y};
		for (var z in values){
			var max = scrollSize[z] - offsetSize[z];
			if ($chk(values[z])) values[z] = ($type(values[z]) == 'number') ? values[z].limit(0, max) : max;
			else values[z] = scroll[z];
			values[z] += this.options.offset[z];
		}
		return this.parent([scroll.x, scroll.y], [values.x, values.y]);
	},

	toTop: function(){
		return this.start(false, 0);
	},

	toLeft: function(){
		return this.start(0, false);
	},

	toRight: function(){
		return this.start('right', false);
	},

	toBottom: function(){
		return this.start(false, 'bottom');
	},

	toElement: function(el){
		var position = document.id(el).getPosition(this.element);
		return this.start(position.x, position.y);
	},

	scrollIntoView: function(el, axes, offset){
		axes = axes ? $splat(axes) : ['x','y'];
		var to = {};
		el = document.id(el);
		var pos = el.getPosition(this.element);
		var size = el.getSize();
		var scroll = this.element.getScroll();
		var containerSize = this.element.getSize();
		var edge = {
			x: pos.x + size.x,
			y: pos.y + size.y
		};
		['x','y'].each(function(axis) {
			if (axes.contains(axis)) {
				if (edge[axis] > scroll[axis] + containerSize[axis]) to[axis] = edge[axis] - containerSize[axis];
				if (pos[axis] < scroll[axis]) to[axis] = pos[axis];
			}
			if (to[axis] == null) to[axis] = scroll[axis];
			if (offset && offset[axis]) to[axis] = to[axis] + offset[axis];
		}, this);
		if (to.x != scroll.x || to.y != scroll.y) this.start(to.x, to.y);
		return this;
	}

});



















/* --- ěščřžýáíé -- utf-8 --- */

/* -------- start of mootools more -------- */

/*
---

name: Events.Pseudos

description: Adds the functionallity to add pseudo events

license: MIT-style license

authors:
  - Arian Stolwijk

requires: [Core/Class.Extras, Core/Slick.Parser, More/MooTools.More]

provides: [Events.Pseudos]

...
*/


var fuckedZoomer;

Events.Pseudos = function(pseudos, addEvent, removeEvent){

	var storeKey = 'monitorEvents:';

	var storageOf = function(object){

		return {
			store: object.store ? function(key, value){
				object.store(storeKey + key, value);
			} : function(key, value){
				(object.$monitorEvents || (object.$monitorEvents = {}))[key] = value;
			},
			retrieve: object.retrieve ? function(key, dflt){
				return object.retrieve(storeKey + key, dflt);
			} : function(key, dflt){
				if (!object.$monitorEvents) return dflt;
				return object.$monitorEvents[key] || dflt;
			}
		};
	};


	var splitType = function(type){
		if (type.indexOf(':') == -1) return null;

		var parsed = Slick.parse(type).expressions[0][0],
			parsedPseudos = parsed.pseudos;

		return (pseudos && pseudos[parsedPseudos[0].key]) ? {
			event: parsed.tag,
			value: parsedPseudos[0].value,
			pseudo: parsedPseudos[0].key,
			original: type
		} : null;
	};


	return {

		addEvent: function(type, fn, internal){
			var split = splitType(type);
			if (!split) return addEvent.call(this, type, fn, internal);

			var storage = storageOf(this),
				events = storage.retrieve(type, []),
				pseudoArgs = Array.from(pseudos[split.pseudo]),
				proxy = pseudoArgs[1];

			var self = this;
			var monitor = function(){
				pseudoArgs[0].call(self, split, fn, arguments, proxy);
			};

			events.include({event: fn, monitor: monitor});
			storage.store(type, events);

			var eventType = split.event;
			if (proxy && proxy[eventType]) eventType = proxy[eventType].base;

			addEvent.call(this, type, fn, internal);
			return addEvent.call(this, eventType, monitor, internal);
		},

		removeEvent: function(type, fn){
			var split = splitType(type);
			if (!split) return removeEvent.call(this, type, fn);

			var storage = storageOf(this),
				events = storage.retrieve(type),
				pseudoArgs = Array.from(pseudos[split.pseudo]),
				proxy = pseudoArgs[1];

			if (!events) return this;

			var eventType = split.event;
			if (proxy && proxy[eventType]) eventType = proxy[eventType].base;

			removeEvent.call(this, type, fn);
			events.each(function(monitor, i){
				if (!fn || monitor.event == fn) removeEvent.call(this, eventType, monitor.monitor);
				delete events[i];
			}, this);

			storage.store(type, events);
			return this;
		}

	};

};

(function(){

var pseudos = {

	once: function(split, fn, args){
		fn.apply(this, args);
		this.removeEvent(split.original, fn);
	}

};

Events.definePseudo = function(key, fn){
	pseudos[key] = fn;
};

var proto = Events.prototype;
Events.implement(Events.Pseudos(pseudos, proto.addEvent, proto.removeEvent));

})();


/*
---

name: Element.Event.Pseudos

description: Adds the functionality to add pseudo events for Elements

license: MIT-style license

authors:
  - Arian Stolwijk

requires: [Core/Element.Event, Events.Pseudos]

provides: [Element.Event.Pseudos]

...
*/

(function(){

var pseudos = {

	once: function(split, fn, args){
		fn.apply(this, args);
		this.removeEvent(split.original, fn);
	}

};

Event.definePseudo = function(key, fn, proxy){
	pseudos[key] = [fn, proxy];
};

var proto = Element.prototype;
[Element, Window, Document].invoke('implement', Events.Pseudos(pseudos, proto.addEvent, proto.removeEvent));

})();


/*
---

script: Element.Delegation.js

name: Element.Delegation

description: Extends the Element native object to include the delegate method for more efficient event management.

credits:
  - "Event checking based on the work of Daniel Steigerwald. License: MIT-style license. Copyright: Copyright (c) 2008 Daniel Steigerwald, daniel.steigerwald.cz"

license: MIT-style license

authors:
  - Aaron Newton
  - Daniel Steigerwald

requires: [/MooTools.More, Element.Event.Pseudos]

provides: [Element.Delegation]

...
*/


Event.definePseudo('relay', function(split, fn, args, proxy){
	var event = args[0];
	var check = proxy ? proxy.condition : null;

	for (var target = event.target; target && target != this; target = target.parentNode){
		var finalTarget = document.id(target);
		if (Slick.match(target, split.value) && (!check || check.call(finalTarget, event))){
			if (finalTarget) fn.call(finalTarget, event, finalTarget);
			return;
		}
	}

}, {
	mouseenter: {
		base: 'mouseover',
		condition: Element.Events.mouseenter.condition
	},
	mouseleave: {
		base: 'mouseout',
		condition: Element.Events.mouseleave.condition
	}
});


/*
---

script: Fx.Elements.js

name: Fx.Elements

description: Effect to change any number of CSS properties of any number of Elements.

license: MIT-style license

authors:
  - Valerio Proietti

requires:
  - Core/Fx.CSS
  - /MooTools.More

provides: [Fx.Elements]

...
*/

Fx.Elements = new Class({

	Extends: Fx.CSS,

	initialize: function(elements, options){
		this.elements = this.subject = $$(elements);
		this.parent(options);
	},

	compute: function(from, to, delta){
		var now = {};

		for (var i in from){
			var iFrom = from[i], iTo = to[i], iNow = now[i] = {};
			for (var p in iFrom) iNow[p] = this.parent(iFrom[p], iTo[p], delta);
		}

		return now;
	},

	set: function(now){
		for (var i in now){
			if (!this.elements[i]) continue;

			var iNow = now[i];
			for (var p in iNow) this.render(this.elements[i], p, iNow[p], this.options.unit);
		}

		return this;
	},

	start: function(obj){
		if (!this.check(obj)) return this;
		var from = {}, to = {};

		for (var i in obj){
			if (!this.elements[i]) continue;

			var iProps = obj[i], iFrom = from[i] = {}, iTo = to[i] = {};

			for (var p in iProps){
				var parsed = this.prepare(this.elements[i], p, iProps[p]);
				iFrom[p] = parsed.from;
				iTo[p] = parsed.to;
			}
		}

		return this.parent(from, to);
	}

});

/* ---------- end of mootools more ---------- */

/*
---
 
name: Zoomer
description: Class to show zoomed image inside original
license: MIT-Style License (http://mifjs.net/license.txt)
copyright: Anton Samoylov (http://mifjs.net)
authors: Anton Samoylov (http://mifjs.net)
requires: core:1.2.4:*
provides: Zoomer
 
...
*/

var Zoomer = new Class({
	
	version: '1.9.1',
	
	Implements: [Options],
	
	options: {
		smooth: 8
	},
	
	initialize: function(element, injector, options,enabled){
		var inj;

	this.disabled=!!!enabled;
	


	
	this.element=element;
	//this.injector=injector;

		
		this.setOptions(options);

		this.injector = $$(injector);
		if (!this.injector || this.injector.length < 1) {
			return false;
		}
		this.injector = this.injector[0].empty();

		
		
		this.small = document.id(element);
		if(!this.small.complete){
			this.small.addEvent('load', function(){
				this.small.removeEvents('load');
				this.prepareSmall();
			}.bind(this));
		}else{
			this.prepareSmall();
		}

		var src = this.imgSrc = this.options.big || this.small.get('big') || (this.small.get('src') && this.small.get('src').replace('85x85', 'large')) || (this.small.get('href') && this.small.get('href').replace('85x85', 'href'));
		
		if(this.disabled)src=this.imgSrc=src.replace("large","600x600")
		
		var styles = {
			position: 'relative',
			top: 0,
			left: 0,
			backgroundColor: 'white',
			cursor: 'crosshair'
		};
				
		if (typeof src === 'string') {
			this.big = new Element('img', {
				src: src,
				styles: styles
			});
		} else {
			this.big = src;
			this.big.setStyles(styles);
		}
		
		this.insider = {
			steps: this.options.smooth,
			dst: {
				left: 0,
				top: 0
			}
		};

		if(!this.big.complete){
			this.big.addEvent('load', function(){
				this.big.removeEvents('load');
				this.prepareBig();
			}.bind(this));
		}else{
			this.prepareBig();
		}
		
		
		
		
		return this;
	},
	
	prepareSmall: function(){
		var z;
		z = this.injector.getSize();
		this.wrapper = new Element('div', {'class': 'zoomer-wrapper'}).inject(this.injector);
		this.wrapper.setStyles({
			position: 'relative',
			overflow: 'hidden',
			height: z.y,
			width: z.x
		});
		this.smallSize = {
			width: this.wrapper.getStyle('width').toInt(),
			height: this.wrapper.getStyle('height').toInt()
		};
		if(this.bigPrepared){
			this.ready();
		}else{
			this.smallPrepared = true;
		}
	},

	prepareBig: function(){
		this.bigSize = {
			width: this.big.width,
			height: this.big.height
		};
		if(this.smallPrepared){
			this.ready();
		}else{
			this.bigPrepared = true;
		}
	},
	
	
	turnon:function(event){
	  //this.disabled=false;
	  $clear(this.timer);
		this.bigWrapper.removeEvents('mouseenter').removeEvents('mouseleave').removeEvents('mousemove');
		this.bigWrapper.empty();
		
	  this.initialize(this.element,this.injector,{},true);
	},
	
	turnoff:function(){
	  
	  //this.disabled=false;
	  $clear(this.timer);
		this.bigWrapper.removeEvents('mouseenter').removeEvents('mouseleave').removeEvents('mousemove');
		this.bigWrapper.empty();
		
	  this.initialize(this.element,this.injector,{},false);
	},
	
	ready: function(){
		this.big.inject(this.wrapper);
		this.bigWrapper = new Element('div', {
			'class': 'zoomer-wrapper-big',
			styles: {
				position: 'absolute',
				overflow: 'hidden',
				
				top: 0,
				left: 0,
				width: '100%',
				height: '100%',
				background: 'url("' + this.imgSrc + '")',
				backgroundRepeat:'no-repeat',
				opacity: 0
			},
			events: this.disabled?{}:{
				mouseenter: this.startZoom.bind(this),
				mouseleave: this.stopZoom.bind(this),
				mousemove: this.move.bind(this)
			}
		}).wraps(this.big);

		this.sizes = this.bigWrapper.getSize();

		if(!this.disabled) this.big.setStyles({left: -(this.bigSize.width-this.smallSize.width) / 2, top: -(this.bigSize.height-this.smallSize.height)});

		this.bigWrapper.fade('show');
//		this.bigWrapper.setStyle('backgroundPosition', '50% -100px').fade('in');
	},
	
	move: function(event){
		this.dstPos = event.page;
	},
	
	startZoom: function(){

		this.position = this.wrapper.getPosition();

		this.ratio = {
			x: 1 - this.bigSize.width / this.wrapper.getStyle('width').toInt(),
			y: 1 - this.bigSize.height / this.wrapper.getStyle('height').toInt()
		};

		this.current = {
			left: this.big.getStyle('left').toInt(),
			top: this.big.getStyle('top').toInt()
		};
		
		this.timer = this.zoom.periodical(30, this);
//		this.big.fade('in');
	},

	stopZoom: function(){
		$clear(this.timer);
//		this.big.fade('out');
	},
	
	zoom: function(){
		if(!this.dstPos) {
			return;
		}
		
		this.insider.dst.left = parseInt((this.dstPos.x - this.position.x) * this.ratio.x, 10);
		this.insider.dst.top = parseInt((this.dstPos.y - this.position.y) * this.ratio.y, 10);

		this.current.left -= (this.current.left - this.insider.dst.left) / this.insider.steps;
		this.current.top -= (this.current.top - this.insider.dst.top) / this.insider.steps;

//		this.bigWrapper.setStyle('backgroundPosition', Math.round((this.dstPos.x - this.position.x) / this.sizes.x * 100, 1) + '% ' + Math.round((this.dstPos.y - this.position.y) / this.sizes.y * 100, 1) + '%');
//		this.bigWrapper.setStyle('backgroundPosition', this.current.left + 'px ' + this.current.top + 'px');
		this.big.setStyles(this.current);
	},

	kill: function() {
		$clear(this.timer);
		this.big.fade('hide');
		this.bigWrapper.removeEvents('mouseenter').removeEvents('mouseleave').removeEvents('mousemove');
		this.bigWrapper.empty();
	}
	
});

/*
---
description: DoubleSlider

authors:
	- Matthias Goebels (http://moo.medienpark.net)

license: MIT-style

requires:
	- core/1.2.4: Class.Extras
	- core/1.2.4: Array
	- core/1.2.4: Function
	- core/1.2.4: Event
	- core/1.2.4: Element.Style
	- core/1.2.4: Element.Dimensions
	- core/1.2.4: Fx.Morph
	- core/1.2.4: Fx.Transitions

provides: [DoubleSlider]

...
*/
var DoubleSlider = new Class({

	Implements: [Events, Options],

	Binds: ['onDrag', 'onStart', 'onComplete'],

	options:
	{/*
		onChange: $empty(intStep),
		onStart: $empty(intStep),
		onComplete: $empty(intStep),*/
	range: [200, 600],
		start: [0, 0],
		mode: 'horizontal',
		knobs: false
	},

	initialize: function(element, options)
	{
		this.setOptions(options);
		this.element = document.id(element);

		var offset;
		switch (this.options.mode)
		{
			case 'vertical':
				this.axis = ['y', 'x'];
				this.property = 'top';
				offset = 'offsetHeight';
				break;
			case 'horizontal':
				this.axis = ['x', 'y'];
				this.property = 'left';
				offset = 'offsetWidth';
		}
		
		var knobs = this.options.knobs === false ? (this.element.getElements('div')) : this.element.getElements(this.options.knobs);
		this.knob_left = knobs[0];
		this.knob_right = knobs[1];
		
		this.full = this.element[offset];
		this.knob_width = this.knob_left[offset];
		this.range = this.full - this.knob_width;
		this.faktor = (this.options.range[1] - this.options.range[0]) / (this.full - 2 * this.knob_width);

		this.options.start[0] = Math.round((this.options.start[0] - this.options.range[0]) / this.faktor);
		this.options.start[1] = Math.round((this.options.start[1] - this.options.range[0]) / this.faktor) + this.knob_width;
		
		var start = [0, 0];
		start[0] = (this.options.start[0] < 0) ? 0 : this.options.start[0];
		start[1] = (this.options.start[1] <= start[0] + this.knob_width) ? start[0] : this.options.start[1] - this.knob_width;
		this.knob_left.setStyle('position', 'absolute').setStyle(this.property, start[0]);
		this.knob_right.setStyle('position', 'absolute').setStyle(this.property, start[1]);

		this.initDrag();

		return this;
	},
	
	initDrag: function()
	{
		var modifiers = {'x': false, 'y': false};
		var limit = {}, limit2, dragOptions, dragOptions2;
		modifiers[this.axis[0]] = this.property;

		
		limit[this.axis[0]] = [0, this.knob_right.getStyle(this.property).toInt()];
		limit[this.axis[1]] = [0, 0];
		limit2 = limit;

		dragOptions = {
			limit: limit,
			modifiers: modifiers,
			onDrag: this.onDrag,
			onBeforeStart: this.onStart,
			onComplete: this.onComplete
		};
		dragOptions2 = dragOptions;

		this.drag_left = new Drag(this.knob_left, dragOptions);
		
		limit2[this.axis[0]] = [this.knob_left.getStyle(this.property).toInt(), this.range - this.knob_width];
		limit2[this.axis[1]] = [0, 0];
		
		dragOptions2.limit = limit2;
		this.drag_right = new Drag(this.knob_right, dragOptions2);
	},
	
	getKnobValues: function()
	{
		var values = {};
		values.knob_left = this.options.range[0] + Math.round(this.knob_left.getStyle(this.property).toInt() * this.faktor);
		values.knob_right = this.options.range[0] + Math.round(this.knob_right.getStyle(this.property).toInt() * this.faktor);
		return values;
	},

	onDrag: function(draggedElement)
	{
		this.updateKnobRange();
		this.fireEvent('change', this.getKnobValues());
	},
	
	onStart: function(draggedElement)
	{
		this.updateKnobRange();
		this.fireEvent('start', this.getKnobValues());
	},
	
	onComplete: function(draggedElement)
	{
		this.updateKnobRange();
		this.fireEvent('complete', this.getKnobValues());
	},
	
	updateKnobRange: function()
	{
		this.drag_left.options.limit[this.axis[0]] = [
			0,
			this.knob_right.getStyle(this.property).toInt()
		];

		this.drag_right.options.limit[this.axis[0]] = [
			this.knob_left.getStyle(this.property).toInt(),
			this.range - this.knob_width
		];
	}
});





/*
Script: PeriodicalExecuter.js
	port of the Prototype.js timer to Mootools

	License: MIT-style license.
	Copyright: Copyright (c) 2007 Thierry bela <bntfr at yahoo dot fr>

	License:
		MIT-style license.

	Authors:
		Thierry Bela

	TODO: possibility to stop the timer when the window is idle ?
*/			
	var PeriodicalExecuter = new Class({
		// name: 'PeriodicalExecuter',
		initialize: function(callback, frequency) {
		
			this.callback = callback;
			this.frequency = frequency;
			this.currentlyExecuting = false;

			this.registerCallback()
		},

		registerCallback: function() {
		
			this.stop();
			this.timer = setInterval(this.onTimerEvent.bind(this), this.frequency * 1000);
			return this
		},

		execute: function() {
		
			this.callback(this);
			return this
		},

		stop: function() {
		
			if (!this.timer) return this;
			clearInterval(this.timer);
			this.timer = null;
			return this
		},

		onTimerEvent: function() {
		
			if (!this.currentlyExecuting) {
			
				try {
				
					this.currentlyExecuting = true;
					this.execute();
				} finally {
				
					this.currentlyExecuting = false;
				}
			}
				
			return this
		}
	});





		
		
/*
---
script: Carousel.js
license: MIT-style license.
description: Tab - Minimalistic but extensible tab swapper.
copyright: Copyright (c) 2010 Thierry Bela
authors: [Thierry Bela]

requires: 
  core:1.3: 
  - Class.Extras
  - Element.Event
  - Element.Style
  - Element.Dimensions
  - Array
provides: [Carousel, Carousel.plugins.Move]
...
*/

!function ($) {

function style(el, style) {

	var mrg = el.getStyle(style);
	
	return mrg == 'auto' ? 0 : mrg.toInt() 
}

var Carousel = this.Carousel = new Class({

		Implements: [Options, Events],
		options: {
		
		/*
			circular: false,
			onChange: function (index) {
			
			},
			previous: element1,
			next: element2,
			container: null,
			selector: '',
			tabs: [],
			activeClass: '',
			inactiveClass: '',
		*/
			link: 'cancel',
			mode: 'horizontal',
			animation: 'Move',
			scroll: 4,
			distance: 1,
			fx: {
			
				link: 'cancel',
				transition: 'sine:out',
				duration: 500
			}
		},
		current: 0,
		plugins: {},
		initialize: function (options) {
		
			this.addEvents({
				change: function (current, selected) { 
				
					if(this.tabs[this.current]) this.tabs[this.current].addClass(this.options.inactiveClass).removeClass(this.options.activeClass)
					if(this.tabs[current]) this.tabs[current].addClass(this.options.activeClass).removeClass(this.options.inactiveClass);
					
					this.current = current;
					this.selected = selected
				},
				complete: function () { this.running = false }
			}).setOptions(options);
			
			['previous', 'next'].each(function (fn) {
				

				
				if($(this.options[fn])) $(this.options[fn]).addEvent('click', function (e) {
				
					e.stop();
					this[fn]()
					
				}.bind(this))
				
			}, this);
			
			var current = options.current || 0,
				events = this.events = {

						click: function(e) {

							e.stop();
							
							var target = e.event.target,
								index = this.tabs.indexOf(target);

							while(target && index == -1) {

								target = target.parentNode;
								index = this.tabs.indexOf(target)
							}
							
							if(index == -1) return;
							this.move(index)

						}.bind(this)
					};
					
			this.tabs = $$(options.tabs).addEvents(events);
			this.elements = $(options.container).getChildren(options.selector);
			
			this.anim = new this.plugins[this.options.animation](this.elements, this.options).addEvents({change: function () { this.fireEvent('change', arguments) }.bind(this), complete: function () { this.fireEvent('complete', arguments) }.bind(this)});
			
			this.move(current || 0);
		},
		
		isVisible: function (index) {
		
			if(typeOf($(index)) == 'element') index = this.elements.indexOf($(index));
			
			var length = this.elements.length,
				current = this.current,
				scroll = this.options.scroll;
			
			if(current <= index && index < current + scroll) return true;
			if(this.options.circular)  while(scroll && --scroll) if((scroll + current)  % length == index) return true;
			
			return false
		},
		
		first: function () { return this.current },
		
		previous: function (direction) { return this.move(this.current - this.options.distance, direction) },
		
		next: function (direction) { return this.move(this.current + this.options.distance, direction) },
	
		add: function (panel, tab, index) {

			panel = $(panel);
			tab = $(tab);

			if(tab) tab.addEvents(this.events);

			if(this.elements.indexOf(panel) != -1) return this;

			if(index == undefined) index = this.elements.length;
			index = Math.min(index, this.elements.length);
			
			switch(index) {

				case 0:
						if(this.elements.length > 0) {

							this.elements.unshift(panel.inject(this.elements[0], 'before'));
							if(tab) this.tabs.unshift(tab.inject(this.tabs[0], 'before'));
						}

						else {
						
							this.elements.push(panel.inject(this.options.container));
							if(tab) this.tabs.push(tab);
						}

						break;
				default:
						this.elements.splice(index, 0, panel.inject(this.elements[index - 1], 'after'));
						if(tab) this.tabs.splice(index, 0, tab.inject(this.tabs[index - 1], 'after'));
						break;
			}
			
			if(this.anim.add) this.anim.add(panel);
			this.current = this.elements.indexOf(this.selected);

			return this
		},

		remove: function (index) {

			var panel = this.elements[index],
				tab = this.tabs[index];
				
			//
			if(this.running || panel == undefined/*  || panel == this.selected */) return null;

			this.elements.splice(index, 1);
			panel.dispose();

			if(this.anim.remove) this.anim.remove(panel, index);

			if(tab) {

				tab.removeEvents(this.events).dispose();
				this.tabs.splice(index, 1);
			}

			this.current = this.elements.indexOf(this.selected);

			return {panel: panel, tab: tab}
		},

		move: function (index, direction) {
		
			if(this.running) {
			
				switch(this.options.link) {
				
					case 'cancel':
								this.anim.cancel();
								break;
					case 'chain':
								break;
					case 'ignore':
							return this;
				}
			}
			
			var elements = this.elements,
				current = this.current,
				length = elements.length,
				scroll = this.options.scroll;
			
			if(typeOf($(index)) == 'element') index = elements.indexOf(index);
			
			if(!this.options.circular) {
		
				if(index > length - scroll) index = length - scroll
			}	
				
			else {
			
				if(index < 0) index += length;
				index %= Math.max(length, 1)
			}			
		
			if(index < 0 || length <= scroll || index >= length) return this;

			if(direction == undefined) {
				
				//detect direction. inspired by moostack
				var forward = current < index ? index - current : elements.length - current + index,
					backward = current > index ? current - index : current + elements.length - index;
				
				direction = Math.abs(forward) <= Math.abs(backward) ? 1 : -1
			}	

			this.anim.move(index, direction);
			return this
		}
	});
	
	Carousel.prototype.plugins.Move = new Class({
	
		Implements: [Events],
		initialize: function (elements, options) {
		
			var up = this.up = options.mode == 'vertical',
				parent;

			if(elements.length > 0) {
			
				parent = elements[0].getParent();
				
				parent.setStyles({height: parent.getStyle('height'), position: 'relative', overflow: 'hidden'}).getStyle('padding' + (this.up ? 'Top' : 'Left'));
				
				this.padding = style(parent, up ? 'paddingTop' : 'paddingLeft');
				this.pad = style(parent, 'paddingLeft');
			}
			
			this.options = options;
			this.elements = elements.invoke('setStyles', {display: 'block', position: 'absolute'});
			this.property = 'offset' + (up ? 'Top' : 'Left');
			this.margin = up ? ['marginTop', 'marginBottom'] : ['marginLeft', 'marginRight'];
		
			this.direction = 1;
			this.current = elements[0];
			this.reset()
		},
		
		cancel: function () { this.fx.cancel() },
		
		reset: function () {
		
			//
			this.fx = new Fx.Elements(this.elements, this.options.fx).addEvents({complete: function () { this.fireEvent('complete', [this.elements.indexOf(this.current), this.current]) }.bind(this)})			
			this.reorder(this.elements.indexOf(this.current), this.direction);
			
			return this
		},
		
		add: function (el) { 
		
			el.setStyles({display: 'block', position: 'absolute'});
			
			if(isNaN(this.pad)) {
			
				var parent = el.getParent();
				
				this.padding = style(parent, this.up ? 'paddingTop' : 'paddingLeft');
				this.pad = style(parent, 'paddingLeft');
			}
			
			this.reset() 
		},
		
		remove: function () { this.reset() },
		
		reorder: function (offset, direction) {
		
			var options = this.options,
				panels = this.elements,
				panel,
				prev,
				ini = pos = this.padding,
				pad = this.pad,
				i,
				index,
				length = panels.length,
				horizontal = options.mode == 'horizontal',
				side = horizontal ? 'offsetWidth' : 'offsetHeight';
								
			//rtl
			if(direction == -1) {
			
				for(i = length; i > options.scroll - 1; i--) {
			
					index = (i + offset + length) % length;
					prev = panel;
					panel = panels[index];
					
					if(prev) pos -= style(prev, this.margin[0]);
					
					if(horizontal) panel.setStyle('left', pos);
					else panel.setStyles({left: pad, top: pos});
					pos -= (panel[side] + style(panel, this.margin[1]));
				}
				
				pos = ini + panel[side] + style(panel, this.margin[0]);
				
				for(i = 1; i < options.scroll; i++) {
			
					index = (i + offset + length) % length;
					
					prev = panel;
					panel = panels[index];			
					
					if(prev) pos += style(prev, this.margin[1]);
					if(horizontal) panel.setStyle('left', pos);
					else panel.setStyles({left: pad, top: pos});
					pos += panel[side] + style(panel, this.margin[0]);		
				}
				
				//ltr
			} else if(direction == 1) for(i = 0; i < length; i++) {
			
				index = (i + offset + length) % length;
				prev = panel;
				panel = panels[index];				
				
				if(horizontal) panel.setStyle('left', pos);
				else panel.setStyles({left: pad, top: pos});
				pos += panel[side] + style(panel, this.margin[0])+(horizontal?5:15);
				//if(prev) pos += style(prev, this.margin[1]);
			}
			
			return this
		},
		
		move: function (current, direction) {
		
			var obj = {}, 
				up = this.up,
				property = this.property,
				offset;
					
			if(this.options.circular) this.reorder(this.elements.indexOf(this.current), direction);
			
			this.direction = direction;
			this.current = this.elements[current];
			offset = this.current[property] - this.padding;
			
			this.elements.each(function (el, index) { obj[index] = up ? {top: el[property] - offset} : {left: el[property] - offset} });
			this.fireEvent('change', [current, this.elements[current]]).fx.cancel().start(obj)
		}
	})
	
}(document.id);		







/*
---
script: Carousel.Extra.js
license: MIT-style license.
description: Tab.Extra - Autosliding carousel.
copyright: Copyright (c) 2010 Thierry Bela
authors: [Thierry Bela]

requires: 
  core:1.2.3: 
  - Class.Extras
  - Element.Event
  - Element.Style
  - Element.Dimensions
  - Array
provides: [Carousel]
...
*/

Carousel.Extra = new Class({

	/*
	
		options: {
		
			interval: 10, //interval between 2 executions in seconds
			delay: 10, //delay between the moment a tab is clicked and the auto slide is restarted
			reverse: true, //move backward
			autostart: true
		},
		*/
	
		Extends: Carousel,
		Binds: ['update', 'start', 'stop'],
		initialize: function(options) {

			this.parent(Object.merge({interval: 10, delay: 10, autostart: true}, options));
			var active,
				events = this.events = {

						click: function(e) {

							e.stop();
							
							active = this.active;

							if(active) this.stop();

							var target = e.event.target,
								index = this.tabs.indexOf(target);

							while(target && index == -1) {

								target = target.parentNode;
								index = this.tabs.indexOf(target)
							}
							
							if(index == -1) return;
							
							this.move(index);
							if(active) this.start.delay(this.options.delay * 1000)

						}.bind(this)
					};
					
			this.tabs.each(function (tab) { tab.removeEvents(this.events).addEvents(events) }, this);
			
			this.events = events;
			
			//handle click on tab. wait 10 seconds before we go
			['previous', 'next'].each(function (fn) {
			
				if($(this.options[fn])) $(this.options[fn]).addEvent('click', function (e) {
			
					e.stop();
					
					active = this.active;
					
					if(active) {
					
						this.stop().start.delay(this.options.delay * 1000);
						this.active = active
					}

				}.bind(this))
			}, this);
		
			this.timer = new PeriodicalExecuter(this.update, this.options.interval).stop();
			this[this.options.autostart ? 'start' : 'stop']()
		},
		
		update: function () { return this[this.options.reverse ? 'previous' : 'next']() },
		
		start: function () {
		
			this.timer.registerCallback();
			this.active = true;
			return this
		},
		
		stop: function() { 
		
			this.timer.stop();
			this.active = false;
			return this
		},
		
		toggle: function() { 
		
			return this[this.active ? 'stop' : 'start']()
		}

	});
		
		
		

































/*
---
 
name: Scrollbar
description: A simple Apple-style productbrowser, that extends Slider using a container with Fx.Scroll.

version: 0.9.8
copyright: Enrique Erne (http://mild.ch)
license: MIT License
authors:
- Enrique Erne

requires: [Core/Class, Core/Element.Event, Core/Element.Dimensions, Core/Fx.Tween, Core/Fx.Transitions, Core/Selectors, More/Fx.Scroll, More/Slider]

provides: ScrollBar
 
...
*/

var ScrollBar = new Class({
	
	Extends: Slider,

	options: {
		scroll: {
			wheelStops: true/*
			onStart: $empty,
			onComplete: $empty*/
		},
		slider: {
			mode: 'vertical',
			wheel: true/*
			onChange: $empty(intStep),
			onComplete: $empty(strStep)*/
		},
		knob: {/*
			onStart: $empty*/
		}
	},

	moved: false,
	scroll: false,
	steps: false,
	scroller: false,
	knob: false,
	slider: false,

	initialize: function(scroller, slider, knob, options) {
		this.knob = document.id(knob).set('tween', options.knob);
		this.slider = document.id(slider);
		this.scroller = document.id(scroller);
		this.scrollElement = this.scroller.getFirst();

		this.parent(this.slider, this.knob, $extend(this.options.slider, options.slider));

		this.offsetType = (this.options.mode == 'vertical' ? 'offsetHeight' : 'offsetWidth');

		this.steps = this.scrollElement.getSize()[this.axis] - this.scroller.getSize()[this.axis];
		this.scroll = new Fx.Scroll(this.scroller, $extend(this.options.scroll, options.scroll));
		if (this.options.mousewheel) {
			this.scroller.addEvent('mousewheel', function(event){
				this.element.fireEvent('mousewheel', event);
			}.bind(this));
		}
		if (!window.bdy) {
			window.bdy = $(document.body);
		}
		this.resize();

		return this;
	},

	resize: function(a, oldWidth) {
		var limit = {};
		this.steps = this.scrollElement.getSize()[this.axis] - this.scroller.getSize()[this.axis];
		this.ratio = this.steps / (this.slider.getSize()[this.axis] - this.knob.getSize()[this.axis]);
		this.stepWidth = this.stepSize * this.full / Math.abs(this.range);
		if (a) {
			this.detach();
			this.attach();
			this.full = this.element.measure(function(){
				this.half = this.knob[this.offsetType] / 2; 
				return this.element[this.offsetType] - this.knob[this.offsetType] + (this.options.offset * 2); 
			}.bind(this));
			this.drag.options.limit[this.axis] = [- this.options.offset, this.full - this.options.offset];
			this.set(0);
		}
	},
	
	move2: function(amount) {
		this.set(this.knob.getPosition(this.slider)[this.axis] + amount);
	},

	set: function(position) {
		if($type(position) === 'element') {
			position = position.getPosition(this.scrollElement)[this.axis] / this.ratio;
		}
		position = position.limit(-this.options.offset, this.full -this.options.offset);
		this.move(position * this.ratio);
		this.knob.tween(this.property, position).get('tween').chain(function(){
			this.fireEvent('complete', Math.round(position * this.ratio) + '');
		}.bind(this));
	},

	move: function(position){
		var to = $chk(position) ? position : this.step;
		if (this.options.mode === 'vertical') {
			this.scroll.cancel().start(0, to);
		}
		else {
			this.scroll.cancel().start(to, 0);
		}
	},

	draggedKnob: function(){
		this.parent();
		this.moved = true;
		if (this.options.mode === 'vertical') {
			this.scroll.cancel().set(0, this.step);
		}
		else {
			this.scroll.cancel().set(this.step);
		}
	},

	clickedElement: function(event) {
		if (event.target === this.knob){
			this.knob.get('tween').cancel();
			return;
		}
		var position = event.page[this.axis] - this.element.getPosition()[this.axis] - this.half;
		position = position.limit(-this.options.offset, this.full -this.options.offset);
		this.set(position);
	},
	
	scrolledElement: function(event){
		var mode = (this.options.mode == 'horizontal') ? (event.wheel < 0) : (event.wheel > 0);
		this.move2(mode ? -this.stepSize * 100 : this.stepSize * 100);
		event.stop();
	}

});


var HpVisuals = new Class({
	Implements: [Options],

	options: {
		classPointsWrapper: 'hpVisualPoints',
		childSelector: 'p',
		delay: 10000
	},

	effects: [],
	imgs: [],
	points: [],
	element: null,
	timer: null,
	timerX: null,
	actualIndex: 0,
	maxSizeX: 0,
	maxSizeY: 0,

	initialize: function (element, options) {
		this.element = $(element);
		if (!this.element) {
			return;
		}
		this.setOptions(options);
		this.element.set('opacity', 0);
		this.build();
		this.element.fade('in');
		return this;
	},

	build: function () {
		this.vizuals = this.element.getChildren(this.options.childSelector);
		if (this.vizuals.length <= 1) {
			return;
		}
		this.wrapper = new Element('ul', {'class': this.options.classPointsWrapper}).setStyles({'width': this.vizuals.length * 25}).injectAfter(this.element.getParent().getParent());
		this.vizuals.each(function(vizual, index) {
			var s, y;
			this.imgs[index] = vizual.getElement('img');
			y = this.imgs[index].getSize();s = y.x.toInt();y = y.y.toInt();
			vizual.store('s', s).removeClass('jshide').removeClass('abshide');
			if (this.maxSizeX < s) {
				this.maxSizeX = s;
			}
			if (this.maxSizeY < y) {
				this.maxSizeY = y;
			}
			this.effects[index] = new Fx.Morph(vizual, {'link': 'cancel', 'duration': 1000});
			if (index > 0) {
				this.effects[index].set({opacity:0});
//				this.effects[index].set({top:-1300});
			}
			else {
				this.effects[index].set({opacity:1});
//				this.effects[index].set({top:0});
			}
			this.points[index] = new Element('li', {events: {click: this.pointClick.bind(this, index)}, 'html': '&bull;', styles:{'color': (index ? '#d5d5d5' : '#a5a5a5')}});
			this.wrapper.adopt(this.points[index]);
		}, this);
		this.points = this.wrapper.getChildren();

		if (!window.bdy) {
			window.bdy = $(document.body);
		}

		this.elementTween = new Fx.Tween(this.element, {link: 'cancel', duration: 500, 'transition': 'sine:in:out'});
		this.element.setStyles({'width': this.maxSizeX, 'height': this.maxSizeY, 'overflow': 'hidden'});


		window.addEvent('resize', this.resize.bind(this));
		this.resize(1);

		this.timer = this.doEffect.delay(this.options.delay, this);
	},

	resize: function (q) {
		var t, a = window.bdy.offsetWidth;
		a = a - 243 - this.maxSizeX;
		this.elementTween[q?'set':'start']('marginLeft', Math.round(a/2));
		t = window.bdy.getHeight();
		this.element.setStyle('height', t - 60);
		this.imgs.each(function(im, index) {
			im.set('height', t - 60).erase('width');
		});
	},

	pointClick: function (index) {
		$clear(this.timer);
		this.doEffect(true, index);
	},

	doEffect: function(override, index) {
		var tIndex;

		$clear(this.timer);
		$clear(this.timerX);

		tIndex = this.actualIndex;

		if (override && index === tIndex) {
			return;
		}
		if (override !== true) {
			override = tIndex + 1;
		}
		else {
			override = index * 1;
		}

		tIndex = tIndex.limit(0,this.points.length-1);

		this.points[tIndex].setStyle('color', '#d5d5d5');
		this.effects[tIndex].set({opacity:1}).start({opacity:0});
//		this.effects[tIndex].set({top:0}).start({top:-1300});

		override %= this.vizuals.length;
		tIndex = override.limit(0,this.points.length-1);

		this.actualIndex = tIndex;

		this.timerX = (function(tIndex){
			this.points[tIndex].setStyle('color', '#a5a5a5');
			this.effects[tIndex].set({opacity:0}).start({opacity:1});
		}.bind(this, tIndex)).delay(1000, this, tIndex);
//		this.effects[tIndex].set({top:1300}).start({top:0});


		this.timer = this.doEffect.delay(this.options.delay, this);

	}

});


var InputLabels2 = new Class({
	initialize: function (selector) {
		this.els = $$(selector);
		if (this.els && this.els.length > 0) {
			this.build();
			return this;
		}
	},

	build: function () {
		this.els.each(function (el) {
			el.addEvents(this.allTheLabelEvents);
			
			if (el.get('value') != '') {
				el.getPrevious().addClass('hide');
			}
			el.getPrevious().addEvent('click', function () {
				this.addClass('hide');
			});
		}, this);
	},

	allTheLabelEvents: {
		keyup: function (event) {
			$(this).getPrevious().addClass('hide');
		},
		keydown: function (event) {
			$(this).getPrevious().addClass('hide');
		},
		click: function (event) {
			if (true || this.get('value') != '') {
				$(this).getPrevious().addClass('hide');
			}
			event = new Event(event);
			if (event && event.preventDefault) {
				event.preventDefault();
			}
		},
		focus: function () {
			if (this.get('value') != '') {
				$(this).getPrevious().addClass('hide');
			}
		},
		blur: function () {
			if (this.get('value') == '') {
				$(this).getPrevious().removeClass('hide');
			}
			else {
				$(this).getPrevious().addClass('hide');
			}
		}
	}

});


var InputLabels = new Class({
	initialize: function (selector) {
		this.els = $$(selector);
		if (this.els && this.els.length > 0) {
			this.build();
			return this;
		}
	},

	build: function () {
		this.els.each(function (el) {
			el.addEvents(this.allTheLabelEvents);
			if (el.get('value') != '') {
				$(el.parentNode.parentNode).getPrevious().addClass('hide');
			}
			$(el.parentNode.parentNode).getPrevious().addEvent('click', function () {
				this.addClass('hide');
			});
		}, this);
	},

	allTheLabelEvents: {
		keyup: function (event) {
			$(this.parentNode.parentNode).getPrevious().addClass('hide');
		},
		keydown: function (event) {
			$(this.parentNode.parentNode).getPrevious().addClass('hide');
		},
		click: function (event) {
			if (true || this.get('value') != '') {
				$(this.parentNode.parentNode).getPrevious().addClass('hide');
			}
			event = new Event(event);
			if (event && event.preventDefault) {
				event.preventDefault();
			}
		},
		focus: function () {
			if (this.get('value') != '') {
				$(this.parentNode.parentNode).getPrevious().addClass('hide');
			}
		},
		blur: function () {
			if (this.get('value') == '') {
				$(this.parentNode.parentNode).getPrevious().removeClass('hide');
			}
			else {
				$(this.parentNode.parentNode).getPrevious().addClass('hide');
			}
		}
	}

});

var Footer = new Class({

	shownBubble: false,

	element: null,
	elements: null,

	initialize: function (element) {
		this.element = $(element);
		if (this.element) {
			this.build();
		}
		this.doc = $(document);
		return this;
	},

	build: function () {
		this.elements = this.element.getElements('li.clickable>a, li.clickable>strong');
		if (this.elements && this.elements.length > 0) {
			this.elements.each(function (lia, parenta) {
				var qq;
				lia.addEvent('click', this.toggle.bindWithEvent(this, lia));
				parenta = lia.getParent();
				lia = parenta.getLast();
				if (parenta.hasClass('showIt')) {
					lia.setStyles({'marginBottom': 0, 'marginTop': 0, 'marginLeft': 0});
					parenta.addClass('vis');
					this.shownBubble = true;
				}
				lia.addEvent('click', this.insideClick.bindWithEvent()).set('morph', {link: 'cancel', duration: 500, transition: 'expo:out'});
			}, this);
		}
		if (this.shownBubble) {
			this.eventBuilder(1);
		}
	},

	eventBuilder: function (e) {
		if (e) {
			this.doc.removeEvent("click", this.outClick).addEvent("click", this.outClick);
		}
		else {
			this.doc.removeEvent("click", this.outClick);
		}
	},

	outClick: function (event) {
		$$('#subnav>li.showIt').each(function(x, i){
			x.removeClass('showIt');
			i = x.getLast();
			i.morph({'marginLeft': -50 - x.getLeft().toInt() - i.getWidth().toInt()});
		});
	},

	insideClick: function (event) {
		event = new Event(event);
		if (event.target) {
			event.stopPropagation();
		}
	},

	resetMorph: function (els) {
		if (els && els.length > 0) {
			els.each(function (aa, i) {
				aa.removeClass('showIt');
				i = aa.getLast();
				i.morph({'marginLeft': -50 - aa.getPosition().x.toInt() - i.getWidth().toInt()});
			});
		}
	},

	toggle: function (event, a, i) {

	
	
		var t;
		t = a.getParent();

		this.resetMorph(t.getAllNext('.showIt'));
		this.resetMorph(t.getAllPrevious('.showIt'));

		if (!i && t.hasClass('showIt')) {
			t.removeClass('showIt');
			a = t.getLast();
			a.morph({'marginLeft': -50 - t.getPosition().x.toInt() - a.getWidth().toInt()});
			this.shownBubble = false;
			this.eventBuilder(0);
			return false;
		}

		t.addClass('showIt');
		a = t.getLast();
		if (!a.hasClass('rounded')) {
			a.addClass('rounded');
			a.adopt(new Element('span', {'class': 'topCorners', 'html': '<span class="mC"></span><span class="lC"></span><span class="rC"></span>'}));
			a.adopt(new Element('span', {'class': 'bottomCorners', 'html': '<span class="mC"></span><span class="lC"></span><span class="rC"></span>'}));
		}
		this.shownBubble = true;
		a.setStyles({'marginBottom': 0, 'marginTop': 0, 'marginLeft': -50 - t.getPosition().x.toInt() - a.getWidth().toInt()}).morph({marginLeft: 0});
		if(a.getParent().get("id")=="wl"){
		  a.setStyle("width",$$("#favesBubble p").length*105);
		}
		this.eventBuilder(1);

		return false;
	},

	showBubble: function (id) {
		
		this.toggle(false, $(id).getParent().getPrevious(), 1);
		
		
		
	},

	hideBubble: function (id) {
	},

	updateBubble: function (id, content) {
		$(id).empty().set('html', content);
	}

});

var CatalogFilter = new Class({

	initialize: function (element) {
		this.element = $(element);
		if (!this.element) {
			return;
		}
		this.buildEvents();
		this.buildSlider();
	},

	buildEvents: function () {
		this.element.addEvent('click:relay(input)', this.toggle);
	},

	toggle: function () {
		var t = this;
		if (this.checked) {
			this.getParent().addClass('on');
		}
		else {
			this.getParent().removeClass('on');
		}
	},

	buildSlider: function () {
		var smalls;
		this.elementPrice = $('pricesWrapper');
		if (!this.elementPrice) {
			return;
		}

		this.smalls = this.elementPrice.getElements('small').map(function(a){return a.get('text').toInt();});
		this.inputs = this.elementPrice.getElements('input[type=text]');
		this.shows = $$('#pricesToShow span');

		this.makeSlider.delay(300, this);

	},

	makeSlider: function () {

		this.shows.each(function (show, i) {
			show.set('text', (i > 0 ? ' do ' : 'od ') + (this.inputs[i].get('value') || this.smalls[i]));
		}, this);

		this.slider = new DoubleSlider($('priceSlider'), {

			'range': [this.smalls[0], this.smalls[1]],
			'start': [this.inputs[0].get('value').toInt() || this.smalls[0], this.inputs[1].get('value').toInt() || this.smalls[1]],

			'onChange': function (werte) {
				this.inputs[0].set('value', werte.knob_left);
				this.inputs[1].set('value', werte.knob_right);
				this.shows[0].firstChild.data = 'od ' + werte.knob_left;
				this.shows[1].firstChild.data = ' do ' + werte.knob_right;
			}.bind(this)
		});
		this.slider.element.set('opacity', 0).fade('in');
		this.shows[0].getParent().set('opacity', 0).fade('in');
	}

});

var inlineLinkClick = function (event) {

	var a, doZoom = false, t;

	t = $(event.target);

	if (t.get('tag') !== 'a') {
		t = t.getParent();
	}

	// document.getElementById("im600").src=t.getFirst().src.replace("85x85","600x600");
	
	
	
	
	if (t.hasClass('active')) {
		return false;
	}

	
	
	t.getParent().getChildren().removeClass('active');
	t.addClass('active');

	if (this.retrieve('zoomer', false)) {
		a = this.retrieve('zoomerObject', false);
		if (a) {
			a.kill();
		}
		this.store('zoomer', false);
	}
	this.store('zoomer', true);
	
	
	
	this.store('zoomerObject', new Zoomer(t.getElement('img'), '#mbCenter div.detailBox-content'),{},false);
    
	fuckedZoomer=this.retrieve('zoomerObject');
	
	
	
	return false;
};

var ProductDetail = new Class({

	onJSON: function (json,txt) {
		if (json && json.ok) {
			this.setTexts();
			this.inWishList = !this.inWishList;
			this.footer.updateBubble('favesBubble', json.wishlist.join(''));
			$('favesCount').set('text', json.quantity + ' ks');
			
			
			
			
			this.footer.showBubble('favesBubble');
		}
	},

	inWishList: false,

	initialize: function (element, footer) {
		this.element = $(element);
		this.footer = footer;
		this.detailLinks = $('detail');
		if (this.detailLinks) {
			this.addToWishList = this.detailLinks.getElement('a.addToWishList');
			if (this.addToWishList) {
				this.addToWishList.store('localization:click:text', this.addToWishList.get('rel') || this.addToWishList.getAttribute('rel') || this.addToWishList.rel).store('original:click:text', this.addToWishList.get('text'));
				this.addToWishList.addEvent('click', this.wishListClick.bind(this));
				if (this.addToWishList.hasClass('doRemove')) {
					this.inWishList = true;
				}
			}
		}
		this.buildIcons();
		
		//this.buildCollage('collages', 'ul', 'vertical', false, '', '', 1);
		//this.buildCollage2('similars', 'div', 'horizontal', false, '', '', 1);
		
		this.scrollOutfit();
		this.scrollSimilar();
		
		this.prevNext();

		Mediabox.scanPage({onClose: this.killBox, inlineAfterInsert: this.makeTheBoxContent});

	},

	killBox: function () {
		if (this.retrieve('zoomer', false)) {
			this.retrieve('zoomerObject').kill();
		}
	},

	makeTheBoxContent: function () {
		var a,i,pics,j;
		a = this.getElements('a');
		if (a) {
			a = $$(a).each(function (odkaz) {
				odkaz.addEvent('click', function(e){
					if (e) {
						e = new Event(e);
					}
					if (e.stop) {
						e.stop();
					}
					inlineLinkClick.delay(50, this, e);
					return false;
				}.bind(this));
			}, this);
			
			pics=$("minipic").getElements("img");
			i=0;
			
			for(j=0;j<pics.length;j++){
			  
			  if(pics[j].src===$("mainphoto").src.replace("260x370","85x85")){
			    i=j;
				break;
			  }
			}
			
			//if (a.length === 1) {
				inlineLinkClick.delay(300, this, {target: a[i]});
			//}
		}
		
		if($$("#mbImage .tabz.step_2 li").length){
      this.tabs = new MGFX.Tabs('#mbImage .tabz li', '#mbImage .tab', {startIndex : 2});
    } else if ($$("#mbImage .tabz li").length) {
      this.tabs = new MGFX.Tabs('#mbImage .tabz li', '#mbImage .tab');
    }
	},



    scrollOutfit:function(){
     

     	var duration = 300,
		l=$$("#collages a").length-3,
						
			carousel = new Carousel.Extra({
				autostart:false,
				container: 'collages',
				scroll: 3,
				circular: false,
				mode: 'vertical',
				current: 0,
				interval: duration / 1000 + 5,
				previous: $("outup"),
				next: $("outdown"),
				onChange: function (index) {
				  if(index==0){
				    $("outup").addClass("ina");
				    $("outdown").removeClass("ina");
				  }else if(index==l){
				    $("outdown").addClass("ina");
				    $("outup").removeClass("ina");
				  }else{
				    $("outdown").removeClass("ina");
				    $("outup").removeClass("ina");
				  }
				},
				fx: {
				
					duration: duration
				}
			});
     
     
     
        
    
    		
    },


    scrollSimilar:function(){
    
    
    
     	var duration = 300,
		l=$$("#collages a").length-5,
						
			carousel = new Carousel.Extra({
				autostart:false,
				container: 'similars',
				scroll: 5,
				circular: false,
				mode: 'horizontal',
				current: 0,
				interval: duration / 1000 + 5,
				previous: $("simprev"),
				next: $("simnext"),
				onChange: function (index) {
				  if(index==0){
				    $("simprev").addClass("ina");
				    $("simnext").removeClass("ina");
				  }else if(index==l){
				    $("simnext").addClass("ina");
				    $("simprev").removeClass("ina");
				  }else{
				    $("simnext").removeClass("ina");
				    $("simprev").removeClass("ina");
				  }
				},
				fx: {
				
					duration: duration
				}
			});
     
    
    
    
    
    
    },



	buildCollage: function (id, selector, typeOfCarousel, hei, prevHtml, nextHtml, howMuch) {


	var a, kid, t;
		kid = $(id);
		if (!kid || !typeOfCarousel) {
			return;
		}
		a = kid.getChildren(selector);
		//alert(selector)
		if (a.length <= howMuch) {
			if (hei) {
			//	 kid.setStyle(hei, 'auto');
			}
		//	return;
		}
		
		kid.getParent().adopt(a[0] = new Element('span', {'class': 'arrow prev ina', 'html': prevHtml}), 
		a[1] = new Element('span', {'class': 'arrow next', 'html': nextHtml}));
		
		t = new Carousel({
			container: kid,
			scroll: howMuch,
			left: a[0],
			right: a[1],
			circular: false,
			selector: selector,
			mode: typeOfCarousel,
			current: 0,
			onChange: function (index) {
				if (hei) {
				//kid.setStyle('height', t.elements[index].getHeight()+30);
				//	kid.tween('height', t.elements[index].getHeight()+30);
				}
				
				// alert(index+"-"+t.elements.length)
				if (index+3 === t.elements.length) {
					a[0].removeClass('ina');
					a[1].addClass('ina');
				}
				else if (index === 0) {
					a[1].removeClass('ina');
					a[0].addClass('ina');
				}
				else {
					a[1].removeClass('ina');
					a[0].removeClass('ina');
				}
			},
			fx: {
				duration: 300
			}
		});
		
		if (hei) {
		//kid.setStyle("height",t.elements[0].getHeight()+30);
			// kid.tween(hei, t.elements[0].getHeight()+30);
		}
	},

	
	
	
	buildCollage2: function (id, selector, typeOfCarousel, hei, prevHtml, nextHtml, howMuch) {


	var a, kid, t;
		kid = $(id);
		if (!kid || !typeOfCarousel) {
			return;
		}
		a = kid.getChildren(selector);
		//alert(selector)
		if (a.length <= howMuch) {
			if (hei) {
				 kid.setStyle(hei, 'auto');
			}
			return;
		}
		
		kid.getParent().adopt(a[0] = new Element('span', {'class': 'arrow prev ina', 'html': prevHtml}), a[1] = new Element('span', {'class': 'arrow next', 'html': nextHtml}));
		
		t = new Carousel({
			container: kid,
			scroll: howMuch,
			left: a[0],
			right: a[1],
			circular: false,
			selector: selector,
			mode: typeOfCarousel,
			current: 0,
			onChange: function (index) {
				if (hei) {
				kid.setStyle('height', t.elements[index].getHeight()+30);
				//	kid.tween('height', t.elements[index].getHeight()+30);
				}
				
				//alert(index+"-"+t.elements.length)
				if (index+1 === t.elements.length) {
					a[0].removeClass('ina');
					a[1].addClass('ina');
				}
				else if (index === 0) {
					a[1].removeClass('ina');
					a[0].addClass('ina');
				}
				else {
					a[1].removeClass('ina');
					a[0].removeClass('ina');
				}
			},
			fx: {
				duration: 300
			}
		});
		
		if (hei) {
		kid.setStyle("height",t.elements[0].getHeight()+30);
			// kid.tween(hei, t.elements[0].getHeight()+30);
		}
	},

	
	
	
	
	
	
	
	
	
	
	buildIcons: function () {
		this.udrzba = $('udrzba');
		if (this.udrzba) {
			this.udrzbaElements = new Hash();
			this.udrzba = this.udrzba.getElement('dl');
			this.udrzbaElements = this.udrzbaElements.getClean();
			this.udrzbaToolTips = new MooTooltips({
				container: 'udrzba',
				hovered: '.tooltiper',
				fromLeft: -40,
				fadeDistance: 0,
				showDelay: 100
			});




		}
		/*
		this.question = $('question');
		if (this.question) {
			this.questionElements = new Hash();
			this.question = this.question.getElement('dl');
			this.questionElements = this.questionElements.getClean();
			this.questionToolTips = new MooTooltips({
				container: 'question',
				hovered: '.tooltiper',
				fromLeft: -40,
				fadeDistance: 0,
				showDelay: 100
			});
		}
		*/
	},

	setTexts: function () {
	 if(this.addToWishList.hasClass("remove")){
     this.addToWishList.set("html", 'Přidat do oblíbených<span class="ir"></span>');
   } else {
     this.addToWishList.set("html", 'Odebrat do oblíbených<span class="ir"></span>');
   }
   this.addToWishList.toggleClass("remove")
	},

	wishListClick: function () {
		var req, a;

		this.footer.hideBubble('favesBubble');
		a = this.addToWishList.getProperty('href').split("?");
		if (this.inWishList) {
			a[1] = {pid: a[1].split('&').shift().split('=').pop(), 'action': 'del_wish', 'back': encodeURI(window.location.pathname + '?ajax=1&captures=wish')};
			req = new Request.JSON({noCache: 1, url: window.location.pathname + '?ajax=1&captures=wish', method: 'get', onSuccess: this.onJSON.bind(this)}).send({data:a[1]});
		}
		else {
			a[1] = {'wish_product_id': a[1].split('&').shift().split('=').pop(), 'back': encodeURI(window.location.pathname + '?ajax=1&captures=wish')};
			req = new Request.JSON({noCache: 1, url: window.location.pathname + '?ajax=1&captures=wish', method: 'get', onSuccess: this.onJSON.bind(this)}).send({data:a[1]});
		}

		return false;
	},

	prevNext: function () {
		$$("p.prevLink img, p.nextLink img").each(function (img) {
			new Element("strong", {
				'class': 'rounded'
				//'styles': {
				//	'background-image': 'url(' + img.getProperty('src') + ')'
				//}
			}).wraps(img);
			//img.set('opacity', 0.5);
		});
	}

});

var Catalog = new Class({

	Implements: [Options],

	options: {
		productWidth: 231,
		productCount: 5,
		arrowChange: 50,
		arrows: 1,
		hover: true,
		scrollbar: false,
		resize: false,
		menu: false,
		effects: false,
		width: 984
	},
	recountTimer: null,

	initialize: function (element, options) {

		this.setOptions(options);

		this.element = $(element);

		if (!this.element) {
			return;
		}
		if (!window.bdy) {
			window.bdy = $(document.body);
		}

		this.mainin = $('mainin');

		if (this.options.resize && !Browser.Engine.trident4) {
			this.resize();
			window.addEvent('resize', this.resize.bind(this, true));
		}

		this.build();
		if (this.options.menu) {
			this.buildMenu();
		}

		return this;
	},

	resize: function (a) {
		var oldC, w;

		oldC = this.options.productCount;
		w = window.bdy.getWidth().toInt();

		this.mainin.style.width = w - 243 - 10 + 221 + 'px';

		this.options.productCount = 1 + Math.floor((w - 243) / this.options.productWidth);
		if (a && oldC != this.options.productCount) {
			$clear(this.recountTimer);
			this.recountTimer = this.recountSize.delay(300, this);
		}
	},

	recountSize: function () {
		var w, oldW;
		if (this.options.scrollbar && (this.products.length + 1) > this.options.productCount) {
			oldW = this.productsScroll.getStyle('width').toInt();
			w = this.options.productWidth * this.options.productCount;
			this.productsScroll.setStyles({"width": (this.products.length + 1) * this.options.productWidth});
			this.productsScroll.getParent().setStyles({'overflow-x': 'hidden', 'overflow-y': 'visible', 'overflow': 'hidden', width: w}).getParent().setStyle('width', w);
			if (this.productScrollBar) {
				this.productScrollBar.resize(1, oldW);
				return;
			}
			this.elementScrollBar = this.element.getElement('#products-scrollbar');
			if (this.elementScrollBar) {
				this.buildScrollBar();
			}
		}
		else if (this.productScrollBar) {
//			this.productScrollBar.detach();
		}
	},

	buildCorners: function () {
		this.roundedBoxSpan = new Element('span', {'class': 'fgImg'});

		this.productsScroll.getElements('img').each(function(img) {
			if (Browser.Engine.trident) {
				var a = new RoundedBox({radius: 10, opacity: 1, backgroundColor: false});
				a.getContent().setStyle('background-image', 'url("' + img.getProperty('src') + '")');
				img.getParent().adopt(a.getElement());
			}
			else {
				img.getNext().setStyle('background-image', 'url("' + img.getProperty('src') + '")').removeClass('fg').addClass('roundedSpan');
			}
			img.dispose();
		}, this);
	},

	build: function () {

		this.hoverProductIndex = false;

		this.productsScroll = $('products-scroll');
		this.products = this.productsScroll.getChildren();

		this.effects = new Array();

		if (this.options.hover) {

			this.products.each(function (product, index) {
				product.addEvents({
					'mouseenter': this.hover.bind(this, index),
					'mouseleave': this.hoverOut.bind(this, index)
				});
				if (this.options.effects) {
					this.effects[index] = new Fx.Tween(product, {link: 'cancel', transition: 'cubic:out', duration: 300});
				}
			}, this);

		}
		if (Browser.Engine.trident4) {
		this.buildCorners();
		}
		if (!Browser.Engine.trident4) {
			this.recountSize();
		}
	},

	buildMenu: function () {
		return; // temporary disable switch

		this.elementMenu = new Element('p', {id: 'catalogmenu', styles: {opacity: 0}}).set('tween', {property:'opacity', duration:1000});
		this.elementMenu.adopt(this.elementLink = new Element('a', {
			events:{
				'click': this.toggleClass.bind(this)
			}
		}).adopt(
			new Element('span', {'class': 'hoverVis', 'text': 'Zobrazit všechny náhledy'}),
			new Element('span', {'class': 'hoverInvis', 'text': 'Skrýt všechny náhledy'})
		));
		this.elementMenu.injectBefore(this.element).get('tween').start(1);
	},

	hover: function (pr) {
		if (this.options.effects) {
			this.effects[pr].start('width', 221 + 220);
		}
		this.products[pr].addClass('hover');
	},

	hoverOut: function (pr) {
		if (this.options.effects) {
			this.effects[pr].start('width', 221);
		}
		this.products[pr].removeClass('hover');
	},

	toggleClass: function () {
		this.element.toggleClass('hover');
		this.elementLink.toggleClass('hover');
	},

	toggler: function () {
		this.removeClass('hover');
	},

	buildScrollBar: function () {
		var knob, handle, hLeft, hRight;
		if (!this.options.scrollbar) {
			return this;
		}
		this.scrollBar = {};
		knob = new Element('div', {'class': 'knob'});
		handle = new Element('span', {'class': 'handle'}).adopt(new Element('span'));
		knob.adopt(new Element('span', {'class': 'handlebg'}).adopt(new Element('span', {'class': 'lbg'}), new Element('span', {'class': 'rbg'}), new Element('span', {'class': 'albg'})), handle);

		this.elementScrollBar.adopt(new Element('div', {'class': 'slider'}).adopt(knob));

		if (this.options.arrows) {
			hLeft = new Element('div', {'class': 'leftArrow'}).inject(this.elementScrollBar);
			hRight = new Element('div', {'class': 'rightArrow'}).inject(this.elementScrollBar);
			knob.getParent().setStyles({'marginLeft': hLeft.getStyle('width'), 'marginRight': hRight.getStyle('width')});
		}

		this.productScrollBar = new ScrollBar(this.productsScroll.getParent(), knob, handle, {
			mousewheel: true,
			slider: {
				mode: 'horizontal'
			},
			knob: {
				transition: 'expo:out'
			},
			scroll: {
				transition: 'expo:out'
			}
		});


		if (hLeft) {
			hLeft.addEvents({
					'mousedown': this.arrowDown.bind(this, [hLeft, -this.options.arrowChange]),
					'mouseup': this.arrowUp.bind(this, hLeft),
					'mouseout': this.arrowOut.bind(this, hLeft)
			});
		}
		if (hRight) {
			hRight.addEvents({
					'mousedown': this.arrowDown.bind(this, [hRight, this.options.arrowChange]),
					'mouseup': this.arrowUp.bind(this, hRight),
					'mouseout': this.arrowOut.bind(this, hRight)
			});
		}

	},

	arrowOut: function (theBtn) {
		$clear(this.arrowTimer);
		theBtn.removeClass('active');
	},

	arrowDown: function(theBtn, change) {
		$clear(this.arrowTimer);
		this.scrollBarMove(change);
		this.arrowTimer = this.scrollBarMove.periodical(50, this, change);
		theBtn.addClass('active');
	},

	arrowUp: function (theBtn) {
		$clear(this.arrowTimer);
		theBtn.removeClass('active');
	},

	scrollBarMove: function (change) {
		this.productScrollBar.move2(change);
	}

});

/* implement wait method :-) */
(function(){

	var wait = {
		wait: function(duration){
			return this.chain(function(){
				this.callChain.delay($pick(duration, 500), this);
			}.bind(this));
		}
	};

	Chain.implement(wait);

	if (window.Fx){
		Fx.implement(wait);
		['Css', 'Tween', 'Elements'].each(function(cls){
			if (Fx[cls]) Fx[cls].implement(wait);
		});
	}

	Element.implement({
		chains: function(effects){
			$splat($pick(effects, ['tween', 'morph', 'reveal'])).each(function(effect){
				effect = this.get(effect);
				if (!effect) return;
				effect.setOptions({
					link:'chain'
				});
			}, this);
			return this;
		},
		pauseFx: function(duration, effect){
			this.chains(effect).get($pick(effect, 'tween')).wait(duration);
			return this;
		}
	});

})();
/* end implementation of the wait method */


var CacheLoader = new Class({
	Implements: [Options],

	options: {
		backgrounds: []
	},

	initialize: function(options) {
		if (!window.documentBody) {
			window.documentBody = $(document.body);
		}
		this.setOptions(options);
		this.wrapper = new Element('div', {'class': 'cacheLoader abshide'}).inject(window['documentBody'].getFirst());
		this.span = new Element('span');
		this.loadImages(this.options.backgrounds, '');
	},

	loadImages: function(arr, pathToHere) {
		var tp;
		if (arr) {
			tp = $type(arr);
			if (tp == 'string') {
				this.span.clone().setStyle('backgroundImage', 'url(' + pathToHere + arr + ')').inject(this.wrapper);
			}
			else if (tp == 'array') {
				while(tp = arr.shift()) {
					this.loadImages(tp, pathToHere);
				}
			}
			else if (tp == 'object') {
				$each(arr, function(a, key) {
					this.loadImages(a, pathToHere + key);
				}, this);
			}
		}
	}
});


 
/*        
        
MooTools Rounded Box v0.1, by Daniel Steigerwald '08            

License: MIT-style license.

Inspiration:
- http://snook.ca/technical/rounded_corners/
- http://elv1s.ru/files/html+css/vector-corners.html

Issues:
- rounded vml needs display block, and width or height, hasLayout has no effect
- arc size is defined as a percentage of half the smaller dimension ArcSize, so when size has changed, arc must by adjusted
- firefox 2 has ugly rounding
                  
*/

var RoundedBox = new Class({

	Implements: Options,

	options: {
		radius: 10,
		backgroundColor: false,
		opacity: 1,
		size: { width: 221, height: 347} // ie rounds parametr needs
	},

	initialize: function(options) {
		this.setOptions(options);
		if (Browser.Engine.trident) {
			if (!RoundedBox.vmlRuleAdded) {
			    RoundedBox.vmlRuleAdded = true;
					if(document.namespaces['v']==null) {
						var e=["shape","shapetype","group","background","path","formulas","handles","fill","stroke","shadow","textbox","textpath","imagedata","line","polyline","curve","roundrect","oval","rect","arc","image"],s=document.createStyleSheet(); 
						for(var i=0; i<e.length; i++) {s.addRule("v\\:"+e[i],"behavior: url(#default#VML);");} document.namespaces.add("v","urn:schemas-microsoft-com:vml");
					}
			}
			var vml = '<v:roundrect style="height:' + this.options.size.height-1+'px;width:' + this.options.size.width + 'px;display:block"><v:stroke /><v:fill /><span class="roundedSpan"></span></v:roundrect>';
			this.el = new Element('span', { html: vml }).getElement('*');
			this.content = this.el.getElement('span');
		}
		else {
			this.content = this.el = new Element('span', {'class':'roundedSpan'});
		}
		this.setRounds().setOpacity().setBackgroundColor();

		return this;
	},

	setRounds: function(radius) {
		radius = radius || this.options.radius;
		Browser.Engine.trident ? this.el.arcsize = radius / Math.min(this.options.size.width, this.options.size.height) :
			Browser.Engine.gecko ? this.el.style.MozBorderRadius = radius + 'px' :
				Browser.Engine.webkit && (this.el.style.WebkitBorderRadius = radius + 'px');
		if (this.el.style.borderRadius !== undefined) {
			this.el.style.borderRadius = radius + 'px';
		}
		return this;
	},

	setOpacity: function(opacity) {
		opacity = (opacity ? opacity : this.options.opacity);
		if (opacity == 1) {
			return this;
		}
		Browser.Engine.trident ? this.el.getElements('stroke, fill').setProperty('opacity', this.options.opacity) : this.el.setOpacity(opacity);
		return this;
	},

	setBackgroundColor: function(color) {
		color = (color ? color : this.options.backgroundColor);
		if (!color) {
			return this;
		}
		Browser.Engine.trident ? this.el.getElements('stroke, fill').setProperty('color', color) : this.el.setStyle('background-color', color)
		return this;
	},

	getElement: function() {
		return this.el;
	},

	getContent: function() { // because ie need inner vml nodes to opacity definition
		return this.content;
	}
});

/**
 * ToolTips - show tooltips on hover
 * @version		0.1
 * @MooTools version 1.2.1
 * @author Constantin Boiangiu <info [at] constantinb.com>
 */

var MooTooltips = new Class({
	
	Implements: [Options],
	
	options: {		
		container: null,	// hovered elements
		hovered:null,		// the element that when hovered shows the tip
		extra:null,
		ToolTipClass:'ToolTips',	// tooltip display class
		toolTipPosition:-1, // -1 top; 1: bottom
		showDelay: 500,
		sticky:false,		// remove tooltip if closed
		fromTop: 0,		// distance from mouse or object
		fromLeft: 0,
		duration: 100,		// fade effect transition duration
		fadeDistance: 20    // the distance the tooltip starts fading in/out
	},
	
	initialize: function(options) {
		this.setOptions(options||null);
		if(!this.options.hovered && !this.options.extra) {
			return;
		}

		if( this.options.hovered ) {
			this.elements = $(this.options.container || document.body).getElements(this.options.hovered);
		}

		if(!$defined(this.elements)) {
			this.elements = new Array();
		}

		var e = new Hash(this.options.extra);
		e.each(function(el){
			$(el.id).set( 'rel', JSON.encode(el) );
			this.elements.include($(el.id));			
		},this);
		
		this.currentElement = null;



		this.attach();

	},
	
	attach: function(){
		this.elements.each(function(elem, key){
			var t = new Hash(JSON.decode(elem.getProperty('rel')));
			t.include('visible',0);
			
			var tooltip = this.createContainer(t.sticky||this.options.sticky);
			/* 
				set the tooltip content.  
				depending on where the content is, set the according parameters.
				
				Parameters for every element are:
				- content: element id to get the tip content from a HTML element ( a div within the page for example )
				- text: just input some text directly into the parameter and there you have it
				- ajax: get the content from a remote page				
			*/
			if( t.content )
				tooltip.message.set({'html':$(t.content).get('html')});
			else if( t.text )
				tooltip.message.set({'html':t.text});
			else if( t.ajax ){
				tooltip.message.set({'html':t.ajax_message||'Loading... please wait.'});
				new Element('div', {'class':'loading'}).injectInside(tooltip.message);
				/* the actual ajax call is made when element is hovered */
			}				
			/*
				by default, the tooltip is positioned below the element.
				if placed above, the script switches the CSS classes on the footer and header
				to make it point at the element hovered
			*/
			if( !t.position ) t.position = this.options.toolTipPosition;
			if( t.position == -1 ){
				tooltip.header.set({'class':'dockTopHeader'});
				tooltip.footer.set({'class':'dockTopFooter'});
			}
			
			tooltip.container.store('properties', t);
			elem.store('tip', tooltip.container);
			$(document.body).adopt(tooltip.container);
			elem.removeProperties('title','rel');
			
			var over = this.enter.bindWithEvent(this, elem);
			var out = this.leave.bindWithEvent(this, elem);
			
			var startEvent = t.focus ? 'focus' : 'mouseenter'; 
			var endEvent = t.focus ? 'blur' : 'mouseleave';			
			
			elem.addEvent(startEvent, over);
			if( t.sticky || this.options.sticky){
				tooltip.close.addEvent('click', this.hide.pass(tooltip.container).bind(this)  );
			}
			elem.addEvent(endEvent, out.pass(tooltip.container));				
			
			
		}, this);
	},
	
	enter: function(event, element){



		var tip = element.retrieve('tip');		
		/* all the tip properties are stored on the element */
		var elProperties = tip.retrieve('properties');
		if(elProperties.visible == 1) return;
		



		if( elProperties.ajax && !elProperties.loaded ){
			new Request.HTML({
				url: elProperties.ajax, 
				update: tip.getElement('.message'),
				/* if loading fails, set the loaded propety back to false so when the element is hovered, a new request is made */
				onFailure: function(){
					elProperties.set('loaded',0);
				}
			}).get();
			/* 
				set it as loaded when user hovers the element. 
				This way, while loading, if the user hovers the element again, it will not make a new request 
			*/
			elProperties.set('loaded',1);
		}
		
		/* if property target set on element, show tooltip after target */	
		var showAfter = elProperties.target ? $(elProperties.target) : element;
		var elSize = showAfter.getCoordinates();
		var tipSize = tip.getCoordinates();
		
		this.fromTop = 0;
		if( elProperties.position == -1 )
			this.fromTop = elSize.top - this.options.fromTop - tipSize.height;
		else
			this.fromTop = elSize.top + this.options.fromTop + elSize.height;
		
		var top_dist = this.fromTop + (elProperties.position||this.options.toolTipPosition) * this.options.fadeDistance ;
		
		tip.setStyles({
			'top': top_dist,
			'left': elSize.left + this.options.fromLeft,			
			'z-index':'110000'
		});		
		
		elProperties.set('leave', top_dist);		
		this.currentElement = tip;
		this.timer = $clear(this.timer);



		this.timer = this.show.delay(this.options.showDelay, this);




	},
	
	leave: function(element){
		var elProperties = element.retrieve('properties');
		/* if tooltip is visible and sticky, it closes when close button is clicked */
		if( (elProperties.sticky || this.options.sticky) && elProperties.visible ){
			return;	
		}
		this.hide(element);
	},
	
	hide: function(element){
		this.timer = $clear(this.timer);		
		var elProperties = element.retrieve('properties');
element.setStyles({'opacity':0,'top': elProperties.leave});
//		element.morph({'opacity':0,'top': elProperties.leave});
		elProperties.visible = 0;
	},
	
	show: function(){

		this.currentElement.setStyles({'display':'block','opacity':1,'z-index':100000});
		// this.currentElement.morph({'opacity':1, 'top':this.fromTop});		




		//this.setVisible.delay(this.options.duration, this);
		this.setVisible();
	},
	
	setVisible: function(){
		var elProperties = this.currentElement.retrieve('properties');
		elProperties.visible = 1;				
	},
	
	createContainer: function( sticky ){
		var container = new Element('div').set({
			'class':this.options.ToolTipClass, 
			'styles':{ 
				'position':'absolute',
				'top':0,
				'left':0,
				'opacity':0,
				'z-index':'100000' 
			},
			'morph':{
				duration:this.options.duration, 
				link:'cancel', 
				transition:Fx.Transitions.Sine.easeOut
			}
		});
		var header = new Element('div', {'class':'dockBottomHeader'});
		if( sticky ){
			var closeBtn = new Element('div', { 'class':'sticky_close' }).injectInside(header);
		}	
		var message = new Element('div', {'class':'message'});
		var footer = new Element('div', {'class':'dockBottomFooter'});
		container.adopt( header, message, footer );
		return {'container':container,'header':header,'message':message,'footer':footer,'close':closeBtn||null};		
	}	
});
