function Placar () {

	return this;
}

Placar.prototype = 
{
	szImagePath: 'http://placaruol.uol.com.br/futebol/i/',
	aJogos:null,
	nJogo:0,
	numJogos:0,
		
	init: function(_aArray) 
	{
		var i;
		
		// Array com os jogos
		this.aJogos = tmpArray = new Array();
		
		// Trata o horário para fazer o sort
		for(i=0;i<_aArray.length;i++)
		{
			// Se o jogo não for válido passa para o próximo
			if ((_aArray[i]['time1'] == "0") || (_aArray[i]['time2'] == "0") || (_aArray[i]['time1'] == "") || (_aArray[i]['time2'] == ""))  
				continue;

			_aArray[i]['sortHorario'] = this.parseHorario(_aArray[i]['horario']);

			tmpArray[this.numJogos] = _aArray[i];
			this.numJogos++;
		}

		
		// Ordena os jogos por horário
		this.aJogos = this.sortMultiArray(tmpArray,"sortHorario");
	},
	
	// Seta o título do campeonato
	setTitulo: function(_szTitulo)
	{
		parent.document.getElementById('spTitulo').innerHTML = _szTitulo;
	},
	
	// Faz o tratamento do horário para o sort
	parseHorario: function(_szHorario)
	{
		if (_szHorario == "") return parseInt(0);
		
		if (_szHorario.length == 3)
			_szHorario = _szHorario.substr(0,2) + "00";
		else if (_szHorario.length == 5)
			_szHorario = _szHorario.replace("h","");
		
		return parseInt(_szHorario);
	},
	
	// Limpa a lista da esquerda
	clearList: function()
	{
		// Documento do frame principal
		var z  = top.document;

		for (i=1;i<=12;i++)
		{
        	z.getElementById('jogo_'+i+'_time1').innerHTML = '&nbsp;';
        	z.getElementById('jogo_'+i+'_placar').innerHTML = '&nbsp;';
        	z.getElementById('jogo_'+i+'_time2').innerHTML = '&nbsp;';
        	z.getElementById('bg'+i).style.backgroundColor = "#000000"; // Fundo diferente para o jogo corrente
		}
	},
	
	// Coloca os jogos na lateral esquerda
	populateList: function()
	{
		var i,x;

		// Documento do frame principal
		var z  = top.document;
		
		// Limpa a lateral esquerda;
		this.clearList();

		// Tempos de jogos válidos
		re = /(2º tempo|1º tempo|Intervalo|Pênalti)/i;
		
		// Insere os dados na lateral esquerda
		for (i=0;i<this.aJogos.length;i++)
		{
			bolinha = "";
			if ((this.aJogos[i]['time1'] != '') && (this.aJogos[i]['time2'] != ''))
			{
				if (this.aJogos[i]['tempo'].match(re))
					bolinha = ((this.aJogos[i]['tipojogo'] == "detalhado") ? '<img src="'+this.szImagePath+'dt.gif" border="0" align="left">' : '<img src="'+this.szImagePath+'sp.gif" border="0" align="left">');
				
        		z.getElementById('jogo_'+(i+1)+'_time1').innerHTML = '<a href="javascript:void(0);" onMouseOver="window.status=\'\';" onMouseOut="window.status=\'\';" onClick="openJogo='+(i+1)+';detailJogo=\'\';tipoJogo=\''+this.aJogos[i]['tipojogo']+'\';top.corpo.frames.location.reload();">'+bolinha+this.aJogos[i]['time1']+'</a>';
        		z.getElementById('jogo_'+(i+1)+'_placar').innerHTML = '<a href="javascript:void(0);" onMouseOver="window.status=\'\';" onMouseOut="window.status=\'\';" onClick="openJogo='+(i+1)+';detailJogo=\'\';tipoJogo=\''+this.aJogos[i]['tipojogo']+'\';top.corpo.frames.location.reload();">'+this.aJogos[i]['placar1']+' <b>X</b> '+this.aJogos[i]['placar2']+'</a>';
        		z.getElementById('jogo_'+(i+1)+'_time2').innerHTML = '<a href="javascript:void(0);" onMouseOver="window.status=\'\';" onMouseOut="window.status=\'\';" onClick="openJogo='+(i+1)+';detailJogo=\'\';tipoJogo=\''+this.aJogos[i]['tipojogo']+'\';top.corpo.frames.location.reload();" >'+this.aJogos[i]['time2']+'</a>';
        		z.getElementById('bg'+(i+1)).style.backgroundColor = "#000000"; // Fundo diferente para o jogo corrente
        		
	        	//if (i > 10) break; // só cabe 12 jogos
        	}
		}
	},
	
	// Pega o primeiro jogo do campeonato
	getFirstGame: function()
	{
		var i;
		
		// Seta a inicialização do placar como 'true'
		parent.init = true;
		
		for (i=0;i<this.aJogos.length;i++)
		{
			re = /(1º tempo|2º tempo|Intervalo|Pênalti)/gi;
			if (this.aJogos[i]['tempo'].match(re))
				return (i+1);
		}
		
		return 1;
	},
	
	showGame: function()
	{
		// Documento do frame principal
		z  = top.document;

		// Coloca os dados na coluna central
  	z.getElementById('time1').innerHTML  = this.aJogos[this.nJogo]['time1']; // Time 1
  	z.getElementById('time2').innerHTML  = this.aJogos[this.nJogo]['time2']; // Time 2
  	z.getElementById('brasao1').innerHTML= '<img src="' + this.szImagePath + "brasoes/" + this.replaceAccent(this.aJogos[this.nJogo]['time1'].toLowerCase()) + '.gif" border="0">'; // Brasao Time 1
  	z.getElementById('brasao2').innerHTML= '<img src="' + this.szImagePath + "brasoes/" + this.replaceAccent(this.aJogos[this.nJogo]['time2'].toLowerCase()) + '.gif" border="0">'; // Brasao Time 2
  	z.getElementById('placar').innerHTML = this.aJogos[this.nJogo]['placar1'] + ' <span style="font:bold 20px Arial; color:#BDB531">x</span> ' + this.aJogos[this.nJogo]['placar2']; //Placar do Jogo
		z.getElementById('fase').innerHTML   = this.aJogos[this.nJogo]['fase'];
		z.getElementById('local').innerHTML  = this.aJogos[this.nJogo]['local'];
		
		re = /(1º tempo|2º tempo|Intervalo|Pênalti)/i;
		if (this.aJogos[this.nJogo]['tempo'] == "Encerrado")
		{
			z.getElementById('tempo').innerHTML = "Encerrado";
		}
		else
		{
			(this.aJogos[this.nJogo]['tempo'].match(re)) ? eval('z.getElementById(\'tempo\').innerHTML = \'<div style="padding:2px 0 2px 3px;background:#FF0000;"><span style="font:bold 10px verdana;color:white;">AO VIVO</span>&nbsp;<span style="color:black">\'+this.aJogos[this.nJogo][\'tempo\']+\'</span></div>\'') : z.getElementById('tempo').innerHTML = this.aJogos[this.nJogo]['horario'];
		}

		// Coloca a cor do fundo diferente
	  	z.getElementById('bg'+(this.nJogo+1)).style.backgroundColor = "#3F3F3F"; // Fundo diferente para o jogo corrente
		
	},

	replaceAccent: function(_szWord)
	{
  		Accent = /[âáàãêéèîíìôóòõûúùüçñ\s\W]/g;
  		Esp = /[\s]/g;
  		Hif = /[\W]/g;
  		reA = /[âáàãä]/g;
  		reE = /[êéè]/g;
  		reI = /[îíì]/g;
  		reO = /[ôóòõ]/g;
  		reU = /[ûúùü]/g;
  		reC = /[ç]/g;
  		reN = /[ñ]/g;
  		reS = /[Š]/g;
  		
  		
  		//Substitui caracteres acentuados em
  		if(_szWord.search(Accent)!=-1)
  		{
  			_szWord = _szWord.replace(reA,"a");
  			_szWord = _szWord.replace(reE,"e");
  			_szWord = _szWord.replace(reI,"i");
  			_szWord = _szWord.replace(reO,"o");
  			_szWord = _szWord.replace(reU,"u");
  			_szWord = _szWord.replace(reC,"c");
  			_szWord = _szWord.replace(reN,"n");
  			_szWord = _szWord.replace(reS,"s");
  			_szWord = _szWord.replace(Esp,"");
  			_szWord = _szWord.replace(Hif,"");
  		}
  		
  		return _szWord;
  	},
  	
	// Seta o jogo em questão
	setGame: function(_nJogo)
	{
		this.nJogo = _nJogo-1;
		
		// Seta o tipo de jogo
		return this.aJogos[this.nJogo]['tipojogo'];
	},
	
	// seta o path da imagem
	setImagePath: function(_szPath)
	{
		this.szImagePath = _szPath;
	},

	sortMultiArray: function (_aArray, campo)
	{ 
		var nIndex1, nIndex2;
		
		
		tmp_aArray = new Array();
  	
		for(nIndex1 = 0;nIndex1 < _aArray.length;	nIndex1++)
		{
			for(nIndex2 = 0;	nIndex2 < _aArray.length - 1;	nIndex2++)
			{
				if(parseInt(_aArray[nIndex2][campo]) > parseInt(_aArray[nIndex2 + 1][campo]))
				{
					tmp_aArray = _aArray[nIndex2];
  	
					_aArray[nIndex2] = _aArray[nIndex2 + 1];
				
					_aArray[nIndex2 + 1] = tmp_aArray;
				}
			}
		}
		
		return _aArray;
	}
}



