function categoryOption(label,link) {
		this.label = label;   // what you see in the pull down
		this.link = link;     // link, the value in the pull down
}

categoryOption.prototype = {
    label   : 'undefined',
    link    : 'undefined'
}

function category(label,link,catoptions) {
		this.label = label;            // what you see in the pull down
		this.link = link;              // link, the value in the pull down
		this.catoptions = catoptions;  // list of categoryOptions
}

categoryOption.prototype = {
    label   : 'undefined',
    link    : 'undefined',
    catoptions : 'undefined'
}

var selectLabel = 'Select...';
var categoryTree = new Array();

categoryTree[0] = new category(selectLabel, "./content/infobank.do", new Array(''));
categoryTree[0].catoptions[0] = new categoryOption(selectLabel, '');

categoryTree[1] = new category("Autofocus", "/content/infobank/autofocus.do", new Array(''));
categoryTree[1].catoptions[0] = new categoryOption(selectLabel, '');
categoryTree[1].catoptions[1] = new categoryOption('Autofocus', '/content/infobank/autofocus/autofocus.do');
categoryTree[1].catoptions[2] = new categoryOption('Autofocus point orientation', '/content/infobank/autofocus/point_orientation.do');


categoryTree[2] = new category("Batteries", "/content/infobank/batteries.do", new Array(''));
categoryTree[2].catoptions[0] = new categoryOption(selectLabel, '');
categoryTree[2].catoptions[1] = new categoryOption('Battery chargers', '/content/infobank/batteries/battery_chargers.do');
categoryTree[2].catoptions[2] = new categoryOption('Care of batteries', '/content/infobank/batteries/care_of_batteries.do');
categoryTree[2].catoptions[3] = new categoryOption('Battery types', '/content/infobank/batteries/battery_types.do');

categoryTree[3] = new category("Capturing the image", "/content/infobank/capturing_the_image.do", new Array(''));
categoryTree[3].catoptions[0] = new categoryOption(selectLabel, '');
categoryTree[3].catoptions[1] = new categoryOption('Photo sensors', '/content/infobank/capturing_the_image/photo_sensors.do');
categoryTree[3].catoptions[2] = new categoryOption('CCD and CMOS sensors', '/content/infobank/capturing_the_image/ccd_and_cmos_sensors.do');
categoryTree[3].catoptions[3] = new categoryOption('DIGIC processing', '/content/infobank/capturing_the_image/digic_processing.do');
categoryTree[3].catoptions[4] = new categoryOption('8 or 16 bit', '/content/infobank/capturing_the_image/8_or_16_bit.do');
categoryTree[3].catoptions[5] = new categoryOption('Pixels and image size', '/content/infobank/capturing_the_image/pixels_and_image_size.do');
categoryTree[3].catoptions[6] = new categoryOption('Colour space', '/content/infobank/capturing_the_image/colour_space.do');
categoryTree[3].catoptions[7] = new categoryOption('Sensor cleaning', '/content/infobank/capturing_the_image/sensor_cleaning.do');

categoryTree[4] = new category("Camera settings", "/content/infobank/camera_settings.do", new Array(''));
categoryTree[4].catoptions[0] = new categoryOption(selectLabel, '');
categoryTree[4].catoptions[1] = new categoryOption('Drive modes', '/content/infobank/camera_settings/drive_modes.do');
categoryTree[4].catoptions[2] = new categoryOption('Self-timer and timed exposures', '/content/infobank/camera_settings/self_timer_and_timed_exposures.do');
categoryTree[4].catoptions[3] = new categoryOption('Shooting modes', '/content/infobank/camera_settings/shooting_modes.do');

categoryTree[5] = new category("Care and maintenance", "/content/infobank/care_and_maintenance.do", new Array(''));
categoryTree[5].catoptions[0] = new categoryOption(selectLabel, '');
categoryTree[5].catoptions[1] = new categoryOption('Camera and lens care', '/content/infobank/camera_and_lens_care.do');

