



//### usage: log('inside coolFunc', this, arguments);
//### http://paulirish.com/2009/log-a-lightweight-wrapper-for-consolelog/
window.log = function () {
	log.history = log.history || []; // store logs to an array for reference
	log.history.push(arguments);
	if (this.console) {
		console.log(Array.prototype.slice.call(arguments));
	}
};




var availability = {
	model: null,
	tabs: {},
	change: function (e) {
		if (e) {
			e.stop();
			var t = e.target;
			if (t.parentNode.parentNode.id === 'tt') {
				this.model = ((t.id === 'tt_mh') ? 'h' : 'c');//### better to add booking model class (eg bm_h) to target element
				$('tfc_model').setValue(this.model);
				var q = this.tabs.length;
				var first = true;
				var prev = false;
				var c = '';
				for (var i = 0; i < q; i++) {
					var me = (this.tabs[i].model === this.model);
					var l = $$('#tt li.' + this.tabs[i].model)[0];//### slooooow! ought to add an id on this element
					this.tabs[i].active = me;
					if (me) {
						l.removeClassName('a');
						l.addClassName('s');
					} else {
						l.removeClassName('s');
						l.addClassName('a');
					}
					l.removeClassName('la');
					l.removeClassName('lb');
					l.removeClassName('ld');
					l.removeClassName('le');
					l.removeClassName('lf');
					if (first && me) {
						c = 'lb';
					} else if (first) {
						c = 'la';
					} else if (me) {
						c = 'ld';
					} else if (prev) {
						c = 'le';
					} else {
						c = 'lf';
					}
					l.addClassName(c);
					first = false;
					prev = me;
				}
				var tt = $('tt');
				if (this.tabs[q - 1].active) {
					tt.removeClassName('last_off');
					tt.addClassName('last_on');
				} else {
					tt.removeClassName('last_on');
					tt.addClassName('last_off');
				}
				var a = $$(
					'#tfc_flexibility',
					'select.tfc_nights',
					'select.tfc_rooms',
					'#tfs_allocation>div.bm'
				), i = a.length;
				while (i--) {
					if (a[i].hasClassName('bm_' + this.model)) {
						a[i].show();
					} else {
						a[i].hide();
					}
				}
			}
		}
		var a = $F('tfc_arrival');
		var da = a.split('-');
		var d = new Date(da[0], da[1] - 1, da[2]);
		var n = parseInt($F('tfc_nights_m' + this.model), 10);
		var r = parseInt($F('tfc_rooms_m' + this.model), 10);
		$('tfc_arrival2').setValue(d.getDate() + '-' + Date.monthabbr[d.getMonth()] + '-' + d.getFullYear());
		d.setDate(d.getDate() + n);
		$('tfi_depart2').update(d.getDate() + '-' + Date.monthabbr[d.getMonth()] + '-' + d.getFullYear());
		var a = $$('.tfi_room'); i = a.length;
		while (i--) {
			if (r > 1) {
				a[i].show();
			} else {
				a[i].hide()
			}
		}
		var a = $$('#tf_allocation_m' + this.model + '>div');
		var i = a.length;
		while (i--) {
			var split = a[i].id.split('_');
			var no = parseInt(split[3], 10);
			if (no > r) {
				a[i].hide();
			} else{
				a[i].show();
			}
		}
		var a = $$('#tfs_types>label');
		var i = a.length;
		while (i--) {
			if (a[i].hasClassName('bm_' + this.model)) {
				a[i].show();
			} else{
				a[i].hide();
			}
		}
	},
	getpricesclick: function (e) {
		if (e) {
			e.stop();
			var t = e.target;
			var l = $('tfc_location');
			var s = $('tfc_search');
			var c = $('tfc_context');
			if (s) {
				s.setValue('0');
			}
			if (c) {
				c.setValue(page.decode(t.rel));
			}
			if (l) {
				l.setValue(searchname);
				this.submit();
			}
		}
	},
	submit: function (e) {
		if (e) {
			e.stop();
		}
		dc.off('tfc_location');
		$('tfc_arrival2').disable();
		(this.model === 'c') || $('tfc_flexibility').disable();
		var a = $$('.tfc_nights');
		var i = a.length;
		while (i--) {
			(a[i].id === ('tfc_nights_m' + this.model)) || a[i].disable();
		}
		var a = $$('.tfc_rooms');
		var i = a.length;
		while (i--) {
			(a[i].id === ('tfc_rooms_m' + this.model)) || a[i].disable();
		}
		var r = parseInt($F('tfc_rooms_m' + this.model));
		var a = $$('#tfs_allocation>div');
		var i = a.length;
		while (i--) {
			if (a[i].hasClassName('bm_' + this.model)) {
				var b = $$('#' + a[i].id + '>div');
				var j = b.length;
				while (j--) {
					var split = b[j].id.split('_');
					var no = parseInt(split[3], 10);
					if (no > r) {
						var c = $$('#' + b[j].id + ' select');
						var k = c.length;
						while (k--) {
							c[k].disable();
						}
					}
				}
			} else{
				var b = $$('#' + a[i].id + '>div>select');
				var j = b.length;
				while (j--) {
					b[j].disable();
				}
			}
		}
		var a = $$('#tfs_types>label>input');
		var i = a.length;
		while (i--) {
			a[i].hasClassName('bm_' + this.model) || a[i].disable();
		}
		page.track(
			{
				action:'search'
			}
		);
		$('tf').submit();
	},
	selectcalendar: function (x) {
	},
	closecalendar: function (x) {
		x.hide();
		$('tfc_arrival').setValue(x.date.print(x.dateFormat));
		this.change();
	},
	init: function () {
		dc.add('tfc_location', 'Enter your UK destination');
		new Ajax.Autocompleter(
			'tfc_location',
			'tfx_location',
			'/location',
			{
				paramName: 'location',
				minChars: 1,
				indicator: 'tfi_location',
				onShow: function (element, update) {
					update.style.width = element.offsetWidth + 'px';
					update.show();
				},
				onHide: function (element, update) {
					update.hide();
				}
			}
		);
		this.model = $F('tfc_model');
		this.tabs = tabs;
		var a = $$('#tt li');
		var i = a.length;
		var x = this.change.bind(this);
		while (i--) {
			a[i].observe('click', x);
		}
		var a = $$('#tf select');
		var i = a.length;
		while (i--) {
			a[i].observe('change', x);
		}
		var f = new Date();
		var t = new Date();
		t.setFullYear(t.getFullYear() + 2);
		IkCalendar.setup(
			{
				id: 'tfx_calendar',
				dateField: 'tfc_arrival',
				triggerElement: 'tft_arrival',
				showYearNav: false,
				dateRangeFrom: f,
				dateRangeTo: t,
				showOtherMonthDays: false,
				selectHandler: this.selectcalendar.bind(this),
				closeHandler: this.closecalendar.bind(this)
		}
		);
		$('tfc_submit').observe('click', this.submit.bind(this));
		var a = $$('a.getprices');
		var i = a.length;
		var x = this.getpricesclick.bind(this);
		while (i--) {
			a[i].observe('click', x);
		}
	}
};




