// $Id: footer-reservations.js 18948 2010-03-26 16:45:46Z stephen $

// TODO: Clean this up
// FIXME: Comment this file

if ($('reservation-form')) {
	Event.observe('venue', 'change', function() {
		var venue = '----'

		if ($F('venue') != null && parseInt($F('venue')) > 0) {
			venue = $('venue').options[$('venue').selectedIndex].text
			//check if venue is o2 to display extra message, FIXME: This is really messy, clean it up
			o2_present = false
			foo = $A($('venue').options)
			foo.each(function(val)
			{
			    if (val.value == 129 || val.value == 87) {
			        o2_present = true
			    }
			})
			if (o2_present == true) {
    			if ($('venue').options[$('venue').selectedIndex].value == 129 || $('venue').options[$('venue').selectedIndex].value == 87) {
    				$('o2-alert').show()
    			}
    			else {
    				$('o2-alert').hide()
    			}
    		}
	    }

		$('summary-venue').innerHTML = venue
		checkIsComplete()
		getOffers()

		if ($('venue-picker-wrapper')) {
			getAreas()
		}
	})

	Event.observe('party-size', 'keyup', function() {
		var partysize = '----'

		var size = parseInt($F('party-size'))
		if (size > 250)
		{
			alert('Sorry, you can not make a reservation for more than 250 people online. Please call the bar directly to discuss your')
			size = 250
			$('party-size').value = 250
		}

		if (size > 0) {
			partysize = size + (size == 1 ? ' person' : ' people')
		}

		$('summary-people').innerHTML = partysize
		checkIsComplete()
		setTicketCounts()
		getOffers();

		$$('input[type="checkbox"].offer-quantity').each(function (ticket) {
			if (ticket.checked)	{
				setSelectedOffers(ticket)
			}
		})
	})

	Event.observe('reservation-form', 'submit', function (e) {
		if (!checkIsComplete()) {
			Event.stop(e)
		}
	})

	Event.observe('accept-terms', 'click', checkIsComplete)
	Event.observe('hour', 'change', setTime)
	Event.observe('minute', 'change', setTime)
	Event.observe(window, 'load', function () {
		$('reservation-offer-load').hide()
		$('safe-confirm-res').hide()
		$('reservation-summary-wrapper').show()
		setupCalendar()
		setupOffers()
		setupTerms()
		checkIsComplete()
	})

	$$('ul#panel-tabs li a').each(function(tab) {
		tab.observe('click', function(e) {
			document.cookie = 'form=' + $('reservation-form').serialize()
		})
	})
}

function checkIsComplete() {
	if ($('res-voucher') && parseInt($F('venue')) > 0) {
		// Check that the voucher is valid, if not hide it
		new Ajax.Request('/reservation/voucher/?type=' + $F('type') + '&date=' + $F('date') + '&venue_id=' + $F('venue') + '&time=' + $F('hour') + '.' + $F('minute') + '&voucher_id=' + $('voucher_id').value, { // Can't use $F('voucher_id') as it returns null if hidden
			method: 'get',
			onSuccess: function(transport) {
				if (transport.responseText == 'valid') {
					$('voucher_id').checked = true
					$('res-voucher').show()
				}
				else {
					$('voucher_id').checked = false // Uncheck the voucher when hidden
					$('res-voucher').hide()
				}
			}
		})
	}

	if (parseInt($F('party-size')) > 0 && parseInt($F('party-size')) <= 250 && parseInt($F('venue')) > 0 && $F('hour') != '' && $F('minute') != '' && $F('date') != '' && $('accept-terms').checked) {
		$('confirm-res').show()
		$('confirm-res-off').hide()
		return true
	}
	else {
		$('confirm-res').hide()
		$('confirm-res-off').show()
		return false
	}
}

function setTime() {
	var time = '----'

	if ($F('hour') != '' && $F('minute') != '') {
		time = $F('hour') + '.' + $F('minute')
	}

	$('summary-time').innerHTML = time
	checkIsComplete()
	getOffers()
}

function setDay(e) {
	$$('a.dayselect').invoke('removeClassName', 'selected')

	var element = Event.element(e)
	$('summary-day').innerHTML = element.parentNode.offsetParent.tHead.rows[0].cells[element.parentNode.cellIndex].abbr
	$('summary-date').innerHTML = element.innerHTML
	$('summary-month').innerHTML = $('curmonth').title
	$('date').value = element.title

	element.addClassName('selected')

	Event.stop(e)
	checkIsComplete()
	getOffers()
}

