// HANDLE ONLOAD
		
		// check if the dom tree is loaded
		function init() {
		  if (arguments.callee.done) return;
		  arguments.callee.done = true;

			
			// THE DOM IS NOW FULLY AVAILABLE
			
			// between these lines are instructions to be executed at page launch
			/* ------------------------------------------ */
			
			
			tvgs_kickstart();
			
			
			/* ------------------------------------------ */

		}
		if (document.addEventListener) {
		  document.addEventListener('DOMContentLoaded', init, false);
		}
		(function() {
		  /*@cc_on
		  if (document.body) {
		    try {
		      document.createElement('div').doScroll('left');
		      return init();
		    } catch(e) {}
		  }
		  /*@if (false) @*/
		  if (/loaded|complete/.test(document.readyState)) return init();
		  /*@end @*/
		  if (!init.done) setTimeout(arguments.callee, 50);
		})();
		
		window.onload = init;
		
		/*
		// original window.onload checker, gives errors on page in explorer
		_prevOnload = window.onload;
		window.onload = function() {
		  if (typeof _prevOnload === 'function') _prevOnload();
		  init();
		};
		*/


		
		

// contains instructions to be executed at page launch
function tvgs_kickstart()
{


			
			
			
			// run load timers
			// note: the timer is started in the header of the page
			document_timer(window.document_start_time);
			//allImagesLoaded(window.document_start_time);
			
			
			//var sizes = ['1px','2px','3px','4px','5px','6px','7px','8px','9px','10px','11px','12px','13px','14px','15px','16px','17px','18px','19px','20px'];
			
			
			//color_pulse(sizes, document.getElementById('flippenzeg'), 'height', 75)
			
			
			// preload selected images
			// hardcoded and specific for in2lifestyle.nl
			var preload_image_src_list = [
			'projects/6/styles/templates/projects/in2lifestyle/interfaces/0/file/top_menu_main_button_1_over.jpg',
			'projects/6/styles/templates/projects/in2lifestyle/interfaces/0/file/top_menu_main_button_2_over.jpg',
			'projects/6/styles/templates/projects/in2lifestyle/interfaces/0/file/top_menu_main_button_3_over.jpg',
			'projects/6/styles/templates/projects/in2lifestyle/interfaces/0/file/top_menu_main_button_4_over.jpg',
			'projects/6/styles/templates/projects/in2lifestyle/interfaces/0/file/top_menu_main_button_5_over.jpg',
			'projects/6/styles/templates/projects/in2lifestyle/interfaces/0/file/top_menu_main_button_6_over.jpg'
			];
			
			var preload_image = [];
			
			for (var i in preload_image_src_list)
			{
				
				if (is_numeric(i))
				{
					
					// must be here so for instance firefox doesn't keep only the last image
					preload_image[i] = new Image();
					
					preload_image[i].src = preload_image_src_list[i];

				}			
			
			}
			
			
			
			// read config
			tvg_read_suite_config();
			
			
			
			
			// ieks fill lists
			if (window.tvg_ieks_index && window.tvg_suite_config[window.tvg_ieks_index][2])
			{
			
				for (var i in window.tvg_suite_config[window.tvg_ieks_index][2])
				{
				
					update_list(window.tvg_suite_config[window.tvg_ieks_index][2][i][2], '');

				}
			
			}
			
			
			
			// inserts the default text into the search field
			setFieldValues();
			
			
			// sets display of a block set
			setMultiToggleDisplay('sm_sitebox_template_options','sm_sitebox_template_options','interface');
			setMultiToggleDisplay('sm_sitebox_record_options','sm_sitebox_record_options','interface');
			setMultiToggleDisplay('sm_sitebox_interface_options','sm_sitebox_interface_options','interface');
			setMultiToggleDisplay('sm_sitebox_block_options','sm_sitebox_block_options','interface');
			
			
			// START EVENT TRACKERS
			// initiate listeners on root node
			
			// all trackers respond globally to the "HTML" node
			var event_tracking_root = document.getElementsByTagName("HTML")[0];
			
			// mousemove tracker
			addListeners('mousemove', event_tracking_root, tvgs_pass_mousemove);
			
			// mouseup tracker (used as onclick so users can rethink their click, move the cursor and "mouseup" somewhere else, like outside the menu they were in, to cancel their action)
			addListeners('mouseup', event_tracking_root, tvgs_pass_mouseup);
			
			// mousedown tracker
			addListeners('mousedown', event_tracking_root, tvgs_pass_mousedown);
			
			// typing tracker, responds only to key up
			addListeners('keyup', event_tracking_root, tvgs_pass_keyup);

			if (document.getElementById('sm_js_console')) document.getElementById('sm_js_console').innerHTML = 'Javascript readout console: tvg_suite handlers running.<br><br>';
			

			// keep session alive
			tvgs_keep_alive('content.php?keep_alive_ticker=1', 1);
			
			
			// start clock
			tvgs_clock('top_menu_time_image', false);
			
			
} // end function tvgs_kickstart








		// Cross-browser implementation of element.addEventListener()

		// Use: listen("event name", elem, func);
		// addListenersThree('mousemove', elem, func)
		function addListeners(evnt, elem, func)
		{
		
		
			if (elem.addEventListener)  // W3C DOM
				elem.addEventListener(evnt,func,false);
			else if (elem.attachEvent)
			{ // IE DOM
				var r = elem.attachEvent("on"+evnt, func);
				return r;
			}
			else window.alert('I\'m sorry Dave, I\'m afraid I can\'t do that.');
			
			
		}
		
		
