
function trace() {
	if (typeof console != 'undefined' && console.log) {
		$A(arguments).each(function (a) {
			console.log(a);
		});
	}
}

IS_INDEX = window.location.toString().indexOf('/html/') == -1;
window.isIE = /MSIE/.test(navigator.userAgent);
window.isIE6 = /MSIE\s6/.test(navigator.userAgent);
window.isIE7 = /MSIE\s7/.test(navigator.userAgent);

if (window.isIE) {
	document.write('<style type="text/css">\n');
	document.write('#estVenues a {\n');
	document.write('  filter:alpha(opacity=75);\n');
	document.write('}\n');
	document.write('#estVenues a:hover { {\n');
	document.write('  filter:alpha(opacity=100);\n');
	document.write('}\n');
	document.write('</style>\n');
}


window.addEvent('domready', function() {
	var venueLogo = $$('#container h1');
	var scale_elements = ['container', 'secondContent'];
	if (venueLogo.length > 0) {
		scale_elements.push(venueLogo[0]);
	}
	var crop_elements = [];
	new PngFixer(scale_elements, crop_elements);

	var path = '';
	$A(document.getElementsByTagName('script')).each(function (s) {
		if (s.src.match(/js\/deckers\.js$/)) {
			path = s.src.replace(/js\/deckers\.js$/, '');
		}
	});

	if ($E('body#home')) {
		if (!window.isIE) {
			$ES('#estVenues img').each(function (e) {
				new Element('img', {src: 'images/20pcblack.png', 'class': 'opacity'}).injectInside(e.getParent());
			});
		}
		new VenueSlider($ES('#estMenu a'), { path: path + 'flash/', minitems: 5 });
	}
	else if (parent.location.href != location.href) {
		$('wrapper').setStyle('overflow', 'hidden');
		var sb = new ScrollBar('main', 'wrapper', {
			'arrows': true,
			'hScroll': false
		});
		var elements = $ES('a.topLink');
		elements.each(function (e) {
			e.addEvent('click', function (evt) {
				evt.stop();
				sb.content.scrollTop = 0,
				sb.vUpdateThumbFromContentScroll();
			}.bindWithEvent(this));
		});
		var elements = $ES('a.internal');
		elements.each(function (e) {
			e.addEvent('click', function (evt) {
				var regex = /#(.+)$/;
				var matches = regex.exec(evt.target.href);
				if (!matches || !$(matches[1])) {
					return;
				}

				var pos = $(matches[1]).getPosition([$('wrapper')]);
				evt.stop();
				sb.content.scrollTop = pos.y,
				sb.vUpdateThumbFromContentScroll();
			}.bindWithEvent(this));
		});
	}
	else {
		var el = $E('body');
		var flashFiles = ['fallenAngels', 'theCrimble', 'pennineManorHotel', 'pennineManor', 'ploughFlail', 'thePeacockRoom', 'theRoyalTobyHotel', 'deckersOnTheWater', 'theRoyalToby', 'theRopeAnchor'];
		if (flashFiles.contains(el.id)) {
			el.setStyle('background-image', 'none');
			var flashLayerId = 'bgflash';
			new Element('div', {id: flashLayerId}).injectTop($E('body'));
			var so = new SWFObject(path + 'flash/' + el.id + '.swf', flashLayerId, '100%', '100%', '8', '#000000');
			so.addParam('wmode', 'transparent');
			so.write(flashLayerId);
		}
	}

	new PaneSwitcher('venueDetails', 'venueMainMenu');

	//work out links on lightbox
	if ($('main')) { //only on popups
		$$('#col1 a').each(function(e) {
			if (e.hasClass('external')) {
				e.target = '_blank';
			}
			else if (!e.hasClass('openInLightbox')) {
				e.target = '_parent';
			}
		});
	}
});

window.addEvent('load', function() {
	if ($E('div#venueGallery ul')) {
		new MotionScroller($E('#venueGallery ul'), { restarea: 20, maxspeed: 4 });
	}
});