function setupTerms() {
	$$('a.termslink').each(function(link) {
		link.observe('click', function(e) {
			window.open(link.href + '?venue_id=' + $F('venue'), 'terms', 'width=600,height=400,scrollbars=1')
			Event.stop(e)
		})
	})
}

function setupCalendar() {
	$$('a.dayselect').each(function(day) {
		day.observe('click', function(e) { setDay(e) })

		if (day.title == $F('date')) {
			day.addClassName('selected')
		}
	})
	Event.observe('next', 'click', function(e) { updateCalendar(e) })
	Event.observe('prev', 'click', function(e) { updateCalendar(e) })
}

var offers = new Array
function setupOffers() {
	offers = new Array
	$('offer-summary').hide()
	$$('input.offer-quantity').each(function(offer) {
		offer.observe('change', function(e) {
			setSelectedOffers(Event.element(e))
		})

		offer.observe('keyup', function(e) {
			setSelectedOffers(Event.element(e))
		})

		// Show the offer summary if any offers have been selected
		if (parseInt($F(offer.id)) > 0 || $(offer.id).checked)
		{
			$('offer-summary').show()
			return
		}
	})
}

function setSelectedOffers(element) {
	var total = 0
	var number = 0

	if (element.type == 'checkbox') {
		if (element.checked) {
			number = parseInt($F('party-size'))
		}
	}
	else {
		number = parseInt($F(element.id))
		if (number > 250) {
			number = 250
			$(element.id).value = 250
		}
	}

	element = element.id

	var text = $(element + '-label').innerHTML
	var price = number * $(element + '-price').innerHTML

	offers[element.replace(/offer/, '')] = new Array(price, number, text)

	// Remove all rows from the tbody because IE won't let us just replace the entire body
	// so instead we have to build objects and append them
	var tbody = $('offer-summary').tBodies[0]
	while (tbody.childNodes.length) {
		tbody.removeChild(tbody.childNodes[0])
	}

	offers.each(function(selected) {
		if (typeof(selected) == 'object' && selected[0] > 0) {
			tr = Builder.node('tr')
			tr.appendChild(Builder.node('td', [ Builder.node('span', { className: 'offer-title' }, selected[1] + ' ' + selected[2])]))
			tr.appendChild(Builder.node('td', '£' + selected[0].toFixed(2)))
			tbody.appendChild(tr)

			total += selected[0]
		}
	})

	if (total > 0) {
		$('total').innerHTML = total.toFixed(2)
		$('offer-summary').appendChild(tbody)
		$('offer-summary').show()
		total = 0
	}
	else {
		$('offer-summary').hide()
	}
}

function updateCalendar(e) {
	var date = Event.findElement(e, 'a').href.split('=')

	new Ajax.Request('/reservation/calendar/?year=' + date[2] + '&month=' + parseInt(date[1]), {
		method: 'get',
		onSuccess: function(transport) {
			$('calendar').replace(transport.responseText)
			setupCalendar()
		}
	})
	Event.stop(e)
}

function getAreas() {
	if ($F('venue') && $F('venue') > 0 ) {
		new Ajax.Request('/reservation/areas/?venue_id=' + $F('venue'), {
			method: 'get',
			onSuccess: function(transport) {
				$('venue-picker-wrapper').show()
				$('venue-picker').innerHTML = transport.responseText
			}
		})
	}
	else {
		$('venue-picker-wrapper').hide()
	}
}

function getOffers() {
	if ($F('date') != '' && $F('venue') > 0 && $F('hour') != '' && $F('minute') != '') {
	    var existing = $$('input.offer-quantity')

		new Ajax.Request('/reservation/offers/?type=' + $F('type') + '&date=' + $F('date') + '&venue_id=' + $F('venue') + '&partysize=' + $F('party-size') + '&time=' + $F('hour') + '.' + $F('minute'), {
			method: 'get',
			onSuccess: function(transport) {
				$('reservation-offer-wrapper').innerHTML = transport.responseText
				setupOffers()
				setupTerms()
				setTicketCounts()
            
				existing.each(function (offer) {
                    var new_element = $(offer.id)
				    new_element.value = offer.value
				    
				    setSelectedOffers(new_element)
				})
			}
		})
	}
	else {
		$('reservation-offer-wrapper').innerHTML = ''
	}
}

