
_TabBox = function()
	{
		this.Cache		= [];
		this.Current	= null;
		this.Less		= 'Less';
		this.MoreTxt	= 'More';
		
		this.Switch = function(Tab, Obj, More)
			{
				var More = (typeof(More) != 'boolean' || More != true) ? false : true;
				if(!More)
					{
						$('TabboxSongsID').className = 'Load';
						this.Current = Tab;
					}
				else
					{
						$('TabboxMoreID').className = 'Load';
					}
				
				if(typeof(Obj) == 'object')
					{
						var Objs = $('TabboxID').getElementsByTagName('div')[0].getElementsByTagName('a');
						for(var $i in Objs)
							Objs[$i].className = (Objs[$i] == Obj) ? 'Selected' : '';
					}
				
				if(typeof(this.Cache[Tab]) == 'object' && (!More || this.Cache[Tab].length > 12))
					{
						this.doProcess(Tab, More);
					}
				else
					{
						this.Switch.AJAX	= new AjaxLite();
						var AJAX			= this.Switch.AJAX;
						AJAX.URL			= 'data.php/tabbox/';
						if(typeof(Tab) == 'string' && Tab == 'new')
							AJAX.Post['new']	= true;
						if(More)
							AJAX.Post['more']	= true;
						AJAX.ORSC			= function() { $TabBox.Switch.AJAX.doCheck(); };
						AJAX.doOnChange		= function()
							{
								var Key			= (typeof(this.Post['new']) != 'undefined') ? 'new' : 'popular';
								
								if(typeof($TabBox.Cache[Key]) != 'object')
									$TabBox.Cache[Key] = [];
								
								var Len = $TabBox.Cache[Key].length;
								
								for(var $i = 1; $i < this.Re.length; $i++)
									{
										var Data = this.Re[$i].split('<><>');
										
										$TabBox.Cache[Key][Len+($i-1)] = Data;
									}
								
								$TabBox.doProcess(Key, (typeof(this.Post['more']) != 'undefined'));
							};
						AJAX.doRequest();
					}
			}
		
		this.Type = {0: 'song', 3: 'album', 6: 'artist'};
		this.doProcess = function(Key, More)
			{
				if(typeof(this.Cache[Key]) == 'object')
					{
						var More		= (typeof(More) == 'boolean' && More == true);
						var Len			= this.Cache[Key].length;
						Len				= (Len < 12 || More) ? Len : 12;						
						var Div			= document.createElement('div');
						for(var $i = (More ? (Len < 12 ? Len : 12) : 0); $i < Len; $i++)
							{
								var Data			= this.Cache[Key][$i];
								
								var Ph				= document.createElement('div');
								Ph.className		= 'Block';
								
								var ImgFix			= 9;
								
								var Img				= document.createElement('img');
								Img.alt				= '';
								Img.src				= Data[ImgFix];
								Img.style.width		= Data[ImgFix+1]+'px';
								Img.style.height	= Data[ImgFix+2]+'px';
								Img.style.background= '#FFF url(/images/icons/Loading.gif) no-repeat 50% 100%';
								Img.onload			= function() { this.style.backgroundImage = 'none'; };
								if(Data[ImgFix+2] < 80)
									Img.style.paddingBottom	= (80 - Data[ImgFix+2]) + 'px';
								Img.title			= Data[0];
								Ph.appendChild(Img);
								Ph.appendChild(document.createElement('br'));
								
								for(var $d = 0; $d < 9; $d += 3)
									{
										var aHref			= document.createElement('a');
										aHref.href			= '/music/'+this.Type[$d]+'/'+Data[$d+1]+'/'+Data[$d+2]+'/';
										aHref.title			= $HTML(Data[$d]);
										aHref.innerHTML		= Data[$d];
										if(!$d)
											{
												aHref.style.fontSize = '8pt';
												aHref.onclick = function() { doMedia(this.href); return false; }
											}
										Ph.appendChild(aHref);
									}
		
								Div.appendChild(Ph);
								
								if((!($i+1 % 4) || $i+1 >= Len))
									{
										var Clear			= document.createElement('br');
										Clear.style.clear	= 'left';
										Div.appendChild(Clear);
									}
							}

						if(!More)
							{
								$('TabboxSongsID').innerHTML	= '';
								$('TabboxSongsID').style.overflow = 'visible';
								$('TabboxMoreID').innerHTML = this.MoreTxt;
							}
						$('TabboxSongsID').className	= '';
						$('TabboxMoreID').className		= '';
						$('TabboxSongsID').appendChild(Div);
						
						if(More)
							{
								$('TabboxSongsID').scrollTop = ($('TabboxSongsID').scrollHeight + $('TabboxSongsID').offsetHeight);
								$('TabboxMoreID').innerHTML = this.Less;
							}
					}
			}
		
		this.More = function()
			{
				if($('TabboxSongsID').style.overflow != 'auto')
					{
						$('TabboxSongsID').style.overflow = 'auto';
						$('TabboxSongsID').style.maxHeight = $('TabboxSongsID').childNodes[0].offsetHeight+'px';
						
						this.Switch(this.Current, false, true);
					}
				else
					{
						$('TabboxMoreID').innerHTML = this.MoreTxt;
						this.Switch(this.Current);
					}
				
				return false;
			}
	}

$TabBox = new _TabBox();
