//
// isound.js - General configuration, plugin detection and player integration
// Version 1.0.0
// Author Michael Pelny
// (c) Audiantis GmbH, 2007
// http://www.audiantis.com/
//

// Declaration
var g_isoundPath2Sounds;
var g_isoundiSoundHost;
var g_isoundStreamID;
var g_isoundStreamingURL;
var g_isoundFlash;
var g_isoundJava;
var g_isoundBrowser;
var g_isoundPath2iSoundFiles;

void (isoundInit());
checkBrowserName("safari");
setScriptLocation("./isound/remote.php");

function checkBrowserName(name){  
    var agent = navigator.userAgent.toLowerCase();  
    if (agent.indexOf(name.toLowerCase())>-1) {  
      enableSafari();  
    }  
    	  
}  

function isoundInit()
{
	g_isoundPath2iSoundFiles = isoundGetPath();
	void (isoundSetSettings());
	void(isoundWaitForBody());
	
	return true;
}

function isoundWaitForBody()
{
	var timer_id;
	
	if (document.body)
	{	
		//void (isoundLoadPlayer());
		window.clearTimeout(timer_id);
	}
	else
	{
		timer_id = window.setTimeout("isoundWaitForBody()", 200);
	}
	
	return true;
}

function isoundSetSettings()
{
	// Path to sounds
	g_isoundPath2Sounds = "sounds/vincenzo/";
	// iSound Hostname
	g_isoundiSoundHost = "85.214.131.230";
	// Don't change. Stream ID is generated by API
	g_isoundStreamID = stream_init(g_isoundiSoundHost, "", "", "", "", "");
	
	
	// Complete streaming URL for Player 
	g_isoundStreamingURL = stream_getURL();
	
	return true;
}



function isoundGetPath()
{
	var ret;
	var objScript;
	var pos;
	var len;
	var src;
	var path;
	
	ret = "";
	objScript = "";
	pos = 0;
	len = 0;
	src = "";
	path = "";
	
	len = document.getElementsByTagName("script").length;
	len--;
	objScript = document.getElementsByTagName("script")[len];
	src = objScript.getAttribute("src");
	pos = src.indexOf("isound.js");
	if (pos == -1)
	{
		pos = src.indexOf("isound-api.js");
	}
	path = (pos == 0) ? "" : src.substr(0, pos);
	ret = path;

	return ret;
}