var NOKE_CALENDAR_DATE_TABLE_ID = 'noke-calendar-date-table';
var NOKE_CALENDAR_HEADING_MONTH_ID = 'noke-calendar-heading-month';
var NOKE_CALENDAR_HEADING_YEAR_ID = 'noke-calendar-heading-year';
var NOKE_CALENDAR_REQUEST_URL = '/event-widget/date-month-year';
var NOKE_CALENDAR_DAILY_EVENT_REQUEST_URL = '/event-widget/date-detail';
var NOKE_CALENDAR_EVENTS_URL = '/calendar';
var NOKE_CALENDAR_EVENTS_LINK_PREFIX = '#date-';
var g_currentDate = new Date();
var g_currentEvents = null;

// Reference for number of days per month
var g_dateReference = new Array(); /* <<<( */

// January
g_dateReference[0] = new Object();
g_dateReference[0]['days'] = 31;
g_dateReference[0]['name'] = 'January';

// February
g_dateReference[1] = new Object();
g_dateReference[1]['days'] = 28; // unless leap year
g_dateReference[1]['name'] = 'February';

// March
g_dateReference[2] = new Object();
g_dateReference[2]['days'] = 31;
g_dateReference[2]['name'] = 'March';

// April
g_dateReference[3] = new Object();
g_dateReference[3]['days'] = 30;
g_dateReference[3]['name'] = 'April';

// May
g_dateReference[4] = new Object();
g_dateReference[4]['days'] = 31;
g_dateReference[4]['name'] = 'May';

// June
g_dateReference[5] = new Object();
g_dateReference[5]['days'] = 30;
g_dateReference[5]['name'] = 'June';

// July
g_dateReference[6] = new Object();
g_dateReference[6]['days'] = 31;
g_dateReference[6]['name'] = 'July';

// August
g_dateReference[7] = new Object();
g_dateReference[7]['days'] = 31;
g_dateReference[7]['name'] = 'August';

// September
g_dateReference[8] = new Object();
g_dateReference[8]['days'] = 30;
g_dateReference[8]['name'] = 'September';

// October
g_dateReference[9] = new Object();
g_dateReference[9]['days'] = 31;
g_dateReference[9]['name'] = 'October';

// November
g_dateReference[10] = new Object();
g_dateReference[10]['days'] = 30;
g_dateReference[10]['name'] = 'November';

// December
g_dateReference[11] = new Object();
g_dateReference[11]['days'] = 31;
g_dateReference[11]['name'] = 'December';
/* )>>> */

function DrawCalendarDatesData(calendar) { /* <<<( */

	var startDay = 0; // start day of the week (0 - 6) for the month
	var daysInMonth = 0; // number of days in the current month
	var currDate = 1; // current day of the month being displayed
	var dateTable = document.getElementById(NOKE_CALENDAR_DATE_TABLE_ID); // table that contains calendar dates
	var tableRow = null; // row of dates table

	if (null != dateTable) {

		// setup calendar
		calendar.setDate(1); // set to first day of month

		// get day of the week for the first of the month
		startDay = calendar.getDay();

		// get number of days in the month
		daysInMonth = g_dateReference[calendar.getMonth()].days;

		// check for February leap year
		if (1 == calendar.getMonth()) {

			var currYear = calendar.getFullYear(); // current year (four digit)

			// if leap year, add an extra day
			if (true == IsLeapYear(currYear)) {
				daysInMonth++;
			}
		}

		// loop through 6 rows (weeks) for each month (the last row being blank for months that only have 5 weeks)
		for (var week = 0; week < 6; week++) {

			tableRow = dateTable.insertRow(dateTable.rows.length);

			// loop through each day in the week
			for (var dayOfWeek = 0; dayOfWeek < 7; dayOfWeek++) {

				// check if a date should be printed for this day
				if ((0 == week) && (dayOfWeek < startDay)) {
					// if not, then display a blank day
					AddDateCell(tableRow, '\xA0', 0, 0, 0);
				}
				else {
					// display date if there are dates to display
					if (daysInMonth >= currDate) {
						var month = calendar.getMonth();
						var day = currDate;
						var checkDate = '';
						var eventDate = '';

						// setup date to check for events
						month++;
						if (month < 10) {
							month = '0' + month.toString();
						}
						if (day < 10) {
							day = '0' + day.toString();
						}
						checkDate = calendar.getFullYear().toString() + month + day;
						if ((null != g_currentEvents) && (null != g_currentEvents[checkDate])) {
							eventDate = checkDate;
						}
						AddDateCell(tableRow, currDate, eventDate, calendar.getFullYear(), month);
						currDate++;
					}
					else {
						// if not, then display a blank day
						AddDateCell(tableRow, '\xA0', false, 0, 0);
					}
				}
			}

			tableRow = null;
		}

		// add submit event row
		tableRow = dateTable.insertRow(dateTable.rows.length);

		if (null != tableRow) {
			var tableCell = null;
			var tableDataContainer = null;
			var cellData = null;

			tableCell = tableRow.insertCell(tableRow.cells.length);
			tableCell.colSpan = 7;

			tableDataContainer = document.createElement('div');
			tableDataContainer.className = 'noke-calendar-submit-event-container';
			tableDataContainer = tableCell.appendChild(tableDataContainer);

			cellData = document.createElement('a');
			cellData.href = NOKE_CALENDAR_EVENTS_URL + '#submit-new-event';

			cellData = tableDataContainer.appendChild(cellData);
			cellData.appendChild(document.createTextNode('Submit New Event'));

			tableDataContainer = null;
			tableCell = null;
			cellData = null;
		}
	}

	return;

} /* )>>> */