function setTicketCounts() {
	var size = parseInt($F('party-size'))

	var value = ''
	if (size > 0) {
		value = size
	}

	$$('span.offer-quantity').each(function(count) {
		count.innerHTML = value
	})
}


var ScrollingPanes = Class.create();
ScrollingPanes.prototype = {
    initialize: function(scrollerClassName) {
 /*
    initialize: function(scrollerClassName, autoscroll) {
    //attempt to make autoscroll use this class but it seems bit there would be to much rewrite to do...
    if (autoscroll)
    {
        this.scrollerClassName = scrollerClassName;
        this.animating = false
        this.pane_size = '175'

        spacing = 20;
        this.pane_size = '175' + spacing;
        //this.pane_size = (offer_list[0].getDimensions().width  + parseInt(spacing))// '175'

        this.scrollers = this.getScrollers()
        this.scrollers.each(function(scroller) {
            this.initializePanes(scroller);
            this.numPanes = scroller.panes.length;

            this.leftPane = 0;
            this.rightPane = 1;
        }.bind(this))

        executor = new PeriodicalExecuter(function (){this.moveScrollers()}.bind(this), 2);

    }*/

    if ($('offer-scroller'))
    {
        this.scrollerClassName = scrollerClassName = 'scroller'
        this.animating = false
        this.pane_size = '175'

        // Calculate the element spacing based on the right css property if it exists
        offer_list = $$('#offer-scroller li')
        offer      = Element.extend(offer_list[0])
        spacing    = offer.getStyle('margin-left')

        $$('#offer-scroller li').each(function(element){
            element.setStyle({'margin-left': '0px'})
        })

        if(spacing)
        {
            spacing = spacing.replace('px', '')
        }

        if(parseInt(spacing) < 28) spacing = 28

        this.pane_size = (offer_list[0].clientWidth  + parseInt(spacing))// '175'

        this.scrollers = this.getScrollers()
        this.scrollers.each(function(scroller) {
            this.initializePanes(scroller);
            this.numPanes = scroller.panes.length;
            if (scroller.panes.length > 3)
            {
                this.activateControls(scroller);
                this.leftPane = 0;
                this.rightPane = 3;
            }
        }.bind(this))
        }
    },

    moveScrollers: function (callback) {
      //implement call backe to
        this.scrollers.each(function(scroller) {
            this.moveRight(scroller);
        }.bind(this))
    },

    getScrollers: function()
    {
        return document.getElementsByClassName(this.scrollerClassName).collect(function(container) {
            return this.getPanes(container)
        }.bind(this))
    },

    getPanes: function(container)
    {
        return {
            container: container,
            panes: container.childElements(),
            controls: {
                left: container.previous('a.left'),
                right: container.next('a.right')
            }
        }
    },

    initializePanes: function(scroller)
    {
        scroller.container.setStyle({
            position: 'relative',
            overflow: 'hidden',
            padding: 0,
            listStyle: 'none'
        })

        pane_size = this.pane_size

        scroller.panes.each(function(pane, index) {
            pane.setStyle({
                position: 'absolute',
                top: 0,
                left: index*Number(this.pane_size)+'px'
            });
            pane.position = index;
        })

        return scroller
    },

    activateControls: function(scroller)
    {
        scroller.controls.left.observe('click', this.moveLeftAction.bindAsEventListener(this, scroller))
        scroller.controls.left.show();
        scroller.controls.right.observe('click', this.moveRightAction.bindAsEventListener(this, scroller))
        scroller.controls.right.show();
    },

    moveLeftAction: function (event, scroller)
    {
        this.moveLeft(scroller)
        Event.stop(event)
    },

    moveRightAction: function (event, scroller)
    {
        this.moveRight(scroller)
        Event.stop(event)
    },

    moveLeft: function(scroller)
    {
        if (this.animating == false)
        {
            this.nextPane = this.leftPane -1;
            if (this.nextPane < 0)
            {
                this.nextPane = this.numPanes -1;
            }
            scroller.panes[this.nextPane].setStyle({
                position: 'absolute',
                top: 0,
                left: (0 - this.pane_size) + 'px'
            });
            this.movePanes(scroller.panes, 'left', 1, 5);
            this.leftPane = this.nextPane;
            this.rightPane = this.rightPane - 1;
            if (this.rightPane < 0)
            {
                this.rightPane = this.numPanes - 1;
            }
        }
    },

    moveRight: function(scroller)
    {
        if (this.animating == false)
        {
            this.nextPane = this.rightPane + 1;
            if (this.nextPane >= this.numPanes)
            {
                this.nextPane = 0;
            }

            pane_size = this.pane_size

            scroller.panes[this.nextPane].setStyle({
                position: 'absolute',
                top: 0,
                left: 4*pane_size + 'px'
            });
            this.movePanes(scroller.panes, 'right', 1, 5);
            this.rightPane = this.nextPane;
            this.leftPane = this.leftPane + 1;

            if (this.leftPane >= this.numPanes)
            {
                this.leftPane = 0;
            }
        }
    },
    movePanes: function(panes, direction, amount)
    {
        this.animating = true
        this.frame = 1;
        this.dist = 0;

        new PeriodicalExecuter(function(exectuer) {
            if (this.frame < 7)
            {
                speed = Math.floor(0.125 * this.pane_size);
                this.dist += speed
            }
            else if (this.frame < 10)
            {
                speed = Math.floor(0.075 * this.pane_size);
                this.dist += speed
            }
            else
            {
                speed = this.pane_size - this.dist;
                this.animating = false;
                exectuer.stop();
            }
            this.frame = this.frame + 1;

            panes.each(function(pane) {
                var currentPosition = parseInt(pane.getStyle('left').replace('px', ''))
                var newPosition = currentPosition

                if (direction == 'left')
                {
                    newPosition += speed
                }
                else if (direction == 'right')
                {
                    newPosition -= speed
                }

                pane.setStyle({left: newPosition+'px'})

            }.bind(this))
        }.bind(this), .005)

        return panes
    },

    atBeginning: function(panes)
    {
        if (panes[0].getStyle('left') == '0%')
        {
            return true
        }
        else
        {
            return false
        }
    },

    atEnd: function(panes)
    {
        if (panes[panes.length-3].getStyle('left') <= '0%')
        {
            return true
        }
        else
        {
            return false
        }
    }
}