// EVENT RELAY
// relay specific events to handler with extra info

// mousemove
function tvgs_pass_mousemove(event)
{
	
	tvg_target_element_watcher(event, 'mousemove');
	
}

// mouseup
function tvgs_pass_mouseup(event)
{
	
	tvg_target_element_watcher(event, 'mouseup');
	
}

// mousedown
function tvgs_pass_mousedown(event)
{
	//if (document.getElementById('sm_js_console')) document.getElementById('sm_js_console').innerHTML += 'Passing mousedown.<br>';	
	tvg_target_element_watcher(event, 'mousedown');
	
}

// keyup
function tvgs_pass_keyup(event)
{
	
	tvg_target_element_watcher(event, 'keyup');
	
}
		
	
	
	
	
// read the config on page load
function tvg_read_suite_config()
{
	
	if (window.tvg_suite_config)
	{
		
		for (var i in window.tvg_suite_config)
		{
			
			if (window.tvg_suite_config[i][1] == 'rollover_index')
			{
				
				window.tvg_rollover_index = i;
				
				if (document.getElementById('sm_js_console')) document.getElementById('sm_js_console').innerHTML += 'Config: rollover config set.<br>';	
				//alert('rollover_index = ' + i);
				
			}
			
			if (window.tvg_suite_config[i][1] == 'popup_index')
			{
				
				window.tvg_popup_index = i;
				
				if (document.getElementById('sm_js_console')) document.getElementById('sm_js_console').innerHTML += 'Config: popup config set.<br>';
				//alert('popup_index = ' + i);
				
			}
			
			if (window.tvg_suite_config[i][1] == 'ieks_index')
			{
				
				window.tvg_ieks_index = i;
				
				if (document.getElementById('sm_js_console')) document.getElementById('sm_js_console').innerHTML += 'Config: ieks config set.<br>';
				//alert('ieks_index = ' + i);
				
			}
			
		}
		
		
		
		
	
		
		
	}
	
}
		
		




		// THESE GLOBALS NEED TO BE REVISED
		// move into global vars array, do away with all other window.something vars for "tvg_" stuff
		var popup_active_id = '';
		var rollover_active_id = '';
		var content_active_id = '';
		var mousemoved = 0;
		var mousedown_time = null;
		var show_info_tracker = false;
		
		if (document.getElementById('sm_js_console')) document.getElementById('sm_js_console').innerHTML += 'Globals: initialized some nasty globals.<br>';
		
		// show/hide menu based on continuous onmousemove tracking
		// ISSUE: browsers may interpret only part of the window as body, and the event will not fire when the mouse is not in it.
		// fix: set the width and height of the body tag to 100% to make sure the entire window is interpreted as body
		
		// todo: make script realize when the mouse is not in the browser window at all, treat as mouseout closing active elements
		