categoryTree[6] = new category("Custom functions", "/content/infobank/custom_functions.do", new Array(''));
categoryTree[6].catoptions[0] = new categoryOption(selectLabel, '');
categoryTree[6].catoptions[1] = new categoryOption('Custom functions', '/content/infobank/custom_functions/custom_functions.do');

categoryTree[7] = new category("Depth-of-field", "/content/infobank/depth_of_field.do", new Array(''));
categoryTree[7].catoptions[0] = new categoryOption(selectLabel, '');
categoryTree[7].catoptions[1] = new categoryOption('Depth-of-field', '/content/infobank/depth_of_field/depth_of_field.do');

categoryTree[8] = new category("Digital camera features", "/content/infobank/digital_camera_features.do", new Array(''));
categoryTree[8].catoptions[0] = new categoryOption(selectLabel, '');
categoryTree[8].catoptions[1] = new categoryOption('Picture Style', '/content/infobank/digital_camera_features/picture_style.do');
categoryTree[8].catoptions[2] = new categoryOption('Dual Axis Electronic Level', '/content/infobank/digital_camera_features/dual_axis_electronic_level.do');


categoryTree[9] = new category("Digital image file", "/content/infobank/digital_image_file.do", new Array(''));
categoryTree[9].catoptions[0] = new categoryOption(selectLabel, '');
categoryTree[9].catoptions[1] = new categoryOption('Binary format', '/content/infobank/digital_image_file/binary_format.do');
categoryTree[9].catoptions[2] = new categoryOption('Compact flash cards', '/content/infobank/digital_image_file/compact_flash_cards.do');

categoryTree[10] = new category("Digital image size and preview", "/content/infobank/digital_image_size_and_preview.do", new Array(''));
categoryTree[10].catoptions[0] = new categoryOption(selectLabel, '');
categoryTree[10].catoptions[1] = new categoryOption('Equivalent focal length', '/content/infobank/digital_image_size_and_preview/equivalent_focal_length.do');
categoryTree[10].catoptions[2] = new categoryOption('Preview screen', '/content/infobank/digital_image_size_and_preview/preview_screen.do');
categoryTree[10].catoptions[3] = new categoryOption('Screen views and information', '/content/infobank/digital_image_size_and_preview/screen_views_and_information.do');

categoryTree[11] = new category("Exposure settings", "/content/infobank/exposure_settings.do", new Array(''));
categoryTree[11].catoptions[0] = new categoryOption(selectLabel, '');
categoryTree[11].catoptions[1] = new categoryOption('ISO speed in the digital age', '/content/infobank/exposure_settings/iso_speed_in_the_digital_age.do');
categoryTree[11].catoptions[2] = new categoryOption('Digital noise', '/content/infobank/exposure_settings/digital_noise.do');
categoryTree[11].catoptions[3] = new categoryOption('Exposure bracketing', '/content/infobank/exposure_settings/exposure_bracketing.do');
categoryTree[11].catoptions[4] = new categoryOption('Exposure compensation', '/content/infobank/exposure_settings/exposure_compensation.do');
categoryTree[11].catoptions[5] = new categoryOption('iFCL metering', '/content/infobank/exposure_settings/iFCL_metering.do');

categoryTree[12] = new category("Firmware", "/content/infobank/firmware.do", new Array(''));
categoryTree[12].catoptions[0] = new categoryOption(selectLabel, '');
categoryTree[12].catoptions[1] = new categoryOption('Camera operating system', '/content/infobank/firmware/camera_operating_system.do');
categoryTree[12].catoptions[2] = new categoryOption('Updating firmware', '/content/infobank/firmware/updating_firmware.do');

