// JavaScript Document
function makeScrollbar(content,scrollbar,handle,horizontal,ignoreMouse){
	var steps = (horizontal?(content.getScrollSize().x - content.getSize().x):(content.getScrollSize().y - content.getSize().y))
	var slider = new Slider(scrollbar, handle, {	
	steps: steps,
	mode: (horizontal?'horizontal':'vertical'),
	onChange: function(step){
		// Scrolls the content element in x or y direction.
		var x = (horizontal?step:0);
		var y = (horizontal?0:step);
		content.scrollTo(x,y);
	}
	}).set(0);
	if( !(ignoreMouse) ){
	// Scroll the content element when the mousewheel is used within the 
	// content or the scrollbar element.
	$$(content, scrollbar).addEvent('mousewheel', function(e){	
		e = new Event(e).stop();
		var step = slider.step - e.wheel * 30;	
		slider.set(step);					
	});
	}
	// Stops the handle dragging process when the mouse leaves the document body.
	$(document.body).addEvent('mouseleave',function(){slider.drag.stop()});
};

window.addEvent('domready', function() {
	if ($('showtimesWrapper')!=null) { //If showtimesWrapper exists we know this is a show detail page so we need to give the page scroll bars!
		//Following creates the scroll ar for
		var Layer3 = $('Layer3');
		var bodyScroll = new Element('div', {
			'id': 'bodyscroll',
			'class': 'myClass',
			'html': Layer3.get('html')
		});
		Layer3.set('html','');
		bodyScroll.inject('Layer3');
	
		var bodyScrollBar = new Element('div', {
			'id':'scrollbar1',
			'class':'scrollbar-vert'
		});
		
		var bodyScrollHandle = new Element('div', {
			'id':'handle1',
			'class':'handle-vert'
		});
		
		//if ($('bodyscroll').getSize().y>360) {
			bodyScrollBar.inject(document.body,'bottom');
			bodyScrollHandle.inject(bodyScrollBar);
			makeScrollbar( $('bodyscroll'), $('scrollbar1'), $('handle1') );
		//} else {
		//	bodyScroll.setStyle('width','360px');
		//}
		
		//Following creates the scroll bar for the show times table
		var rows = $$('#showtimesWrapper tr');
		if (rows.length>7) {
			$('showtimesWrapper').set('class','scroll');
			var timesScrollBar = new Element('div', {
				'id':'scrollbar2',
				'class':'scrollbar-vert'
			});
			
			var timesScrollHandle = new Element('div', {
				'id':'handle2',
				'class':'handle-vert'
			});
			
			timesScrollHandle.inject(timesScrollBar);
			timesScrollBar.inject(document.body,'bottom');
			makeScrollbar( $('showtimesWrapper'), $('scrollbar2'), $('handle2') );
		}
	}
	
	/*var VatLine = $$('div#Layer4 h2.showtimes')[0];
	if (VatLine!=null) {
		VatLine.innerHTML = VatLine.innerHTML + '&nbsp;<span class="VAT-Discount">VAT discount applied at end of transaction</span>';
	}*/
	
	/* var BojanglesBodge = $$('div#showtimesWrapper table.showtimes')[0];
	var theHTML = BojanglesBodge.innerHTML;
	if (BojanglesBodge!=null) {
		BojanglesBodge.innerHTML = theHTML.replace(/<tr><td class=""date"">Sat 17 Jan<\/td><td class=""time"">3:30 PM<\/td><td class=""price"">&#163;14, &#163;7.50 (children) <\/td><td class=""book"">TBC<\/td><\/tr>/, "<tr><td class=""date"">Sat 17 Jan</td><td class=""time"">11:30 AM</td><td class=""price"">&#163;14, &#163;7.50 (children) </td><td class=""book"">TBC</td></tr><tr><td class=""date"">Sat 17 Jan</td><td class=""time"">3:30 PM</td><td class=""price"">&#163;14, &#163;7.50 (children) </td><td class=""book"">TBC</td></tr>");
	} */
	
});

window.addEvent('domready', function() {
	if ($('showtimesWrapper')!=null) {
		if (Browser.Engine.trident4) {
			var a = $$('div#Layer8 a');
			for (i=0; i<a.length; i++) {
				var child = a[i].getChildren('span')[0];
				//alert(child);
				if (child != null) {
					var image = child.getChildren('img')[0];
					image.inject(a[i]);
					child.destroy();
					a[i].set('class', 'productionshot');
				}
			}
		}	
	}
});