function DrawCalendarHeading(container, calendar) { /* <<<( */

	var headingContainer = null; // heading container DOM object
	var headingControl = null; // calendar control DOM object that resides in the heading container
	var headingText = null; // contains either the month or year of the current calendar

	if (null != container) {

		// create heading container
		headingContainer = document.createElement('div');
		headingContainer.className = 'noke-calendar-heading-container';

		// append heading container
		container.appendChild(headingContainer);

		/*
			The order of creation below is important, as the styles
			are set to 'float: right'.  Should this change, then
			the order below may need to be changed as well.

			Because with a 'float: right' style, the first element
			will be on the far right, the order below must be
			from right-to-left, rather than left-to-right.
		 */

		// create next month control
		headingControl = document.createElement('div');
		headingControl.className = 'noke-calendar-control noke-calendar-control-next';
		headingControl.onclick = CalendarMonthNext;
		headingControl.appendChild(document.createTextNode('\xa0'));

		// append next control and remove DOM reference
		headingContainer.appendChild(headingControl);

		// append year (four-digit)
		headingText = document.createElement('div');
		headingText.className = 'noke-calendar-heading-year';
		headingText.id = NOKE_CALENDAR_HEADING_YEAR_ID;
		headingText = headingContainer.appendChild(headingText);
		headingText.appendChild(document.createTextNode(calendar.getFullYear()));

		// append month name
		headingText = document.createElement('div');
		headingText.className = 'noke-calendar-heading-month';
		headingText.id = NOKE_CALENDAR_HEADING_MONTH_ID;
		headingText = headingContainer.appendChild(headingText);
		headingText.appendChild(document.createTextNode(g_dateReference[calendar.getMonth()].name));

		// create previous month control
		headingControl = document.createElement('div');
		headingControl.className = 'noke-calendar-control noke-calendar-control-prev';
		headingControl.onclick = CalendarMonthPrev;
		headingControl.appendChild(document.createTextNode('\xa0'));

		// append previous control and remove DOM reference
		headingContainer.appendChild(headingControl);

		// clean up references
		headingContainer = null;
		headingControl = null;
		headingText = null;
	}

	return;
} /* )>>> */

