/**
 * setYahooDir.js
 * @author R.A. Ray
 * @version 0.1.0
 * @date 06/09/08
 * 
 * @requires /scripts/jquery/core.js
 */

var setYahooDir = function ()
{
	$( '.get-dir' ).click( function ()
		{
			to_y();
		}
	);
};

var to_y = function () 
{
	var address = '';
	
	$( '.dir' ).each( function ( i )
		{
			var val = $( this ).attr( 'value' );
			
			if( val )
			{
				if( i > 0 )
				{
					address = address + "+" + ( trim( val ) ).replace(/ /g,'+');
				}
				else
				{
					address = address + ( trim( val ).replace(/ /g,'+') );
				}
			}
		}
	);
	
	var y_url="http://maps.yahoo.com/index.php#mvt=m&q2=1803%20Deacon%20Drive%20College%20Station%2C%20TX%2077845+&q1=" + address;
				
	window.open( y_url, "YahooMaps" );
};

var trim = function ( str )
{  
	while( str.charAt(0) == (" ") )
	{  
		str = str.substring(1);
	}
	
	while( str.charAt(str.length-1) == " " )
	{  
		str = str.substring(0,str.length-1);
	}
	
	return str;
};

$( document ).ready(
	function ()
	{
		setYahooDir();	
	}
);