categoryTree[13] = new category("Flash", "/content/infobank/flash.do", new Array(''));
categoryTree[13].catoptions[0] = new categoryOption(selectLabel, '');
categoryTree[13].catoptions[1] = new categoryOption('Flash basics', '/content/infobank/flash/flash_basics.do');
categoryTree[13].catoptions[2] = new categoryOption('Speedlite compatibility', '/content/infobank/flash/speedlite_compatibility.do');
categoryTree[13].catoptions[3] = new categoryOption('Speedlite range', '/content/infobank/flash/speedlite_range.do');
categoryTree[13].catoptions[4] = new categoryOption('Speedlite zoom', '/content/infobank/flash/speedlite_zoom.do');
categoryTree[13].catoptions[5] = new categoryOption('Flash on camera', '/content/infobank/flash/flash_on_camera.do');
categoryTree[13].catoptions[6] = new categoryOption('Red-eye', '/content/infobank/flash/red-eye.do');
categoryTree[13].catoptions[7] = new categoryOption('Dark backgrounds with flash', '/content/infobank/flash/dark_backgrounds_with_flash.do');
categoryTree[13].catoptions[8] = new categoryOption('Fill in flash', '/content/infobank/flash/fill_in_flash.do');
categoryTree[13].catoptions[9] = new categoryOption('Flash exposure lock and compensation', '/content/infobank/flash/flash_exposure_lock_and_compensation.do');
categoryTree[13].catoptions[10] = new categoryOption('Wireless flash', '/content/infobank/flash/wireless_flash.do');
categoryTree[13].catoptions[11] = new categoryOption('Macroflash photography', '/content/infobank/flash/macroflash_photography.do');
categoryTree[13].catoptions[12] = new categoryOption('Bounce flash', '/content/infobank/flash/bounce_flash.do');
categoryTree[13].catoptions[13] = new categoryOption('Flash synchronisation', '/content/infobank/flash/flash_synchronisation.do');
categoryTree[13].catoptions[14] = new categoryOption('Stroboscopic flash', '/content/infobank/flash/stroboscopic_flash.do');
categoryTree[13].catoptions[15] = new categoryOption('Studio-style flash lighting with Speedlites', '/content/infobank/flash/studio_style_flash_lighting_with_speedlites.do');
categoryTree[13].catoptions[16] = new categoryOption('Integrated Speedlite Transmitter', '/content/infobank/flash/speedlite_transmitter.do');

categoryTree[14] = new category("Focus points", "/content/infobank/focus_points.do", new Array(''));
categoryTree[14].catoptions[0] = new categoryOption(selectLabel, '');
categoryTree[14].catoptions[1] = new categoryOption('Automatic focusing', '/content/infobank/focus_points/automatic_focusing.do');
categoryTree[14].catoptions[2] = new categoryOption('A single focusing point', '/content/infobank/focus_points/a_single_focusing_point.do');
categoryTree[14].catoptions[3] = new categoryOption('Multiple focusing points', '/content/infobank/focus_points/multiple_focusing_points.do');
categoryTree[14].catoptions[4] = new categoryOption('Wider focusing points', '/content/infobank/focus_points/wider_focusing_points.do');
categoryTree[14].catoptions[5] = new categoryOption('Setting point selection', '/content/infobank/focus_points/setting_point_selection.do');

categoryTree[15] = new category("HD movies", "/content/infobank/hd_movies.do", new Array(''));
categoryTree[15].catoptions[0] = new categoryOption(selectLabel, '');
categoryTree[15].catoptions[1] = new categoryOption('HD movies', '/content/infobank/hd_movies/hd_movies.do');

categoryTree[16] = new category("Introduction to digital photography", "/content/infobank/introduction_to_digital_photography.do", new Array(''));
categoryTree[16].catoptions[0] = new categoryOption(selectLabel, '');
categoryTree[16].catoptions[1] = new categoryOption('Differences between analogue and digital', '/content/infobank/introduction_to_digital_photography/differences_between_analogue_and_digital.do');
categoryTree[16].catoptions[2] = new categoryOption('Digital images from film', '/content/infobank/introduction_to_digital_photography/digital_images_from_film.do');

categoryTree[17] = new category("Image download", "/content/infobank/image_download.do", new Array(''));
categoryTree[17].catoptions[0] = new categoryOption(selectLabel, '');
categoryTree[17].catoptions[1] = new categoryOption('Transfering image files', '/content/infobank/image_download/transfering_image_files.do');
categoryTree[17].catoptions[2] = new categoryOption('ZoomBrowser EX/ImageBrowser', '/content/infobank/image_download/zoombrowser.do');
categoryTree[17].catoptions[3] = new categoryOption('Remote Capture', '/content/infobank/image_download/remote_capture.do');
categoryTree[17].catoptions[4] = new categoryOption('Wireless transmission', '/content/infobank/image_download/wireless_transmission.do');
categoryTree[17].catoptions[5] = new categoryOption('DPP', '/content/infobank/image_download/dpp.do');

