function PassageParser(){

		this.distance = 10;    
		this.animationTime = 50;    
		this.hideDelay = 1;
		this.contentSelector="#post";
		this.loadingImagePath = '/passageLookup/';
		var passageHandlerUrl = "http://www.roanokechurchofchrist.org/passageLookup/PassageHandler.php";
	this.setPassageHandlerUrl = function(url){
	passageHandlerUrl = url;
	}
	this.parse = function (){
		if ( !Get_Cookie( 'ql-version' ) ){
			Set_Cookie( 'ql-version', '1', '60', '/', '', '' );

			}

			var version = Get_Cookie( 'ql-version' ) -1;
			$("input[name='ql-ver']:nth("+version+")").attr("checked",true); //Check the radio
			setName();
			var regex=/(?:\d|I{1,3})?\s?\w{2,}\.?\s*\d{1,}\:\d{1,}-?,?\d{0,2}(?:-\d{0,2}){0,2}/gi;
			
			var post = $(this.contentSelector).html();
			
			if (post !=null){
				matches  = post.match(regex);
				if (matches.length>0){
					var i=0;
					for (i=0;i<matches.length;i++){
						post = post.replace(matches[i],'<cite class=passage>'+matches[i]+'</cite>');
					}
					$(this.contentSelector).html(post);
				}
			}
    
		var hideDelayTimer = null;    
		// tracker    
		var beingShown = false;    
		var shown = false;        
		//var trigger = $('.trigger', this);    
		var popup = $('#passageContainer');
		popup.css('opacity', 1);    
		// set the mouseover and mouseout on both element    
		$('cite.passage,#passageContainer').mouseover(function () {     
			
			// stops the hide event if we move from the trigger to the popup element      
			if (hideDelayTimer) clearTimeout(hideDelayTimer);      

			// don't trigger the animation again if we're being shown, or already visible      
			if (beingShown || shown) {        
				
				return;      
			} else {       
				
				 beingShown = true;        
				 // reset position of popup box      
				 $('#passageBox h1').html("Please Wait");
				 $('#passageBox p').html("<img src='/passageLookup/ajax-loader.gif'> Loading " +$(this).text() +"..." );
				var origOffset = $(this).offset();
				var offset = $(this).offset();

				$.getJSON(passageHandlerUrl+'?version='+Get_Cookie( 'ql-version' )+'&passage='+$.trim($(this).text()+'&jsoncallback=?'), function(data) {
					//set title
					$('#passageBox h1').html(data.passage);

					//format the text
					var html='';
						$.each(data.verses,function( intIndex, verse ){html+=verse.versenumber + ') ' + verse.content+'<br />';});
						$('#passageBox p').html(html);
						});
					var leftOffset =  offset.left -Math.abs($(this).width()-popup.width())/2 ;

					if(leftOffset <=0) leftOffset =0;

					if (leftOffset + popup.width()> $(window).width())leftOffset = $(window).width()-popup.outerWidth();
				if (offset.top-$(this).height()-$(window).scrollTop() < popup.height()){
					showWhich = 'Top';

					cssarr={          
							top:offset.top+$(this).height()-15,
							left: leftOffset,
							 display: 'block' 
       
							 };
					 aniarr = {          
							 //top: '+=' + this.distance,          
							 opacity: 1        
						 };
					 aniarroff={          
							 //top: '+=' + this.distance ,          
							 opacity: 0        
							 };
				}else{
					showWhich = 'Bottom';
					cssarr={          
							top:offset.top-$(this).height()-popup.height()-5,
							left: leftOffset,
							 display: 'block' 
    
							 };
					 aniarr = {          
							 //top: '-=' + this.distance ,          
							 opacity: 1        
						 }	;
					 aniarroff={          
							 //top: '-=' + this.distance,          
							 opacity: 0        
							 };					 
				}
				 popup.css(cssarr).animate(aniarr,this.animationTime,'swing', 
					 function() {          
						// once the animation is complete, set the tracker variables          
						beingShown = false;          
						shown = true;    
					});      
				
				 }    
			 }).mouseout(function () {      
				 // reset the timer if we get fired again - avoids double animations      
				 if (hideDelayTimer) clearTimeout(hideDelayTimer);            
				 // store the timer so that it can be cleared in the mouseover if required      
				 hideDelayTimer = setTimeout(function () {        
					hideDelayTimer = null;        
					popup.animate(aniarroff, this.animationTime, 'swing', function () {          
							 // once the animate is complete, set the tracker variables          
							 shown = false;  
							 beingShown=false;							 
							 // hide the popup entirely after the effect (opacity alone doesn't do the job)          
							 popup.css('display', 'none');   
							 var offset = $(this).offset();

							 popup.offset(offset);     
							 });      
					 }, this.hideDelay);    
				
				 });  
		// });
		}
	this.changeSize = function(size){
			
			$('#passageBox p').animate({height:(size=='l')?108:162},500);
		}		
	
	this.setVer = function (radio){

			Set_Cookie( 'ql-version', radio.value, '60', '/', '', '' );
			setName();
			updateVerse();
			this.changeSize('s');
			
		}

	function setName(){
			var verId = $("input[name='ql-ver']:checked").val();
			$('#ql-vername').html((verId==1)?'KJV':'ASV');
		}

	function updateVerse(){

		$.getJSON(passageHandlerUrl+'?version='+Get_Cookie( 'ql-version' )+'&passage='+$.trim($('#passageBox h1').text()+'&jsoncallback=?'), function(data) {
		$('#passageBox h1').html(data.passage);
		var html='';
			$.each(
					data.verses,
					function( intIndex, verse ){

					html+=verse.versenumber + ' ' + verse.content+'<br />';
					}
					);
			$('#passageBox p').html(html);
			});
		
	}

	function Set_Cookie( name, value, expires, path, domain, secure ){
		// set time, it's in milliseconds
		var today = new Date();
		today.setTime( today.getTime() );

		/*
		if the expires variable is set, make the correct
		expires time, the current script below will set
		it for x number of days, to make it for hours,
		delete * 24, for minutes, delete * 60 * 24
		*/
		if ( expires )
		{
		expires = expires * 1000 * 60 * 60 * 24;
		}
		var expires_date = new Date( today.getTime() + (expires) );

		document.cookie = name + "=" +escape( value ) +
		( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
		( ( path ) ? ";path=" + path : "" ) +
		( ( domain ) ? ";domain=" + domain : "" ) +
		( ( secure ) ? ";secure" : "" );
		}

	function Get_Cookie( check_name ) {
			// first we'll split this cookie up into name/value pairs
			// note: document.cookie only returns name=value, not the other components
			var a_all_cookies = document.cookie.split( ';' );
			var a_temp_cookie = '';
			var cookie_name = '';
			var cookie_value = '';
			var b_cookie_found = false; // set boolean t/f default f

			for ( i = 0; i < a_all_cookies.length; i++ )
			{
				// now we'll split apart each name=value pair
				a_temp_cookie = a_all_cookies[i].split( '=' );


				// and trim left/right whitespace while we're at it
				cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

				// if the extracted name matches passed check_name
				if ( cookie_name == check_name )
				{
					b_cookie_found = true;
					// we need to handle case where cookie has no value but exists (no = sign, that is):
					if ( a_temp_cookie.length > 1 )
					{
						cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
					}
					// note that in cases where cookie is initialized but no value, null is returned
					return cookie_value;
					break;
				}
				a_temp_cookie = null;
				cookie_name = '';
			}
			if ( !b_cookie_found )
			{
				return null;
			}
		}

	function transferText(){
			
			$('#post').html($('#testText').val());
			this.parse();
		}
}
