setTimeout(function() {
    var docroot = document.documentElement;

    var istouchscreen = 'undefined' != typeof docroot.ontouchstart && screen.width <= 1024; /* screen size just in case desktop browsers add touch stubs */
    if (istouchscreen) docroot.className += ' touchscreen';

    var isslow = /MSIE [6-7]\./.test(navigator.userAgent) || screen.width <= 980; /* fixme: this is lame assumption */
    var maxfps = isslow ? 20 : 25;

    var supports_transitions = 'undefined' != typeof docroot.style.transition || 'undefined' != typeof docroot.style.MozTransition || 'undefined' != typeof docroot.style.webkitTransition || 'undefined' != typeof docroot.style.OTransition;

    function preload()
    {
        var i = new Image();
        i.src = this.href;
    }

    function set_high_quality(img)
    {
        if (isslow) return;
        img.className += ' high-quality';
    }

window.flickr_init = function(flickr, container_width, container_height) {

    var thumbnail_container = flickr.down('ul');

    // this is ran before onload, so CSS may not be available yet to read the value
    container_width = container_width || 450;
    container_height = container_height || 259;
    thumbnail_container_width = container_width - 34*2; // 34px is for arrows

    flickr.style.width = container_width + 'px';
    flickr.style.height = container_height + 'px';
    thumbnail_container.style.width = thumbnail_container_width + 'px';

    var is_paused = flickr.hasClassName('paused');

    flickr.unselectable = 'on'; // IE

    var displayed_image = flickr.down('img');
    var displayed_background;
    var attrib = flickr.down('div.attribution');

    if (supports_transitions) {
        flickr.className += ' transitions';
    } else {
        function bubbling_mouseover_is_useless(e,thiselement, ismouseover) {
            var target = e.relatedTarget||(ismouseover? e.fromElement : e.toElement);
            do {
                if (target === thiselement) return true;
            }
            while(target && (target = target.parentNode));
            return false;
        }

        flickr.onmouseover = function(e) {
            if (bubbling_mouseover_is_useless(e||event,this,true)) return;
            thumbnail_container.morph('bottom:25px;opacity:1',{duration:0.25, fps:maxfps});
        }
        flickr.onmouseout = function(e) {
            if (bubbling_mouseover_is_useless(e||event,this,false)) return;
            thumbnail_container.morph('bottom:-75px;opacity:0.5',{duration:0.25, fps:maxfps});
        }
    }


    var current_li;
    function get_photo(next_or_prev)
    {
        var n = current_li[next_or_prev](); return n ? n.down('a.photo') : null;
    }

    function make_button(src,name,className)
    {
        var img = document.createElement('img');
        img.setAttribute('alt',name);
        img.src = src;
        img.tabindex=0;
        img.className = className;
        flickr.appendChild(img);
        return img;
    }

    var prevbutton = make_button(assets_url + 'btn-flickr-prev.png','Previous image','prev-image');
    prevbutton.onclick = function(e){var n = get_photo('previous'); if (n) n.onclick(e);}
    var nextbutton = make_button(assets_url + 'btn-flickr-next.png','Next image','next-image');
    nextbutton.onclick = function(e){var n = get_photo('next'); if (n) n.onclick(e);};

    function update_buttons()
    {
        nextbutton[get_photo('next') ? 'show' : 'hide']();
        prevbutton[get_photo('previous') ? 'show' : 'hide']();
    }

    function hey_flickr_dont_flicker() // If <ul> is below the photo, browsers will scroll *down* to make it visible
    {
        flickr.scrollTop=0; flickr.scrollLeft=0;
    }

    var scrolltimer, scrollstarttimer;
    function scroll_to()
    {
        var self = this;
        hey_flickr_dont_flicker();
        if (scrollstarttimer) clearTimeout(scrollstarttimer);
        scrollstarttimer = setTimeout(function(){
            scrollstarttimer=null;
            var scrollsrc = thumbnail_container.scrollLeft;
            var scrolldest;
            if (thumbnail_container_width < 500) { // FIXME: this should calculate center and round to even number of thumbs
                scrolldest = self.offsetLeft - thumbnail_container.clientWidth/2 + self.offsetWidth+4;
            } else {
                scrolldest = self.offsetLeft - thumbnail_container.clientWidth/2 + (self.offsetWidth+4)/2;
            }

            if (scrolltimer) clearInterval(scrolltimer);
            scrolltimer = setInterval(function() {
                if (Math.abs(scrollsrc - scrolldest) < 3 || is_paused) {
                    thumbnail_container.scrollLeft = scrolldest;
                    clearInterval(scrolltimer);scrolltimer=null;
                } else {
                    scrollsrc = (scrollsrc + scrolldest)/2;
                    thumbnail_container.scrollLeft = scrollsrc;
                }
            },50);
        },150); // Firefox triggers focus before mouseup, and won't register click if element moves... :(
    }

    var auto_show_next_timer, user_selected_photo;
    function show_large(e)
    {
        if (auto_show_next_timer) clearTimeout(auto_show_next_timer); auto_show_next_timer = null;

        var my_li = $(this).up('li');
        current_li = my_li;

        user_selected_photo = !!e;  // e will be non-null on click, null on first run
        if (user_selected_photo && this !== document.activeElement) this.focus();

        update_buttons();

        // show attribution
        if (attrib) {
            var thisattrib = this.up().down('.attribution');
            attrib.innerHTML = thisattrib ? thisattrib.innerHTML : '';
        }

        // display large image
        var oldimg = displayed_image;
        var oldbg = displayed_background;
        var newimg = $(document.createElement('img'));
        displayed_image = newimg;

        newimg.className += ' displayed-image';
        oldimg.className += ' previous-image';

        oldimg.parentNode.insertBefore(newimg,(displayed_background && displayed_background.parentNode === oldimg.parentNode) ? displayed_background : oldimg);

        newimg.src = this.href;
        hey_flickr_dont_flicker();

        var onloadran=false;
        var onloadhandler = function() {
            if (onloadran) return; // prevent handler from running twice for same picture
            onloadran=true;

            newimg.style.visibility=''; // show if it was hidden during loading

            // this must run at least once
            Effect.Fade(oldimg, {duration:0.3, afterFinish:function(){
                if (displayed_image === oldimg) displayed_image = null; // just safety net
                oldimg.remove();
                if (oldbg) {
                    oldbg.remove();
                    if (oldbg === displayed_background) displayed_background = null;
                }
            }});

            // don't run after next picture has been displayed already.
            if (my_li !== current_li || !newimg.width || !newimg.height) return;

            var extrasize = container_width*0.06; // ensure that image overflows in both directions for better sliding anim

            // fit to fill
            if (newimg.width < container_width) {
                var ratio = (extrasize+container_width)/newimg.width;
                newimg.height *= ratio;
                newimg.width = (extrasize+container_width);
            } 
            if (newimg.height < container_height) {
                var ratio = (extrasize+container_height)/newimg.height;
                newimg.width *= ratio;
                newimg.height = (extrasize+container_height);
            }

            // points in the image to animate from/to
            var x = {start:((container_width - newimg.width)/3), end:((container_width - newimg.width)*2/3)};
            var y = {start:((container_height - newimg.height)/3), end:((container_height - newimg.height)*2/3)};

            if (Math.random()>0.5) {
                var t = x.start; x.start = x.end; x.end = t;
            }
            if (Math.random()>0.5) {
                var t = y.start; y.start = y.end; y.end = t;
            }

            // start position
            newimg.style.left = x.start+'px';
            newimg.style.top = y.start+'px';

            if (is_paused) return;

            // end position
            newimg.morph('left:'+x.end+'px;top:'+y.end+'px', {duration:1, fps:maxfps, afterFinish:function(){
                /////// second stage of anim //////

                if (!newimg.parentNode) return; // image has been changed since

                var newheight = newimg.height;
                var newwidth = newimg.width;

                // fit to bounds
                if (newwidth > container_width) {
                    var ratio = container_width/newwidth;
                    newheight *= ratio;
                    newwidth = container_width;
                }
                if (newheight > container_height*1.1) { // allows small differences in aspect ratio by cropping 10% of image
                    var ratio = container_height/newheight;
                    newwidth *= ratio;
                    newheight = container_height;
                }

                set_high_quality(newimg); // otherwise scaling animation looks wobbly

                // add bg if needed
                if (newheight+3 < container_height || newwidth+3 < container_width) {
                    displayed_background = newimg.cloneNode(true);
                    if (displayed_background) {
                        $(displayed_background).className += ' displayed-background';
                        newimg.parentNode.insertBefore(displayed_background, newimg);
                        set_high_quality(displayed_background);
                    }
                }

                // center within area
                newimg.morph('top:'+Math.round((container_height-newheight)/2)+'px;left:'+Math.round((container_width-newwidth)/2)+'px;width:'+Math.round(newwidth)+'px;height:'+Math.round(newheight)+'px',
                    {duration:0.8, fps:maxfps });

                // show next image after anim finishes
                if (auto_show_next_timer) clearTimeout(auto_show_next_timer);

                var n = get_photo('next');
                if (n) {
                    preload.call(n); // preload next photo
                    auto_show_next_timer = setTimeout(function(){
                        var n = get_photo('next'); if (n) {n.onclick(); scroll_to.call(n)}
                    }, user_selected_photo ? 7000 : 5000); // 2s anim 3s delay
                }
            }});
        }

        if (newimg.complete) {
            setTimeout(onloadhandler,1);  // Chrome needs a delay
        }
        else {
            newimg.style.visibility = 'hidden'; // partially loaded image before layout script runs looks ugly
            newimg.onload = onloadhandler;
            setTimeout(onloadhandler,2000); // add fallback in case image fails to load (script would get stuck waiting)
        }
        return false;
    }

    flickr.down('ul').childElements().each(function(e) {
        var a = e.down('a.photo');
        a.onclick = show_large;
        a.onfocus = scroll_to;
        a.onmouseover = preload;
    });


    flickr.flickr_pause = function(tf) {
        if (is_paused == tf) return;

        is_paused = tf;
        if (is_paused) {
            if (auto_show_next_timer) clearTimeout(auto_show_next_timer); auto_show_next_timer = null;
            if (scrollstarttimer) clearTimeout(scrollstarttimer); scrollstarttimer = null;
            if (scrolltimer) clearInterval(scrolltimer); scrolltimer = null;
        }
        else
        {
            // timeout to allow browser to lay out newly shown viewer
            setTimeout(function(){show_large.call((current_li || flickr).down('a.photo'))},1);
        }
    }

    show_large.call(flickr.down('a.photo'));
}

if (window.onflickrload) window.onflickrload(); else $$('.flickr-viewer').each(flickr_init);

},1);