categoryTree[18] = new category("Image compression", "/content/infobank/image_compression.do", new Array(''));
categoryTree[18].catoptions[0] = new categoryOption(selectLabel, '');
categoryTree[18].catoptions[1] = new categoryOption('Lossless and lossy compression', '/content/infobank/image_compression/lossless_and_lossy_compression.do');
categoryTree[18].catoptions[2] = new categoryOption('RAW + JPEG shooting', '/content/infobank/image_compression/raw_jpeg_shooting.do');
categoryTree[18].catoptions[3] = new categoryOption('How to set RAW + JPEG', '/content/infobank/image_compression/how_to_set_raw_jpeg.do');
categoryTree[18].catoptions[4] = new categoryOption('File types RAW, sRAW and JPEG', '/content/infobank/image_compression/file_types_raw_sraw_and_jpeg.do');

categoryTree[19] = new category("Image information", "/content/infobank/image_information.do", new Array(''));
categoryTree[19].catoptions[0] = new categoryOption(selectLabel, '');
categoryTree[19].catoptions[1] = new categoryOption('Histograms', '/content/infobank/image_information/histograms.do');
categoryTree[19].catoptions[2] = new categoryOption('IPTC data', '/content/infobank/image_information/iptc_data.do');

categoryTree[20] = new category("Internet", "/content/infobank/internet.do", new Array(''));
categoryTree[20].catoptions[0] = new categoryOption(selectLabel, '');
categoryTree[20].catoptions[1] = new categoryOption('Canon Image Gateway', '/content/infobank/internet/canon_image_gateway.do');
categoryTree[20].catoptions[2] = new categoryOption('E-mailing images', '/content/infobank/internet/emailing_images.do');
categoryTree[20].catoptions[3] = new categoryOption('Image size, colour and online albums', '/content/infobank/internet/image_size_colour_and_online_albums.do');

categoryTree[21] = new category("Image verification", "/content/infobank/image_verification.do", new Array(''));
categoryTree[21].catoptions[0] = new categoryOption(selectLabel, '');
categoryTree[21].catoptions[1] = new categoryOption('Data verification', '/content/infobank/image_verification/data_verification.do');
categoryTree[21].catoptions[2] = new categoryOption('Canon data verification system', '/content/infobank/image_verification/canon_data_verification_system.do');