function tvg_target_element_watcher(event, event_type)
{
	
	
	// GET EVENT
	
	// Explorer
	if (event.srcElement)
	{
	
		var current_element = event.srcElement;
		
	}
	// Mozilla
	else if (event.target)
	{	
	
		var current_element = event.target;
		
	}
	
	
	
	

	
	
	// build element id-tree to document HTML root
	function build_element_to_root_id_tree(current_element)
	{
		
		var element_to_root_id_tree = [];
		var element_parent_count = 0;
		var check_element = current_element;
		
		while (check_element.nodeName != 'HTML')
		{
			
			// expand tree
			element_to_root_id_tree[element_parent_count] = check_element.id;
			
			// step up to to parent
			check_element = check_element.parentNode;
			
			// increase parent count
			element_parent_count = element_parent_count + 1;
		
		}
		
		// HTML node parent number
		// used by info tracker, move this global to somewhere else
		window.distance_to_html_node = element_parent_count;
		
		
		
		return element_to_root_id_tree;
		
		
	
	}
	
	
	
	// build element class-tree to document HTML root
	function build_element_to_root_class_tree(current_element)
	{
		
		var element_to_root_class_tree = [];
		var element_parent_count = 0;
		var check_element = current_element;
		
		while (check_element.nodeName != 'HTML')
		{
			
			// expand tree
			element_to_root_class_tree[element_parent_count] = check_element.className.split(' ');
			
			// step up to to parent
			check_element = check_element.parentNode;
			
			// increase parent count
			element_parent_count = element_parent_count + 1;
		
		}
		
		// HTML node parent number
		// used by info tracker, move this global to somewhere else
		window.distance_to_html_node = element_parent_count;
		
		
		
		return element_to_root_class_tree;
		
		
	
	}
	
	
	// build element info-tree to document HTML root
	function build_element_to_root_element_tree(current_element)
	{
		
		var element_to_root_element_tree = [];
		var element_parent_count = 0;
		var check_element = current_element;
		
		
		while (check_element.nodeName != 'HTML')
		{
			
			// expand tree
			element_to_root_element_tree[element_parent_count] = check_element; // element reference
			
			// step up to to parent
			check_element = check_element.parentNode;
			
			// increase parent count
			element_parent_count = element_parent_count + 1;
		
		}
		
		
		// HTML node parent number
		// used by info tracker, move this global to somewhere else
		window.distance_to_html_node = element_parent_count;
		
		
		return element_to_root_element_tree;
		
	}
	
	
	
	// detect if the monitored element is or is a parent of the current element
	function get_monitored_element_status(monitored_element_id, check_tree)
	{
	
		for (var i in check_tree)
		{
		
			if (check_tree[i] == monitored_element_id)
			{
			
				return true;
			
			}
		
		}
		
		return false;
		
	}
	
	
	
	
	// detect if the monitored element class or is a current element class
	function check_monitored_element_class(monitored_element_class, check_tree)
	{
	
		for (var i in check_tree)
		{
		
			for (var j in check_tree[i])
			{
			
				if (check_tree[i][j] == monitored_element_class)
				{
				
					return true;
				
				}
			
			}
		
		}
		
		return false;
		
	}
	
	
	
	
	// return the first element from the parent tree that has a specific class
	function get_first_parent_element_by_class(parent_element_class, check_tree_element)
	{
	
		for (var i in check_tree_element)
		{
			
			var classnames = check_tree_element[i].className.split(' ');

			
			for (var j in classnames)
			{
			
				if (classnames[j] == parent_element_class)
				{
				
					return check_tree_element[i];
				
				}
			
			}
		
		}
		
		return false;
		
	}
	
	
	
	
	// get check trees
	var check_tree_id = build_element_to_root_id_tree(current_element);
	var check_tree_class = build_element_to_root_class_tree(current_element);
	var check_tree_element = build_element_to_root_element_tree(current_element);
	
	
	
	
	// MOUSEMOVE HANDLERS
	if (event_type == 'mousemove')
	{
		
		
		// we're moving!
		// used by info tracker, move this global to somewhere else
		window.mousemoved++;
		
		
		
		
		
		// ROLLOVER TYPE 1 CONFIG
		// inline here... needs to be autogenerated/parsed sometime
		
		// check if the config variable exists
		if (window.tvg_rollover_index)
		{
		
			var rollover_index = window.tvg_suite_config[window.tvg_rollover_index][2];
			
	
			// HANDLE ROLLOVER TYPE 1
			
			// experimental: rollovers are based on unique class naming convention (same as id, to keep config simple), appending or removing "_over" to the element's class, paths to images are set in the css
			
		
			// check to deactivate rollover
			// this does not use a config list, but just checks/modifies the classname when a rollover_active_id is set
			
			// when a rollover is active, and thecursor is not in it (a "mouseout", but really a "mousenotin"), switch to passive
			if (window.rollover_active_id != '')
			{
			
				// check if it is really active
				// if "_over" is in the classname, it is assumed to be active
				if (document.getElementById(rollover_active_id).className.indexOf('_over') != -1)
				{
				
					// check if the mouse is in the active rollover, if not switch current active to passive
					if (get_monitored_element_status(rollover_active_id, check_tree_id) != true)
					{
					
						// change status from active to passive
						// the switch is assumed to work by just removing "_over" from the classname
						document.getElementById(rollover_active_id).className = document.getElementById(rollover_active_id).className.replace('_over', '');
						
						// clear active popup
						window.rollover_active_id = '';
						
					}
				
				}
				
			}
			
			// check to activate rollover, do not check anything when a rollover is still active
			// when a rollover from the config is under the cursor (a "mouseover", but really a "mousein"), switch to active
			if (window.rollover_active_id == '')
			{
				
				// check config list
				for (var i in rollover_index)
				{
					
					// when config id is found and is passive activate rollover
					if (get_monitored_element_status(rollover_index[i], check_tree_id) == true && document.getElementById(rollover_index[i]).className.indexOf('_over') == -1)
					{
						
						// change status from passive to active
						document.getElementById(rollover_index[i]).className = document.getElementById(rollover_index[i]).className.replace(rollover_index[i], rollover_index[i] + '_over');
						
						// set to active rollover
						window.rollover_active_id = rollover_index[i];
						
						break;
					
					}
					
				
				}
			
			}
			
		
		} // end if rollover_index
		
		
	
		
		
		
		//var popup_index = window.popup_index;
		
		
		// check if the config variable exists
		if (window.tvg_popup_index)
		{
		
			var popup_index = window.tvg_suite_config[window.tvg_popup_index][2];
			
			
			// HANDLE POPUP MENU TYPE 1
			
			
			// check to show popup_passive
			// when a popup_content is visible, and the cursor is not in its content area (a "mouseout", but really a "mousenotin"), switch to popup_passive
		
		
			
			// get associated popup values from popup_index
			for (var i in popup_index)
			{
					
				// check for correct popup type (1)
				if (is_numeric(i) && popup_index[i][0] == 1)
				{ 	
				
				
					// check active id set
					if (document.getElementById(popup_index[i][2]) && document.getElementById(popup_index[i][2]).style.display != 'none')
					{ 
					
					/*
					 
						// check if the mouse is in the active popup_content, if not switch current active to passive
						if (get_monitored_element_status(popup_index[i][3], check_tree_id) != true)
						{
						
						//	document.getElementById('console').innerHTML += 'setting to passive ' + popup_index[i][1] + ' <br>';
						
							// change status from active to passive
							//switchDisplayFade(popup_index[i][1], popup_index[i][2]);
							
							// fade active portion
							fade_out_element( popup_index[i][2], 10);
							
							// clear active popup
							//window.popup_active_id = '';
							
							//alert('hiding ' + popup_index[i][2]);
							
						}
						*/
						
						
						// check if the mouse is in the active popup_content, if not switch current active to passive
						if (check_monitored_element_class(popup_index[i][3], check_tree_class) != true)
						{
						
						//	document.getElementById('console').innerHTML += 'setting to passive ' + popup_index[i][1] + ' <br>';
						
							// change status from active to passive
							//switchDisplayFade(popup_index[i][1], popup_index[i][2]);
							
							// fade active portion
							fade_out_element(popup_index[i][2], 10);
							
							// clear active popup
							// not essential, just for info tracker
							window.popup_active_id = '';
							
							//alert('hiding ' + popup_index[i][2]);
							
						}
					
					}
				
				}
			
			}
				
		
		
		
			
			// check to show popup_active
			// when a popup_passive is under the cursor (a "mouseover", but really a "mousein"), switch to popup_active
			for (var i in popup_index)
			{
			
				//document.getElementById('console').innerHTML += 'CHECK for ' + i + ' = ' + get_monitored_element_status(popup_index[i][1], check_tree_id) + ' <br>';
				
				// check for correct popup type (1) and look for the active id set
				if (is_numeric(i) && popup_index[i][0] == 1 && get_monitored_element_status(popup_index[i][1], check_tree_id) == true)
				{
				
				
					// check active id set
					//if (document.getElementById(popup_index[i][2]) && document.getElementById(popup_index[i][2]).style.display != 'none')
				//	{ 
					
				
					
					// change status from passive to active
					//switchDisplay(popup_index[i][1], popup_index[i][2]);
					
					
					// show active portion
					//if (document.getElementById('sm_js_console')) document.getElementById('sm_js_console').innerHTML += 'Popup type 1: setting to active "' + popup_index[i][2] + '".<br>';
					
				tvg_show_element_by_id(popup_index[i][2]);
				
				
					
					//if (document.getElementById('sm_js_console')) document.getElementById('sm_js_console').innerHTML += 'Popup type 1: setting to active "' + popup_index[i][2] + '".<br>';
					
					// set to active popup
					// not essential, just for info tracker
					window.popup_active_id = popup_index[i][2];
					
					//alert('showing ' + popup_index[i][2]);
					
					break;
				
				}
			
			}
		
		
		} // end if popup_index
		
		
		if (window.show_info_tracker == true)
		{
			
			showPopup(event, 'linkPopup', current_element);
			
		}
	
	
		
	} // end mousemove handlers
	
	
	
	
		// MOUSEDOWN HANDLERS	
	if (event_type == 'mousedown')
	{
	
	
				// set mousedown time
				window.mousedown_time = get_millitime();
				
				
				//if (document.getElementById('sm_js_console')) document.getElementById('sm_js_console').innerHTML += 'Mousedown tracker: button pressed at ' + window.mousedown_time + '.<br>';
		
	
	
		} // end mousedown handlers
		
		
		
		
		
	// MOUSEUP HANDLERS	
	if (event_type == 'mouseup')
	{
		
		
		
		
		
		
		// GET CLICK INFO
		
		// get mouseup time and mousepress time
		var mouseup_time = get_millitime();
		var mousepress_time_delta = 0;
		
		//if (document.getElementById('sm_js_console')) document.getElementById('sm_js_console').innerHTML += 'Mouseup tracker: button released at ' + mouseup_time + '.<br>';
		
		
		if (window.mousedown_time != null && window.mousedown_time < mouseup_time)
		{
		
				// see how long user is holding down the button
				var mousepress_time_delta = mouseup_time - mousedown_time;
				
				if (document.getElementById('sm_js_console')) document.getElementById('sm_js_console').innerHTML += 'Mouseup tracker: mousebutton pressed for ' + (mousepress_time_delta / 1000) + ' seconds.<br>';
		
				
				// reset
				window.mousedown_time = null;
				
		}
				
				
				
		
		// HANDLE LINKBLOCK
		
		// see if a linkblock is clicked, get the url and redirect
		// the a-tag with the link is three div's down from the block
		
		// check if this click was in a linkblock and get the block element
		var linkblock = get_first_parent_element_by_class('linkblock', check_tree_element);

		// check for linkblock
		if (linkblock != false)
		{
		
			// set vars
			var depth = 0;
			var progress = true;
			var search_group = linkblock.childNodes;
			

			while (progress == true)
			{
				
				// check all child nodes
				for (var i in search_group)
				{
					
					// skip properties
					if (is_numeric(i))
					{
					
						// check for link at the right position
						if (search_group[i].nodeName == 'A' && depth == 3)
						{
							
							// set link values
							var url = '';
							var url_target = '';
							
							
							// get url info from a-tag
							if (search_group[i].href) var url = search_group[i].href;
							if (search_group[i].target) var url_target = search_group[i].target;
							
							
							if (url != null && url != '')
							{
								
								//alert (url);
								
								// MAKE FUNCTION add-parameter-to-url
								// set clicktime in get-string, only if parameters are present
								//if (url.indexOf('?') > -1) url = url + '&clicktime=' + mousepress_time_delta;
								

								if (mousepress_time_delta > 750)
								{
								
									tvgs_open_url(url, 'blank');
									
									//alert ('link to blank');
								
								}
								else
								{
								
									//	alert ('link to self');
									if (url_target == '_blank' || url_target == '_top')
									{
										
										// send to correct target, strip underscore
										tvgs_open_url(url, url_target);
										
									}
									else
									{
									
										tvgs_open_url(url);
									
									}
								
								}
								
								
								// stop handling anything and wait for redirect
								return;
							
							}
							else
							{
								
								// invalid link
								progress = false;
								
							}
							
						}
						// advance only on div tag
						else if (search_group[i].nodeName == 'DIV')
						{
							
							// update search group
							search_group = search_group[i].childNodes;
							
							progress = true;
							
							depth++;
							
							break;
							
						}
						else
						{
						
							progress = false;
							
						}
						
					}

				}
		
			}
			
			
			// stopped searching because of invalid linkblock
			if (document.getElementById('sm_js_console')) document.getElementById('sm_js_console').innerHTML += 'Linkblock mouseup tracker: aborting redirect for inconsistent linkblock.<br>';
		
		}
		
		
		
		// HANDLE SUBMITBLOCK
		
		// see if a submitblock is clicked, get the enclosing form and submit

		// check if this click was in a submitblock and get the block element
		var submitblock = get_first_parent_element_by_class('submitblock', check_tree_element);
		
		// check for linkblock
		if (submitblock != false)
		{

			var active_form = tvgs_get_enclosing_form_element(submitblock);
			
			
			// set clicktime in post-array
			var input_hidden = document.createElement('input');
			
			input_hidden.type = 'hidden';
			input_hidden.name = 'clicktime';
			input_hidden.value = mousepress_time_delta;
			
			active_form.appendChild(input_hidden);
			
		
          
          // if (document.getElementById('sm_js_console')) document.getElementById('sm_js_console').innerHTML += 'Submitblock mouseup tracker: setting clicktime to ' + input_hidden.value + '.<br>';
		
          
          
          
          // set submitblock to inactive
          var submitblock_classnames = submitblock.className.split(' ');
          var new_submitblock_classnames = [];
          
          for (var i in submitblock_classnames)
          {
          	
          	// rebuild classname, leaving out 'submitblock' so submit will not be triggered again
          	if (submitblock_classnames[i] != 'submitblock')
          	{
          	
          		new_submitblock_classnames[new_submitblock_classnames.length] = submitblock_classnames[i];
          	
          	}
          	
          }
          
          submitblock.className = new_submitblock_classnames.join(' ');
		
		
			// submit the form
			active_form.submit();
			
		
			// stop handling anything and wait for submit
			return;
								
								
		}
		
		
		
		
		
		
		
		
		
		
		//alert('mouseup on id "' + current_element.id + '"');
		  
	} // end mouseup handlers
	
	
	
	
	
	// KEYUP HANDLERS	
	if (event_type == 'keyup')
	{
		
		//alert('keyup on id "' + current_element.id + '" with value "' + current_element.value + '"');
		

		// HANDLE IEKS LISTS
		
		// check if the config variable exists
		if (window.tvg_ieks_index)
		{
		
			var ieks_index = window.tvg_suite_config[window.tvg_ieks_index][2];
			
			// check if it's an ieks field call
			for (var i in ieks_index)
			{
			
				if (is_numeric(i) && ieks_index[i][0] == 0 && get_monitored_element_status(ieks_index[i][1], check_tree_id) == true)
				{
	
					// activate list handler
					update_list(ieks_index[i][2], current_element.value);
				
				}
			
			} 
			
		
		} // end if ieks_index
		
		
		// end handle ieks lists
		
	} // end keyup handlers
	
	
	
	

	
	
	// HANDLE COLOR TRANSITION
	// see if the mouse has left an element
	
	/*
	if (window.content_active_id != '')
	{
	
		// check if it is really active
		//if (document.getElementById(content_active_id).style.display != 'none')
		//{
		
			// check if the mouse is in the active popup_content, if not switch current active to passive
			if (current_element.id != window.content_active_id)
			{
				
				
				background_color_transition(document.getElementById(window.content_active_id));
				
				// clear active content
				window.content_active_id = '';
				
			}
		
		//}
		
	}
	// check to show popup_content
	// when a popup_title is under the cursor (a "mouseover", but really a "mousein"), switch to popup_content
	else if (current_element.id.indexOf('popup_content') >= 0)
	{
	
		clearInterval(current_element.name);
		
		current_element.style.backgroundColor='#870082';
	
		window.content_active_id = current_element.id;
		
	}
	*/
	
	

	
	
	
	
	
	
	
}
				
		
		
		
		
		
		
		// IEKS
		
		
		function update_list(option_list, query_string)
		{
			
			
			//var ieks_index = window.tvg_suite_config[window.tvg_ieks_index][2];
			
			
			//alert(output_id);
			
			// set default config vars
			var label_mask = '#label#';
			var match_highlight_mask = '#match#';
			
			// get config vars when specified
			 for (var i in option_list)
			 {
			 	
			 	// see if the query string is contained in the option
			 	if(is_numeric(i) && option_list[i][0] == 0)
			 	{
			 	
			 		if (option_list[i][1] == 'list_output_id')
			 		{
			 			output_id = option_list[i][2];
			 		}
			 		
			 		if (option_list[i][1] == 'label_mask')
			 		{
			 			label_mask = option_list[i][2];
			 		}
			 		
			 		if (option_list[i][1] == 'match_highlight_mask')
			 		{
			 			match_highlight_mask = option_list[i][2];		
			 			
			 		}
			 		
			 	}
			 
			 }
				
			
			// process options
			var match_query = eval('/' + query_string + '/i');
			
			var option_id = '';
			
			var matching_option = '';
			var matching_option_list = '';
				
			 for (var i in option_list)
			 {
			 	
			 	// use case insensiteve query
			 //	match_query = eval('/' + query_string + '/i');
			 	
			 	
			 	
			
			 	// see if the query string is contained in the option
			 	if(is_numeric(i) && option_list[i][0] == 1)
			 	{
			 		
			 		
			 		if (query_string == '')
			 		{
			 			
			 			// no query, just show all
			 			matching_option = option_list[i][1];
			 		
			 		}
			 		else if (option_list[i][1].match(match_query) != null)
			 		{

			 			// highlight the first occurence op the string in the option label
			 			matching_option = option_list[i][1].replace(match_query, match_highlight_mask.replace('#match#', option_list[i][1].match(match_query)));
			 		
			 		}
			 		else
			 		{
			 			
			 			// no match, leave out
			 			matching_option = '';
			 		
			 		}
			 		
			 		
			 		// construct option code
			 		if (matching_option != '')
			 		{

			 			// wrap label in label mask
			 			matching_option = label_mask.replace('#label#', matching_option);
			 			
			 			// set option_id
			 			option_id = output_id + '_option_' + i;
			 			
			 			matching_option = matching_option.replace('#option_id#', option_id);
			 			
			 		}
			 		
			 		
			 		// add to list
			 		matching_option_list += matching_option;
			 		
			 		//alert(matching_option_list);	 		
			 		
			 		//reset option
			 		matching_option = '';
			 	
			 	}
			 	
			 	// reset match query
			 	//match_query = '';
			 
			 }
			 
			 
			 // check result
	 		if (matching_option_list == '')
	 		{

	 			// display no results message
	 			matching_option_list = 'No matches!';
	 			
	 		}
			 
			 // write to page
			document.getElementById(output_id).innerHTML = matching_option_list;
		
		}
		