var book = {
	radio: [],
	init: function () {
		this.radio = $$('#book input[type="radio"]');
		var a = this.radio;
		var i = a.length;
		var x = this.options.bind(this);
		while (i--) {
			a[i].observe('change', x);
			a[i].observe('click', x);
		}
		var a = $$('#book a.btn');
		var i = a.length;
		var x = this.submit.bind(this);
		while (i--) {
			a[i].observe('click', x);
		}
		var a = $$('#book .moreless a');
		var i = a.length;
		var x = this.fold.bind(this);
		while (i--) {
			a[i].observe('click', x);
		}
	},
	options: function (e) {
		var a = this.radio;
		var i = a.length;
		while (i--) {
			if (a[i].getValue()) {
				$(a[i].parentNode.parentNode).removeClassName('unselected');
			} else {
				$(a[i].parentNode.parentNode).addClassName('unselected');
			}
		}
		var i = listing_availability.display_providers.length;
		while (i--) {
			var errs = [];
			var tp = 0;
			var s = listing_availability.display_providers[i].id;
			var rdk = Object.keys(listing_availability.providers[s].room_definitions);
			var rdkl = rdk.length;
			while (rdkl--) {
				listing_availability.providers[s].room_definitions[rdk[rdkl]].c = 0;
			}
			var rooms = $$('#book_form_' + s + ' ul.br li.brr');
			var j = rooms.length;
			while (j--) {
				var room_li = rooms[j];
				var inputs = $$('#' + room_li.id + ' input');
				var k = inputs.length;
				while (k--) {
					var input = inputs[k];
					if ((input.name==='rooms[' + j + ']') && input.checked) {
						var sv = $F(input);
						listing_availability.providers[s].room_definitions[sv].c++;
						var rd = listing_availability.providers[s].room_definitions[sv];
						tp += ((rd.price_gbp === 0) ? 0 : (Math.round(rd.price_gbp * 100) / 100));
						break;
					}
				}
			}
			$('book_' + s + '_tp').update(tp.toFixed(2));
			$('book_' + s + '_tph').setValue(tp.toFixed(2));
			var rdkl = rdk.length;
			while (rdkl--) {
				rd = listing_availability.providers[s].room_definitions[rdk[rdkl]];
				if ((rd.num_available >= 0) && (rd.c > rd.num_available)) {
					errs.push('There ' + ((rd.num_available === 1) ? 'is only 1 room' : ('are only ' + rd.num_available + ' rooms')) + " of type '" + rd.name + "' available");
				}
			}
		}
	},
	fold: function (e) {
		e.stop();
		var i = $(e.target.parentNode.parentNode);
		if (i) {
			if (i.hasClassName('folded')) {
				i.removeClassName('folded');
			} else {
				i.addClassName('folded');
			}
		}
	},
	submit: function (e) {
		e.stop();
		var l = e.target;
		page.track(
			{
				action:'submit'
			}
		);
		l.parentNode.parentNode.parentNode.submit();
	}
};