var PanelsRotate = Class.create();
PanelsRotate.prototype = {
    initialize: function(slot, delay)
    {
        this.slot = slot;
        this.panes =   $$('#'+slot.id+' > li');
        if (this.panes[0])
            this.current = this.panes[0];

        this.animating = false
        this.pane_size = this.current.clientWidth;

        offer      = $(this.panes[0]);
        spacing    = offer.getStyle('margin-left')

        $A(this.panes).each(function(element){
            element.setStyle({'margin-left': '0px'})
        })

        if(spacing)
        {
            spacing = spacing.replace('px', '')
        }

        if(parseInt(spacing) < 12) spacing = 12;

        this.pane_size = parseInt(this.panes[0].getDimensions().width) + parseInt(spacing);


        this.initialize_panes();

        this.numPanes = this.panes.length;

        this.leftPane = 0;
        this.rightPane = 0;

        new PeriodicalExecuter(function (){this.moveRight()}.bind(this), delay);

    },
    initialize_panes: function ()
    {
        this.panes.each(function (pane, index)
        {
            pane.setStyle({
                    position: 'absolute',
                    left: index*Number(this.pane_size)+'px'
                });
            }.bind(this));
    },

    moveLeft: function()
    {
        if (this.animating == false)
        {
            this.nextPane = this.leftPane -1;
            if (this.nextPane < 0)
            {
                this.nextPane = this.numPanes -1;
            }
            this.panes[this.nextPane].setStyle({
                position: 'absolute',
                left: (0 - this.pane_size) + 'px'
            });
            this.movePanes(this.panes, 'left', 1, 5);
            this.leftPane = this.nextPane;
            this.rightPane = this.rightPane - 1;
            if (this.rightPane < 0)
            {
                this.rightPane = this.numPanes - 1;
            }
        }
    },

    moveRight: function()
    {
        if (this.animating == false)
        {

            this.nextPane = this.rightPane + 1;
            if (this.nextPane >= this.numPanes)
            {
                this.nextPane = 0;
            }

            pane_size = parseInt(this.pane_size);

            this.panes[this.nextPane].setStyle({
                position: 'absolute',
                top: 0,
                left: (this.pane_size) + 'px'
            });
            this.movePanes(this.panes, 'right', 1, 5);
            this.rightPane = this.nextPane;
            this.leftPane = this.leftPane + 1;

            if (this.leftPane >= this.numPanes)
            {
                this.leftPane = 0;
            }
        }
    },
    movePanes: function(panes, direction, amount)
    {
        this.animating = true
        this.frame = 1;
        this.dist = 0;

        new PeriodicalExecuter(function(exectuer) {
            if (this.frame < 7)
            {
                speed = Math.floor(0.125 * this.pane_size);
                this.dist += speed
            }
            else if (this.frame < 10)
            {
                speed = Math.floor(0.075 * this.pane_size);
                this.dist += speed
            }
            else
            {
                speed = this.pane_size - this.dist;
                this.animating = false;
                exectuer.stop();
            }
            this.frame = this.frame + 1;

            panes.each(function(pane) {
                var currentPosition = parseInt(pane.getStyle('left').replace('px', ''))
                var newPosition = currentPosition

                if (direction == 'left')
                {
                    newPosition += speed
                }
                else if (direction == 'right')
                {
                    newPosition -= speed
                }

                pane.setStyle({left: newPosition+'px'})

            }.bind(this))
        }.bind(this), .075)

        return panes
    }
}