function DrawCalendarDatesHeader(container) { /* <<<( */

	var dayOfWeekTable = null; // table that contains the day of the week headings
	var tableContainer = null; // table container for the day of the week table header
	var tableRow = null; // row in day of weeks table
	var tableCell = null; // cell in day of weeks table

	if (null != container) {

		// create date table
		dayOfWeekTable = document.createElement('table');
		dayOfWeekTable.id = NOKE_CALENDAR_DATE_TABLE_ID;
		dayOfWeekTable.cellSpacing = 0;
		dayOfWeekTable.cellPadding = 0;
		dayOfWeekTable.border = 0;

		// append table
		container.appendChild(dayOfWeekTable);

		// add row for day of week headings
		tableRow = dayOfWeekTable.insertRow(dayOfWeekTable.rows.length);

		// add cell for Sunday
		tableCell = tableRow.insertCell(tableRow.cells.length);
		tableContainer = document.createElement('div');
		tableContainer.className = 'noke-calendar-date-heading';
		tableContainer = tableCell.appendChild(tableContainer);
		tableContainer.appendChild(document.createTextNode('Su'));
		
		// add cell for Monday
		tableCell = tableRow.insertCell(tableRow.cells.length);
		tableContainer = document.createElement('div');
		tableContainer.className = 'noke-calendar-date-heading';
		tableContainer = tableCell.appendChild(tableContainer);
		tableContainer.appendChild(document.createTextNode('Mo'));
		
		// add cell for Tuesday
		tableCell = tableRow.insertCell(tableRow.cells.length);
		tableContainer = document.createElement('div');
		tableContainer.className = 'noke-calendar-date-heading';
		tableContainer = tableCell.appendChild(tableContainer);
		tableContainer.appendChild(document.createTextNode('Tu'));
		
		// add cell for Wednesday
		tableCell = tableRow.insertCell(tableRow.cells.length);
		tableContainer = document.createElement('div');
		tableContainer.className = 'noke-calendar-date-heading';
		tableContainer = tableCell.appendChild(tableContainer);
		tableContainer.appendChild(document.createTextNode('We'));
		
		// add cell for Thursday
		tableCell = tableRow.insertCell(tableRow.cells.length);
		tableContainer = document.createElement('div');
		tableContainer.className = 'noke-calendar-date-heading';
		tableContainer = tableCell.appendChild(tableContainer);
		tableContainer.appendChild(document.createTextNode('Th'));
		
		// add cell for Friday
		tableCell = tableRow.insertCell(tableRow.cells.length);
		tableContainer = document.createElement('div');
		tableContainer.className = 'noke-calendar-date-heading';
		tableContainer = tableCell.appendChild(tableContainer);
		tableContainer.appendChild(document.createTextNode('Fr'));
		
		// add cell for Saturday
		tableCell = tableRow.insertCell(tableRow.cells.length);
		tableContainer = document.createElement('div');
		tableContainer.className = 'noke-calendar-date-heading';
		tableContainer = tableCell.appendChild(tableContainer);
		tableContainer.appendChild(document.createTextNode('Sa'));
		
		// clean up references
		tableCell = null;
		tableRow = null;
		tableContainer = null;
		dayOfWeekTable = null;
	}

	return;
} /* )>>> */

function DrawCalendar(containerId) { /* <<<( */

	var container = document.getElementById(containerId);

	if (null != container) {

		RequestDates(g_currentDate);
		DrawCalendarHeading(container, g_currentDate);
		DrawCalendarDatesHeader(container);
		DrawCalendarDatesData(g_currentDate);
	}

	return;

} /* )>>> */


//initialize 2 static vars to ensure that only one popup will be presented on screen at any time
// each day-link on the calenday will create a timeout event on mouseout to destroy the popup div.
//   on mouseover, the popup div needs to cancel the link's timeout for the div
//   on mouseout of the popup div, the popup div needs to set a timeout to destroy itself.
var timeout_id = null;
var popupExists = false; //allow only one events popup hover div for the calendar
var eventDateForPopup = null; //distinguish this var from eventDate, which is used elsewhere in this file