var PromotionViewer = new Class({
	reshowDelay: 14, // in days
	cookieName: 'promotions',
	initialize: function(img, hash) {
		var show = true;
		var data = this.getCookie();

		var now = new Date().getTime();
		if (data) {
			// check the data for the current image
			var time = data[hash];
			var delay = this.reshowDelay * 86400;
			if (time && (time + delay) > now) {
				show = false;
			}
		}
		else {
			data = {};
		}

		if (show) {
			Lightbox.show(img, '', '');
			data[hash] = now;
			this.setCookie(data);
		}
	},
	getCookie: function() {
		var data = Cookie.get(this.cookieName);
		return Json.evaluate(data);
	},
	setCookie: function(data) {
		var options = {
			path: '/',
			duration: 30 // in days
		};
		var data = Json.toString(data);
		return Cookie.set(this.cookieName, data, options);
	}

});

var PaneSwitcher = new Class({
	current: 1,
	panels: [],
	initialize: function (container, nav) {
		var container = $(container);
		var nav = $(nav);
		if (!container || !nav) {
			return;
		}

		// get the panels
		var panels = container.getChildren();
		panels.each(function (panel) {
			if (panel.getTag() != 'div') {
				return;
			}
			if (/^pane-.+$/.test(panel.id)) {
				this.panels.push(panel.id);
			}
			else {
				panel.setStyle('display', 'none');
			}
		}, this);

		if (!this.panels.length) {
			return;
		}


		$(nav).getElements('a').each(function (a) {
			a.addClass('cross-link');
		});

		// go through all the cross-links on the page and test the links against the panels
		var regex = /#(pane-.+)$/
		$ES('a.cross-link').each(function (a) {
			var matches = regex.exec(a.href);
			if (matches) {
				a.addEvent('click', this.linked.bindWithEvent(this, matches[1]));
			}
		}, this);
	},
	linked: function (evt, panel) {
		evt.stop();
		this.show(panel);
	},
	show: function (panel) {
		if (!isNaN(parseInt(panel))) {
			// pane is number
			if (panel < 1 || panel > this.panels.length) {
				return false;
			}
		}
		else {
			// pane is a title so get the number
			this.panels.each(function (p, i) {
				if (p == panel) {
					panel = i + 1;
					return;
				}
			}, this);
			if (isNaN(panel)) {
				return false;
			}
		}
		this.current = panel;

		this.panels.each(function (el, i) {
			el = $(el);
			if (i == this.current - 1) {
				el.setStyle('display', 'block');
			}
			else {
				el.setStyle('display', 'none');
			}
		}, this);
	}
});


var MotionScroller = new Class({
	element: null,
	width: 0,
	left: 0,
	timer: null,
	parent: {
		element: null,
		width: 0,
		left: 0
	},
	options: {
		restarea: 10,	// width in pixels of the dead area in the center
		maxspeed: 7		// pixels to move with each iteratio
	},
	initialize: function (element, options) {
		this.element = $(element);
		this.setOptions(options);

		// hide the element while it's loading
		this.element.setStyle('visibility', 'hidden');

		this.loaded();
		// we need to wait until all the images have loaded before we can get the width
		//window.addEvent('load', this.loaded.bind(this));
	},
	loaded: function () {
		// set the width of the element
		var width = 0;
		this.element.getChildren().each(function (e) {
			var widths = e.getStyles('margin-left', 'margin-right');
			for (var property in widths) {
				width += isNaN(parseInt(widths[property])) ? 0 : parseInt(widths[property]);
			}
			width += e.getSize().size.x;
		});

		this.element.setStyles({
			width: width,
			visibility: 'visible'
		});

		this.width = width;
		this.left = 0;

		var parent = this.element.getParent();
		this.parent = {
			element: parent,
			width: parent.getSize().size.x,
			left: parent.getPosition().x
		}

		this.element.getParent().addEvent('mousemove', this.mousemove.bindWithEvent(this));
		this.element.getParent().addEvent('mouseleave', this.mouseout.bindWithEvent(this));
	},
	mouseout: function () {
		$clear(this.timer);
	},
	mousemove: function (evt) {
		$clear(this.timer);

		var posx = evt.client.x - this.parent.left;

		var leftbound = (this.parent.width - this.options.restarea) / 2;
		var rightbound = (this.parent.width + this.options.restarea) / 2;

		if (posx > rightbound) {
			// scroll left
			var direction = 'left';
			var speed = (posx - rightbound) / ((this.parent.width - this.options.restarea) / 2) * this.options.maxspeed;
			this.move(direction, speed);
		}
		else if (posx < leftbound) {
			// scroll right
			var direction = 'right';
			var speed = (leftbound - posx) / ((this.parent.width - this.options.restarea) / 2) * this.options.maxspeed;
			this.move(direction, speed);
		}

		this.timer = this.mousemove.delay(10, this, evt);
	},
	move: function (direction, speed) {
		var pos = Math.round(direction == 'left' ? this.left - speed : this.left + speed);

		if (direction == 'left' && pos > (this.parent.width - this.width)) {
			this.left = pos;
		}
		else if (direction == 'right') {
			this.left = (pos < 0) ? pos : 0;
		}

		this.element.setStyles({
			left: this.left
		});
	}
});
MotionScroller.implement(new Options);


