Array.implement({
	
	invoke: function(fn, args){
		var result = [];
		
		for (var i = 0, l = this.length; i < l; i++){
			if(this[i] && this[i][fn])
				result.push(args ? this[i][fn].pass(args, this[i])() : this[i][fn]());
		}
		return result;
	}
	
});

(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) {
			
			},
			left: $('next'),
			right: $('prev'),
		/*
			container: null,
			selector: '',
			mode: 'horizontal',
		*/
			animation: 'Move',
			scroll: 4,
			fx: {
			
				link: 'cancel',
				transition: 'sine:out',
				duration: 500
			}
		},
		plugins: {},
		initialize: function (options) {
		
			this.addEvent('change', function (current) {
			
				this.current = current
				
			}.bind(this)).setOptions(options);
			
			$each({left: 'previous', right: 'next'}, function (val, key) {
				
				if(this.options[key]) $(this.options[key]).addEvent('click', function (e) {
				
					e.stop();
					this[val]()
					
				}.bind(this))
				
			}, this);
			
			this.elements = $(options.container).getChildren(options.selector);
			
			this.current = 0;
			this.anim = new this.plugins[this.options.animation](this);
			
			this.move(this.options.current || 0);
		},
		
		isVisible: function (index) {
		
			if($type($(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) for(var i = 1; i < scroll; i++) {
			
				if((i + current)  % length == index) return true;
			}
			
			return false
		},
		
		first: function () {
		
			return this.current
		},
		
		previous: function (direction) {
	
			return this.move(this.current - this.options.scroll, direction)
		},
		
		next: function (direction) {
		
			return this.move(this.current + this.options.scroll, direction)
		},
		
		move: function (index, direction) {
		
			var elements = this.elements,
				current = this.current,
				length = elements.length,
				scroll = this.options.scroll;
			
			if($type($(index)) == 'element') index = elements.indexOf($(index));
			
			if(this.isVisible(index)) return this;
			
			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(this, index, direction);
			
			return this
		}
	});
	
	Carousel.prototype.plugins.Move = new Class({
	
		initialize: function (carousel) {
		
			var up = this.up = carousel.options.mode == 'vertical',
				options = this.options = carousel.options,
				elements = this.elements = carousel.elements.map(function (el) { 
						
					return el.setStyles({display: 'block', position: 'absolute'})
						
				}),
				parent = elements[0].getParent(),
				pos = parent.setStyles({height: parent.offsetHeight, position: 'relative', overflow: 'hidden'}).getStyle('padding' + (this.up ? 'Top' : 'Left'));
				
				this.property = 'offset' + (up ? 'Top' : 'Left');
				this.margin = 'margin' + (up ? 'Top' : 'Left');
			
			this.reorder(0, 1).fx = new Fx.Elements(elements, options.fx)
		},
		
		reorder: function (offset, direction) {
		
			var options = this.options,
				panels = this.elements,
				ini = pos = style(panels[0].getParent(), 'padding' + (this.up ? 'Top' : 'Left')),
				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;
					panel = panels[index];
					
					if(horizontal) panel.setStyle('left', pos);
					else panel.setStyles({left: 0, top: pos});
					pos -= (panel[side] + style(panel, this.margin));
				}
				
				pos = ini + panel[side] + style(panel, this.margin);
				
				for(i = 1; i < options.scroll; i++) {
			
					index = (i + offset + length) % length;
					
					panel = panels[index];
					
					if(horizontal) panel.setStyle('left', pos);
					else panel.setStyles({left: 0, top: pos});
					pos += panel[side] + style(panel, this.margin);
				}
				
				//ltr
			} else if(direction == 1) for(i = 0; i < length; i++) {
			
				index = (i + offset + length) % length;
				panel = panels[index];				
				
				if(horizontal) panel.setStyle('left', pos);
				else panel.setStyles({left: 0, top: pos});
				pos += panel[side] + style(panel, this.margin);
			}
			
			return this
		},
		
		move: function (carousel, current, direction) {
		
			var obj = {}, 
				up = this.up,
				property = this.property,
				offset;
		
/* 			if(this.options.circular) this.reorder(carousel.current, direction); */
			
			offset = carousel.elements[current][property];
			
			carousel.elements.each(function (el, index) {
			
				obj[index] = up ? {top: el[property] - offset} : {left: el[property] - offset}
			});
			
			this.fx.start(obj).chain(function () { carousel.fireEvent('change', current) })
		}
	})
})();

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
	},
	reverse: false, //move direction