function createDailyEventsPopup(eventDateForPopup, tableDataContainer) {
	//create and display a popup on the calendar with a synopsis of event data for the day being hovered over
    //popup will be able to manage it's presence by auto canceling timeouts on mouseover and setting
	//timeouts when losing focus

	//allow only one popup for calendar
	if (true == popupExists) {
		//user moved off of one date onto another before the timeout on the popup could occurr.
		//first clear existing timeout that will probably be scheduled
		clearTimeout(timeout_id);
		//now immediately destroy the div
		destroyDailyEventsPopup();
		//the next block (false===popupExists) should now execute
	}
	
	if (false == popupExists) {

		var popupNode = document.createElement('div');
		popupNode.className = 'popup-node-for-calendar';
		popupNode.setAttribute('id', 'popup_calendar_node');
		
		popupExists = true;

		//onmouseover event
		var popup_onmouseover_function = "cancelTimeout();";
		popupNode.onmouseover = Function(popup_onmouseover_function);
		//onmouseout event
		var popup_onmouseout_function = "setTimeoutForDailyEventsPopup(" + 1000 + ");";
		popupNode.onmouseout = Function(popup_onmouseout_function);

		//AJAX call to get actual data
		var eventLinksForPopup = ''; 
		//return markup for direct inclusion into the popup div.
		eventLinksForPopup = getDailyEventsForPopup(eventDateForPopup);
		popupNode.innerHTML = eventLinksForPopup;

		//append the popup to the document body and position absolutly @ the 
		//position of the mouse
		//attach to the popupTarget which was passed to this function above
		// via the element id of the date-link div
		var popupTarget = document.getElementById(eventDateForPopup);
		appendPopupToDocumentBody(popupNode, popupTarget);
		
		//the following method for attaching the popup to the document works, 
		//but IE 7 has z-index isses such that all other elements painted in the browser
		//after the calendar is created have a higher z-index than the popup.
		//append the popup div to the current date's parent div (will be a td)
		//
		//var currentDaysElement = document.getElementById(eventDateForPopup);
		//var currentDaysParentElement = currentDaysElement.parentNode;
		//currentDaysParentElement.appendChild(popupNode)

	}//popup exists?
} 


function appendPopupToDocumentBody(popupNode, popupTarget) {
	//append the popup to the document body and position absolutly @ the 
	//position of the mouse

	//get height of document
	var clientY = document.body.scrollHeight;
	//get window height
	var windowHeight = 0;
	windowHeight = getWindowHeight(windowHeight);

	//get scroll bar position
	var scrollPos = 0;
	scrollPos = getScrollBarPosition(scrollPos);

	//get the offset of the tableDataContainer (which is the parent
	// of date link on the calendar.  we want to attach the popup
	// to the document just to the right of the tableDataContainer
	var arr_winDimensions = new Array();
	arr_winDimensions['height'] = 0;
	arr_winDimensions['width'] = 0;
  	arr_winDimensions = getOffsetDimensions(popupTarget, arr_winDimensions);	

	//must adjust for differences in browser positioning
	var isBrowserIE = isIE();
	if (true === isBrowserIE) {
		//IE requires a slight adjustment to move the control to the left and down 
		arr_winDimensions['height'] += 0;
		arr_winDimensions['width'] -= 380; 

	} else {
		//FF requires moving the control further left and down than IE
		arr_winDimensions['height'] += 20; 
		//arr_winDimensions['width'] -= arr_winDimensions['width'];
		arr_winDimensions['width'] -= 380;
	}

	//now absolutly position the element and append it to the document's body.
	popupNode.style.position = "absolute";
	popupNode.style.top = arr_winDimensions['height'] + 'px';
	popupNode.style.left = arr_winDimensions['width'] + 'px';
	popupNode.style.fontFamily = "sans-serif";
	document.body.appendChild(popupNode);

}

function getOffsetDimensions(targetElement, arr_winDimensions) { /* <<<( */

	if (null != targetElement && targetElement.offsetParent) {
		while (targetElement = targetElement.offsetParent) {
			arr_winDimensions['height'] += targetElement.offsetTop;
			arr_winDimensions['width'] += targetElement.offsetLeft;
		}
	}
	return arr_winDimensions;
} /* )>>> */


function cancelTimeout() { 
	if (null !== timeout_id && true === popupExists) {
		clearTimeout(timeout_id);
		timeout_id = null;
	} else {
		destroyDailyEventsPopup();
	}
} 


function setTimeoutForDailyEventsPopup(timeToLive) { 
	if (null !== timeout_id) {
		//immediately clear any existing timeout
		cancelTimeout();
		destroyDailyEventsPopup();	
	}	
	if ( (document.getElementById("popup_calendar_node")) ) {
		//set the timeout to destroy the popup div
		if (null == timeout_id && true === popupExists) {
			timeout_id = setTimeout(destroyDailyEventsPopup, timeToLive);
		} else {
		}
	}
} 


function destroyDailyEventsPopup() {

	if (true === popupExists) {
		//get the element containing the <a> tag
		if ((document.getElementById('popup_calendar_node')) && (null !== timeout_id))  {
			var currentDaysPopup = document.getElementById("popup_calendar_node");
			var currentPopupParentElement = currentDaysPopup.parentNode;
			currentPopupParentElement.removeChild(currentDaysPopup);
			timeout_id = null;
			//this is the only place where popupExists should be set to false
			popupExists = false;
		}
	}
}


