
window.onload = function() {

	//document.ondblclick = OnDocumentDblClick;
	var aLaunchMitchRyder = document.getElementById('launchMitchRyder');
	var aLaunchThursdayRide = document.getElementById('launchThursdayRide');
	
	if(aLaunchMitchRyder !== null && aLaunchThursdayRide !== null) {
	
		aLaunchMitchRyder.onclick = function() {
			OnDocumentDblClick('mdlMitchRyder');
		}
		
		aLaunchThursdayRide.onclick = function() {
			OnDocumentDblClick('mdlThursdayRide');
		}
		
		//$modal('modalWindow').onclick = OnModalWindowClick;
		
		$modal('mdlThursdayRide').onclick = function() {
			OnModalWindowClick('mdlThursdayRide');
		}
		
		$modal('mdlMitchRyder').onclick = function() {
			OnModalWindowClick('mdlMitchRyder');
		}
		
		$modal('mdl1672').onclick = function() {
			OnModalWindowClick('mdl1672');
		}
		
		$modal('mdlRain').onclick = function() {
			OnModalWindowClick('mdlRain');
		}
		
	}
	
}
 
var _rulesAdded = false;
 
function OnDocumentDblClick(sId)
{
	//$modal('modalWindow').style.display = $modal('modalBackground').style.display = 'block';
	$modal(sId).style.display = $modal('modalBackground').style.display = 'block';
	
	// special < IE7 -only processing for windowed elements, like select	
	if (window.XMLHttpRequest == null)
	{
		var type = $modal('hideType').value;
		
		if (type == 'iframe')
			$modal('modalIframe').style.display = 'block';
		if (type == 'replace')
			ReplaceSelectsWithSpans();
	}
 
	// call once to center everything
	OnWindowResize(sId);
	
	if (window.attachEvent)
		//window.attachEvent('onresize', OnWindowResize);
		window.attachEvent('onresize', function() {
			OnWindowResize(sId)
		});
	else if (window.addEventListener)
		//window.addEventListener('resize', OnWindowResize, false);
		window.addEventListener('resize', function() {
			OnWindowResize(sId)
		}, false);
	else
		window.onresize = function() {
			OnWindowResize(sId)
		}
	
	// we won't bother with using javascript in CSS to take care
	//   keeping the window centered
	if (document.all)
		document.documentElement.onscroll = function() {
			OnWindowResize(sId);
		}
}
 
function OnWindowResize(sId)
{
	// we only need to move the dialog based on scroll position if
	//   we're using a browser that doesn't support position: fixed, like < IE 7
	var left = window.XMLHttpRequest == null ? document.documentElement.scrollLeft : 0;
	var top = window.XMLHttpRequest == null ? document.documentElement.scrollTop : 0;
	var div = $modal(sId);
	
	div.style.left = Math.max((left + (GetWindowWidth() - div.offsetWidth) / 2), 0) + 'px';
	div.style.top = Math.max((top + (GetWindowHeight() - div.offsetHeight) / 2), 0) + 'px';
}
 
function OnModalWindowClick(sId)
{
	//$modal('modalWindow').style.display = $modal('modalBackground').style.display = 'none';
	$modal(sId).style.display = $modal('modalBackground').style.display = 'none';
	
	// special IE-only processing for windowed elements, like select	
	if (document.all)
	{
		var type = $modal('hideType').value;
		
		if (type == 'iframe')
			$modal('modalIframe').style.display = 'none';
		if (type == 'replace')
			RemoveSelectSpans();
	}
	
	if (window.detachEvent)
		//window.detachEvent('onresize', OnWindowResize);
		window.detachEvent('onresize', function() {
			OnWindowResize(sId);
		});
	else if (window.removeEventListener)
		//window.removeEventListener('resize', OnWindowResize, false);
		window.removeEventListener('resize', function() {
			OnWindowResize(sId)
		}, false);
	else
		window.onresize = function() {
			OnWindowResize(sId);
		}
}
 
/* These functions deal with IE's retardedness in not allowing divs to 
 * cover select elements by replacing the select elements with spans. */
 