var cookie = {
	get: function (n) {
		var e = (n + '=');
		var a = document.cookie.split(';');
		var q = a.length;
		for (var i = 0; i < q; i++) {
			var c = a[i];
			while (c.charAt(0) === ' ') {
				c=c.substring(1, c.length);
			}
			if (c.indexOf(e) === 0) {
				return c.substring(e.length, c.length);
			}
		}
		return null;
	},
	set: function (n, v, d) {
		var x = '';
		if (d) {
			var o=new Date();
			o.setDate(o.getDate() + d);
			x = '; expires=' + o.toGMTString();
		}
		document.cookie = n + '=' + v + x + '; path=/';
	}
};




var dc = {
	add: function (l, c) {
		l = $(l);
		if (l) {
			l.writeAttribute(
				{
					'default': c
				}
			);
			l.observe('focus', this.focus.bind(this));
			l.observe('blur', this.blur.bind(this));
			this.on(l);
		}
	},
	focus: function (e) {
		e.stop();
		this.off(e.target);
	},
	blur: function (e) {
		e.stop();
		this.on(e.target);
	},
	on: function (l) {
		l = $(l);
		if (l) {
			var d = l.readAttribute('default');
			if (!l.value.length) {
				l.value = d;
			}
			if (l.value == d) {
				l.addClassName('g');
			} else {
				l.removeClassName('g');
			}
		}
	},
	off: function (l) {
		l = $(l);
		if (l) {
			var d = l.readAttribute('default');
			if (l.value == d) {
				l.value = '';
			}
			l.removeClassName('g');
		}
	}
};