/*! http://mths.be/placeholder v1.8.5 by @mathias */
;(function(window, document, $) {

var isInputSupported = 'placeholder' in document.createElement('input'),
isTextareaSupported = 'placeholder' in document.createElement('textarea');

if (isInputSupported && isTextareaSupported) {

$.fn.placeholder = function() {
return this;
};

$.fn.placeholder.input = $.fn.placeholder.textarea = true;

} else {

$.fn.placeholder = function() {
return this.filter((isInputSupported ? 'textarea' : ':input') + '[placeholder]')
.bind('focus.placeholder', clearPlaceholder)
.bind('blur.placeholder', setPlaceholder)
.trigger('blur.placeholder').end();
};

$.fn.placeholder.input = isInputSupported;
$.fn.placeholder.textarea = isTextareaSupported;

$(function() {
// Look for forms
$('form').bind('submit.placeholder', function() {
// Clear the placeholder values so they don’t get submitted
var $inputs = $('.placeholder', this).each(clearPlaceholder);
setTimeout(function() {
$inputs.each(setPlaceholder);
}, 10);
});
});

// Clear placeholder values upon page reload
$(window).bind('unload.placeholder', function() {
$('.placeholder').val('');
});

}

function args(elem) {
// Return an object of element attributes
var newAttrs = {},
rinlinejQuery = /^jQuery\d+$/;
$.each(elem.attributes, function(i, attr) {
if (attr.specified && !rinlinejQuery.test(attr.name)) {
newAttrs[attr.name] = attr.value;
}
});
return newAttrs;
}

function clearPlaceholder() {
var $input = $(this);
if ($input.val() === $input.attr('placeholder') && $input.hasClass('placeholder')) {
if ($input.data('placeholder-password')) {
$input.hide().next().show().focus().attr('id', $input.removeAttr('id').data('placeholder-id'));
} else {
$input.val('').removeClass('placeholder');
}
}
}

function setPlaceholder() {
var $replacement,
$input = $(this),
$origInput = $input,
id = this.id;
if ($input.val() === '') {
if ($input.is(':password')) {
if (!$input.data('placeholder-textinput')) {
try {
$replacement = $input.clone().attr({ 'type': 'text' });
} catch(e) {
$replacement = $('<input>').attr($.extend(args(this), { 'type': 'text' }));
}
$replacement
.removeAttr('name')
// We could just use the `.data(obj)` syntax here, but that wouldn’t work in pre-1.4.3 jQueries
.data('placeholder-password', true)
.data('placeholder-id', id)
.bind('focus.placeholder', clearPlaceholder);
$input
.data('placeholder-textinput', $replacement)
.data('placeholder-id', id)
.before($replacement);
}
$input = $input.removeAttr('id').hide().prev().attr('id', id).show();
}
$input.addClass('placeholder').val($input.attr('placeholder'));
} else {
$input.removeClass('placeholder');
}
}

}(this, document, jQuery));