categoryTree[22] = new category("Lenses", "/content/infobank/lenses.do", new Array(''));
categoryTree[22].catoptions[0] = new categoryOption(selectLabel, '');
categoryTree[22].catoptions[1] = new categoryOption('Construction', '/content/infobank/lenses/construction.do');
categoryTree[22].catoptions[2] = new categoryOption('Focal length', '/content/infobank/lenses/focal_length.do');
categoryTree[22].catoptions[3] = new categoryOption('All about apertures', '/content/infobank/lenses/all_about_apertures.do');
categoryTree[22].catoptions[4] = new categoryOption('Lens speed', '/content/infobank/lenses/lens_speed.do');
categoryTree[22].catoptions[5] = new categoryOption('Focusing and depth of field', '/content/infobank/lenses/focusing_and_depth_of_field.do');
categoryTree[22].catoptions[6] = new categoryOption('Black or white lenses', '/content/infobank/lenses/black_or_white_lenses.do');
categoryTree[22].catoptions[7] = new categoryOption('Coloured rings', '/content/infobank/lenses/coloured_rings.do');
categoryTree[22].catoptions[8] = new categoryOption('Lens mount', '/content/infobank/lenses/lens_mount.do');
categoryTree[22].catoptions[9] = new categoryOption('EF-S and field of view', '/content/infobank/lenses/ef-s_and_field_of_view.do');
categoryTree[22].catoptions[10] = new categoryOption('L-series lenses', '/content/infobank/lenses/l-series_lenses.do');
categoryTree[22].catoptions[11] = new categoryOption('Fluorite, aspherical and UD lenses', '/content/infobank/lenses/fluorite_aspherical_and_ud_lenses.do');
categoryTree[22].catoptions[12] = new categoryOption('Prime and zoom lenses', '/content/infobank/lenses/prime_and_zoom_lenses.do');
categoryTree[22].catoptions[13] = new categoryOption('Image stabilisation', '/content/infobank/lenses/image_stabilisation.do');
categoryTree[22].catoptions[14] = new categoryOption('Tilt and shift lenses', '/content/infobank/lenses/tilt_and_shift_lenses.do');
categoryTree[22].catoptions[15] = new categoryOption('Extenders', '/content/infobank/lenses/extenders.do');
categoryTree[22].catoptions[16] = new categoryOption('Extension tubes', '/content/infobank/lenses/extension_tubes.do');
categoryTree[22].catoptions[17] = new categoryOption('Macro lenses', '/content/infobank/lenses/macro_lenses.do');
categoryTree[22].catoptions[18] = new categoryOption('Close-up lenses', '/content/infobank/lenses/close-up_lenses.do');
categoryTree[22].catoptions[19] = new categoryOption('Filters', '/content/infobank/lenses/filters.do');
categoryTree[22].catoptions[20] = new categoryOption('DO elements', '/content/infobank/lenses/multi_layer_diffractive_optical_element.do');

categoryTree[23] = new category("Media cards", "/content/infobank/media_cards.do", new Array(''));
categoryTree[23].catoptions[0] = new categoryOption(selectLabel, '');
categoryTree[23].catoptions[1] = new categoryOption('Media cards', '/content/infobank/media_cards/media_cards.do');

categoryTree[24] = new category("Panoramic images", "/content/infobank/panoramic_images.do", new Array(''));
categoryTree[24].catoptions[0] = new categoryOption(selectLabel, '');
categoryTree[24].catoptions[1] = new categoryOption('Creating panoramics', '/content/infobank/panoramic_images/creating_panoramics.do');

categoryTree[25] = new category("Printers", "/content/infobank/printers.do", new Array(''));
categoryTree[25].catoptions[0] = new categoryOption(selectLabel, '');
categoryTree[25].catoptions[1] = new categoryOption('The daylight darkroom', '/content/infobank/printers/the_daylight_darkroom.do');
categoryTree[25].catoptions[2] = new categoryOption('Dye sublimation', '/content/infobank/printers/dye_sublimation.do');
categoryTree[25].catoptions[3] = new categoryOption('Bubble jet technology', '/content/infobank/printers/bubble_jet_technology.do');
categoryTree[25].catoptions[4] = new categoryOption('RGB and CMYK', '/content/infobank/printers/rgb_and_cmyk.do');
categoryTree[25].catoptions[5] = new categoryOption('Printing from memory cards', '/content/infobank/printers/printing_from_memory_cards.do');

categoryTree[26] = new category("Remote photography", "/content/infobank/remote_photography.do", new Array(''));
categoryTree[26].catoptions[0] = new categoryOption(selectLabel, '');
categoryTree[26].catoptions[1] = new categoryOption('Remote photography', '/content/infobank/remote_photography/remote_photography.do');

categoryTree[27] = new category("Scanning & copying", "/content/infobank/scanning_and_copying.do", new Array(''));
categoryTree[27].catoptions[0] = new categoryOption(selectLabel, '');
categoryTree[27].catoptions[1] = new categoryOption('Scanning & copying', '/content/infobank/scanning_and_copying/scanning_and_copying.do');

categoryTree[28] = new category("Storage and archiving", "/content/infobank/storage_and_archiving.do", new Array(''));
categoryTree[28].catoptions[0] = new categoryOption(selectLabel, '');
categoryTree[28].catoptions[1] = new categoryOption('Archiving', '/content/infobank/storage_and_archiving/archiving.do');
categoryTree[28].catoptions[2] = new categoryOption('File numbering and naming', '/content/infobank/storage_and_archiving/file_numbering_and_naming.do');