var enquiry = {
	init: function () {
		dc.add('ef_name', 'Your Name');
		dc.add('ef_email', 'Your Email');
		dc.add('ef_email2', 'Confirm Your Email');
		dc.add('ef_phone', 'Your Phone Number');
		$('ef_send_to_visitor').observe(
			'click',
			function(e) {
				if (!$('ef_send_to_visitor').checked) {
					$('ef_signup').checked = false;
				}
			}
		);
		$('ef_signup').observe(
			'click',
			function(e) {
				if ($('ef_signup').checked) {
					$('ef_send_to_visitor').checked = true;
				}
			}
		);
		$('ef_submit').observe('click', this.submit.bind(this));
		var a = $$('#ef_confcontainer a.edit');
		var i = a.length;
		var x = this.edit.bind(this);
		while (i--) {
			a[i].observe('click', x);
		}
		var f = new Date();
		var t = new Date();
		t.setFullYear(t.getFullYear() + 2);
		IkCalendar.setup(
			{
				id: 'ef_calendar_popup',
				dateField: 'ef_arrival',
				triggerElement: 'ef_e_arrival',
				showYearNav: false,
				dateRangeFrom: f,
				dateRangeTo: t,
				showOtherMonthDays: false
			}
		);
	},
	edit: function (e) {
		e.stop();
		$('ef_f') && $('ef_f').show();
		$('ef_r') && $('ef_r').hide();
		return false;
	},
	submit: function (e) {
		e.stop();
		var df = $$('#ef input[default]');
		var dfq = df.length;
		while (dfq--) {
			dc.off(df[dfq]);
		}
		var p = $('ef').serialize(true);
		var dfq = df.length;
		while (dfq--) {
			dc.on(df[dfq]);
		}
		p.id = ident.listing;
		p.ident = Object.toJSON(
			page.track(
				{
					action: 'submit'
				},
				false
			)
		);
		new Ajax.Request(
			'/form',
			{
				asynchronous: false,
				parameters: p,
				onSuccess: this.response.bind(this)
			}
		);
	},
	response: function (t) {
		var a = $$('.ef_e1');
		var i = a.length;
		var r = t.responseJSON;
		while (i--) {
			a[i].removeClassName('ef_e2');
		}
		if (r.success) {
			var s = $H(r.summary);
			var sa = s.unset('additional');
			var la = $('ef_r_additional');
			s.each(
				function(i) {
					var l = $('ef_r_' + i.key);
					l && l.update(page.encode(i.value));
				}
			);
			if (la && sa.length) {
				la.show();
			} else {
				la.hide();
			}
			$('ef_f') && $('ef_f').hide();
			$('ef_r') && $('ef_r').show();
		} else {
			$H(r.errors).each(
				function(i) {
					var e = $('ef_e_' + i.key);
					e && e.addClassName('ef_e2');
				}
			);
		}
	}
};