/*		
		
function mouseEventHandler(event)
{
	// Internet Explorer
	if (event.srcElement)
	{
		showPopup(event, 'linkPopup', event.srcElement);
	}
	// Netscape and Firefox
	else if (event.target)
	{
		showPopup(event, 'linkPopup', event.target);
	}
}

function getPopupObject(myId)
{
   if (document.getElementById(myId))
   {
     return document.getElementById(myId);
   }
   else
   {
     return window.document[myId]; 
	}     
}
*/




function toggleInfoTracker()
{
	
	if (window.show_info_tracker == true)
	{
		
		window.show_info_tracker = false;
		
		document.getElementById('linkPopup').style.display = 'none';
		
	//	if (document.getElementById('sm_js_console')) document.getElementById('sm_js_console').innerHTML += 'Info tracker: disabled.<br>';
		
	}
	else
	{
		window.show_info_tracker = true;
		
	//	if (document.getElementById('sm_js_console')) document.getElementById('sm_js_console').innerHTML += 'Info tracker: enabled.<br>';
	}
	
}





function showPopup(event, tracker_id, element)
{
	
	// get position
	var x = parseInt(event.clientX+document.body.scrollLeft);
	var y = parseInt(event.clientY+document.body.scrollTop);


	//var popup=getPopupObject(id);
	
	
	
	if (document.getElementById(tracker_id))
	{	
		
		var tracker = document.getElementById(tracker_id);
		
		
		// show
		if(tracker.style.display == 'none')
		{
			tracker.style.display = '';	
		}
		// update contents
		//var popupText=getPopupObject(id+"Text");
		
		var text = '';
		
		text += 'Node: ' + element.nodeName + '(distance to HTML root: ' + window.distance_to_html_node +  ')<br>';
		
		if (element.id != '')
		{
		
			text += 'Id: "' + element.id + '"<br>';
			
		}
		
		if (element.className != '')
		{
		
			text += 'Class: "' + element.className + '"<br>';
			
		}
			
		//text += element.parentNode.nodeName + ", id '"+element.parentNode.id+"'<br>";
		
		
		
	//	text += 'Distance to HTML node: ' + window.distance_to_html_node + '<br>';
			
	
		text += 'Mouse moves: ' + window.mousemoved + ' (' + x + ', ' + y + ')<br>';
		
		
		if (window.popup_active_id != '')
		{
			
			text += 'Popup type 1 id: ' + window.popup_active_id + '<br>';
			
		}
		
		if (window.rollover_active_id != '')
		{
			
			text += 'Rollover type 1 id: ' + window.rollover_active_id + '<br>';
			
			//text += 'Active rollover class: ' + document.getElementById(rollover_active_id).className + '<br>';
			
		}
		
		// update content
		tracker.innerHTML = text;
		
		// info window offset from cursor
		x = x + 10;
		y = y + 10;
		
		// style string values
		x = x + 'px';
		y = y + 'px';
		
		// update position
		tracker.style.left = x;
		tracker.style.top = y;
		
	}
	
}

		
		