// $Id: footer-reservations.js 41290 2011-10-05 13:22:48Z russ $

// 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('type', 'change', function() {
		var restype = '----'

		if ($F('type') != null) {
			restype = $('type').options[$('type').selectedIndex].text
	    }

		$('summary-res-type').innerHTML = restype
		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()
		if($('summary-res-type'))
	    {
	       $('summary-res-type').innerHTML = $('type').options[$('type').selectedIndex].text;
	    }
		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)
            // Workaround for a bug replacing the content with Firefox 4
            document.getElementById('calendar').innerHTML = 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
	})
}


$j(function(){
	var fixed = false;
	
	$j(document).scroll(function() {
		if( $j(this).scrollTop() >= 455) {
			if( $j(this).scrollTop() <= 1025) {
				if( !fixed ) {
					fixed = true;
					$j('#booking-static').css({position:'fixed',top:15});
				}
			}
			else
			{
				if( fixed ) {
					fixed = false;
					$j('#booking-static').css({position:'absolute',top:575});
				}	
			}
		} else {
			if( fixed ) {
				fixed = false;
				$j('#booking-static').css({position:'static'});
			}
		}
	});
});




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)
    {
        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, nav_container)
    {
        this.slot = slot;
        this.delay = delay;
        this.nav_container = nav_container;
        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;

        if(nav_container)
        {
            this.initNavContainer();
            this.initMouseOver();
        }
        this.startAutoAdvance();
    },


    // Because mouseover bubbling is a horrible horrible misfeature,
    // and we're using outdated Prototype that can't do anything about it,
    // here's an ugly hack
    initMouseOver: function()
    {
        var self=this;
        var restartTimer;

        function update_mouseover() {
            if (self.mouseover_state === self.old_mouseover_state) return;
            self.old_mouseover_state = self.mouseover_state;

            if (self.mouseover_state) {
                if (restartTimer) clearTimeout(restartTimer);
                restartTimer = null;

                self.nav_container.morph('opacity:1',{duration:0.2});
                self.stopAutoAdvance();
            }
            else {
                self.nav_container.morph('opacity:0.5',{duration:0.2});
                if (!restartTimer) {
                    restartTimer = setTimeout(function(){
                        self.startAutoAdvance();
                    },1000);
                }
            }
        }

        self.nav_container.setStyle({opacity:0.5});

        $(this.slot.parentNode).observe('mouseover',function(){
            self.mouseover_state = true;
            setTimeout(update_mouseover,10);
        });

        $(this.slot.parentNode).observe('mouseout',function(){
            self.mouseover_state = false;
            setTimeout(update_mouseover,10);
        });
    },

    startAutoAdvance: function()
    {
        this.stopAutoAdvance();
        this.autoadvance_executer = new PeriodicalExecuter(function (){this.moveRight()}.bind(this), this.delay);
    },

    stopAutoAdvance: function()
    {
        if (this.autoadvance_executer) this.autoadvance_executer.stop();
        this.autoadvance_executer = null;
    },

    initNavContainer: function()
    {

        var self = this;

        function addNavButton(name,description) {
            var button = document.createElement('img');
            button.src = assets_url + name + '.png';
            button.setAttribute('alt',description);
            button.className = name;
            self.nav_container.appendChild(button);
            return button;
        }

        addNavButton('slot_prev','Previous').onclick = function() {
            self.stopAutoAdvance();
            self.moveLeft();
            return false;
        }

        addNavButton('slot_next','Next').onclick = function() {
            self.stopAutoAdvance();
            self.moveRight();
            return false;
        }
    },

    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)
    {
        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), .055)

        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, 4, slot.next('.slot_nav'));
       }
   })
})


