// JavaScript Document
function TG8MP3()
{
	this.fl = new Array();
	
	this.ao;
	this.pos = 0;
	
	this._url 		= 'dadsad';
	this._container = 'asdasd';
	this._width 	= 0;
	this._height 	= 0;
	
	this.pc;
	
	this.Over   = new Object();
	this.Over.FontColor = '';
	this.Over.BackgroundColor = '';
	
	this.Out    = new Object();
	this.Out.FontColor = '';
	this.Out.BackgroundColor = '';
	
	this.Active = new Object();
	this.Active.FontColor = '';
	this.Active.BackgroundColor = '';
	
	this.Player = new Object();
	this.Player._color_1 = ''; 
	this.Player._color_2 = '';
	this.Player._color_3 = '';
	
	
	this.init = function()
	{
		
		
		p = new Array();
		p = document.getElementsByTagName('a');
		
		k='';
		
		for(i=0; p[i]; i++)
		{
			if(p[i].rel)
			{
				rel = p[i].rel;
				rel = rel.split(':');
				if(rel[0]=='mp3')
				{
					this.fl.push({o:p[i],v:rel[1]});
					
					try{
						p[i].parent = this;
						p[i].file	= rel[1];
						this.addEvents(p[i]);
					} catch(e){
						alert(e);
					}
				}
			}
		}
	}
	
	this.callPlayer = function(s)
	{
		this.pc = document.getElementById(this._container);
		try {
			if(!this.pc.id)
			{
				alert('ERROR:\nNo player container defined!');
			}
		} catch(e) {
			alert('ERROR:\nNo player container defined!');
		}
		if(this.SWFObjectCheck)
		{
			if(s!=null)
			{
				pS = new SWFObject(this._url+"?link="+s+"&color_1="+this.Player._color_1+"&color_2="+this.Player._color_2+"&color_3="+this.Player._color_3, "TG8ClutterBox", this._width, this._height, "8", "#FFFFFF");
				pS.addParam("wmode", "transparent");
				pS.addParam("allowscriptaccess","true"	);
  				pS.write(this._container);
			}else{
				pS = new SWFObject(this._url+"?color_1="+this.Player._color_1+"&color_2="+this.Player._color_2+"&color_3="+this.Player._color_3, "TG8ClutterBox", this._width, this._height, "8", "#FFFFFF");
				pS.addParam("wmode", "transparent");
				pS.addParam("allowscriptaccess","true"	);
  				pS.write(this._container);
			}
			
		}else{
			alert('ERROR:\nNO SWFObject Object found,\nfirst include SWFObject!')
		}
	}
	
	this.addEvents = function(o)
	{
		o.style.cursor  = 'pointer';
		o.onmouseup 	= this.callMP3;
		
		o.onmouseover 	= this.overMP3;
		o.onmouseout 	= this.outMP3;
	}
	
	this.callMP3 = function(e)
	{
		this.parent.ActivateTrack(this);
		this.parent.callPlayer(this.file);
	}
	
	this.overMP3 = function(e)
	{
		if(this!=this.parent.ao)
		{
			this.style.color = this.parent.Over.FontColor;
			this.style.backgroundColor = this.parent.Over.BackgroundColor;
		}
	}
	
	this.outMP3 = function(e)
	{
		if(this!=this.parent.ao)
		{
			this.style.color = this.parent.Out.FontColor;
			this.style.backgroundColor = this.parent.Out.BackgroundColor;
		}
	}
	
	this.ActivateTrack = function(o)
	{
		try{
			
			if(this.Active.FontColor!='')
			{
				this.ao.style.backgroundColor = this.Out.BackgroundColor;
				this.ao.style.color = this.Out.FontColor;
			}
			this.ao.style.cursor = 'pointer';
			this.ao.onmouseup = this.callMP3;
		} catch(e){
			//do nothing
		}
		
		this.ao = o;
		o.style.cursor = 'default';
		o.onmouseup = null;
		if(this.Active.FontColor!='')
		{
			o.style.backgroundColor = this.Active.BackgroundColor;
			o.style.color = this.Active.FontColor;
		}
		
	}
	
	this.getPos = function(o)
	{
		for(i=0; this.fl[i]; i++)
		{
			if(this.fl[i].o==o)
			{
				this.pos = i;
				return i;
				break;
			}
		}
		
		return false;
	}
	
	this.getNextTrack = function()
	{
		if(this.pos>=(this.fl.length-1))
		{
			this.pos = 0;
		}else{
			this.pos++;
		}
		
		this.ActivateTrack(this.fl[this.pos].o);
		return this.fl[this.pos].v;
	}
	
	this.getPrevTrack = function()
	{
		if(this.pos<=0)
		{
			this.pos = this.fl.length-1;
		}else{
			this.pos--;
		}
		this.ActivateTrack(this.fl[this.pos].o);
		return this.fl[this.pos].v;
	}
	
	this.SWFObjectCheck = function()
	{
		return new String(document.getElementsByTagName('html')[0].innerHTML).toLowerCase().indexOf('swfobject')!=-1?true:false;
		
	}
	
	this.SWFObjectCheck()==true ? null : alert('ERROR:\nNO SWFObject Object found,\nfirst include SWFObject!')
	new String(window.onload).indexOf('TG8MP3')!=-1? this.init() : alert('ERROR:\nThe TG8MP3 Object must instanced placed in higher level at window.onload!');
	
}
