
// basic browser support check :o)

if (document.getElementById && document.createTextNode && navigator.userAgent.toLowerCase().indexOf("opera") == -1) {

	// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // 

	function eshop_add_row_highlight(e) {

		// find correct target

		var target = (window.event) ? window.event.srcElement : e.currentTarget;
		if (target) {

			while (target && !target.className.match(/\s*use-highlighter/)) target = target.parentNode;

			if (target && (!target.className.match(/^highlight/) && !target.className.match(/[\s]highlight/))) {

				var classes = target.className.split(/\s+/);

				classes[classes.length] = 'highlight';

				target.className = classes.join(' ');

			}

		}

	}

	function eshop_remove_row_highlight(e) {

		// find correct target

		var target = (window.event) ? window.event.srcElement : e.currentTarget;
		if (target) {

			while (target && !target.className.match(/\s*use-highlighter/)) target = target.parentNode;

			if (target && (target.className.match(/^highlight/) || target.className.match(/[\s]highlight/))) {

				var classes = target.className.split(/\s+/);

				var filtered_classes = new Array();

				for (var i = 0; i < classes.length; i++) if (classes[i] != 'highlight') filtered_classes[filtered_classes.length] = classes[i];

				target.className = filtered_classes.join(' ');

			}

		}

	}

	// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // 

	function eshop_add_row_mark(e) {

		// find correct target

		var target = (window.event) ? window.event.srcElement : e.currentTarget;
		if (target) {

			while (target && !target.className.match(/\s*use-marker/)) target = target.parentNode;
			if (target) {

				if ((!target.className.match(/^mark/) && !target.className.match(/[\s]mark/))) {

					var classes = target.className.split(/\s+/);

					classes[classes.length] = 'mark';

					target.className = classes.join(' ');

				} else {

					var classes = target.className.split(/\s+/);

					var filtered_classes = new Array();

					for (var i = 0; i < classes.length; i++) if (classes[i] != 'mark') filtered_classes[filtered_classes.length] = classes[i];

					target.className = filtered_classes.join(' ');

				}

			}

		}

	}

	// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // 

	function _add_event(object, event, function_reference, capture) {

		if (object.addEventListener) object.addEventListener(event, function_reference, capture);
		else if (object.attachEvent) return object.attachEvent("on" + event, function_reference);

	}

	// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // 

	// apply triggers to table rows

	function apply_triggers() {

		// look for tables

		var _tables = document.getElementsByTagName("body").item(0).getElementsByTagName("table");

		for (var _tables_index = 0; _tables_index < _tables.length; _tables_index++) {

			var _table = _tables.item(_tables_index);

			// get thead, tfoot and tbody row groups

			var _table_section_lists = new Array();

			_table_section_lists = _table_section_lists.concat(_table.getElementsByTagName("thead"));

			_table_section_lists = _table_section_lists.concat(_table.getElementsByTagName("tfoot"));

			_table_section_lists = _table_section_lists.concat(_table.getElementsByTagName("tbody"));

			for (i = 0; i < _table_section_lists.length; i++) {

				_table_section_list = _table_section_lists[i];

				for (var _table_section_list_index = 0; _table_section_list_index < _table_section_list.length; _table_section_list_index++) {

					var _table_section = _table_section_list.item(_table_section_list_index);

					// get th and tr rows

					var _table_section_rows = _table_section.getElementsByTagName("tr");

					for (var _table_section_row_index = 0; _table_section_row_index < _table_section_rows.length; _table_section_row_index++) {

						var _table_section_row = _table_section_rows.item(_table_section_row_index);

						// add inherited `use` trigger classes

						var _classes = _table_section_row.className.split(/\s+/);

						{

							// add inherited `apply-stripes` trigger to class list

							if ((_table.className.match(/\s*apply-stripes/) || _table_section.className.match(/\s*apply-stripes/)) && !_table_section_row.className.match(/\s*apply-stripes/)) _classes.push('apply-stripes');

							// add inherited `use-highlighter` trigger to class list

							if ((_table.className.match(/\s*use-highlighter/) || _table_section.className.match(/\s*use-highlighter/)) && !_table_section_row.className.match(/\s*use-highlighter/)) _classes.push('use-highlighter');

							// add inherited `use-marker` trigger to class list

							if ((_table.className.match(/\s*use-marker/) || _table_section.className.match(/\s*use-marker/)) && !_table_section_row.className.match(/\s*use-marker/)) _classes.push('use-marker');

						}

						_table_section_row.className = _classes.join(' ');

					}

				}

			}

		}

		// apply class triggers

		var _tables = document.getElementsByTagName("table");

		for (var _tables_index = 0; _tables_index < _tables.length; _tables_index++) {

			var _table = _tables.item(_tables_index);

			// get th and tr rows

			var _table_rows = _table.getElementsByTagName("tr");

			var _table_row_stripe = true;

			for (var _table_row_index = 0; _table_row_index < _table_rows.length; _table_row_index++) {

				var _table_row = _table_rows.item(_table_row_index);

				// add `highlighter` event handler

				if (_table_row.className.match(/\s*use-highlighter/)) {

					_add_event(_table_row, 'mouseover', eshop_add_row_highlight, false);

					_add_event(_table_row, 'mouseout', eshop_remove_row_highlight, false);

				}

				// add `marker` event handler

				if (_table_row.className.match(/\s*use-marker/)) {

					_add_event(_table_row, 'click', eshop_add_row_mark, false);

				}

				// stripe row ;o)

				if (_table_row.className.match(/\s*apply-stripes/)) {

					_table_row.className = _table_row.className.replace(/\s*striped/, '');

					if (_table_row_stripe) {

						var _classes = _table_row.className.split(/\s+/);

						_classes.push('stripe');

						_table_row.className = _classes.join(' ');

					}

					// flip the stripe variable

					_table_row_stripe = !_table_row_stripe;

				}

			}

		}

	}

	// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // 

	// register for onload ;o)

	var is_macintosh_ie = (navigator.userAgent.toLowerCase().indexOf("mac") != -1) && (navigator.userAgent.toLowerCase().indexOf("msie") != -1) && (navigator.userAgent.toLowerCase().indexOf("opera") == -1);
	if (window.addEventListener && !is_macintosh_ie) window.addEventListener("load", apply_triggers, false);
	else if (window.attachEvent && !is_macintosh_ie) window.attachEvent("onload", apply_triggers);
	else window.onload = apply_triggers;

}
