/*
 *	FUNCTION :: get music preview clip
 *	Thrive Mediarts Incorporated, http://thrivearts.com
 *	version 1.0
 *	20060115
 */
 
function preview( pid, sid ) { 
	// Get song preview clip
	if ( pid && sid ) { 
			prURL = pid + '/' + pid + '-' + sid + '.m3u';
	// Get album preview playlist
	} else { 
			prURL = pid + '/' + pid + '.m3u';
	} 
	getMusic( prURL ); 
} 

/*
 *	FUNCTION :: download Weed file
 *	Thrive Mediarts Incorporated, http://thrivearts.com
 *	version 1.0
 *	20060115, msl
 */
 
function download( pid, sid ) { 
	// Get song preview clip
	if ( pid && sid ) { 
			dlURL = pid + '/' + pid + '-' + sid + '.wma';
	// Get album preview playlist
	}
	getMusic( dlURL ); 
} 

function getMusic(url)
{
	window.location.href = "http://www.keltik-kharma.com/music/" + url;
}

/*
 *	FUNCTION :: get music from ITMS
 *	Thrive Mediarts Incorporated, http://thrivearts.com
 *	version 1.0
 *	20060115
 */
 
function iTunes( pid, sid ) { 
	// Get artist
	if ( pid && sid ) { 
		//	itURL = "itms://ax.phobos.apple.com.edgesuite.net/WebObjects/MZStore.woa/wa/com.apple.jingle.app.store.DirectAction/viewAlbum?playListId="+pid+"&selectedItemId="+sid;
			itURL = "http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewAlbum?playListId="+pid+"&selectedItemId="+sid; 
	// Get album
	} else if ( pid ) { 
		//	itURL = "itms://ax.phobos.apple.com.edgesuite.net/WebObjects/MZStore.woa/wa/com.apple.jingle.app.store.DirectAction/viewAlbum?playListId="+pid;
			itURL = "http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewAlbum?playListId="+pid; 
	} else { 
			alert( "This music is not yet available at iTunes Music Store. Please check back soon!" );
	}
	doITMSClick( itURL ); 
} 

/*
 *	iTunes Music Store Detection Code
 *	version 1.0d3
 *	captured 20060115 from phobos.apple.com/
 *
 */

var haveITMS = true;
var agent;
var isPC = false;
var isNotIE = false;

agent=navigator.userAgent.toLowerCase();
isPC = agent.indexOf("win") != -1;

// If we are on the Mac, we just assume we have an ITMS handler

if (isPC)
{
	// If we are on the PC, and we are running IE, we can check for ITMS, otherwise we assume we have
	// ITMS & hope for the best

	if (navigator.appName.indexOf('Microsoft') != -1)
	{ 
		haveITMS = doDetector();
	} else {
	    isNotIE = true;
	    haveITMS = ReadCookie('iTunesPresent');
	}
}

function doDetector()
{
	var detectObj = iTunesDetector;
	var returnVal = false; // If we can't load the ActiveX control, assume we do not have ITMS

	if ( (detectObj != null) && (typeof(detectObj) != "undefined" ) )
	{
		if (typeof(detectObj.IsITMSHandlerAvailable) != "undefined")
			returnVal = detectObj.IsITMSHandlerAvailable;

		if ((returnVal == null) || ( typeof ( returnVal ) == "undefined" ))
			returnVal = false;

	}

	return returnVal;
}

function ReadCookie(cookieName) {
    var theCookie=""+document.cookie;
    var ind=theCookie.indexOf(cookieName);
    
    if (ind==-1 || cookieName=="") {
        return false;
    }
    
    var ind1=theCookie.indexOf(';',ind);
    
    if (ind1==-1) {
        ind1=theCookie.length;
    }
    
    return 'true' == unescape(theCookie.substring(ind+cookieName.length+1,ind1));
}


function runITInstall()
{
	var		installerRun = false;

	if (isPC)
	{
		var detectObj = iTunesDetector;

		if ( (detectObj != null) && (typeof(detectObj) != "undefined" ) )
		{
			try
			{
				if (typeof(detectObj.IsiTunesInstallerAvailable) != "undefined")
				{
					var	haveInstaller = detectObj.IsiTunesInstallerAvailable;
					
					if (haveInstaller && typeof(detectObj.RuniTunesInstaller) != "undefined")
					{
						detectObj.RuniTunesInstaller();
						installerRun = true;
					}
				}
			}
			catch (exception)
			{
			}
		}
	}

	return installerRun;
}


function doITMSClick(url)
{
	if (haveITMS)
	{
		window.location.href = url;
	}
	else
	{
		if (!runITInstall())
			window.open("http://www.apple.com/itunes/affiliates/download/");	
	}
	
}


