function init_tabs() {
	// x is a list of all images
	var x = document.getElementById('tabs').getElementsByTagName('IMG');
	var y = document.getElementById('bottom_flaps').getElementsByTagName('IMG');
	var z = document.getElementById('top_flaps').getElementsByTagName('IMG');
	var tabSections = new Array(x, y, z);

	var preloads = new Object();
	
	for (var j=0; j<tabSections.length; j++) {
		var tabs = tabSections[j];

		for (var i=0; i<tabs.length; i++) {
			var el = tabs[i];
	
			// only do this if the element has an id defined, otherwise, we can't find the images to do the swapping (eg. could be cosmetic images)
			if (el.id) { 
				if (el.runtimeStyle && el.runtimeStyle.filter) {
					// IE 5.5 PNG hack
					preloads['off_'+el.id] = new Image;
					preloads['on_'+el.id] = new Image;
					preloads['off_'+el.id].runtimeStyle.filter = el.runtimeStyle.filter;
					preloads['on_'+el.id].runtimeStyle.filter = el.runtimeStyle.filter.replace(/_off\.png/, "_on.png");

					el.onmouseover = function () {this.runtimeStyle.filter=preloads['on_'+this.id].runtimeStyle.filter;}
					el.onmouseout = function () {this.runtimeStyle.filter=preloads['off_'+this.id].runtimeStyle.filter;}
				} else {
					var filetype = (/\.png$/.test(el.src)) ? "png" : "gif";
					preloads['off_'+el.id] = new Image;
					preloads['on_'+el.id] = new Image;
					preloads['off_'+el.id].src = '/images/'+ el.id + '_off.' + filetype;
					preloads['on_'+el.id].src = '/images/'+ el.id + '_on.' + filetype;

					el.onmouseout = function () {this.src=preloads['off_'+this.id].src;}
					el.onmouseover = function () {this.src=preloads['on_'+this.id].src;}
				}
			}
		}
	}
}

function highlight_tab(id) {
	var el = document.getElementById(id);
	if (el && el.tagName == 'IMG') {
		if (el.runtimeStyle && el.runtimeStyle.filter) {
			el.runtimeStyle.filter = el.runtimeStyle.filter.replace(/_off\.png/, "_on.png");	
		} else {
			// replace it with the 'on' image
			var filetype = (/\.png$/.test(el.src)) ? "png" : "gif";
			el.src = '/images/' + el.id + '_on.' + filetype;
		}
		// remove the events
		el.onmouseover = null;
		el.onmouseout = null;
	}
}

function init_menu() {

	if (!document.getElementById('flavour-menu')) {
		return;
	}

    var x = document.getElementById('flavour-menu').getElementsByTagName('IMG');
    var tabSections = new Array(x);

    var preloads = new Object();

    for (var j=0; j<tabSections.length; j++) {
        var tabs = tabSections[j];

        for (var i=0; i<tabs.length; i++) {
            var el = tabs[i];
            if (el.runtimeStyle && el.runtimeStyle.filter) {
                // IE 5.5 PNG hack
                preloads['off_'+el.id] = new Image;
                preloads['on_'+el.id] = new Image;
                preloads['off_'+el.id].runtimeStyle.filter = el.runtimeStyle.filter;
                preloads['on_'+el.id].runtimeStyle.filter = el.runtimeStyle.filter.replace(/_off\.png/, "_on.png");

                el.onmouseover = function () {this.runtimeStyle.filter=preloads['on_'+this.id].runtimeStyle.filter;}
                el.onmouseout = function () {this.runtimeStyle.filter=preloads['off_'+this.id].runtimeStyle.filter;}
            } else {
                var filetype = (/\.png$/.test(el.src)) ? "png" : "gif";
                preloads['off_'+el.id] = new Image;
                preloads['on_'+el.id] = new Image;
                preloads['off_'+el.id].src = '/images/'+ el.id + '_off.' + filetype;
                preloads['on_'+el.id].src = '/images/'+ el.id + '_on.' + filetype;

                el.onmouseout = function () {this.src=preloads['off_'+this.id].src;}
                el.onmouseover = function () {this.src=preloads['on_'+this.id].src;}
            }
        }
    }
}

function highlight_menu(id) {
    var el = document.getElementById(id);
    if (el && el.tagName == 'IMG') {
        if (el.runtimeStyle && el.runtimeStyle.filter) {
            el.runtimeStyle.filter = el.runtimeStyle.filter.replace(/_off\.png/, "_on.png");
        } else {
            // replace it with the 'on' image
            var filetype = (/\.png$/.test(el.src)) ? "png" : "gif";
            el.src = '/images/' + el.id + '_on.' + filetype;
        }
        // remove the events
        el.onmouseover = null;
        el.onmouseout = null;
    }
}