var VenueSlider = new Class({
	items: [],
	timer: null,
	loaded: false,
	links: [],
	backgroundColor: '',
	options: {
		path: '/flash/',
		defaultFlashFile: 'welcome',
		flashLayerId: 'bgflash',
		duration: 1200,
		period: 500,
		minitems: 0,
		selectedLinkClass: 'selected',
		//transition: Fx.Transitions.Quart.easeOut
		transition: Fx.Transitions.Circ.easeOut
	},
	initialize: function (links, options) {
		this.setOptions(options);
		this.backgroundColor = $$('body').getStyle('background-color');

		window.addEvent('load', this.setLoaded.bind(this));
		this.bodyClasses = [];
		links.each(function (e) {
			this.addLink(e);
		}, this);


		$E('body').setStyle('background-image', 'none');

		var currentLink = null;

		if (location.hash) {
			var p = location.hash.slice(1);

			this.links.each(function (link) {
				if (link.layer.id == p) {
					currentLink = link;
				}
			}, this);
		}

		if (currentLink) {
			currentLink.link.addClass(this.options.selectedLinkClass);
			this.showLayer(currentLink.layer);
		}
		else {
			this.showFlash(this.options.defaultFlashFile);
		}

		this.setBackgroundColor();
		return;
	},
	setLoaded: function () {
		this.loaded = true;
	},
	addLink: function (e) {
		var el = this.getLayer(e);
		if (!el) {
			return false;
		}
		this.links.push({link: e, layer: el})
		el.setStyle('display', 'none');
		e.addEvent('click', this.linkClicked.bindWithEvent(this));
	},
	getLayer: function (href) {
		href = new String(href);
		var pos = href.indexOf('#');
		if (pos < 0) {
			return null;
		}
		var el = $(href.substr(pos + 1));
		if ($type(el) == 'element') {
			return el;
		}
		return null;
	},
	removeFlash: function () {
		if (!$(this.options.flashLayerId)) {
			return;
		}
		$(this.options.flashLayerId).setHTML('');
	},
	showFlash: function (flashFile) {
		this.animating = false;
		if (!$(this.options.flashLayerId)) {
			this.options.flashLayerId = new Element('div', {id: this.options.flashLayerId}).injectTop($E('body'));
		}
		var so = new SWFObject(this.options.path + flashFile + '.swf', this.options.flashLayerId, '100%', '100%', '8', '#000000');
		so.addParam('wmode', 'transparent');
		so.write(this.options.flashLayerId);
	},
	linkClicked: function (evt) {
		var target = evt.target;

		var el = this.getLayer(target.href);
		if (el) {
			evt.stop();
//			var anchor = trace(target.href).split('#');
			window.location = target.href;
			if (this.animating) {
				return false;
			}

//			var color = this.backgroundColor;
//			var rel = target.getAttribute('rel');
//			if (rel) {
//				var regex = new RegExp('bg\\[(.*?)\\]');
//				var matches = regex.exec(rel);
//				if (matches) {
//					color = matches[1];
//				}
//			}
//			$(document.body).setStyle('background-color', color);

			this.links.each(function (link) {
				if (target == link.link) {
					link.link.addClass(this.options.selectedLinkClass);
					this.showLayer(link.layer);
				}
				else {
					link.link.removeClass(this.options.selectedLinkClass);
					this.hideLayer(link.layer);
				}
			}, this);

			this.setBackgroundColor();
		}
	},
	setBackgroundColor: function () {
		this.links.each(function(e) {
//			trace($(e).hasClass(this.options.selectedLinkclass));
			var rel = e.link.getAttribute('rel');
			if (e.link.hasClass(this.options.selectedLinkClass)) {
				var color = this.backgroundColor;
				if (rel) {
					var regex = new RegExp('bg\\[(.*?)\\]');
					var matches = regex.exec(rel);
					if (matches) {
						color = matches[1];
					}
					$(document.body).addClass(rel.replace(/[^a-z0-9]/gi, ''));
				}
				$(document.body).setStyle('background-color', color);
			}
			else if (rel) {
				$(document.body).removeClass(rel.replace(/[^a-z0-9]/gi, ''));
			}
		}, this);
	},
	hideLayer: function (el) {
		el.setStyle('display', 'none');
	},
	showLayer: function (el) {
		if (this.timer) {
			$clear(this.timer);
		}
		this.removeFlash();

		el.setStyles({
			display: '',
			visibility: 'hidden'
		});

		var ul = el.getElement('ul');
		var lis = el.getElements('li');
		if (lis.length < this.options.minitems) {
			for (var i = 0; i < this.options.minitems; i++) {
				new Element('li', {'class': 'blank'}).injectInside(ul);
			}
			lis = el.getElements('li');
		}

		var animations = [];
		var widths = lis[0].getStyles('margin-left', 'margin-right');
		var width = 0;
		for (var property in widths) {
			width += isNaN(parseInt(widths[property])) ? 0 : parseInt(widths[property]);
		}
		var dims = lis[0].getSize().size;
		width += dims.x;
		width *= lis.length;

		ul.setStyles({
			width: width,
			height: dims.y,
			position: 'relative',
			overflow: 'hidden'
		});

		var ulPos = ul.getPosition();
		var effects = [];
		var positions = [];
		lis.each(function (e) {
			positions.push(e.getPosition());
		});

		var posleft = el.getSize().size.x;
		var posTop = el.getSize().size.y;
		lis.each(function (e, i) {
			var pos = positions[i];
			/*
			e.setStyles({
				position: 'absolute',
				top: '0px',
				left: pos.x - ulPos.x,
				opacity: 0.5
			});
			if ((pos.x - ulPos.x) < posleft) {
				e.setStyles({
					top: posTop
				});
				effects.push({
					effect: new Fx.Styles(e, this.options),
					options: {
						top: 0,
						opacity: [0, 1]
					}
				});
			}
			*/
			e.setStyles({
				position: 'absolute',
				top: '0px',
				left: pos.x - ulPos.x,
				opacity: 0.5
			});
			if ((pos.x - ulPos.x) < posleft) {
				e.setStyles({
					left: posleft + (pos.x - ulPos.x)
				});
				effects.push({
					effect: new Fx.Styles(e, {duration: this.options.duration }),
					options: {
						left: pos.x - ulPos.x,
						opacity: [0, 1]
					}
				});
			}
		}, this);

		el.setStyles({
			visibility: ''
		});

		var chain = new Chain();
		effects.each(function (effect) {
			chain.chain(function () {
				effect.effect.start(effect.options);
			});
		});

		var runChain = function() {
			chain.callChain();
			if (chain.chains.length == 0) {
				runChain = $clear(timer);
			}
		}
		//var timer = runChain.periodical(this.options.duration + 10);

		this.showFlash.delay((chain.chains.length * 200) + this.options.duration, this, el.id);

		this.animating = true;
		runChain();
		var timer = runChain.periodical(200);


		/*
		this.items = el.getElements('li');
		this.currentItem = 0;
		this.slideItems();
		*/
		// this.periodical = this.slideItem.periodical(this.options.period, this);
	},
	slideItems: function () {
		if (this.currentItem == this.items.length) {
			$clear(this.timer);
		}
		this.currentItem++;
	}
});
VenueSlider.implement(new Options);


