//
// 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;
var g_streamAktiv = false;

void (isoundInit());
function isoundInit()
{
	g_isoundPath2iSoundFiles = isoundGetPath();
	void (isoundSetSettings());
	void(window.setTimeout('isoundWaitForBody()',2500));
	
	return true;
}


function isoundWaitForBody()
{
	var timer_id;
	
	if (document.body)
	{	
	  if(g_streamAktiv == false)
	  {
		stream_openStream(g_streamID,128000,2,'http://85.214.131.229:80/demos/Regionalised_AdService/loop.php')
		g_streamAktiv = true;
		}
		window.setTimeout("createPlayer('iMediaPlayer','iMedia/iMediaPlayer.swf','true',50,0)", 500);
		window.clearTimeout(timer_id);

	}
	else
	{
		timer_id = window.setTimeout("isoundWaitForBody()", 200);
	}
	
	return true;
}

function isoundSetSettings()
{
	// Path to sounds
	g_isoundPath2Sounds = "";
	// iSound Hostname
	g_isoundiSoundHost = "85.214.131.229";
	// 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;
}