*/

	Extends: Carousel,
	Binds: ['update', 'start', 'stop'],
	initialize: function(options) {

		this.parent($merge({interval: 10, delay: 10}, options));
		
		var parentDiv = $(options.container).getParent();
		if (parentDiv.get('tag') == 'div' && parentDiv.hasClass('carousel')) {
		
			parentDiv.addEvent('mouseenter', function (){
				this.stop();
			}.bind(this));
			
			parentDiv.addEvent('mouseleave', function (){
				this.start();
			}.bind(this));
			
		}

		//handle click on tab. wait 10 seconds before we go
		['previous', 'next'].each(function (val) {
		
			if($(this.options[val])) $(this.options[val]).addEvent('click', function (e) {
		
				e.stop();
				
				if(this.running) this.stop().start.delay(this.options.delay * 1000)
				
			}.bind(this))
			
		}, this);
	
		this.reverse = !!this.options.reverse;
		this.running = false;
		this.timer = new PeriodicalExecuter(this.update, this.options.interval);
		
		return this
	},
	
	update: function () { return this[this.reverse ? 'previous' : 'next']() },
	
	start: function () {
	
		this.timer.registerCallback();
		this.running = true;
		return this
	},
	
	stop: function() { 
	
		this.timer.stop();
		this.running = false;
		return this
	}
});

var GMapHandler = new Class( {
	Implements: Options,
	
	options: {
		addMarkerToCentre: true,
		center: '',
		latitude: 'lon',
		longitude: 'lat',
		controls: false,
		oMap: 'gmap',
		zoom: 14
	},

	map: false,
	
	initialize: function(gmap, options) {
		var self = this;
	
		options.oMap = gmap;
		this.setOptions(options);

		latitude = this.options.latitude.toFloat();
		longitude = this.options.longitude.toFloat();
	    myLatlng = new google.maps.LatLng(latitude, longitude);

	    var myOptions = {
			zoom: this.options.zoom.toInt(),
			center: myLatlng,
			mapTypeControl: this.options.controls,
			mapTypeId: google.maps.MapTypeId.ROADMAP
	    }
		var points = this.options.oMap.getElements('span.marker');
	    this.map = new google.maps.Map((this.options.oMap), myOptions);
		if (points.length) {
			points.each(function(point){
				var options = JSON.decode(point.getAttribute('rel'));
				loc = new google.maps.LatLng(options.latitude, options.longitude);
				var info = point.get('html');
				if (options.marker !== false) {
				    var marker = new google.maps.Marker({
				        position: loc,
				        map: self.map
			        })
					if (info.length) {
				        var popup = new google.maps.InfoWindow({
				        	content: info
				        })
						google.maps.event.addListener(marker, 'click', function() {
							popup.open(self.map, marker);
						});
					}
				}
			});
		}
		
		gmap.store('gmap', this);
	},
	
	setCenter: function(lat, lon, zoom) {
		this.map.setCenter(new google.maps.LatLng(lat, lon));
		this.map.setZoom(zoom);
	}
	
});

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
	}
});

