var IDTimeOut = 0;
var TimeOut = 31000;
var VideoEnDirecto = false;
var Streaming;

var Navegador = navigator.appVersion;
var IE = Navegador.indexOf("MSIE") != -1;
var VersionMayor = 0;
var VersionMenor = 0;
if (IE){
  
  var PosicionInicio = Navegador.indexOf("MSIE");
  var PosicionFin = Navegador.indexOf(";",PosicionInicio);
  VersionMayor = parseInt(Navegador.substring(PosicionInicio+5,PosicionFin).split(".")[0],10);
  VersionMenor = parseInt(Navegador.substring(PosicionInicio+5,PosicionFin).split(".")[1],10);
}

if (screen.availWidth<1000){ location.href = "http://www.vinseum.cat/Site800/TV";}

function Refrescar(){
	clearTimeout(IDTimeOut);
  ComprobarVideoEnDirecto();
}

function ComprobarVideoEnDirecto(){
  var xmlHttp;
  try{
  // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
  }catch (e){
  // Internet Explorer
    try{
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }catch (e){
      try{
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }catch (e){
        alert("Your browser does not support AJAX!");
        return false;
      }
    }
  }
  xmlHttp.onreadystatechange=function()
    {
    if(xmlHttp.readyState==4)
      {
        if (xmlHttp.responseText == "offline"){
          if (VideoEnDirecto && IE && VersionMayor <= 6){
            Streaming.close();
          }
          VideoEnDirecto = false;
       		var so = new SWFObject("IntroTV.swf", "TVVinseum", "320px", "240px", "6", "#FFFFFF",false, "high");
        	so.addParam("menu", "false");
        	so.addParam("wmode", "transparent");
        	so.addParam("allowScriptAccess", "sameDomain");
      		so.write("Video");
      		
      		IDTimeOut = setTimeout("Refrescar()",TimeOut);
        }else if (xmlHttp.responseText == "online"){
          if (!VideoEnDirecto){
            VideoEnDirecto = true;
            var HTML = "";
            if (IE && VersionMayor <= 6){
              HTML = "Si el seu navegador ha bloquejat el pop-up,<br/>ha d'habilitar aquest pop-up per a poder<br/>visualitzar la TVinseum.";
              document.getElementById("Video").innerHTML = HTML;
            
              Streaming = window.open("http://theorasea.org/itheora/index.php?v=http://coclea.tv:8000/vinseum.ogg&w=340&h=280&n=TVinseum&l=es&d=mtdos","TVinseum","width=340,height=280,left="+(screen.width/2 - 340/2)+",top="+(screen.height/2 - 280/2)+",toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no");
            }else{
              HTML = "<iframe src=\"http:\/\/theorasea.org\/itheora\/index.php?v=http://coclea.tv:8000/vinseum.ogg&amp;w=340&amp;h=280&amp;n=TVinseum&amp;l=es&amp;d=m\" type=\"text\/html\" style=\"border: 0px none ; width:340px; height:280px;\" allowtransparency=\"true\" frameborder=\"0\" ><\/iframe>";
//              HTML = "<iframe id=\"Tele\" frameborder=\"0\" marginheight=\"0\" marginwidth=\"0\" scrolling=\"No\" style=\"width:100%; height:100%;\" src=\"http://www.barcelona-design.net/ITheora/index.php?v=http://coclea.tv:8000/vinseum.ogg&w=340&h=280&n=TVinseum&l=es&d=mtdos\"><\/iframe>";
              document.getElementById("Video").innerHTML = HTML;
            }
          }
          IDTimeOut = setTimeout("Refrescar()",TimeOut);
        }
      }
    }
  xmlHttp.open("GET","ComprobarVideoEnDirecto.asp",true);
  xmlHttp.send(null);
}

function Redimensionar(){
  window.moveTo(0,0);
  window.resizeTo(screen.availWidth, screen.availHeight);
}
function Medidas(){
  var myWidth=0;
  var myHeight=0;
    
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  }else if( document.documentElement ){
    if ( document.documentElement.clientWidth || document.documentElement.clientHeight ){
      //IE 6+ in 'standards compliant mode'
      myWidth = document.documentElement.clientWidth;
      myHeight = document.documentElement.clientHeight;
    }
  }else if( document.body ){
    if( document.body.clientWidth || document.body.clientHeight ){
      //IE 4 compatible
       myWidth = document.body.clientWidth;
       myHeight = document.body.clientHeight;
    }
  }
      
  if (myHeight > 713){
    document.getElementById("Central_Contenido").style.height = myHeight + "px";
    document.getElementById("C_Vints").style.height = (myHeight-40-197) + "px";
    document.getElementById("C_Programacio").style.height = (myHeight-40-197) + "px";
    document.getElementById("C_Projeccions").style.height = (myHeight-40-197) + "px";
    document.getElementById("Patrocinadores").style.top = (myHeight-40-197-108) + "px";
  }
}

function VerFicha(){
  var HTML = "<a class=\"Negro\" href=\"javascript:;\" onclick=\"VerVideos();\">Veure Videos<\/a>";
  document.getElementById("VF").innerHTML = HTML;
  
  document.getElementById("C_Vints").innerHTML = CVintsFitxa;
}

function VerVideos(){
  var HTML = "<a class=\"Negro\" href=\"javascript:;\" onclick=\"VerFicha();\">Veure Fitxa<\/a>";
  document.getElementById("VF").innerHTML = HTML;
  
  if (Seccion == "AltresPropostes") document.getElementById("C_Vints").innerHTML = CVints_Vints;
  else if (Seccion == "Entrevistes") document.getElementById("C_Vints").innerHTML = CVints_Entrevistes;
  else if (Seccion == "Presencies") document.getElementById("C_Vints").innerHTML = CVints;
}

function CambiarSeccion( Secc ){
  var HTML = "";
  if ( Secc == "Presencies" ){ HTML = CVints;}
  else if ( Secc == "Entrevistes" ){ HTML = CVints_Entrevistes;}
  else if ( Secc == "AltresPropostes" ){ HTML = CVints_Vints;}

  document.getElementById("C_Vints").innerHTML = HTML;  

  if (Secc == "AltresPropostes") document.getElementById("C_Programacio").innerHTML = Vin;
  else if (Secc == "Entrevistes") document.getElementById("C_Programacio").innerHTML = Ent;
  else if (Secc == "Presencies") document.getElementById("C_Programacio").innerHTML = Pre;
  
  Seccion = Secc;
}
