// JavaScript Document
var contentVisible = true;
var baseURL = 'http://cuestream.dustyroxx.com/player/';
var playerID = 18;
window.onload = new Function('init()');
window.onload = new Function('IEMenu()');

function init(){
	//loadItem('');
}

function loadItem(type){
	activateMenuItem(type);
	fadeContent('out');
	loadURL(baseURL + '?action=' + type + '&id=' + playerID);
	var interval = setInterval(function(){
		if(contentVisible == false){
			setContent('<div id="loading"><img src="images/loading.gif"/> <span>Loading ...</span></div>');
			fadeContent('in');
			clearInterval(interval);
		}
	},100);
}

function parseAJAXResult(result){
	fadeContent('out');
	var interval = setInterval(function(){
		if(contentVisible == false){
			setContent(result); 
			fadeContent('in');
			clearInterval(interval);
		}
	},100);
}

function activateMenuItem(type){
	var menuItem = type.split('_');
	var menuItems = $('menu').getElementsByTagName('a');
	for(var i in menuItems)	menuItems[i].className = '';
	$(menuItem[0]).className = 'active';
	if($(type)) $(type).className = 'active';
}

function setContent(html){
	$('content').innerHTML = html;
}

function fadeContent(type){
	contentVisible = null;
	//$('content').innerHTML += '<br/><b>NEW ORDER: fade ' + type + '</b>';
	var content = $('content');
	var step = 10;
	var currentOpacity = 100;
	if(parseInt(content.style.opacity) >= 0 && parseInt(content.style.opacity) <= 1){
		//$('content').innerHTML += '<br/>EXISTING OPACITY: ' + content.style.opacity;
		var currentOpacity = content.style.opacity*100;
	}else{
		//$('content').innerHTML += '<br/>NO EXISTING OPACITY FOUND - ' + content.style.opacity;
	}
	if(type == 'out' && currentOpacity != 0) step *= -1;
	if(type == 'out' && currentOpacity == 0){
		contentVisible = false;
		//$('content').innerHTML += '<br/>FASTDETECT: INVISIBLE';
		return true;
	}if(type == 'in' && currentOpacity == 100){
		//$('content').innerHTML += '<br/>FASTDETECT: VISIBLE';
		contentVisible = true;
		return true;
	}
	var interval = setInterval(function(){
		currentOpacity += step;
		//$('content').innerHTML += '<br/>currentOpacity = ' + currentOpacity;
		content.style.opacity = (currentOpacity/100);
		content.style.filter = 'alpha(opacity=' + currentOpacity + ')';
		if(currentOpacity == 0){
			contentVisible = false;
			//$('content').innerHTML += '<br/>INVISIBLE';
			clearInterval(interval);
		}else if(currentOpacity == 100){
			contentVisible == true;
			//$('content').innerHTML += '<br/>VISIBLE';
			clearInterval(interval);
		}
	},50);
	return true;
}

function IEMenu() {
if (document.all&&document.getElementById) {
navRoot = document.getElementById("menu_ul");
for (i=0; i<navRoot.childNodes.length; i++) {
node = navRoot.childNodes[i];
if (node.nodeName=="LI") {
node.onmouseover=function() {
this.className+=" over";
  }
  node.onmouseout=function() {
  this.className=this.className.replace(" over", "");
   }
   }
  }
 }
}

function $(id){
	return document.getElementById(id);
}