function initTabs(_hold, tabs_hold, nav_hold, _autorotate, _switchTime){
	$j(_hold).each(function(){
		var _timer;
		var _btn = $j(this).find(nav_hold+' a').not('.more');
		var _tabs = $j(this).find(tabs_hold).children();
		var _tabCount = _btn.length-1;
		_tabs.hide();
		var _a = _btn.index(_btn.filter('.selected:eq(0)'));
		if(_a == -1) _a = 0;
		_btn.removeClass('selected').eq(_a).addClass('selected');
		_tabs.hide().filter(_btn.get(_a).hash).show();
		_btn.click(function(){
			_tabs.hide().filter(this.hash).show();
			_btn.removeClass('selected');
			$j(this).addClass('selected');
			_autorotate = false;
			if(_timer) clearTimeout(_timer);
			return false;
		});
		$j(this).find(nav_hold+' a.more').click(function(){
			var _currentIndex = _btn.index(_btn.filter('.selected:eq(0)'));
			if(_currentIndex<_tabCount) _btn.eq(++_currentIndex).trigger('click');
			return false;
		});		
		function nextSlide(){
			if(_autorotate && _switchTime){
				_timer = setTimeout(function(){
					var _currentIndex = _btn.index(_btn.filter('.selected:eq(0)'));
					if(_currentIndex<_tabCount) _currentIndex++;
					else _currentIndex=0;
					_tabs.hide().filter(_btn.get(_currentIndex).hash).show();
					_btn.removeClass('selected').eq(_currentIndex).addClass('selected');
					nextSlide();
				},_switchTime);
			}
		}
		if(_autorotate && _switchTime){
			_timer = setTimeout(function(){
				nextSlide();
			},_switchTime);
		}
	});
}

function initExpandOnToday(){
	var _holder = $j('div.on-today');
	_holder.each(function(){
		var _list = $j('ul', $j(this)).find('li:gt(4)').hide();
		var _btn = $j(this).find('span.btn-expand');
		_btn.click(function()
		{
			if($j(this).hasClass("shown"))
			{
				$j(this).removeClass("shown");
				_list.each(function(){$j(this).hide(200);})
			} else
			{
				$j(this).addClass('shown');
				_list.each(function(){$j(this).show(200);})
			}
			return false;
		});
	})
}

function initAlphbet(){
	var _hold = $j("div.alphaholder");
	_hold.each(function(){
		var _nav = $j("ul.alphanavigation");
		var _numLink = $j("li a", _nav);
		var _itemHold = $j("ul.alphalist");
		var _item = $j("> li", _itemHold);
		var _lable = $j(this).find("span.hidden-lable");

		_numLink.click(function(){
			_numLink.removeClass("selected");
			$j(this).addClass("selected");
			var _letter = $j(this).children().text();
			_item.hide();
			_lable.each(function(){
				if ($j(this).text()== _letter ) {
					$j(this).parents("li").show();
					return;
				};
			});
			if (_letter == "All") {
				_lable.parents("li").show();
			}
			return false;
		})
	});
}
function initExpandTextArea(){
	$j('div.comments textarea').each(function(){
		var _hold = $j(this).parents('div.comments:eq(0)');
		var _text = this.value;
		this.onfocus = function(){
			_hold.addClass('active-text');
			if(this.value == _text) this.value = '';
		}
		this.onblur = function(){
			if(this.value == '') this.value = _text;
		}
	});
}



function initMenu()
{
	var _nav = document.getElementById("nav");
	if (_nav) {
		var nodes = _nav.getElementsByTagName("li");
		for (var i=0; i<nodes.length; i++)
		{
			nodes[i].onmouseover = function()
			{
				if (this.className.indexOf('hover') == -1)
				this.className += " hover";
			}
			nodes[i].onmouseout = function()
			{
				this.className = this.className.replace(" hover", "");
			}
		}
	}
	var _log = document.getElementById("log");
	if (_log) {
		var nodes = _log.getElementsByTagName("li");
		for (var i=0; i<nodes.length; i++)
		{
			nodes[i].onmouseover = function()
			{
				if (this.className.indexOf('hover') == -1)
				this.className += " hover";
			}
			nodes[i].onmouseout = function()
			{
				this.className = this.className.replace(" hover", "");
			}
		}
	}
}
if (document.all && !window.opera) attachEvent("onload", initMenu);


function ClearText()
{
	var inputs = document.getElementsByTagName("input");
	for (var i=0; i<inputs.length; i++)
	{
		if (inputs[i].type == "text")
		{
			inputs[i].onfocus = function ()
			{
					if (this.value == "What would you like to say?")
						this.value = "";
					if (this.value == "Find Entertainment...")
						this.value = "";
					if (this.value == "Search Over 2,600 TV Shows and 30,000 Movies")
						this.value = "";
					if (this.value == "Search over 2,500 TV shows, 10 million songs, and 25,000 movies")
						this.value = "";
					if (this.value == "Search and watch over 2,600 TV shows")
						this.value = "";
					if (this.value == "Gossip")
						this.value = "";
					if (this.value == "Search and Listen to over 8 million songs")
						this.value = "";
					if (this.value == "Search real-time entertainment")
						this.value = "";
					if (this.value == "Search and watch over 30,000 Movies")
						this.value = "";
					if (this.value == "Search and Learn about Celebrities")
						this.value = "";
					if (this.value == "Search over 1,000 anime titles")
						this.value = "";	
			}
			inputs[i].onblur = function ()
			{
					if (this.value == "" && this.name == "search") this.value = "What would you like to say?";
					if (this.value == "" && this.name == "status_new2") this.value = "What would you like to say?";
					if (this.value == "" && this.name == "find") this.value = "Find Entertainment...";
					if (this.value == "" && this.name == "search-content") this.value = "Search Over 2,600 TV Shows and 30,000 Movies";
					if (this.value == "" && this.name == "search-content") this.value = "Search over 2,500 TV shows, 10 million songs, and 25,000 movies";
					if (this.value == "" && this.name == "search-content2") this.value = "Search and watch over 2,600 TV shows";
					if (this.value == "" && this.name == "search_form_value") this.value = "Search real-time entertainment";
					if (this.value == "" && this.name == "search-content-result") this.value = "Gossip";
					if (this.value == "" && this.name == "search-content-music") this.value = "Search and Listen to over 8 million songs";
					if (this.value == "" && this.name == "search-content-movie") this.value = "Search and watch over 30,000 Movies";
					if (this.value == "" && this.name == "search-content-celebr") this.value = "Search and Learn about Celebrities";
					if (this.value == "" && this.name == "search-content-anime") this.value = "Search over 1,000 anime titles";					
			}
		}
		
	}
}




$j(document).ready(function initPage() {
	initTabs('div.tabs.video-banner','div.banner','ul.tabNavigation',true,5000);
	initTabs('div.tabs','div.tabs-holder','ul.tabNavigation');
	initTabs('div.tabs-main','div.tabs-holder-main','ul.tabNavigation-main');
	initExpandTextArea();
	initExpandOnToday();
	initAlphbet();
	ClearText();
});