var map = {
	stats: {
		total: 0,
		pass: 0,
		fail: 0
	},
	warnpopulation: 18,
	bounds: null,
	infowindow: null,
	data: {},
	map: null,
	markers: {},
	icon_data:{
		'lai':{'is':[55, 100], 'ia':[27, 100], 's':['li', 106, 100]},
		'lfi':{'is':[55, 100], 'ia':[27, 100], 's':['li', 106, 100]},
		'lei':{'is':[55, 100], 'ia':[27, 100], 's':['li', 106, 100]},
		'lac':{'is':[23, 42], 'ia':[11, 42], 's':['lc', 45, 42]},
		'lfc':{'is':[23, 42], 'ia':[11, 42], 's':['lc', 45, 42]},
		'lec':{'is':[23, 42], 'ia':[11, 42], 's':['lc', 45, 42]},
		'lab':{'is':[23, 42], 'ia':[11, 42], 's':['lb', 45, 42]},
		'lfb':{'is':[23, 42], 'ia':[11, 42], 's':['lb', 45, 42]},
		'leb':{'is':[23, 42], 'ia':[11, 42], 's':['lb', 45, 42]},
		'i101':{'is':[30, 28], 'ia':[12, 15], 's':['i101s', 45, 28]},
		'i102':{'is':[30, 28], 'ia':[12, 15], 's':['i102s', 45, 28]},
		'i103':{'is':[64, 64], 'ia':[31, 63], 's':['i103s', 97, 64]},
		'i104':{'is':[30, 28], 'ia':[12, 15], 's':['i104s', 45, 28]},
		'i105':{'is':[30, 28], 'ia':[12, 15], 's':['i105s', 45, 28]},
		'i1001':{'is':[64, 64], 'ia':[31, 63], 's':['i1001s', 97, 64]}
	},
	icon_definition: function (number, me, quarter, full) {
		var name = (this.icon_data['i' + number] && !me) ? ('i' + number) : ('l' + quarter + (me ? 'i' : (full ? 'c' : 'b')));
		if (this.icon_data[name]) {
			var r = this.icon_data[name];
			if (!r.i) {
				var i = {};
				i.iconSize = new google.maps.Size(r.is[0], r.is[1]);
				i.iconAnchor = new google.maps.Point(r.ia[0], r.ia[1]);
				i.image = 'http://includes.iknow-uk.com/img/gmap/' + name + '.png';
				i.name = name;
				if (r.s) {
					i.shadow = 'http://includes.iknow-uk.com/img/gmap/' + r.s[0] + '.png';
					i.shadowSize = new google.maps.Size(r.s[1], r.s[2]);
				}
				this.icon_data[name]['i'] = i;
			}
			return this.icon_data[name]['i'];
		} else {
			return{};
		}
	},
	draw: function () {
		while (shorts.length) {
			var item = shorts.shift();
			var listing = parseInt(ident.listing, 10);
			var me = (item.id === listing);
			var book = (item.a && item.a.display_providers && (item.a.display_providers.length > 0));
			var prices = '';
			if (item.p.t) {
				prices = '<span class="p"><span class="pn"><span class="' + pricelabels[item.p.t].c + '">' + pricelabels[item.p.t].l + '</span><span class="pnn">' + item.p.s + item.p.n + '</span></span><span class="pb">' + item.p.b + '</span></span></span>';
			}
			var iwc = '<a id="mi" class="q_' + item.q + '" href="' + item.u + '" title="' + item.t + '"><img src="' + item.i + '" alt="' + item.t + '" /><span class="ts">' + (item.ts || item.t) + '</span><span class="s">' + item.s + '</span>' + prices + '</a>';
			var i = item.m.length;
			this.stats.total++;
			if (i) {
				this.stats.pass++;
			} else {
				this.stats.fail++;
			}
			while (i--) {
				var m = item.m[i];
				var d = this.icon_definition(m[3], me, item.q, item.c);
				var c = new google.maps.LatLng(parseFloat(m[1]), parseFloat(m[2]));
				var o = {};
				o.position = c;
				o.map = this.map;
				o.title = page.decode(item.t);
				if (d.image) {
					o.icon = new google.maps.MarkerImage(
						d.image,
						d.iconSize,
						new google.maps.Point(0, 0),
						d.iconAnchor
					);
				}
				if (d.shadow) {
					o.shadow = new google.maps.MarkerImage(
						d.shadow,
						d.shadowSize,
						new google.maps.Point(0, 0),
						d.iconAnchor
					);
				}
				var n = 'l_' + m[0].toString();
				this.markers[n] = new google.maps.Marker(o);
				this.markers[n].iwc = iwc;
				this.bounds.extend(c);
				google.maps.event.addListener(
					this.markers[n],
					'click',
					function() {
						map.infowindow.setContent(this.iwc);
						map.infowindow.open(this.map, this);
					}
				);
			}
			if (ident.automap) {
				this.map.fitBounds(this.bounds);
			}
		}
		if (this.stats.fail && (this.stats.total <= this.warnpopulation)) {
			$('mq').update('<h3>Showing ' + this.stats.pass + ' of ' + this.stats.total + ' result' + (this.stats.total === 1 ? '' : 's') + '</h3><p>(We do not have location data for ' + this.stats.fail + ' establishment' + (this.stats.fail === 1 ? '' : 's') + ')</p>');
			$('mq').show();
		}
	},
	init: function () {
		if (!ident.gmap || !$('mc')) {
			return;
		}
		var f = (ident.pagetype === 'filter');
		this.data.lat = ident.lat;
		this.data.lng = ident.lng;
		this.data.zoom = ident.zoom;
		if (f) {
			this.data.subregion = ident.subregion;
			this.data.area = ident.area;
			this.data.quarter = ident.quarter;
			var sraq = cookie.get('sraq');
			if (sraq !== null) {
				var o = sraq.evalJSON();
				if (
					(this.data.subregion === o.subregion) &&
					(this.data.area === o.area) &&
					(this.data.quarter === o.quarter)
				) {
					this.data.subregion = o.subregion;
					this.data.area = o.area;
					this.data.quarter = o.quarter;
					this.data.lat = o.lat;
					this.data.lng = o.lng;
					this.data.zoom = o.zoom;
				}
			}
			this.save();
		}
		this.map = new google.maps.Map(
			$('mc'),
			{
				zoom: this.data.zoom,
				center: new google.maps.LatLng(this.data.lat, this.data.lng),
				mapTypeId: google.maps.MapTypeId.ROADMAP,
				backgroundColor: '#EFEFEF'
			}
		);
		this.bounds = new google.maps.LatLngBounds();
		if (!ident.automap) {
			this.bounds.extend(new google.maps.LatLng(parseFloat(ident.lat), parseFloat(ident.lng)));
		}
		this.infowindow = new google.maps.InfoWindow();
		google.maps.event.addListener(
			this.map,
			'click',
			function() {
				map.infowindow.close();
			}
		);
		this.draw();
		if (f) {
			google.maps.event.addListener(
				this.map,
				'zoom_changed',
				function() {
					map.zoom();
				}
			);
			google.maps.event.addListener(
				this.map,
				'center_changed',
				function() {
					map.center();
				}
			);
		}
	},
	zoom: function () {
		this.data.zoom = this.map.getZoom();
		this.save();
	},
	center: function () {
		var mc = this.map.getCenter();
		this.data.lat = mc.lat();
		this.data.lng = mc.lng();
		this.save();
	},
	save: function () {
		cookie.set('sraq', Object.toJSON(this.data));
	}
};