function document_timer(document_start_time)
{
	
	var document_dom_loaded_time = get_millitime();
	
	var document_dom_completion_delta = document_dom_loaded_time - document_start_time;
	
	window.timer_info_dom = document_dom_completion_delta;
	
	if (document.getElementById('sm_js_console')) document.getElementById('sm_js_console').innerHTML += 'DOM completion time: ' + window.timer_info_dom + 'ms.<br>';
	
}

function get_millitime()
{
	
	var time = new Date();
 return time.getTime();

}








// sends a useless query to server at a set interval to keep session alive
// interval is in seconds
function tvgs_keep_alive(url, interval)
{

	if (document.getElementById('sm_js_console')) document.getElementById('sm_js_console').innerHTML += 'Keep alive ticker: initialized.<br>';
	
	
	
	if (document.getElementById('sm_keep_alive_count'))
	{
			
		var counter = document.getElementById('sm_keep_alive_count');
		
		var interval = 1; // tick interval in seconds
		
		var beq_interval = 60; // beq interval in seconds
		
		var tick = 0;
		
		var beq_tick = 0;
		
		var beq_response = null;
		
		var tick_opacity = 100;
		
		var image_link = counter.name;
		
		if (document.getElementById('sm_js_console')) document.getElementById('sm_js_console').innerHTML += 'Keep alive ticker image link: ' + image_link + '.<br>';
			
	}
	else
	{
		
		// no output element
		return;
	
	}
	

	function tvgs_keep_alive_ticker()
	{
	
			// update counter image
			//counter.src = image_link + tick + '&op=' + tick_opacity;


			// refresh session through responder
			if (beq_tick == beq_interval)
			{
				
				beq_tick = 0;
				
				beq_response = initiate_backend_query(url);

		 	}
		 	
		 	
			if (document.getElementById('sm_keep_alive_message'))
			{
				
				// update message
				if (beq_response != null)
				{
					
					if (document.getElementById('sm_js_console')) document.getElementById('sm_js_console').innerHTML += 'Keep alive message sent at: tick ' + tick + '.<br>';
		
					var message = document.getElementById('sm_keep_alive_message');
					
					message.innerHTML = beq_response;
					message.style.display = '';
					
					fade_out_element('sm_keep_alive_message', 20);
					
					
				}
				
				
				
			}
		
		
			beq_response = null;
			
			tick++;
			
			if (tick_opacity > 20) tick_opacity = tick_opacity - 4;
		
			beq_tick++;
		 
	}
	
	setInterval(tvgs_keep_alive_ticker, (interval * 1000));
				
}