/***
 * 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 31498 2010-11-08 12:04:40Z kornel $

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: ' + 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_directions(map) {
   var form = $('directions-form');
   if (!form) return;

   var directions_panel = $('directions-panel');
   var directions_error = $('directions-error');

   form.onsubmit = function() {
       if (is_iDevice()) return true; // display using built-in maps
       return load_directions(this.elements.saddr.value,this.elements.daddr.value);
   }

   function is_iDevice()
   {
       // it's not supposed to match non-Apple webkits
       return /\(iP.*like Mac OS X.*AppleWebKit.*Mobile/.test(navigator.userAgent)
   }

   var directions = new GDirections(map, directions_panel);
   GEvent.addListener(directions, "error", function() {
       if (directions.getStatus().code == G_GEO_UNKNOWN_ADDRESS) {
           show_directions_error("No corresponding geographic location could be found for the specified address");
       } else if (directions.getStatus().code == G_GEO_UNKNOWN_DIRECTIONS) {
           show_directions_error("We could not find route from the specified address");
       } else {
            show_directions_error("There was an error loading directions");
       }
   });

   GEvent.addListener(directions, "load", function() {
       // directions panel is not laid out yet
       setTimeout(function(){
           Effect.BlindDown(directions_panel, {duration:0.5});
       },100);
   });

   function load_directions(saddr, daddr) {
       if (!/[^\s]/.test(saddr)) {
           show_directions_error("Please specify an address");
           return false;
       }
       form.elements.saddr.blur();
       directions_panel.hide();
       directions_error.innerHTML = '';
       directions.load("from:"+saddr+" to:"+daddr, {locale:"en_GB"});
       return false;
   }

   function show_directions_error(err)
   {
       Effect.BlindUp(directions_panel, {duration:0.2});
       // opera places autocomplete in wrong place if focused before layout runs
       setTimeout(function(){form.elements.saddr.focus()},1);

       directions_error.innerHTML = err;
       Effect.Highlight(directions_error);
   }
}

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

		setup_google_map_directions(map);
	}
}