Event.observe(window, 'load', function() {
    // @todo might need to shift this to the body if the
    // copy on lnl was there for a reason

    if($('offer-scroller'))
    {
	    new ScrollingPanes();
        $('offer-scroller').setStyle({
            position: 'relative',
            overflow: 'hidden',
            padding: 0,
            listStyle: 'none'
        })
    }

    $$('ul.slot_holder').each(function (slot)
    {
       if (slot.childElements().length > 1)
       {
          new PanelsRotate(slot, 8);
       }
   })
})


/***
 * Slideshow.js
 * version 1.5.5
 * Tom McFarlin / May 2008
 *---------------------------------------------------------------------------*/
//document.observe('load', function(e) {
//	if($('slideshow-title'))
//		$('slideshow-title').hide();
//	$$('div#slideshow-container img').each(function(i) {
//		if($$('div#slideshow-container img').first() != i)
//			i.hide();
//	});
//});

Event.observe(window, 'load', function(e) {
    if ($('slideshow-container')) {
		var imgs = $$('div#slideshow-container img')
		if (imgs.length > 1) {
        	if($('slideshow-title')) {
				$('slideshow-title').hide()
			}

    		imgs.each(function(i) {
    			if (imgs.first() != i) {
    				i.hide();
				}
    		})

    		Slideshow.Control.Container = $('slideshow-container');
    		Slideshow.Control.Images.All = $$('div#slideshow-container img');
    		Slideshow.Control.Titlebar = $('slideshow-title');

    		Slideshow.Control.Images.All.each(function(i) {
    			if(!Slideshow.Control.Images.Widest || Slideshow.Control.Images.Widest.getWidth() < i.getWidth())
    				Slideshow.Control.Images.Widest = i;
    			if(!Slideshow.Control.Images.Tallest || Slideshow.Control.Images.Tallest.getHeight() < i.getHeight())
    				Slideshow.Control.Images.Tallest = i;
    			if(i != Slideshow.Control.Images.All.first())
    				i.hide();
    		})

    		Slideshow.Methods.start();
		}
    }

});