// make query to backend script
function initiate_backend_query(url)
{

	// create empty query variable
	var backend_query = null;
	
	
	// setup request, alert on fail
	try
	{
	
		// firefox, opera 8+, safari, ie7
		backend_query = new XMLHttpRequest();
		
	}
	catch(e)
	{
		
		// old ie
		try
		{
		
			backend_query = new ActiveXObject('Microsoft.XMLHTTP');
		
		}
		catch(e)
		{
		
			alert ('This webbrowser does not support XMLHTTP!');
			return;  
		
		}
	
	}
	
	
	// send query, wait for response
	backend_query.open('GET',url,false);
	
	backend_query.send(null);
	
	
	// get result
	return backend_query.responseText;

}


// updates an image src with the time like "16:34" every second
function tvgs_clock(img_id, show_seconds)
{

	if (document.getElementById(img_id))
	{
	
		// set vars
		var clock = document.getElementById(img_id);
		var clock_base_img_src = clock.name;
		
		var clock_display = '';
		window.tvgs_clock_display = '';	
		
		var current_date = null;
		var current_hours = null;
		var current_minutes = null;
		var current_seconds = null;
	
		var tick_count = 0;
		
		
		function tvgs_clock_ticker()
		{
			
			// get current date
			current_date = new Date()
			
			// get current hours
			current_hours = current_date.getHours();
			if ((current_hours + '').length == 1) current_hours = '0' + current_hours + '';
			
			// get current minutes
			current_minutes = current_date.getMinutes();
			if ((current_minutes + '').length == 1) current_minutes = '0' + current_minutes + '';
			
		
			// set clock display text				
			clock_display = current_hours + ':' + current_minutes;
			
			
			if (show_seconds == true)
			{
			
				// get current seconds
				current_seconds = current_date.getSeconds();
				if ((current_seconds + '').length == 1) current_seconds = '0' + current_seconds + '';
				
				// set clock display text
				clock_display = clock_display + ':' + current_seconds;
			
			}
			
			
			// check if the displayed time will change
			if (window.tvgs_clock_display != clock_display)
			{
				
				// update current display
				window.tvgs_clock_display = clock_display;	
				
				// update image
				clock.src = clock_base_img_src + clock_display;
				
			}
			
			
			// update ticker
			tick_count++;
		
		}
	
	
		// start ticking
		//tvgs_clock_ticker();
		setInterval(tvgs_clock_ticker, 100); // interval is 0.1 second to provide for smooth seeming display of seconds when the interval is slighty off
		
		
		if (document.getElementById('sm_js_console')) document.getElementById('sm_js_console').innerHTML += 'Clock: initialized.<br>';
			
	}
	else
	{
		
		if (document.getElementById('sm_js_console')) document.getElementById('sm_js_console').innerHTML += 'Clock: output element not found.<br>';
		
		// no output element
		return;
	
	}
	

}



