// Odeon user script
// version 0.1
// 2005-05-14
// Copyright (c) 2005, Matthew Somerville
// Released under the GPL license
// http://www.gnu.org/copyleft/gpl.html
//
// --------------------------------------------------------------------
//
// This is a Greasemonkey user script.
//
// To install, you need Greasemonkey: http://greasemonkey.mozdev.org/
// Then restart Firefox and revisit this script.
// Under Tools, there will be a new menu item to "Install User Script".
// Accept the default configuration and install.
//
// To uninstall, go to Tools/Manage User Scripts,
// select "Odeon", and click Uninstall.
//
// --------------------------------------------------------------------
//
// ==UserScript==
// @name          Odeon
// @namespace     http://www.dracos.co.uk/odeon/
// @description   Makes the Odeon site work
// @include       http://www.odeon.co.uk/*
// @include       https://www.odeon.co.uk/*
// ==/UserScript==

// Helpful function
function addGlobalStyle(css) {
	var head, style;
	head = document.getElementsByTagName('head')[0];
	if (!head) return;
	style = document.createElement('style');
	style.type = 'text/css';
	style.innerHTML = css;
	head.appendChild(style);
}

// Give arrows IDs to refer to them later
allArrows = document.evaluate('//img[@name]', document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
for (var i=0; i<allArrows.snapshotLength; i++) {
	Arrow = allArrows.snapshotItem(i);
	if (Arrow.name.match(/^(up|down)/))
		Arrow.id = Arrow.name;
	if (Arrow.name == 'below') Arrow.id = 'down';
	if (Arrow.name == 'above') Arrow.id = 'up';
}

// Remove flashing menu items
menu = document.getElementById('menus')
if (menu) {
	allImages = menu.getElementsByTagName('img');
	for (var i=0; i<allImages.length; i++) {
		if (allImages[i].alt == 'REGISTER') {
			allImages[i].src = '../../Odeon/img/menus/register.gif'
		} else if (allImages[i].alt == 'BOOK NOW') {
			allImages[i].src = '../../Odeon/img/menus/booknow.gif'
		}
	}
}

// Get menu working
doc = 'document.getElementById("'
stylo = '").style'
pxt = '.top'
pxl = '.left'
n4 = 0

// Stop most tracking
if (this.logclientdata02 != null) {
	window.onunload = function(){}
	window.onload = function(){}
	if (this.rollin != null) window.addEventListener('load', rollin, true);
	else if (this.drop != null) window.addEventListener('load', drop, true);
	if (this.fill != null) window.addEventListener('load', fill, true);
	if (this.init != null) window.addEventListener('load', init, true);
	if (this.touch != null) window.addEventListener('load', touch, true);
	if (this.popfilms != null) window.addEventListener('load', popfilms, true);
}

// Get cinema page working
function fotosee(imgsrc,pp) {
	document.foto.src = imgsrc;
	var ddp = 'pointer';
	var xx = eval(doc + ddp + stylo + pxl);
	if (!xx) xx = 0
	var yyf = parseInt(getComputedStyle(document.getElementById("filmtitles"), '').top)
	put(ddp,parseInt(xx),parseInt(yyf+2+pp*12)); // pointer moves
	whatson(2); // clear times
}

// Get booking working
function positioning() {
	document.getElementById('proceed').style.top=(document.getElementById('legend').scrollHeight+285);
}

// Get crappy scroll arrows working
if (document.getElementById('listaf')) {
	function sDown2() { ms_sdown('listaf', '3', filter, 0) }
	function sUp2() { ms_sup('listaf', '3') }
} else if (document.getElementById('listzffi')) {
	function sDown2() { ms_sdown('listzffi', '3', filter, 0) }
	function sUp2() { ms_sup('listzffi', '3') }
	function sDown2r() { ms_sdown('listzfh', '3r', filterr, fh_films.length * 60 ) }
	function sUp2r() { ms_sup('listzfh', '3r') }
} else if (document.getElementById('listz')) {
	function sDown2() { ms_sdown('listz', '3', filter, 0) }
	function sUp2() { ms_sup('listz', '3') }
} else if (document.getElementById('info')) {
	function sDown() { ms_sdown('info', '3', filter, 0) }
	function sUp() { ms_sup('info', '3') }
} else if (document.getElementById('copy')) {
	function sDown() { ms_sdown('copy', '', 190, 0) }
	function sUp() { ms_sup('copy', '') }
} else if (document.getElementById('venues')) {
	function sDown() { ms_sdown('venues', '', filter, 0) }
	function sUp() { ms_sup('venues', '') }
} else if (document.getElementById('filmtitles')) {
	function sDown1() { ms_sdown('filmtitles', '1', 88, 0) }
	function sUp1() { ms_sup('filmtitles', '1') }
	function sDown2() { ms_sdown('perftimes', '2', 88, 0) }
	function sUp2() { ms_sup('perftimes', '2') }
}

function ms_sdown(id, arr, filter, overrideScroll) {
	l = document.getElementById(id)
	ls = getComputedStyle(l, '')
	if (!overrideScroll) overrideScroll = l.scrollHeight
	if (parseInt(ls.top) > filter - overrideScroll) {
		l.style.top = parseInt(ls.top) - 5;
		document.getElementById('up'+arr).src = up.src
	} else {
		if (zip.src) document.getElementById('down'+arr).src = zip.src
		else document.getElementById('down'+arr).src = zip
	}
}
function ms_sup(id, arr) {
	l = document.getElementById(id)
	ls = getComputedStyle(l, '')
	if (parseInt(ls.top) <= 0) {
		l.style.top = parseInt(ls.top) + 5;
		document.getElementById('down' + arr).src = down.src
	} else {
		if (zip.src) document.getElementById('up' + arr).src = zip.src
		else document.getElementById('up' + arr).src = zip
	}
}

addGlobalStyle(
' #listaf, #listzffi, #listzfh { height: auto; } #banner { display: none; }'
);