categoryTree[29] = new category("The digital darkroom", "/content/infobank/the_digital_darkroom.do", new Array(''));
categoryTree[29].catoptions[0] = new categoryOption(selectLabel, '');
categoryTree[29].catoptions[1] = new categoryOption('The digital darkroom', '/content/infobank/the_digital_darkroom/the_digital_darkroom.do');

categoryTree[30] = new category("White balance", "/content/infobank/white_balance.do", new Array(''));
categoryTree[30].catoptions[0] = new categoryOption(selectLabel, '');
categoryTree[30].catoptions[1] = new categoryOption('White balance', '/content/infobank/white_balance/white_balance.do');


var categorySelectIndex = 0;
var subjectSelectIndex = 0;

function loadCategories() {
    // get the link..
    var pageLink = document.location.href;
    var categorySelect = document.getElementById("infobank_category");
    //categorySelect.options.length = null; // Clean the subjects
    categorySelect.innerHTML = ''; // Clean the subjects
    for (var i=0; i < categoryTree.length; i++) {
        var nwOption = document.createElement('option');
        nwOption.setAttribute('value',categoryTree[i].link);
        nwOption.innerHTML = categoryTree[i].label;
        if (pageLink.indexOf(categoryTree[i].link)>0) categorySelectIndex = i; // so this is the current page
        for (var j=0; j < categoryTree[i].catoptions.length; j++) {
          if (pageLink.indexOf(categoryTree[i].catoptions[j].link)>0)  categorySelectIndex = i;
        }
        categorySelect.appendChild(nwOption);
    }
    setTimeout('initialiseCategories()', 20);
    return false;
}

function initialiseCategories() {
	// Safari on Mac gives problems. That should be fixed
    if (categorySelectIndex) document.getElementById("infobank_category").selectedIndex = categorySelectIndex;
}

function updateCategories() {
    categorySelectIndex = document.getElementById("infobank_category").selectedIndex;
    var submit = document.getElementById("button_category_submit");

    if (categorySelectIndex == 0) {
        submit.onclick = function onclick(event){
            alert('Please select a category');
            return false;
        };
    } else {
        // Set the active class so the button is shown highlited
        submit.className = "active";
        // Change the behaviour of the onclick event
        submit.onclick = function onclick(event) {
          if (document.getElementById("infobank_category").value)
             document.location = createLink(document.getElementById("infobank_category").value);
          else alert('Please select a category');
          return false;
        };
    }

    setTimeout('loadSubjects()', 100);
    return false;
}

window.onload = function() {
	updateCategories();
}

function loadSubjects() {
    var pageLink = document.location.href;
    var subjectSelect = document.getElementById("infobank_subject");
    // Clean the subjects
    subjectSelectIndex = 0;
	//subjectSelect.options.length = null;
	subjectSelect.innerHTML = '';
    var subjects = categoryTree[categorySelectIndex].catoptions;
    for (var j=0; j < subjects.length; j++) {
        var nwOption = document.createElement('option');
        nwOption.setAttribute('value',subjects[j].link);
        nwOption.innerHTML = subjects[j].label;
        if (pageLink.indexOf(subjects[j].link)>0)  subjectSelectIndex = j;
        subjectSelect.appendChild(nwOption);
    }
    setTimeout('initialiseSubjects()', 100);
    return false;
}

function initialiseSubjects() {
	// Safari on Mac gives problems. That should be fixed.
    if (subjectSelectIndex) document.getElementById("infobank_subject").selectedIndex = subjectSelectIndex;
    updateSubjectLink();
}

function updateSubjectLink() {
    subjectSelectIndex = document.getElementById("infobank_subject").selectedIndex;
    var submit = document.getElementById("button_subject_submit");
    submit.onclick = function onclick(event){
      if (document.getElementById("infobank_subject").value)
        document.location = createLink(document.getElementById("infobank_subject").value);
      else alert('Please select a subject');
      return false;
    };

}
function createLink(url) {
    return location.href.substring(0,location.href.lastIndexOf('/content'))+url;
}