function AddDateCell(tableRow, cellData, eventDate, currYear, currMonth) { /* <<<( */

var tableCell = null;
var tableDataContainer = null;
var eventLink = null;

if (null != tableRow) {

	tableCell = tableRow.insertCell(tableRow.cells.length);
	tableDataContainer = document.createElement('div');
	tableDataContainer.className = 'noke-calendar-date';
	if ('' != eventDate) {
		tableDataContainer.className += ' noke-calendar-date-event';
		tableDataContainer = tableCell.appendChild(tableDataContainer);
		eventLink = document.createElement('a');
		eventLink.href = NOKE_CALENDAR_EVENTS_URL + '?year=' + currYear + '&month=' + currMonth + NOKE_CALENDAR_EVENTS_LINK_PREFIX + eventDate;
		
		//added to easily get parent node of the current date's element for positioning the popup div.
		eventLink.setAttribute("id", eventDate); 
		
		// add event listeners to link for mouse over/out
		eventLink.onmouseover = function () {
			createDailyEventsPopup(eventDate, tableDataContainer);
		};

		var link_onmouseout_function = "setTimeoutForDailyEventsPopup(" + 500 + ");";
		eventLink.onmouseout = Function(link_onmouseout_function);
		eventLink = tableDataContainer.appendChild(eventLink);
		eventLink.appendChild(document.createTextNode(cellData));
	}
	else {
		tableDataContainer = tableCell.appendChild(tableDataContainer);
		tableDataContainer.appendChild(document.createTextNode(cellData));
	}

	tableDataContainer = null;
	tableCell = null;
}

return;
} /* )>>> */

function CalendarMonthPrev() { /* <<<( */

	var monthHeading = document.getElementById(NOKE_CALENDAR_HEADING_MONTH_ID);
	var yearHeading = document.getElementById(NOKE_CALENDAR_HEADING_YEAR_ID);
	var month = g_currentDate.getMonth(); // get current month

	// check if month is January
	if (0 == month) {

		// decrement year and set month to December
		var year = g_currentDate.getFullYear() - 1;
		g_currentDate.setFullYear(year);
		month = 11;
	}
	else {
		// decrement month index
		month--;
	}

	// set new month in global calendar
	g_currentDate.setMonth(month);

	// get new events
	RequestDates(g_currentDate);

	// replace month name on calendar
	if (null != monthHeading) {
		RemoveChildNodes(monthHeading);
		monthHeading.appendChild(document.createTextNode(g_dateReference[g_currentDate.getMonth()].name));
	}

	// replace year on calendar
	if (null != yearHeading) {
		RemoveChildNodes(yearHeading);
		yearHeading.appendChild(document.createTextNode(g_currentDate.getFullYear()));
	}

	// remove old dates
	RemoveDates();

	// create new dates
	DrawCalendarDatesData(g_currentDate);

	return;
} /* )>>> */

function CalendarMonthNext() { /* <<<( */

	var monthHeading = document.getElementById(NOKE_CALENDAR_HEADING_MONTH_ID);
	var yearHeading = document.getElementById(NOKE_CALENDAR_HEADING_YEAR_ID);
	var month = g_currentDate.getMonth(); // get current month

	// check if month is December
	if (11 == month) {

		// increment year and set month to January
		var year = g_currentDate.getFullYear() + 1;
		g_currentDate.setFullYear(year);
		month = 0;
	}
	else {
		// increment month index
		month++;
	}

	// set new month in global calendar
	g_currentDate.setMonth(month);

	// get new events
	RequestDates(g_currentDate);

	// replace month name on calendar
	if (null != monthHeading) {
		RemoveChildNodes(monthHeading);
		monthHeading.appendChild(document.createTextNode(g_dateReference[g_currentDate.getMonth()].name));
	}

	// replace year on calendar
	if (null != yearHeading) {
		RemoveChildNodes(yearHeading);
		yearHeading.appendChild(document.createTextNode(g_currentDate.getFullYear()));
	}

	// remove old dates
	RemoveDates();

	// create new dates
	DrawCalendarDatesData(g_currentDate);

	return;
} /* )>>> */

