var channelCount = 10;
var tvContentX = 0;
var tvContentY = 0;
var tvContentWidth = 749;
var tvContentHeight = 421;
var tvInfoWidth = 406;
var tvInfoHeight = 202;
var aLinkId = '';
var countTvThumb = 0;
var timeoutId = 0;
var tvImgId = '';


var tvThumbArray = new Array();

function getTvInfoPosition(xLink, yLink, el)
{
	var x = y= 0;
	if(xLink + tvInfoWidth > tvContentWidth)
		x = xLink - tvInfoWidth;
	else
		x = xLink;
	if(yLink + tvInfoHeight > tvContentHeight)
		y = yLink - tvInfoHeight;
	else
		y = yLink+20;

   return {x:x, y:y};
}

function showTvInfo(id, linkEl)
{
             //alert(linkEl.id);
	el = document.getElementById(id);
	if(el && linkEl.id!= '')
	{
		el.style.visibility = 'visible';
		el.style.display = 'block';

        hideOtherTv(id);

        aLinkId = linkEl.id;
	    xL = absPosition(linkEl).x+30;
	    yL = absPosition(linkEl).y+30;

	    x = getTvInfoPosition(xL, yL, el).x;
	    y = getTvInfoPosition(xL, yL, el).y;

		el.style.left = (x)+'px';
		el.style.top = (y)+'px';

        countTvThumb = 0;
        changeTvThumb('tv-img-'+id);
	}
}
function hideOtherTv(id)
{
	for(i=1;i<=channelCount;i++)
	{
		el2 = document.getElementById("ch"+i);
		if(el2 && el2.id != id)
		{
			hideTvInfo(el2.id);
		}
	}
}
function hideAllTvInfo()
{
	for(i=1;i<=channelCount;i++)
	{
		el2 = document.getElementById("ch"+i);
		hideTvInfo(el2.id);
	}
}
function hideTvInfo(infoId, elSender)
{
   // if(elSender.id == aLinkId)
	info = document.getElementById(infoId);
	info.style.visibility = 'hidden';
	info.style.display = 'none';

    clearTimeout(timeoutId);
}

function setContentCoordinates(elemId)
{
	el = document.getElementById(elemId);
	tvContentX = el.offsetLeft;
	tvContentY = el.offsetTop;
}

function absPosition(obj)
{
      var x = y = 0;
      //while(obj) {
            x = obj.offsetLeft;
            y = obj.offsetTop;
           // obj = obj.offsetParent;
     // }
    //alert(x+'='+y);
      return {x:x, y:y};
}

function changeTvThumb(imgId)
{
    //alert(imgId);
    if(tvImgId != imgId)
    {
        tvImgId = imgId;
        //alert('Сменили вкладку');
        countTvThumb = 0;
    }

    if(timeoutId>0)
        clearTimeout(timeoutId);


	countTvThumb++;

    var img = document.getElementById(imgId);
    if(img)
    {
        if(countTvThumb == tvThumbArray[imgId].length)
            countTvThumb = 0;
        img.src = tvThumbArray[imgId][countTvThumb];
    }

	timeoutId = setTimeout('changeTvThumb(\''+imgId+'\')',4000);
}

/*function showTvSubmenu(menuId)
{
    var menu = document.getElementById(menuId);
    if(menu)
    {
        menu.style.visibility = 'visible';
	    menu.style.display = 'block';
    }
}

function hideTvSubmenu(menuId)
{
    var menu = document.getElementById(menuId);
    if(menu)
    {
        menu.style.visibility = 'hidden';
	    menu.style.display = 'none';
    }
}*/


startList = function()
{
      if (document.all&&document.getElementById)
      {
            navRoot = document.getElementById("channel-nav");
            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", "");
                        }
                  }
            }

          navRoot2 = document.getElementById("tvInfo-nav");
            for (i=0; i<navRoot2.childNodes.length; i++) {
                  node = navRoot2.childNodes[i];
                  if (node.nodeName=="LI") {
                        node.onmouseover=function() {
                              this.className+=" over";
                        }
                        node.onmouseout=function() {
                              this.className=this.className.replace (" over", "");
                        }
                  }
            }
      }
}
//window.onload=startList;