/**
  * musicframe - Insure's the web page is in a frameset
  *
  * Copyright (C) 2005 Red Spark <mitch@redspark.com>
  * 
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License.
  * 
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
  * 
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  *
  * @version 1.2
  *
  */

function NewFullURL( BaseURL, NewURL )
{
	// if it is a full URL
	if( NewURL.match( /.*:\/\// ) )
	{
		return NewURL;
	}
	// if it is an absolute path
	else if( NewURL.indexOf( '/ ') == 0 )
	{
		return NewURL;
	}
	// if it is a relative path
	else
	{
		FullURL = BaseURL;

		// remove the ending file, if there is one
		if( FullURL.length > 0 && FullURL.charAt( FullURL.length - 1 ) != '/' )
		{
			FullURL = FullURL.substring( 0, FullURL.lastIndexOf( '/' )+1 );
		}

		while( NewURL.indexOf( '../' ) == 0 )
		{
			if( FullURL.length > 0 && FullURL.lastIndexOf( '/', FullURL.length-2 ) >= 0 )
			{
				FullURL = FullURL.substring( 0, FullURL.lastIndexOf( '/', FullURL.length-2 )+1 );
			}

			NewURL = NewURL.substring( 3 );
		}

		return FullURL + NewURL;
	}
}

function InsureTopFrame( FrameURL )
{
	var CurrentTopURL = top.location.href;
	if( CurrentTopURL.lastIndexOf('?') > 0 )
	{
		CurrentTopURL = CurrentTopURL.substring( 0, CurrentTopURL.lastIndexOf('?') );
	}

	if( CurrentTopURL != NewFullURL( location.href, FrameURL ) )
	{
		top.location.href = FrameURL + '?src=' + location.href;
	}
}