var Slideshow = {

	Version: "1.5.5",

	Browser: {
		IE: Prototype.Browser.IE,
		IE6: parseInt(navigator.appVersion.split('MSIE')[1]) == 6 ? true : false,
		Opera: Prototype.Browser.Opera,
		Safari: Prototype.Browser.WebKit
	},

	Settings: {
		Fade: false,
		Speed: 0,
		Pause: false,
		Manual: false,
		UpperLimit: 0,
		Transition: 1
	},

	Control: {
		Images: {
			Active: null,
			Next: null,
			Largest: null,
			All: null
		},
		Container: null,
		Executer: null,
		PauseMessage: null,
		Titlebar: null
	},

	Util: {
		Images: null,
		Container: null,
		Titlebar: null,
		Executer: null,
		PauseMessage: null,

		Image: {
			Active: null,
			Next: null,
			Widest: null,
			Tallest: null
		}
	},

	Methods: {

		start: function() {

			Slideshow.Methods._setupImages();
			Slideshow.Methods._setupContainer();
			Slideshow.Methods._startExecuter();

		},

		_setupImages: function() {

			Slideshow.Control.Images.All.each(function(i) {
				Slideshow.Methods._setImageStyles(i);
				if(Slideshow.Control.Images.All.first() == i) {
					Slideshow.Control.Images.Active = i;
					Slideshow.Methods._updateCaption(Slideshow.Control.Images.Active);
				} else {
					i.hide();
				}
			});
		},

		_setImageStyles: function(image) {

			var leftMargin = ((Slideshow.Control.Images.Widest.getWidth() - image.getWidth()) / 2);
			leftMargin += 'px';

			/* opera failsafe */
			if(Slideshow.Browser.Opera)
				leftMargin = 0 + 'px';

			var margin = '-' + image.height + 'px';
			if(image.getStyle('margin-bottom') != margin) {
				image.setStyle({
					marginBottom: margin,
					'float': 'left',
					marginLeft: leftMargin
				});
			}

		},

		_setupContainer: function() {

			Slideshow.Control.Container.setStyle({
				height: Slideshow.Control.Images.Tallest.getHeight() + 'px',
				width: Slideshow.Control.Images.Widest.getWidth() + 'px',
				position: 'relative'
			});

			Slideshow.Control.Container.classNames().each(function(n) {

				n = n.toLowerCase();

				if(n == 'fade')
					Slideshow.Settings.Fade = true;

				if (n == 'pause') {
					Slideshow.Settings.Pause = true;
					Slideshow.Control.Container.observe('mouseover', function(e) {
						Slideshow.Methods._mouseOverHandler(e);
					});
					Slideshow.Control.Container.observe('mouseout', function(e) {
						Slideshow.Methods._mouseOutHandler(e);
					});
				}

				if (n == 'manual') {
					Slideshow.Settings.Manual = true;
					Slideshow.Control.Container.observe('click', function(e) {
						Slideshow.Methods._mouseClickHandler(e);
					});
				}

				var strParam = n.split(':');
				if(strParam[0].toLowerCase() == 'speed')
					Slideshow.Settings.Speed = strParam[1];

				if(strParam[0].toLowerCase() == 'limit')
					Slideshow.Settings.UpperLimit = strParam[1];

				if(strParam[0].toLowerCase() == 'transition')
					Slideshow.Settings.Transition = strParam[1];



			});

			if(!Slideshow.Control.PauseMessage && Slideshow.Settings.Pause)
				Slideshow.Methods._createPauseMessage();

			if (Slideshow.Control.Titlebar) {
				Slideshow.Control.Titlebar.setStyle({
					position: 'absolute',
					bottom: 0
				});
				Slideshow.Control.Titlebar.show();
			}

		},

		_startExecuter: function() {

			if (Slideshow.Settings.Speed != 0) {
				Slideshow.Control.Executer = new PeriodicalExecuter(function(pe){
					Slideshow.Methods._rotate();
				}, Slideshow.Settings.Speed);
			}
		},

		_rotate: function() {

			var images = Slideshow.Control.Images.All;
			var image = Slideshow.Control.Images;

			image.Active == images.last() ?
				image.Next = images.first() :
				image.Next = images[images.indexOf(image.Active) + 1];

			if (Slideshow.Settings.UpperLimit != 1) {
				Slideshow.Methods._swap(image.Active, image.Next);
				Slideshow.Settings.UpperLimit--;
			}

		},

		_swap: function(current, next) {

			/* opera failsafe */
			Slideshow.Methods._setImageStyles(current);

			if(Slideshow.Settings.Fade ) {
				new Effect.Fade(current, {
					duration: Slideshow.Settings.Transition
				});
				new Effect.Appear(next, {
					duration: Slideshow.Settings.Transition
				});
			} else {
				current.hide();
				next.show();
			}

			if(Slideshow.Control.Titlebar)
				Slideshow.Methods._updateCaption(next);

			Slideshow.Control.Images.Active = next;

		},

		_updateCaption: function(image) {

			var titlebar = null;
			if(Slideshow.Control.Titlebar)
				titlebar = Slideshow.Control.Titlebar;
			else
				return;

			if(titlebar.down(0))
				titlebar.removeChild(titlebar.down(0))

			var captionContainer = $(document.createElement('span'));
			var captionText = $(document.createTextNode(image.readAttribute('alt')));
			captionContainer.appendChild(captionText);

			titlebar.appendChild(captionContainer);

		},

		_createPauseMessage: function() {

			var PauseMessage = $(document.createElement('div'));
			var message = document.createTextNode('paused');
			PauseMessage.setAttribute('id', 'slideshow-pause');
			PauseMessage.appendChild(message);

			PauseMessage.setStyle({
				top: '0',
				right: '0',
				position: 'absolute'
			});

			PauseMessage.hide();
			Slideshow.Control.Container.appendChild(PauseMessage);
			Slideshow.Control.PauseMessage = PauseMessage;

		},

		_mouseOverHandler: function(e) {
			e.stopPropagation();
			if(Slideshow.Control.Executer)
				Slideshow.Control.Executer.stop();
			Slideshow.Control.PauseMessage.show();
		},

		_mouseOutHandler: function(e) {
			e.stopPropagation();
			if(Slideshow.Control.Executer)
				Slideshow.Methods._startExecuter();
			Slideshow.Control.PauseMessage.hide();
		},

		_mouseClickHandler: function(e) {
			e.stopPropagation();
			if(Slideshow.Control.Executer)
				Slideshow.Control.Executer.stop();
			if(Slideshow.Control.PauseMessage)
				Slideshow.Control.PauseMessage.hide();
			Slideshow.Methods._rotate();
			if(Slideshow.Control.Executer)
				Slideshow.Methods._startExecuter();
		}
	}
};