var Shared = new Class({

	initialize: function() {
	
		var self = this;
	
		var basket = $('basket');
		if (basket) {
			$('basket').addEvent('click', function() {
				document.location.href = '/shop/basket';
			});
		}
		
		var basketAdded = null;
		if ((basketAdded = $('basket_added')) != null) {
			var fx = new Fx.Tween(basketAdded, {property: 'opacity', duration: 1000});
			(function() { fx.start([1,0]) }).delay(2000);
			$('basket_added').addEvent('click', function(){
				this.dispose();
			});
		}
		
		var buttons = $$('.btn_delete');
		if (buttons.length) {
			buttons.each(function(btn) {
				btn.addEvent('click', function(e) {
					this.confirmDelete(e);
				}.bind(this));
			}.bind(this));
		}
		var carousel = $$('div.carousel');
		if (carousel.length) {
			var duration = 700,
	        links = $$('div.carousel a.cat_link'),
	        tab = new Carousel.Extra({
	            container: 'carousel',
	            scroll: 1,
	            circular: true,
	            current: 3,
	            interval: 2.5,
	            previous: links.shift(),
	            next: links.pop(),
	            mode: 'horizontal',
	            onChange: function (index) {
	                links.each(function (el, off) {
	                    el[off == index ? 'addClass' : 'removeClass']('selected')
	                })
	            },
				left: $('prev-carousel'),
				right: $('next-carousel'),
	            fx: {
	                duration: duration
	            }
	        });
		}
		
		if ($('basket_contents')) {
			var btnDeletes = $('basket_contents').getElements('a.btn_delete');
			if (btnDeletes.length) {
				btnDeletes.each(function(btn) {
					btn.removeEvents('click');
					btn.addEvent('click', function(e) {
						if (this.confirmDelete(e)) {
							var row = $(e.target).getParent().getParent().getParent();
							var tbl = row.getParent().getParent();
							if (tbl.rows.length == 4) document.location.reload();
							else $('shipping_category').fireEvent('change');
						}
					}.bind(this));
				}.bind(this));
			}
			
			if ($('shipping_destination')) {
				var objDestination = $('shipping_destination');
				var objCategory = $('shipping_category');
				var objShippingPrice = $('shipping_price');
				var objTotalPrice = $('basket_total');
				
				objDestination.addEvent('change', function() {
					objCategory.empty();
					objShippingPrice.empty();
					new Element('div', {'class': 'spinner', 'html': '&nbsp;'}).inject(objShippingPrice);
					
					new Request.JSON({
						url: '/shop/update-basket',
						onSuccess: function(json) {
							json.categories.each(function(category)  {
								new Element('option', {'value': category.id, 'text': category.name}).inject(objCategory);
							});
							objCategory.fireEvent('change');
						}
					}).get({'action': 'shipping', 'destination_id': objDestination.get('value')});
				});
				
				objCategory.addEvent('change', function() {
					objShippingPrice.empty();
					new Element('div', {'class': 'spinner', 'html': '&nbsp;'}).inject(objShippingPrice);
					objTotalPrice.empty();
					new Element('div', {'class': 'spinner', 'html': '&nbsp;'}).inject(objTotalPrice);
	
					var date = new Date();
					new Request.JSON({
						url: '/shop/update-basket',
						onSuccess: function(json) {
							$('basket_items').set('html',json.basket_items);
							$('basket_items_price').set('html',json.basket_items_price);
							objShippingPrice.empty().set('html',json.shipping_price);
							objTotalPrice.empty().set('html',json.total_price);
						}
					}).get({'action': 'shipping', 'category_id': this.get('value'), 'time': date.getTime()});
				});
			}
			
			if ($('purchased_yes')) {
				var yesSlide = new Fx.Slide('purchased_yes');
				var noSlide = new Fx.Slide('purchased_no');
				var yesQuestion = $('already_purchased_yes');
				var noQuestion = $('already_purchased_no');
				if (yesQuestion.get('checked')) {
					noSlide.hide();
				}
				if (noQuestion.get('checked')) {
					yesSlide.hide();
				}
				yesQuestion.addEvent('click', function() {
					yesSlide.toggle();
					noSlide.toggle();
				});
				noQuestion.addEvent('click', function() {
					yesSlide.toggle();
					noSlide.toggle();
				});
			
				var registerForm = ($('purchased_no')) ? $('purchased_no') : $('confirm_details');
				var inputs = registerForm.getElements('input[type="text"]');
				inputs.each(function(input) {
					if (!input.get('name').contains('delivery_')) {
						input.addEvent('blur', function() {
							var sibling = $('delivery_'+input.get('name'));
							if (sibling && (sibling.get('value') == '')) sibling.set('value',input.get('value'));
						});
					}
				});
			}
		}
		
		var gmaps = $$('div.gmap');
		if (gmaps.length) {
			gmaps.each(function(gmap){
				var options = gmap.getAttribute('rel');
				options = JSON.decode(options);
				new GMapHandler(gmap, options);
			});
		}

		$$('.print-window').addEvent('click', function(e) {
			new Event(e).stop();
			window.print();
		});

		if ($('subnav')) {			
			$$('li.expander, li.expanded').each(function(li) {
				var subcat = li.getElement('ul');
				if (subcat) {
					subcat.setStyle('display','block');
					var subcatSlide = new Fx.Slide(subcat, {'duration': 'short'});
					if (li.hasClass('expander')) subcatSlide.hide();
					li.addEvent('click', function(e) {
						if (e) e.stopPropagation();
						subcatSlide.toggle();

						if (li.hasClass('expander')) li.removeClass('expander').addClass('expanded');
						else li.removeClass('expanded').addClass('expander');

						if (parentLi = li.getParent('li.expanded')) {
							if (parentLiDiv = parentLi.getElement('div')) {
								var newHeight = parentLiDiv.getSize().y;
								newHeight += (subcatSlide.open) ? -subcatSlide.element.getHeight() : subcatSlide.element.getHeight();
								parentLiDiv.get('tween').start('height', newHeight+'px')
							}
						}
					});
					li.getElement('a').addEvent('click', function(e) {
						var event = new Event(e).stop();
						if (!subcatSlide.open) {
							$(event.target).getParent().fireEvent('click');
						} else {
							document.location.href = this.get('href');
						}
					});
				}
			});
			
			$('subnav').getElements('a').each(function(link) {
				link.addEvent('click', function(e) {
					e.stopPropagation();
				});
			});
		}
		
		var quantities = $$('input.quantity');
		if(quantities.length) {
			quantities.each(function(quantity){
				var spinPlus = new Element('span', {
				    'class': 'spin_plus',
				    'html': '&nbsp;',
				    'events': {
				        'click': function(e){				        	
							var input = $(e.target).getPrevious();
				        	var value = input.get('value').toInt();
				        	value += 1;
				        	input.set('value', value);
				    	}
				    }
				});
				var spinMinus = new Element('span', {
				    'class': 'spin_minus',
				    'html': '&nbsp;',
				    'events': {
				        'click': function(e){
				        	var input = $(e.target).getNext();
				        	var value = input.get('value').toInt();
				        	if (value > 0) { value -= 1; }
				        	input.set('value', value);
				    	}
				    }
				});
				spinPlus.inject(quantity, 'after');
				spinMinus.inject(quantity, 'before');
			});
		}
		
		var updateBasket = $$('div.purchase');
		if(updateBasket.length) {
			updateBasket.each(function(update){
				update.getElement('label').addEvent('click', function() {
					if (update.hasClass('success')){
						window.location.href = "/shop/basket";
					}
				});
				var plus = update.getElement('span.spin_plus');
				plus.addEvent('click', function(){
					self.updateBasket(update);
				});
				var minus = update.getElement('span.spin_minus');
				minus.addEvent('click', function(){
					self.updateBasket(update);
				});
				var keyboardInput = update.getElement('input.quantity');
				keyboardInput.addEvent('keyup', function(){
					self.updateBasket(update);
				});
				var add = update.getElement('a.button');
				add.addEvent('click', function(){
					var pid 		= update.getElement('input.pid').get('value').toInt();
					var qtyInput 	= update.getElement('input.quantity');
					var qty			= qtyInput.get('value').toInt();
					
					if (qty > 0) {
						var jsonRequest = new Request.JSON({
							'url': '/shop/update-basket',
							onSuccess: function(product) {
								if(pid == product.product_id) {
									var label = update.getElement('label');
									label.set('text', product.product_quantity+" in basket");
									qtyInput.set('value', '0');
									if (update.hasClass('update')) {
										update.removeClass('update');
									} 
									if (!update.hasClass('success')) {
										update.addClass('success');
									}
									$('basket_items').set('text', product.basket_quantity);
									$('basket_items_price').set('text', product.basket_total);
								}
							}
						}).get({'action' : 'add', 'pid' : pid, 'qty' : qty});
					} else {
						self.updateBasket(update, "Please enter quantity");
					}
				});
			});
		}
		
		new ZebraTable({'elements': 'div.product_page_left table', 'mouseEvents': false});
		
		$$('.print-window').addEvent('click', function(e) {
			e.stop();
			window.print();
		});
		
		if ($('purchase_date')) this.addDateUtil($('purchase_date'));
		
		this.addTooltips();
		
		var btnFindStockists = null;
		if (btnFindStockists = $('find_stockists')) {
			btnFindStockists.addEvent('click', function() {
				var stockists = $$('div.stockist');
				stockists.fade('hide').setStyle('display','none');
				$(document.body).getElement('#stockists div.loading').setStyle('display','block');
				
				new Request.JSON({
					'url': '/stockists',
					'onSuccess': function(json) {
						$(document.body).getElement('#stockists div.loading').setStyle('display','none');
						if (json && json.latitude && json.longitude) {
							var gmap = $('stockists_map').retrieve('gmap');
							gmap.setCenter(json.latitude, json.longitude, 9);
							
							json.matches.each(function(match) {
								var matchDiv = $('stockist_'+match.stockist_id).setStyle('display','block');
								matchDiv.getElement('dd.distance').set('html',match.miles+' miles');
								matchDiv.removeClass('distance_hide').addClass('distance_show');
								matchDiv.inject($('stockists')).fade('in');
							});
						}
					}
				}).get({'postcode':$('postcode').get('value')});
			});
			
			$('postcode').addEvent('keydown', function(e) {
				if (e.key == 'enter') {
					$('find_stockists').fireEvent('click');
				}
			});
			
			$('reset_stockists').addEvent('click', function() {
				$('postcode').set('value','');
				
				var gmap = $('stockists_map').retrieve('gmap');
				var json = JSON.decode($('stockists_map').get('rel'));
				gmap.setCenter(json.latitude, json.longitude, 6);
				
				var stockists = $$('div.stockist');
				stockists.removeClass('distance_show').addClass('distance_hide').fade('in').setStyle('display','block');
			});
			
			$$('div.stockist a.view_map').addEvent('click', function(e) {
				e.stop();
				var uri = new URI($(e.target).get('href'));
				var gmap = $('stockists_map').retrieve('gmap');
				gmap.setCenter(uri.getData('lat','fragment'), uri.getData('lon','fragment'), 13);
				
				new Fx.Scroll(window).toElement($('stockists_map'));
			});
		}
	},
	
	addDateUtil: function(dateFields) {
		if ($type(dateFields) != 'array') dateFields = [dateFields];
	
		dateFields.each(function(el) {
			new vlaDatePicker(el, {separator: '-', prefillDate: false});
		});
	},
	
	addTooltips: function() {
		$$('.tooltip').each(function(element,index) {
			var content = element.get('title').split('::');
			element.store('tip:title', content[0]);
			element.store('tip:text', content[1]);
		});
		
		//create the tooltips
		var tipz = new Tips('.tooltip',{
			className: 'tipz',
			fixed: true,
			hideDelay: 50,
			showDelay: 50,
			offset: {'x': 0, 'y': 16}
		});	
	},
	
	confirmDelete: function(e) {
		var btn = $(e.target).getParent();

		var parts = btn.get('title').split(' | ');
		switch (parts.length) {
			case 1: var msg = 'Are you sure you want to delete?'; break;
			case 2: var msg = 'Are you sure you want to delete this '+parts[1]+'?'; break;
			case 3: var msg = 'Are you sure you want to delete this '+parts[1]+'?\n- '+parts[2]; break;
		}
		
		if (!confirm(msg)) e.stop();
		else {
			if (btn.href.indexOf('xhr') > -1) {
				e.stop();
				var link = btn.href.split('&xhr');
				var parts = link[0].split('?');
				var date = new Date();
				parts[1] += '&rowIndex='+(btn.getParent().getParent().rowIndex-1)+'&time='+date.getTime();
				return new Request.JSON({
					method: 'get',
					url: parts[0],
					onSuccess: function(json) {
						if (json.status == 'deleted') {
							var row = btn.getParent().getParent();
							return this.removeTableRow(row);
						} else if (json.status == 'error') {
							alert('It was not possible to remove the item from your basket!');
							return false;
						}
					}.bind(this)
				}).send(parts[1]);
			}
		}
	},
	
	removeTableRow: function(row) {
		var children = row.getChildren();
		
		var cellHeight = 0;
		children.each(function(child) {
			if (parseInt(child.getStyle('height')) > cellHeight) cellHeight = parseInt(child.getStyle('height'));
		});
		children.invoke('setStyle', ['height',cellHeight]);

		var fx = new Fx.Tween(row);
		fx.start('opacity','0.2').chain(function() {
			var childFx = [];
			children.each(function(child) {
				childFx.push(new Fx.Tween(child));
			});
			children.invoke('set', ['html','']);
			childFx.invoke('start', ['height','0px']);
			
			this.start('border','0').chain(function() {
				row.dispose();
				return true;
			});
		});
	},
	
	updateBasket: function(update) {
		var input = update.getElement('input.quantity');
		var label = update.getElement('label');
		var inputValue = input.get('value');
		
		if(arguments.length > 1) {
			var message = arguments[1];
		} else if(isNaN(inputValue)) {
			var message = "Please enter quantity";
		} else {
			var message = "Click 'Add' to update basket";
		}

		if( inputValue == 0 && arguments.length == 1 && !isNaN(inputValue)) {
			if(update.hasClass('update')) {
				update.removeClass('update');
				var text = label.retrieve('quantity');
				label.set('text', text);
			}
		} else {
			if(update.hasClass('success')) {
				update.removeClass('success');
			}
			if(!update.hasClass('update')) {
				update.addClass('update');
				var text = label.get('text');
				label.store('quantity', text);
			}
			label.set('text', message);
		}
	}

});

