var SB;
var CurrentContent = 0;
var NumContent = 0;
var Content = "";
var Tipo = "";

var myRequestRb = null;

function CreateXmlHttpReq(handler)
{
    var xmlhttp = null;
    try
    {
        xmlhttp = new XMLHttpRequest();
    }
    catch(e)
    {
        try
        {
            xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch(e)
        {
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
    xmlhttp.onreadystatechange = handler;
    return xmlhttp;
}
function myHandlerRb()
{
    if (myRequestRb.readyState == 4 && myRequestRb.status == 200)
    {
        e = document.getElementById("ytapiplayer");
        if(myRequestRb.responseText.length==0)
        {
            e.innerHTML = 'contenuto non disponibile';
        }
        else
        {
            e.innerHTML = myRequestRb.responseText;
        }
    }
}
function GetContent()
{
    e = document.getElementById("ytapiplayer");
    e.innerHTML = '<img src="componenti/eio_rokbox/image/ajax-loader.gif"> <font>Caricamento Pagina....</font>';
    myRequestRb = CreateXmlHttpReq(myHandlerRb);
    myRequestRb.open("GET","componenti/eio_rokbox/eio_rokbox.php?eio_rokbox_link="+Content+"&eio_rokbox_type="+Tipo+"&eio_rokbox_action="+CurrentContent);
    myRequestRb.send(null);
    return false;
}
function getmovie(qta,lin,tipo)
{
    NumContent=qta;
    Content=lin;
    CurrentContent=0;
    Tipo=tipo;
    
    var parent = window.parent.document;
    var div = parent.createElement('div');
    
    div.id="backbox";
    
    if (document.body.scrollHeight)
        docHt = sh = document.body.scrollHeight;
    if (document.body.offsetHeight)
        docHt = oh = document.body.offsetHeight;
    if (sh && oh)
        docHt = Math.max(sh, oh);
    if (document.body.scrollWidth)
        docWt = sw = document.body.scrollWidth;
    if (document.body.offsetWidth)
        docWt = ow= document.body.offsetWidth;
    if (sw && ow)
        docWt = Math.min(sw,ow);

    div.style.height=docHt+50+"px";
    div.style.width=docWt+"px";
    div.style.position = "absolute";
    div.style.zIndex = 2;
    
    document.body.appendChild(div);
    
    setOpacity(20);
    div.onclick=closemovie;
    
    var box = parent.createElement('div');
    box.id="boxeio";
    box.innerHTML="<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr><td width=\"20\" background=\"componenti/eio_rokbox/image/tl.png\" height=\"20\"></td><td background=\"componenti/eio_rokbox/image/top.png\" height=\"20\"></td><td width=\"20\" background=\"componenti/eio_rokbox/image/tr.png\" height=\"20\"></td></tr><tr><td width=\"20\" background=\"componenti/eio_rokbox/image/left.png\"></td><td valign=\"top\" align=\"left\" bgcolor=\"#ffffff\" height=\"25\"><a href=\"javascript:;\" onclick=\"closemovie()\"><img src=\"componenti/eio_rokbox/image/close.png\" border=\"0\"/></a></td><td width=\"20\" background=\"componenti/eio_rokbox/image/right.png\"></td></tr><tr><td width=\"20\" background=\"componenti/eio_rokbox/image/left.png\"></td><td id=\"centertd\" style=\"background-color: rgb(255, 255, 255);\" width=\"425\" height=\"344\"><div id=\"ytapiplayer\" style=\"width:auto;background-color: rgb(255, 255, 255);\"></div></td><td width=\"20\" background=\"componenti/eio_rokbox/image/right.png\"></td></tr><tr><td width=\"20\" background=\"componenti/eio_rokbox/image/left.png\"></td><td valign=\"top\" align=\"right\" bgcolor=\"#ffffff\" height=\"25\"><br/><br/><a href=\"javascript:;\" id=\"prior\" onClick=\"GetPrior();\"><img src=\"componenti/eio_rokbox/image/prev.png\" border=\"0\"></a>&nbsp;&nbsp;&nbsp;<a href=\"javascript:;\" id=\"next\" onClick=\"GetNext();\"><img src=\"componenti/eio_rokbox/image/next.png\" border=\"0\"></a></td><td width=\"20\" background=\"componenti/eio_rokbox/image/right.png\"></td></tr><tr><td width=\"20\" background=\"componenti/eio_rokbox/image/bl.png\" height=\"20\"></td><td background=\"componenti/eio_rokbox/image/bottom.png\" height=\"20\"></td><td width=\"20\" background=\"componenti/eio_rokbox/image/br.png\" height=\"20\"></td></tr></table>";
    box.style.zIndex = 3;
    document.body.appendChild(box);
    ScrollBanOK();
    
    if(CurrentContent==0)
        document.getElementById("prior").style.display="none";
    if(CurrentContent+1>=NumContent)
        document.getElementById("next").style.display="none";
    
    GetContent();
    return false;
}
function GetNext()
{
    if(CurrentContent+1<NumContent)
    {
        CurrentContent++;
        if(CurrentContent>0)
            document.getElementById("prior").style.display="inline";
        if(CurrentContent+1>=NumContent)
            document.getElementById("next").style.display="none";
        GetContent();
    }
}
function GetPrior()
{
    if(CurrentContent>0)
    {
        CurrentContent--;
        if(CurrentContent==0)
            document.getElementById("prior").style.display="none";
        if(CurrentContent+1<NumContent)
            document.getElementById("next").style.display="inline";
        GetContent();
    }
}
function closemovie()
{
	ScrollBanNO();
	var element = document.getElementById("boxeio");
	document.body.removeChild(element);
	element = document.getElementById("backbox");
	document.body.removeChild(element);
}
function ScrollBanOK()
{
    var chrome = (/Chrome/.test(navigator.userAgent))?1:0;
    var safari = (/safari/.test(navigator.userAgent))?1:0;
    var firefox = (/firefox/.test(navigator.userAgent))?1:0;
    var ie=(/MSIE (\d+\.\d+);/.test(navigator.userAgent))?1:0;

    document.getElementById("boxeio").style.position = "absolute";
    if(chrome || safari)
        document.getElementById("boxeio").style.top = document.body.scrollTop +"px";
    else document.getElementById("boxeio").style.top = document.documentElement.scrollTop +"px";
    document.getElementById("boxeio").style.left = "0px";
    document.getElementById("boxeio").style.marginLeft = (screen.width/2 - ((document.getElementById("boxeio").offsetWidth/2)+20) ) +"px";
    document.getElementById("boxeio").style.marginTop = "10px";
    
    if(document.getElementById("boxeio").offsetHeight<screen.height-250)
        SB = window.setTimeout("ScrollBanOK()", 1);
}
function ScrollBanNO()
{
    window.clearTimeout(SB);
}
function setOpacity(opacity)
{
    var element = document.getElementById("backbox");
    opacity=(opacity==100) ? 99.999 : opacity;
    element.style.filter = "alpha(opacity:"+opacity+")";
    element.style.KHTMLOpacity = opacity/100;
    element.style.MozOpacity = opacity/100;
    element.style.opacity = opacity/100;
}
