	//timeSelector jQuery UI Plugin,
	//written by Andrew R. Dennis
	//Free for non-commercial use.

<script type="text/JavaScript" src="js/jquery-1.3.2.js"></script>

	//SETTING UP OUR POPUP  
	//0 means disabled; 1 means enabled;  
	var popupStatus = 0;  
	
	$(function() {
	
		cellsperrow = 4;
		earlyrowshide = 2;
		laterowshide = 1;
		row = 0;
			
		$('#timeSelectorPopup').append("<a id='popupContactClose'>Close</a>");
		$('#timeSelectorPopup').append("<table id='tsMainTable' border=1>");
		$('#tsMainTable').append("<tr id='earlyHoverRow' />");
		$('#earlyHoverRow').append("<td class='leftblankcell'/><td class='blankcells'/><td id='earlyHoverTd' colspan='" + (cellsperrow-2) + "' >Early Hours</td>");
		
		for (var hour=0;hour<24;) {
			rowclass = '';
			if (hour%cellsperrow == 0) {
				if (row < earlyrowshide) {rowclass = " class='earlyhours '";}
				if (row >= (24/cellsperrow)-laterowshide) {rowclass = " class='latehours '";}
				row++;
				$('#tsMainTable').append("<tr id='tsMainRow"  + row + "'"  + rowclass + ">");
			}
			
			textTime = '';
			if (hour == 0) {textTime = '12a'; ampm='a';}
			else if (hour < 12) {textTime = hour + 'a'; ampm='a';}
			else if (hour == 12) {textTime = '12p'; ampm='p';}
			else if (hour > 12) {textTime = (hour-12) + 'p'; ampm='p';}
			
			$('#tsMainRow' + row).append("<td id='tsCell" + hour + "'>");
			$('#tsCell' + hour ).append("<table class='quarttable' id='tsCellTable" + hour + "'>");
			$('#tsCellTable' + hour).append("<tr id='tsCellHeaderRow" + hour + "'>");
			$('#tsCellHeaderRow' + hour).append("<th class='zeromin timebox' colspan=4 align=left id='" + hour + ":00'>" + textTime +"</td>");
			$('#tsCellTable' + hour).append("<tr id='tsCellQuartRow" + hour + "'>");
			$('#tsCellQuartRow' + hour).append("<td  class='fifteenmin timebox' id='" + hour + ":15'>:15</td>");
			$('#tsCellQuartRow' + hour).append("<td  class='thirtymin timebox' id='" + hour + ":30'>:30</td>");
			$('#tsCellQuartRow' + hour).append("<td  class='fortyfivemin timebox' id='" + hour + ":45'>:45</td>");
			
			hour++;
		}

		$('#tsMainTable').append("<tr id='lateHoverRow' />");
		$('#lateHoverRow').append("<td class='leftblankcell'/><td class='blankcells'/><td id='lateHoverTd' colspan='" + cellsperrow + "' >Late Hours</td>");

		
		$('.timeSelector').each( function() {
			this.onclick = function(event) {
				if (!event) event=window.event;  //MS BS
				
				callingElement = this;
				//centering with css  
				centerPopup(event);  
				//load popup  
				loadPopup();  
				
				
				//alert(callingElement);
			}
		});
		
		$('.timebox').each( function() {
			this.onclick = function(event) {
				if (!event) event=window.event;  //MS BS
				
				tmpTime = this.id;
				timeArray = tmpTime.split(':');
				hour = timeArray[0];
				min = timeArray[1];
				if (hour == 0) {textTime = '12'; ampm='a';}
				else if (hour < 12) {textTime = hour; ampm='a';}
				else if (hour == 12) {textTime = '12'; ampm='p';}
				else if (hour > 12) {textTime = (hour-12); ampm='p';}
				
				finalTime = textTime + ':' + min + ampm;
				//alert(finalTime);
				$(callingElement).text(finalTime);
				disablePopup();
				//this.id.append('q');
			}
		});

		$('#earlyHoverTd').bind('mouseover', enableRows);
		$('#lateHoverTd').bind('mouseover', enableRows);
		
		function enableRows(event){   
			$("#earlyHoverRow").fadeOut("slow");  
			$("#lateHoverRow").fadeOut("slow");  
			$("#tsMainRow1").fadeIn("slow"); 
			$("#tsMainRow2").fadeIn("slow"); 
			$("#tsMainRow6").fadeIn("slow");  
		} 
			
		function loadPopup(){  
		 //loads popup only if it is disabled  
			 if(popupStatus==0){  
				 $("#backgroundPopup").css({  
					 "opacity": "0.7"  
				 });  
				 $("#backgroundPopup").fadeIn("slow");  
				 $("#timeSelectorPopup").fadeIn("slow");  
				 popupStatus = 1;  
			 }  
		} 
		
		//disabling popup with jQuery magic!  
		function disablePopup(){  
		//disables popup only if it is enabled  
			if(popupStatus==1){  
				$("#earlyHoverRow").fadeIn("slow");  
				$("#lateHoverRow").fadeIn("slow");  
				$("#tsMainRow1").fadeOut("slow"); 
				$("#tsMainRow2").fadeOut("slow"); 
				$("#tsMainRow6").fadeOut("slow"); 
				$("#backgroundPopup").fadeOut("slow");  
				$("#timeSelectorPopup").fadeOut("slow");   
				popupStatus = 0;  
			}  
		}  
		
		//centering popup  
		function centerPopup(event){    
			//centering  
			$("#timeSelectorPopup").css({  
				"position": "absolute",  
				"top": event.clientY + 2,  
				"left": event.clientX + 2 
			});  
		
			//only need force for IE6  
			var windowHeight = document.documentElement.clientHeight;
			$("#backgroundPopup").css({  
				"height": windowHeight  
			});  
		} 
		

		//CLOSING POPUP  
		//Click the x event!  
		$("#popupContactClose").click(function(){  
			disablePopup();  
		});  
		//Click out event!  
		$("#backgroundPopup").click(function(){  
			disablePopup();  
		});  
		//Press Escape event!  
		$(document).keypress(function(e){  
			if(e.keyCode==27 && popupStatus==1){  
				disablePopup();  
			}  
		}); 
		


	});