var ScrollBar = new Class({

	//Implements: [Events, Options],

	options: {
		maxThumbSize: 20,
		wheel: 8,
		arrows: true,
		hScroll: true // horizontal scrollbars
	},

	initialize: function(main, content, options){
		this.setOptions(options);

		this.main = $(main);
		this.content = $(content);

		if (this.options.arrows == true){
			this.arrowOffset = 36;
		} else {
			this.arrowOffset = 0;
		}

		if (this.options.hScroll == true){
			this.hScrollOffset = 20;
		} else {
			this.hScrollOffset = 0;
		}

		this.vScrollbar = new Element('div', {
				'class': 'vScrollbar'
			}).injectAfter(this.content);

		if (this.options.arrows == true){
			this.arrowUp = new Element('div', {
					'class': 'arrowUp'
				}).injectInside(this.vScrollbar);
		}

		this.vTrack = new Element('div', {
				'class': 'vTrack'
			}).injectInside(this.vScrollbar);

		this.vThumb = new Element('div', {
				'class': 'vThumb'
			}).injectInside(this.vTrack);

		if (this.options.arrows == true){
			this.arrowDown = new Element('div', {
					'class': 'arrowDown'
				}).injectInside(this.vScrollbar);
		}

		this.hScrollbar = new Element('div', {
				'class': 'hScrollbar'
			}).injectAfter(this.vScrollbar);

		if (this.options.arrows == true){
			this.arrowLeft = new Element('div', {
					'class': 'arrowLeft'
				}).injectInside(this.hScrollbar);
		}

		this.hTrack = new Element('div', {
				'class': 'hTrack'
			}).injectInside(this.hScrollbar);

		this.hThumb = new Element('div', {
				'class': 'hThumb'
			}).injectInside(this.hTrack);

		if (this.options.arrows == true){
			this.arrowRight = new Element('div', {
					'class': 'arrowRight'
				}).injectInside(this.hScrollbar);
		}

		this.corner = new Element('div', {
				'class': 'corner'
			}).injectAfter(this.hScrollbar);

		this.bound = {
			'vStart': this.vStart.bindWithEvent(this),
			'hStart': this.hStart.bindWithEvent(this),
			'end': this.end.bindWithEvent(this),
			'vDrag': this.vDrag.bindWithEvent(this),
			'hDrag': this.hDrag.bindWithEvent(this),
			'wheel': this.wheel.bindWithEvent(this),
			'vPage': this.vPage.bindWithEvent(this),
			'hPage': this.hPage.bindWithEvent(this)
		};

		this.vPosition = {};
		this.hPosition = {};
		this.vMouse = {};
		this.hMouse = {};
		this.update();
		this.attach();
	},

	update: function(){
		this.main.setStyle('height', this.content.offsetHeight + this.hScrollOffset);
		this.vTrack.setStyle('height', this.content.offsetHeight - this.arrowOffset);

		this.main.setStyle('width', this.content.offsetWidth + 22);
		this.hTrack.setStyle('width', this.content.offsetWidth - this.arrowOffset);

		// Remove and replace vertical scrollbar
		if (this.content.scrollHeight <= this.main.offsetHeight) {
			this.vScrollbar.setStyle('display', 'none');
			if (this.options.hScroll == true){
				this.hTrack.setStyle('width', this.hTrack.offsetWidth + 22);
			}
			this.content.setStyle('width', this.content.offsetWidth + 22);
		} else {
			this.vScrollbar.setStyle('display', 'block');
		}

		if (this.options.hScroll == true){

			// Remove and replace horizontal scrollbar
			if (this.content.scrollWidth <= this.main.offsetWidth) {
				this.hScrollbar.setStyle('display', 'none');
				this.vTrack.setStyle('height', this.vTrack.offsetHeight + this.hScrollOffset);
				this.content.setStyle('height', this.content.offsetHeight + this.hScrollOffset);
			} else {
				this.hScrollbar.setStyle('display', 'block');
			}

			// Remove and replace bottom right corner spacer
			if (this.content.scrollHeight <= this.main.offsetHeight || this.content.scrollWidth <= this.main.offsetWidth) {
				this.corner.setStyle('display', 'none');
			} else {
				this.corner.setStyle('display', 'block');
			}

			// Horizontal

			this.hContentSize = this.content.offsetWidth;
			this.hContentScrollSize = this.content.scrollWidth;
			this.hTrackSize = this.hTrack.offsetWidth;

			this.hContentRatio = this.hContentSize / this.hContentScrollSize;

			this.hThumbSize = (this.hTrackSize * this.hContentRatio).limit(this.options.maxThumbSize, this.hTrackSize);

			this.hScrollRatio = this.hContentScrollSize / this.hTrackSize;

			this.hThumb.setStyle('width', this.hThumbSize);

			this.hUpdateThumbFromContentScroll();
			this.hUpdateContentFromThumbPosition();

		} else {
				this.hScrollbar.setStyle('display', 'none');
				this.corner.setStyle('display', 'none');
		}


		// Vertical

		this.vContentSize = this.content.offsetHeight;
		this.vContentScrollSize = this.content.scrollHeight;
		this.vTrackSize = this.vTrack.offsetHeight;

		this.vContentRatio = this.vContentSize / this.vContentScrollSize;

		this.vThumbSize = (this.vTrackSize * this.vContentRatio).limit(this.options.maxThumbSize, this.vTrackSize);

		this.vScrollRatio = this.vContentScrollSize / this.vTrackSize;

		this.vThumb.setStyle('height', this.vThumbSize);

		this.vUpdateThumbFromContentScroll();
		this.vUpdateContentFromThumbPosition();

	},

	vUpdateContentFromThumbPosition: function(){
		this.content.scrollTop = this.vPosition.now * this.vScrollRatio;
	},

	hUpdateContentFromThumbPosition: function(){
		this.content.scrollLeft = this.hPosition.now * this.hScrollRatio;
	},

	vUpdateThumbFromContentScroll: function(){
		this.vPosition.now = (this.content.scrollTop / this.vScrollRatio).limit(0, (this.vTrackSize - this.vThumbSize));
		this.vThumb.setStyle('top', this.vPosition.now);
	},

	hUpdateThumbFromContentScroll: function(){
		this.hPosition.now = (this.content.scrollLeft / this.hScrollRatio).limit(0, (this.hTrackSize - this.hThumbSize));
		this.hThumb.setStyle('left', this.hPosition.now);
	},

	attach: function(){
		this.vThumb.addEvent('mousedown', this.bound.vStart);
		if (this.options.wheel) this.content.addEvent('mousewheel', this.bound.wheel);
		this.vTrack.addEvent('mouseup', this.bound.vPage);

		this.hThumb.addEvent('mousedown', this.bound.hStart);
		this.hTrack.addEvent('mouseup', this.bound.hPage);

		if (this.options.arrows == true){
			this.arrowUp.addEvent('mousedown', function(event){
					this.interval = (function(event){
					this.content.scrollTop -= this.options.wheel;
					this.vUpdateThumbFromContentScroll();
				}.bind(this).periodical(40))
			}.bind(this));

			this.arrowUp.addEvent('mouseup', function(event){
				$clear(this.interval);
			}.bind(this));

			this.arrowUp.addEvent('mouseout', function(event){
				$clear(this.interval);
			}.bind(this));

			this.arrowDown.addEvent('mousedown', function(event){
					this.interval = (function(event){
					this.content.scrollTop += this.options.wheel;
					this.vUpdateThumbFromContentScroll();
				}.bind(this).periodical(40))
			}.bind(this));

			this.arrowDown.addEvent('mouseup', function(event){
				$clear(this.interval);
			}.bind(this));

			this.arrowDown.addEvent('mouseout', function(event){
				$clear(this.interval);
			}.bind(this));

			this.arrowLeft.addEvent('mousedown', function(event){
					this.interval = (function(event){
					this.content.scrollLeft -= this.options.wheel;
					this.hUpdateThumbFromContentScroll();
				}.bind(this).periodical(40))
			}.bind(this));

			this.arrowLeft.addEvent('mouseup', function(event){
				$clear(this.interval);
			}.bind(this));

			this.arrowLeft.addEvent('mouseout', function(event){
				$clear(this.interval);
			}.bind(this));

			this.arrowRight.addEvent('mousedown', function(event){
					this.interval = (function(event){
					this.content.scrollLeft += this.options.wheel;
					this.hUpdateThumbFromContentScroll();
				}.bind(this).periodical(40))
			}.bind(this));

			this.arrowRight.addEvent('mouseup', function(event){
				$clear(this.interval);
			}.bind(this));

			this.arrowRight.addEvent('mouseout', function(event){
				$clear(this.interval);
			}.bind(this));
		}

	},

	wheel: function(event){
		this.content.scrollTop -= event.wheel * this.options.wheel;
		this.vUpdateThumbFromContentScroll();
		event.stop();
	},

	vPage: function(event){
		if (event.page.y > this.vThumb.getPosition().y) this.content.scrollTop += this.content.offsetHeight;
		else this.content.scrollTop -= this.content.offsetHeight;
		this.vUpdateThumbFromContentScroll();
		event.stop();
	},

	hPage: function(event){
		if (event.page.x > this.hThumb.getPosition().x) this.content.scrollLeft += this.content.offsetWidth;
		else this.content.scrollLeft -= this.content.offsetWidth;
		this.hUpdateThumbFromContentScroll();
		event.stop();
	},

	vStart: function(event){
		this.vMouse.start = event.page.y;
		this.vPosition.start = this.vThumb.getStyle('top').toInt();
		document.addEvent('mousemove', this.bound.vDrag);
		document.addEvent('mouseup', this.bound.end);
		this.vThumb.addEvent('mouseup', this.bound.end);
		event.stop();
	},

	hStart: function(event){
		this.hMouse.start = event.page.x;
		this.hPosition.start = this.hThumb.getStyle('left').toInt();
		document.addEvent('mousemove', this.bound.hDrag);
		document.addEvent('mouseup', this.bound.end);
		this.hThumb.addEvent('mouseup', this.bound.end);
		event.stop();
	},

	end: function(event){
		document.removeEvent('mousemove', this.bound.vDrag);
		document.removeEvent('mousemove', this.bound.hDrag);
		document.removeEvent('mouseup', this.bound.end);
		this.vThumb.removeEvent('mouseup', this.bound.end);
		this.hThumb.removeEvent('mouseup', this.bound.end);
		event.stop();
	},

	vDrag: function(event){
		this.vMouse.now = event.page.y;
		this.vPosition.now = (this.vPosition.start + (this.vMouse.now - this.vMouse.start)).limit(0, (this.vTrackSize - this.vThumbSize));
		this.vUpdateContentFromThumbPosition();
		this.vUpdateThumbFromContentScroll();
		event.stop();
	},

	hDrag: function(event){
		this.hMouse.now = event.page.x;
		this.hPosition.now = (this.hPosition.start + (this.hMouse.now - this.hMouse.start)).limit(0, (this.hTrackSize - this.hThumbSize));
		this.hUpdateContentFromThumbPosition();
		this.hUpdateThumbFromContentScroll();
		event.stop();
	}

});
ScrollBar.implement(new Options, new Events);