var page = {
	init: function () {
		visibility.init(this.show.bind(this));
	},
	show: function () {
		if (window.iknow_bug) {
			ident.affiliate = iknow_bug.affiliate.id;
			ident.affiliateref = iknow_bug.affiliate.ref;
			ident.guid = iknow_bug.guid;
		}
		ident.showdelay = visibility.showdelay;
		this.track();
		relregex = /^(ANALYTICS|PLUS|FEATURED|EXTERNAL):(\w)+$/;
		Date.monthabbr = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
		Date.monthname = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
		Date.suffix = ['st', 'nd', 'rd', 'th', 'th', 'th', 'th', 'th', 'th', 'th', 'th', 'th', 'th', 'th', 'th', 'th', 'th', 'th', 'th', 'th', 'st', 'nd', 'rd', 'th', 'th', 'th', 'th', 'th', 'th', 'th', 'st'];
		ident.gmap && map.init();
		switch (ident.pagetype) {
		case 'filter':
			cookie.set('filter', ident.url);
			cookie.set('filterq', ident.quarter);
			$('info') && $('info').observe('click', this.filterinfo.bind(this));
			break;
		case 'listing':
		switch (ident.feature) {
		case 'booking':
			book.init();
			break;
		case 'recommendations':
			$('mb').observe('click', this.buddiesfilter.bind(this));
			break;
		case 'form':
			enquiry.init();
			break;
		}
		if (window.photos && $('photomain_img')) {
			this.photos = Object.clone(window.photos);
			this.photos.a = $('photomain');
			this.photos.img = $('photomain_img');
			var x = this.imageover.bind(this);
			for (id in this.photos.d) {
				if (this.photos.d.hasOwnProperty(id)) {
					this.photos.d[id].image = new Image();
					this.photos.d[id].image.src = this.photos.d[id].p;
					var l = $(id);
					l && l.observe('mouseover', x);
				}
			}
		}
		var a = $$('#srbpn a.form');
		var i = a.length;
		var x = this.bpnclick.bind(this);
		while (i--) {
			a[i].observe('click', x);
		}
		break;
		}
		if ($('tf')) {
			availability.init();
		}
		var a = $$('a.ext');
		var i = a.length;
		while (i--) {
			a[i].writeAttribute({'target':'_blank'});
		}
		var a = $$('a.trackme');
		var i = a.length;
		var x = this.click.bind(this);
		while (i--) {
			a[i].observe('click', x);
			a[i].removeClassName('trackme');
			a[i].addClassName('tracked');
		}
	},
	bpnclick: function (e) {
		e.stop();
		var l = e.target;
		$(l.getAttribute('rel')).submit();
	},
	filterinfo: function (e) {
		e.stop();
		var a = $$('#info div');
		var i = a.length;
		while (i--) {
			if (a[i].hasClassName('hide')) {
				a[i].removeClassName('hide');
			} else {
				a[i].addClassName('hide');
			}
		}
		cookie.set('filterp', (cookie.get('filterp') == '1') ? 0 : 1);
	},
	imageover: function (e) {
		e.stop();
		var p = this.photos.d[e.target.id];
		this.photos.img.src = p.p;
		if (this.photos.a) {this.photos.a.href = p.u;}
	},
	click: function (e) {
		var l = e.currentTarget;
		var a=l.rel.split(' ').grep(relregex);
		if (a.length) {
			var r = a[0].split(':');
			var f = r[0];
			if (f === 'ANALYTICS') {
				if (window._gaq) {
					_gaq.push(['r._trackEvent', f, r[1], l.href]);
					_gaq.push(['a._trackEvent', f, r[1], l.href]);
				}
			} else {
				this.track(
					{
						action: 'click',
						clickfeature: f,
						clickid: r[1],
						clickurl: l.href
					}
				);
				if (f === 'EXTERNAL') {
					$(l).writeAttribute(
						{
							'target': '_blank'
						}
					);
				}
			}
		}
		return true;
	},
	track: function (n, x) {
		var o=Object.clone(ident);
		if (n) {
			for (i in n) {
				if (n.hasOwnProperty(i)) {
					o[i] = n[i];
				}
			}
		}
		if (typeof(x) !== 'undefined' ? x : true) {
			new Ajax.Request(
				'/log',
				{
					asynchronous: false,
					parameters: {
						ident: Object.toJSON(o)
					}
				}
			);
		}
		return o;
	},
	buddiesfilter: function (e) {
		var l = e.target;
		if (l.type && (l.type === 'radio')) {
			var n = l.value;
			var a = $$('#r a');
			var i = a.length;
			while (i--) {
				if ((n == '') || a[i].hasClassName(n)) {
					a[i].parentNode.show();
				} else {
					a[i].parentNode.hide();
				}
			}
		}


	},
	encode: function (s) {
		var l = document.createElement('div');
		l.appendChild(document.createTextNode(s));
		return l.innerHTML;
	},
	decode: function (s) {
		var l = document.createElement('textarea');
		l.innerHTML = s.replace(/</g, '&lt;').replace(/>/g, '&gt;');
		return l.value;
	}
};