Event.observe(window, 'load', function () {
	if ($('toggleall-enquiries')) {
		Event.observe('toggleall-enquiries', 'click', function (e) {
			// Hide the link
			$('toggleall-enquiries').up().hide()
			
			// Show all the rows
			$$('div.other-brand-enquiries').each(function (entries) {
				Effect.Appear(entries)
			})
			
			Event.stop(e)
		})
	}
	
	if ($('toggleall-feedback')) {
		Event.observe('toggleall-feedback', 'click', function (e) {
			// Hide the link
			$('toggleall-feedback').up().hide()
			
			// Show all the rows
			$$('div.other-brand-feedback').each(function (entries) {
				Effect.Appear(entries)
			})
			Event.stop(e)
		})
	}
	
	if ($('toggleall-vouchers')) {
		Event.observe('toggleall-vouchers', 'click', function (e) {
			// Hide the link
			$('toggleall-vouchers').up().hide()
			
			// Show all the rows
			$$('div.other-brand-vouchers').each(function (entries) {
				Effect.Appear(entries)
			})
						
			Event.stop(e)
		})
	}
	
	
	if ($('toggleall-subscriptions')) {
		Event.observe('toggleall-subscriptions', 'click', function (e) {
			// Hide the link
			$('toggleall-subscriptions').up().hide()
			
			// Show all the rows
			$$('fieldset.other-brand-subscriptions').each(function (entries) {
				Effect.Appear(entries)
			})
						
			Event.stop(e)
		})
	}
	
	if ($('toggleall-subscriptions-list')) {
		Event.observe('toggleall-subscriptions-list', 'click', function (e) {
			$('email-prefs-subscribe').hide()
			$('email-prefs-subscribe-all').show()
			Event.stop(e)
		})
	}
	
	if ($('email-prefs')) {
		$$('input.national').each(function(checkbox) {
			Event.observe(checkbox, 'click', function (e) {
				if (!checkbox.checked) {
					var brand_id = checkbox.className.replace(' national', '').replace('brand_', '')
					$$('input.brand_' + brand_id).each(function (list) {
						list.checked = false
					})
				}
			})
		})
		
		$$('input.local').each(function(checkbox) {
			Event.observe(checkbox, 'click', function(e) {
				if (checkbox.checked) {
					var brand_id = checkbox.className.replace(' local', '').replace('brand_', '')
					$$('input.national').each(function (list) {
						if (list.hasClassName('brand_' + brand_id)) {
							list.checked = true
						}
					})
				}
			})
		})
	}
})

// $Id: footer-venues.js 19633 2010-04-23 14:50:20Z stephen $

Event.observe(window, 'load', function() {
	if ($('ukmap'))	setup_national_maps()
	if ($('googlemap')) setup_google_map()
	if ($('hahamap')) setup_england_map()
})

function setup_national_maps() {
	$$('a.areaselect').each(function(area) {
		area.observe('click', function(e) {	
			$$('a.areaselect').invoke('removeClassName', 'current')
			$$('a.venueselect').each(function(venue) {
				if (venue.rel == area.rel) venue.up().show()
				else venue.up().hide()
			})
			
			area.addClassName('current')
			
			$('mapwrapper').removeClassName('step2')
			$('slug-detail-wrapper').hide()
			$('slug-detail').innerHTML = '&nbsp;'
			$('step2-title').innerHTML = 'Step 2. All ' + Event.element(e).title
			
			Event.stop(e)
		})
	})
	
	$$('a.venueselect').each(function(venue) {
		venue.observe('click', function(e) {
			new Ajax.Updater('slug-detail', '/venue/hcard/', {
				method: 'get',
				parameters: { venue: venue.id },
				asynchronous: false,
				onFailure: function() {
					window.location = Event.findElement(e, 'a').href
				},
				onSuccess: function() {
					$('slug-detail-wrapper').show()
					$('mapwrapper').addClassName('step2')
				}
			})
			
			Event.stop(e)
		})
	})
}

