function initNewsFeed()
{
	var newsContent = document.getElementById("NewsContent");
	var scrollBar = document.getElementById("NewsScrollBar");
	
	if (newsContent != null)
	{
		if (newsContent.scrollHeight <= 290)
		{
			scrollBar.style.visibility = "hidden";
		}
	}
}

window.addEvent('domready', initPage);

function initPage()
{
	setThumbsWidth();
	initNewsFeed();
	TB_init();
	initNoob();
}

function findNoobHeight()
{
	var noobBox = document.getElementById("NoobBox");
	var noobMask = document.getElementById("NoobMask");
	
	if (noobBox != null)
	{
		if (noobMask != null)
		{
			noobMask.style.height = noobBox.offsetHeight + "px";
		}
	}
}

var newsScrollInterval = null;
function startNewsScroll(direction)
{
	newsScrollInterval = setInterval("newsScroll('" + direction + "')",50);
}

function stopNewsScroll()
{
	clearInterval(newsScrollInterval);
}

function newsScroll(direction)
{
	var newsContent = document.getElementById("NewsContent");
	var scrollBar = document.getElementById("scrollBar");
	var scrollStatus = document.getElementById("scrollStatus");
	
	if (newsContent != null && scrollBar != null && scrollStatus != null)
	{
		newsHeight = newsContent.scrollHeight;
		newsShownHeight = 290;
		scrollBarHeight = scrollBar.offsetHeight;
		scrollStatusHeight = scrollStatus.offsetHeight;
		
		if (direction == "down")
		{
			var scrollPercent = 0;
			var curScrollTop = (!isNaN(parseInt(scrollStatus.style.top))) ? parseInt(scrollStatus.style.top) : 0;
			newStatusPos = curScrollTop + 10;
			
			if (newStatusPos <= (scrollBarHeight - scrollStatusHeight))
			{
				scrollStatus.style.top = newStatusPos + "px";
				scrollPercent = newStatusPos / scrollBarHeight;
			}
			else 
			{
				scrollStatus.style.top = (scrollBarHeight - scrollStatusHeight) + "px";
				scrollPercent = 100;
			}
			
			newPos = (newsHeight * scrollPercent) - (scrollPercent * newsShownHeight);
			if (newsContent.scrollTo)
			{
				newsContent.scrollTo(0, newPos);
			}
			else
			{
				newsContent.scrollTop = newPos;
			}
		}
		else if (direction == "up")
		{
			var scrollPercent = 0;
			var curScrollTop = (!isNaN(parseInt(scrollStatus.style.top))) ? parseInt(scrollStatus.style.top) : 0;
			newStatusPos = curScrollTop - 10;
			
			if (newStatusPos >= 0)
			{
				scrollStatus.style.top = newStatusPos + "px";
				scrollPercent = newStatusPos / scrollBarHeight;
			}
			else 
			{
				scrollStatus.style.top = "0px";
				scrollPercent = 0;
			}

			newPos = (newsHeight * scrollPercent) - (scrollPercent * newsShownHeight);
			if (newsContent.scrollTo)
			{
				newsContent.scrollTo(0, newPos);
			}
			else
			{
				newsContent.scrollTop = newPos;
			}
		}
	}
}

function shiftBandThumbs(direction)
{
	var images = document.getElementById("ThumbsImgs");
	var handles = document.getElementById("thumbs_handles7");
	
	var curLeft = parseInt(images.style.left);
	if (curLeft == "" || isNaN(curLeft))
	{
		curLeft = 0;
	}
	
	if (direction == "left")
	{
		if (parseInt(images.style.width) > 626)
		{
			newPos = curLeft - 626;
			if (Math.abs(newPos) <= parseInt(images.style.width))
			{
				$('ThumbsImgs').tween('left', [curLeft, newPos]);
				$('thumbs_handles7').tween('left', [curLeft, newPos]);

				subPosition = Math.abs(newPos) / 626;
				nS4.walk(subPosition*8);
			}
		}
	}
	else if (direction == "right")
	{
		if (Math.abs(curLeft) > 0)
		{
			newPos = curLeft + 626;
			$('ThumbsImgs').tween('left', [curLeft, newPos]);
			$('thumbs_handles7').tween('left', [curLeft, newPos]);

			subPosition = Math.abs(newPos) / 626;
			nS4.walk(subPosition*8);
		}
	}	
}

function showInfoMenu(show)
{
	var infoMenu = document.getElementById("InfoMenu");
	
	if (show)
	{
		infoMenu.style.visibility = "visible";
	}
	else
	{
		infoMenu.style.visibility = "hidden";
	}
}

var currentMouseY;
function startNewsDrag(scrollStatus)
{
	var newsContent = document.getElementById("NewsContent");
	var scrollBar = document.getElementById("scrollBar");
	var scrollStatus = document.getElementById("scrollStatus");
	
	document.onmousemove = mouseMove;
}

function stopNewsDrag()
{
	document.onmousemove = null;
}

function mouseMove(ev)
{
	ev = ev || window.event;
	var mousePos = mouseCoords(ev);
	
	var scrollStatus = document.getElementById("scrollStatus");
	if (isNaN(parseInt(scrollStatus.style.top)))
	{
		scrollStatus.style.top = 0;
	}
	
	if (isNaN(currentMouseY))
	{
		currentMouseY = mousePos.y;
	}
	
	newStatusPos = parseInt(scrollStatus.style.top) + (mousePos.y - currentMouseY);
	scrollStatus.style.top = newStatusPos + "px";

	currentMouseY = mousePos.y;
}

function mouseCoords(ev)
{
	if (ev.pageX || ev.pageY)
	{
		return {x:ev.pageX, y:ev.pageY};
	}
	
	return { 
		x:ev.clientX + document.body.scrollLeft - document.body.clientLeft, 
		y:ev.clientY + document.body.scrollTop  - document.body.clientTop 
	}; 
}

function launchPlayer()
{
	window.open("player.php", "PMF2009", "width=900, height=714, toolbar=0");
}