var ZebraTable = new Class({
	Implements: [Options,Events],
	
	options: {
		elements: 'table.list-table',
		cssEven: 'zebra_even',
		cssOdd: 'zebra_odd',
		cssHighlight: 'zebra_highlight',
		cssMouseEnter: 'zebra_mo',
		mouseEvents: true
	},
	
	initialize: function(options) {
		this.setOptions(options);

		$$(this.options.elements).each(function(table) {
			this.zebraize(table);
		},this);
	},
	
	zebraize: function(table) {
		table.getElements('tbody tr').each(function(tr,i) {
			var options = this.options, klass = i % 2 ? options.cssEven : options.cssOdd;
			tr.addClass(klass);
			if (this.options.mouseEvents) {
				tr.addEvents({
					mouseenter: function () {
						if(!tr.hasClass(options.cssHighlight)) tr.addClass(options.cssMouseEnter).removeClass(klass);
					},
					mouseleave: function () {
						if(!tr.hasClass(options.cssHighlight)) tr.removeClass(options.cssMouseEnter).addClass(klass);
					},
					click: function() {
						if(!tr.hasClass(options.cssHighlight))
							tr.removeClass(options.cssMouseEnter).addClass(options.cssHighlight);
						else
							tr.addClass(options.cssMouseEnter).removeClass(options.cssHighlight);
					}
				});
			}
		}, this);
	}
});


var shared;
window.addEvent('domready', function() {
	shared = new Shared();
});