var PngFixer = new Class({
	initialize: function(crop_elements, scale_elements) {
		if (!/MSIE\s6/.test(navigator.userAgent)) {
			// not IE6
			return;
		}
		var imgs = $ES('img');
		var pngs = new Array();
		imgs.each(function (e) {
			if (/\.png$/i.test(e.src)) {
				var p = e.getParent();
				p.setStyles({
					width: e.getAttribute('width'),
					height: e.getAttribute('height'),
					display: 'block',
					filter: 'progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=\'crop\', src=\'' + e.src + '\')'
				});
				e.setStyles({
					display: 'none'
				})
				if (p.nodeName == 'A') {
					p.style.cursor = 'pointer';
				}
			}
		});

		var regex = /url\(['"]?(.*)['"]?\)/;
		if (crop_elements) {
			crop_elements.each(function (e) {
				var e = $(e);
				if (!e) {
					return;
				}
				var matches = regex.exec(e.getStyle('backgroundImage'));
				if (matches) {
					e.setStyles({
						background: 'none',
						filter: 'progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod="crop", src="' + matches[1] + '")'
					})
				}
			});
		}
		if (scale_elements) {
			scale_elements.each(function (e) {
				var e = $(e);
				if (!e) {
					return;
				}
				var matches = regex.exec(e.getStyle('backgroundImage'));
				if (matches) {
					e.setStyles({
						background: 'none',
						filter: 'progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod="scale", src="' + matches[1] + '")'
					})
				}
			});
		}
	}
});

