/******************************************************************************

  util-edenfm.js - Common functions for Antfarm-P2P-enabled web broadcasts.

  (C) 2007 Antfarm, Rawflow

 ******************************************************************************/

var secs
var timerID = null
var timerRunning = false
var delay = 1000
var haStarted = false
var isEnd = false
var client
////////////////////////////// Utility Functions //////////////////////////////

function doPopups() {
  if (!document.getElementsByTagName) return false;
  var links=document.getElementsByTagName("a");
  for (var i=0; i < links.length; i++) {
    if (links[i].className.match("popup1")) {
      links[i].onclick=function() {
        // Below - to open a full-sized window, just use: window.open(this.href);
        window.open(this.href, "", "top=200,left=200,width=355,height=327,scrollbars=no");
        return false;
      }
    }
    if (links[i].className.match("popup2")) {
      links[i].onclick=function() {
        // Below - to open a full-sized window, just use: window.open(this.href);
        window.open(this.href, "", "top=200,left=200,width=355,height=207,scrollbars=no");
        return false;
      }
    }
  }
}

function killP2PClient() {

	client = null;
	player = null;
        setLoadingElement("Unloading");
        return client;
}

function InitializeMediaPlayer(os) {

    if (os=="time-limit") {
       alert("As you are using a browser that is not supported by the P2P streaming service, your streaming session does not share in the P2P streaming network and it is therefore necessary to limit your listening session period to 1 hour. After an hour of streaming elapses, you will be automatically disconnected...");
       doStart(client, player);
       InitializeTimer();
    }
    else		
       doStart(client, player);	
}

function InitializeTimer()
{
    // set the player timeout, in seconds
    secs = 3600
    StopTheClock()
    StartTheTimer()
}

function StopTheClock()
{
    if(timerRunning)
        clearTimeout(timerID)
    timerRunning = false
}

function StartTheTimer()
{
    if (secs==0)
    {
        StopTheClock();
	haStarted = false;
	isEnd = true;
//	killP2PClient();
	self.location = "endplayer.asp";
        alert("Your streaming session limit of 1 hour has elapsed.");
    }
    else
    {    
        secs = secs - 1
        timerRunning = true
        timerID = self.setTimeout("StartTheTimer()", delay)
    }
}