function RemoveSelectSpans()
{
	var selects = document.getElementsByTagName('select');
	
	for (var i = 0; i < selects.length; i++)
	{
		var select = selects[i];
		
		if (select.clientWidth == 0 || select.clientHeight == 0 || 
			select.nextSibling == null || select.nextSibling.className != 'selectReplacement')
		{
			continue;
		}
			
		select.parentNode.removeChild(select.nextSibling);
		select.style.display = select.cachedDisplay;
	}
}
 
function ReplaceSelectsWithSpans()
{
	var selects = document.getElementsByTagName('select');
	
	for (var i = 0; i < selects.length; i++)
	{
		var select = selects[i];
		
		if (select.clientWidth == 0 || select.clientHeight == 0 || 
			select.nextSibling == null || select.nextSibling.className == 'selectReplacement')
		{
			continue;
		}
			
		var span = document.createElement('span');
		
		// this would be "- 3", but for that appears to shift the block that contains the span 
		//   one pixel down; instead we tolerate the span being 1px shorter than the select
		span.style.height = (select.clientHeight - 4) + 'px';
		span.style.width = (select.clientWidth - 6) + 'px';
		span.style.display = 'inline-block';
		span.style.border = '1px solid rgb(200, 210, 230)';
		span.style.padding = '1px 0 0 4px';
		span.style.fontFamily = 'Arial';
		span.style.fontSize = 'smaller';
		span.style.position = 'relative';
		span.style.top = '1px';
		span.className = 'selectReplacement';
		
		span.innerHTML = select.options[select.selectedIndex].innerHTML + 
			'<img src="custom_drop.gif" alt="drop down" style="position: absolute; right: 1px; top: 1px;" />';
		
		select.cachedDisplay = select.style.display;
		select.style.display = 'none';
		select.parentNode.insertBefore(span, select.nextSibling);
	}
}
 
/* The following two functions are not used, but have been kept here because 
 *   they might be useful; one must use this method to programmatically add
 *   javascript-valued CSS values (using element.style.div = expresssion(...)
 *   does not work).  These are only useful for IE.
 */
 
function AddStyleRules()
{
	if (_rulesAdded)
		return;
		
	_rulesAdded = true;
 
	var stylesheet = document.styleSheets[document.styleSheets.length - 1];
	
	if (!document.all)
	{
		InsertCssRule(stylesheet, '#modalBackground', 'position: fixed; height: 100%; width: 100%; left: 0; top: 0;');		
		InsertCssRule(stylesheet, '#modalWindow', 'position: fixed; left: 0; top: 0;');		
	}
	else
	{
		InsertCssRule(stylesheet, '#modalBackground', 
			'position: absolute; ' +
			'left: expression(ignoreMe = document.documentElement.scrollLeft + "px"); ' +
			'top: expression(ignoreMe = document.documentElement.scrollTop + "px");' +
			'width: expression(document.documentElement.clientWidth + "px"); ' +
			'height: expression(document.documentElement.clientHeight + "px");');
 
		InsertCssRule(stylesheet, '#modalWindow', 
			'position: absolute; ' +
			'left: expression(ignoreMe = document.documentElement.scrollLeft + "px"); ' +
			'top: expression(ignoreMe = document.documentElement.scrollTop + "px");');
 
	}
}
 
function InsertCssRule(stylesheet, selector, rule)
{
	if (stylesheet.addRule)
	{
		stylesheet.addRule(selector, rule, stylesheet.rules.length);
		return stylesheet.rules.length - 1;
	}
	else
	{
		stylesheet.insertRule(selector + ' {' + rule + '}', stylesheet.cssRules.length);
		return stylesheet.cssRules.length - 1;
	}
}
 
 
 
/* utiltiy functions */
 
function GetWindowWidth()
{
	var width =
		document.documentElement && document.documentElement.clientWidth ||
		document.body && document.body.clientWidth ||
		document.body && document.body.parentNode && document.body.parentNode.clientWidth ||
		0;
		
	return width;
}
 
function GetWindowHeight()
{
    var height =
		document.documentElement && document.documentElement.clientHeight ||
		document.body && document.body.clientHeight ||
  		document.body && document.body.parentNode && document.body.parentNode.clientHeight ||
  		0;
  		
  	return height;
}
 
function $modal(id)
{
	return document.getElementById(id);
}