var visibility = {
	callback: null,
	loadtime: null,
	showtime: null,
	showdelay: null,
	init: function (callback) {
		this.callback = callback;
		document.observe('dom:loaded', this.load.bind(this));
	},
	load: function () {
		var d=new Date();
		this.loadtime = d.getTime();
		if (document.visibilityState && (document.visibilityState !== PAGE_VISIBLE)) {
			document.observe('visibilitychange', this.visibilitychange.bind(this));
		} else if (document.webkitVisibilityState && (document.webkitVisibilityState !== 'visible')) {
			document.observe('webkitvisibilitychange', this.webkitvisibilitychange.bind(this));
		} else {
			this.show();
		}
	},
	visibilitychange: function () {
		if (document.visibilityState === PAGE_VISIBLE) {
			document.stopObserving('visibilitychange', this.visibilitychange.bind(this));
			this.show();
		}
	},
	webkitvisibilitychange: function () {
		if (document.webkitVisibilityState === 'visible') {
			document.stopObserving('webkitvisibilitychange', this.webkitvisibilitychange.bind(this));
			this.show();
		}
	},
	show: function () {
		var d=new Date();
		this.showtime = d.getTime();
		this.showdelay = ((this.showtime - this.loadtime) / 1000);
		this.callback();
	}
};




page.init();