function setup_england_map() {
	$$('a.mapselect').each(function (link) {
		link.observe('click', function (e) {
			$$('a.mapselect').each(function (venue) {
				var img = venue.down()
				img.src = img.src.replace('-on', '-off')
			})
			
			new Ajax.Updater('haha-detail', '/venue/hcard/', {
				method: 'get',
				parameters: { venue: link.up().id },
				asynchronous: false,
				onFailure: function() {
					window.location = Event.findElement(e, 'a').href
				},
				onSuccess: function() {
					var img = Event.findElement(e, 'img')
					img.src = img.src.replace('-off', '-on')
				}
			})			
			
			Event.stop(e)
		})
	})
}

if (typeof places == 'undefined') var places = []
if (typeof hide_minimap == 'undefined') var hide_minimap = false
if (typeof default_zoom == 'undefined') var default_zoom = 15
if (typeof venue_type == 'undefined') var venue_type = 'bar'

function setup_google_map() {
	var shown_on_map = 'btn-shownonmap.png'
	var plot_on_map = 'btn-plotonmap.png'
	
	if (GBrowserIsCompatible()) {
		$('googlemap').show()	
		var map = new GMap2($('googlemap'))
		map.setCenter(new GLatLng(default_lat, default_lon), default_zoom)
		
		map.addControl(new GSmallMapControl())
		if (hide_minimap == false) {
			map.addControl(new GOverviewMapControl())
		}
		
		map.enableDoubleClickZoom()
		map.enableContinuousZoom()
		
		var icon = new GIcon(null, assets_url + 'icon-mapmarker.png')
		icon.iconSize = new GSize(icon_data.iconw, icon_data.iconh)
		icon.iconAnchor = new GPoint(icon_data.pointx, icon_data.pointy)

		// Loop through and mark all the places on the map
		places.each(function(place) {
			var point = new GLatLng(place.lat, place.lon)
			
			var marker = new GMarker(point, { icon: icon, title: place.name })
			if (place.alt_icon) {
				var alt_icon = new GIcon(null, assets_url + 'alt/icon-mapmarker.png')
				alt_icon.iconSize = icon.iconSize
				alt_icon.iconAnchor = icon.iconAnchor
				
				var marker = new GMarker(point, { icon: alt_icon, title: place.name })
			}
			map.addOverlay(marker)
			
			// Add click handlers to the points so that clicking will pan to them
			GEvent.addListener(marker, 'click', function() {
				map.panTo(point)
			})
		
			// Add double click so you can zoom in
			GEvent.addListener(marker, 'dblclick', function() {
				if (map.getCenter() == point) {
					map.setZoom(default_zoom)
				}
			})

			// Activate the "plot on map" buttons
			if ($('plot-' + place.id)) {
				var link = $('plot-' + place.id)
				link.show()
				link.observe('click', function (e) {
					map.setZoom(default_zoom)
					map.panTo(point)

					$$('div.nearest').each(function(block) {
						block.addClassName('nearby');
						block.removeClassName('nearest')
						
						var img = block.down('img')
						var link = block.down('a')
						
						img.src = img.src.replace(shown_on_map, plot_on_map)
						img.alt = 'Plot this ' + venue_type + ' on the map above'
						link.title = 'Plot this ' + venue_type + ' on the map above'
					})
					
					var block = Event.findElement(e, 'div')
					var img = Event.findElement(e, 'img')
					var link = Event.findElement(e, 'a')
										
					block.addClassName('nearest')
					block.removeClassName('nearby')
					
					img.src = img.src.replace(plot_on_map, shown_on_map)
					img.alt = 'This ' + venue_type + ' is shown on the map above'
					link.title = 'This ' + venue_type + ' is shown on the map above'
				})
			}
		})
		
		/*
		Event.observe('plot', 'click', function(e) {
		    //alert('clicked')
    		var directions = new GDirections(map, $('direction_panel'));
   		    directions.load("from: " + $F('plot_postcode') + " to: SW11 1RU");
    	})
    	*/
	}
}