function IsLeapYear(year) { /* <<<( */

	var isLeapYear = false;

	/*
		A year is a leap year if it is divisible by 4.  If the year is also divisible
		by 100, then it is not a leap year UNLESS it is also divisible by 400.
	 */
	if (0 == (year % 4)) {

		// preliminarily set leap year to true
		isLeapYear = true;

		// is year divisible by 100?
		if (0 == (year % 100)) {

			// if year is also not divisible by 400, then it is not a leap year
			if (0 != (year % 400)) {
				isLeapYear = false;
			}
		}
	}


	return isLeapYear;
} /* )>>> */

function RemoveDates() { /* <<<( */

	var dateTable = document.getElementById(NOKE_CALENDAR_DATE_TABLE_ID);

	if (null != dateTable) {

		// remove all but the header row
		while (1 < dateTable.rows.length) {

			// remove all cells
			while (0 < dateTable.rows[1].cells.length) {

				// remove cells and data from cells
				RemoveChildNodes(dateTable.rows[1].cells[0]);
				dateTable.rows[1].deleteCell(0);
			}

			// remove table row
			dateTable.deleteRow(1);
		}
	}

	return;
} /* )>>> */

function RemoveChildNodes(container) { /* <<<( */

	while (true == container.hasChildNodes()) {
		RemoveChildNodes(container.lastChild);
		container.removeChild(container.lastChild);
	}

	return;
} /* )>>> */


function getDailyEventsForPopup(eventDateForPopup) {
	var dailyEventRequest = GetXmlRequest();
	var dailyEventRequest_url = NOKE_CALENDAR_DAILY_EVENT_REQUEST_URL + '?eventDate=' + eventDateForPopup;
	//var dailyEventString = '';  //hold the result
	// the result of the query will be a markup-formatted string which will be ready for insertion into the popup div.
	
	var dailyEvents = null;
	if (null != dailyEventRequest) {
		dailyEventRequest.open('GET', dailyEventRequest_url, false);
		dailyEventRequest.send(null);

		dailyEvents = eval("(" + dailyEventRequest.responseText + ")");
	}
	//console.log(dailyEvents);	
	return dailyEvents;
}


function RequestDates(calendar) { /* <<<( */

	var request = GetXmlRequest();
	var request_url = NOKE_CALENDAR_REQUEST_URL + '?month=' + (calendar.getMonth() + 1) + '&year=' + calendar.getFullYear();

	if (null != request) {
		request.open('GET', request_url, false);
		request.send(null);

		g_currentEvents = eval("(" + request.responseText + ")");
	}

	return;
} /* )>>> */

// returns an XMLHttpRequest object
function GetXmlRequest() { /* <<<( */

	var obj_xml_request = null;

	// firefox, Opera, Safari
	try {
		obj_xml_request = new XMLHttpRequest();
	}
	catch (e) {

		// Internet Explorer
		try {
			obj_xml_request = new ActiveXObject('Msxml2.XMLHTTP');
		}
		catch (e) {

			// Internet Explorer (alternative)
			try {
				obj_xml_request = new ActiveXObject('Microsoft.XMLHTTP');
			}
			catch (e) {
				alert('Sorry, your browser does not support AJAX.');
			}
		}
	}

	return obj_xml_request;
} /* )>>> */


function getWindowHeight(windowHeight) {
	if (!window.innerHeight) {
		//using IE
		if (0 == document.documentElement.clientHeight) {
			//using IE quirks mode
			windowHeight = document.body.clientHeight;
		} else {
			//using IE strict
			windowHeight = document.documentElement.clientHeight;
		}
	} else {
		// NOT using IE
		windowHeight = window.innerHeight;
	}//!win.innerHeight

	return windowHeight;
}


function isIE() {
	if ('number' == typeof(window.pageYOffset)) {
		//NOT IE
		return false;

	} else if (document.body && document.body.scrollTop) {
		//DOM compliant IE
		return true;

	} else if (document.documentElement && document.documentElement.scrollTop) {
		//IE 6 standards compliant mode
		return true;
	}
}


function getScrollBarPosition(scrollPos) {
	if ('number' == typeof(window.pageYOffset)) {
		// non-IE
		scrollPos = window.pageYOffset;
	} else if (document.body && document.body.scrollTop) {
		// DOM compliant IE
		scrollPos = document.body.scrollTop;
	} else if (document.documentElement && document.documentElement.scrollTop) {
		//IE6 standards compliant mode
		scrollPos = document.documentElement.scrollTop;
	}

	return scrollPos;
}

