var ns = (document.layers)? true:false
var ie = (document.all)? true:false





// construtor
function Player() {
	// ** métodos **
	this.ra = null;
	player.raIsFake = false;
	this.embed = playerEmbed;
	this.play = onPlay;
	this.stop = onStop;
	this.pause = onPause;
	this.next = onNext;
	this.volumeUp = onVolumeUp;
	this.volumeDown = onVolumeDown;
}

function GetRealPlayer() {
	real = (ie)?document.frames["player"]:document.layers["player"];
	if (real.document.embeds.length>0) {
		old_window_error = window.onerror;
		window.onerror = erroDeteccao;
		var v, obj;
		obj =real.document.embeds["RealPlayer"];
		player.ra = obj;
		v = obj.GetVersionInfo();
		
		if (Number(v.charAt(0)) < 6) {
			player.raIsFake = true;
			player.ra = new FakeRealPlayer();
		} else {
			player.raIsFake = false;
		}
	
		window.onerror = old_window_error;
		
		callback();
	} 
	else {
		setTimeout("GetRealPlayer();",100);
	}
}

function erroDeteccao() {
	player.raIsFake = true;
	player.ra = new FakeRealPlayer();
	window.onerror = old_window_error;
	callback();
	return true;
}

function callback() {
	for (i=0; i<player.callStack.length; ++i) {
		eval(player.callStack[i]);
	}
	player.callStack = new Array();
}

function FakeRealPlayer() {
	f1 = new Function("return false;");
	f2 = new Function("return 0;");
	this.source = "";
	this.DoPlay = new Function("alert('Você precisa ter o Real Player G2 ou superior (www.real.com) instalado.');");
	this.CanPlay = f1;
	this.CanPause = f1;
	this.DoPause = f1;
	this.DoStop = f1;
	this.SetVolume = f1;
	this.GetVolume = f2;
	this.SetLength = f1;
	this.GetLength = f2;
	this.SetPosition = f1;
	this.GetPosition = f2;
	this.SetSource = new Function("this.source = arguments[0];");
	this.GetSource = new Function("return this.source;");
}

// embed a Real Player
function playerEmbed(caller) {
	if (ie) {
		document.frames["player"].window.location = "embed.html";
	}
	else {
		//
		oi = "1";
	}
	
	if (this.ra) {
		if (this.raIsFake) {
			if (ns) {
				document.layers["player"].src = "/clickstation/getreal.html";
	//			document.layers["player"].left = this.tela.left;
	//			document.layers["player"].top = this.tela.top;
	//			document.layers["player"].width = this.tela.width;
	//			document.layers["player"].height = this.tela.height;
			} 
			else {
				document.frames["player"].window.location = "/clickstation/getreal.html";
			}
		}
		return true;
	} 
	else {
		this.callStack[this.callStack.length] = caller;
		if (ns) {
			document.layers["player"].src = "/clickstation/plugin.html";
			document.layers["player"].left = this.tela.left;
			document.layers["player"].top = this.tela.top;
			document.layers["player"].width = this.tela.width;
			document.layers["player"].height = this.tela.height;
		} else {
			document.frames["player"].window.location = "/clickstation/plugin.html";
		}
		setTimeout("GetRealPlayer();",0);
		return false;
	}
}

function ClickStation_playVideo() {
	if (this.playerEmbed("player.playVideo()")) {
		if (!this.setouVolume) {
			this.setouVolume = true;
			player.setVolume(50);
		}
		if (this.ra.GetSource()!="") {
			this.ra.DoPlay();
		}
	}
}


function onPause()
{
 if (!RealPlayer.CanPlay())
  RealPlayer.DoPlayPause();
}
 
function onStop()
{
  RealPlayer.DoStop();
}
 
 function onPlay()
{
  if (RealPlayer.CanPlay()) 
    RealPlayer.DoPlayPause();
}

 function onNext()
{
  RealPlayer.DoNextItem();
}

function onVolumeUp()
{
 volume = RealPlayer.GetVolume();
 if (volume<90)
   volume = volume + 10;
 RealPlayer.SetVolume(volume);
}
 
function onVolumeDown()
{
 volume = RealPlayer.GetVolume();
 if (volume>10)
   volume = volume - 10;
 RealPlayer.SetVolume(volume);
}
 
function onFullScreen()
{
 if (bWin32IE == true) {
  RealPlayer.DisplaySize = 3;
 } else {
  document.RealPlayer.DisplaySize = 3;
  document.RealPlayer.SetCurrentPosition(0);
 }
}

function setAuthor(new_author) {
	RealPlayer.SetAuthor(new_author);
}

function getAuthor() {
	artista.innerHTML = "<b>"+RealPlayer.GetAuthor()+"</b>"; 
}

function getTitle() {
	musica.innerHTML = "<b>"+RealPlayer.GetTitle()+"</b>";
}

function getNumEntries() {
	alert("oi");
	entradas.innerHTML = "<b>"+RealPlayer.GetNumEntries()+"</b>";
}

 


 

