var curPic = 0;
function nextSlide()
{
  curPic++;
  if(curPic == arrPics.length)
	curPic = 0;

  hp = document.getElementById('ekran');

  var isIE =navigator.userAgent.toLowerCase().indexOf("msie") != -1;
  if (isIE) 
    if(hp.filters.item(0))
      hp.filters.item(0).Apply();

  hp.style.backgroundImage = "url('/header_pics/" + arrPics[curPic] + "')";

  if (isIE)
    if(hp.filters.item(0))
      hp.filters.item(0).Play();

  window.setTimeout(nextSlide, 5000);
};

function bodyLoad()
{
	curPic = Math.ceil(arrPics.length*Math.random()) - 1;
	window.setTimeout(nextSlide, 5000);
	
	bodyResize();
	if (window.addEventListener)//mozilla
		window.addEventListener("resize", bodyResize, false);
	else
		window.attachEvent("onresize", bodyResize);
	//window.onresize=function(){bodyResize();};
	
	
}

function swapImage(img, src)
{
	if(img)
	{
		img.src = src;
	}
}

function gotoURL(url)
{
	top.document.location = url;
}

function getX_old( oElement )
{
	var iReturnValue = 0;
	while( oElement != null ) 
	{
		iReturnValue += oElement.offsetLeft;
		oElement = oElement.offsetParent;
	}
	return iReturnValue;
}

function getX(o) {
	//if(!isIE)
		//return NaN;
	var t = o.offsetLeft;
	while (o.offsetParent) {
		o  = o.offsetParent;
		t += o.offsetLeft;
	}
	//alert(t);
	return t;
};

function bodyResize()
{
	
	var logo = document.getElementById('logo');
	var biker = document.getElementById('biker');
	var ekran = document.getElementById('ekran');

	var edge = getX(ekran);// + hpic.width;
	
	//alert(logo.width);
	logo.style.left = edge - logo.width - 20 + 'px';
	logo.style.visibility = "visible";
	
	biker.style.left = edge - biker.width + 50 + 'px';
	biker.style.visibility = 'visible';
	
	if(navigator.userAgent.toLowerCase().indexOf("msie") != -1)
	{
		var menu=document.getElementById('menu');
		menu.style.left = edge+10 + 'px';
		menu.style.position = 'absolute';
		
		/*var logo2 = document.getElementById('logo2');
		logo2.style.left = logo.style.left;
		logo2.style.visibility = 'visible';*/
	}
}

function programDetails(id)
{
    document.location="?page=program_details&prog=" + id;
}

var vid;
function videoGallery()
{
	var isIE =navigator.userAgent.toLowerCase().indexOf("msie") != -1;
	
	var vurl = "/video_gallery.php";
	var vname = "VideoGallery";
	var spar = "fullscreen=1,left=0,top=0,width=" + screen.width + ",height=" + screen.height + ",menubar=0,toolbar=0,status=0,location=0";
	if(null != vid)
	{
		try
		{
			if(isIE)
			{
			popup.focus();
			//popup.location.href = url;
			return;
			}
		
			vid.close();
			//vid.location.href = url;
			//return;
		}
		catch(err)
		{
			//vid.close();
			vid = null;
		}
	}

	vid = window.open(vurl, vname, spar);
	vid.focus();
}