// NOT FUNCTIONAL: BREAKS SCRIPT
// allImagesLoaded()
// Checks if all the images are loaded in the document
// It Does this by looping through all the images and checks the attribute .complete
// If .complete is false then we set the return variable to 0
function allImagesLoaded(document_start_time)
{

 

 	function wait_for_images()
	{
		
								
							
		var all_images = document.images;
		
		// Loop through all the images
		for (var i = 0;i<all_images.length;i++)
		{
			// If the image isnt loaded we set the return varible to 0
			if(all_images[i].complete == false)
			{
				return false;
			}
		}
					
		clearTimeout(timer_intervalset);
							
							
		var document_images_loaded_time = get_millitime();
		
		var document_images_completion_delta = document_images_loaded_time - document_start_time;
		
		window.timer_info_images = document_images_completion_delta;
						
						
		display_timer_result();
						

	}
	
	
	
	var timer_intervalset = setTimeout(wait_for_images, 50);
	
	
	
	
	
	// display report
	function display_timer_result()
	{
		
		if (document.getElementById('sm_js_console')) document.getElementById('sm_js_console').innerHTML += 'Images completion time: ' + window.timer_info_images + 'ms.<br>';
		//document.getElementById('page_info_load_time').innerHTML = 'DOM completion time: ' + 	window.timer_info_dom + 'ms. Images completion time: ' + window.timer_info_images + 'ms.';
		//alert('DOM completion time: ' + 	window.timer_info_dom + 'ms. Images completion time: ' + window.timer_info_images + 'ms.');

	}
				
								
								
								
}




