﻿///Lista contenente i video
var playlistslot=new Array();
playlistslot[0]="swf/Player_video_Art3.swf";
playlistslot[1]="swf/Player_video_Art15.swf";
playlistslot[2]="swf/Player_video_Art19.swf";
playlistslot[3]="swf/Player_video_Art34.swf";
playlistslot[4]="swf/Player_video_Art36.swf";

///Lista contenente i download dei video
var playlistslotdownload=new Array();
playlistslotdownload[0]="download/Art_03.zip";
playlistslotdownload[1]="download/Art_15.zip";
playlistslotdownload[2]="download/Art_19.zip";
playlistslotdownload[3]="download/Art_34.zip";
playlistslotdownload[4]="download/Art_36.zip";

///Restituisce il DIV corrente a seconda del browser
function getObj(name)
{
  var obj;
  if (document.getElementById)
  {
    obj = document.getElementById(name);
  }
  else if (document.all)
  {
    obj = document.all[name];
  }
  else if (document.layers)
  {
    obj = document.layers[name];
  }
  return obj;
}

function PageQuery(q) 
{
  if(q.length > 1) 
    this.q = q.substring(1, q.length);
  else this.q = null; 
  
  this.keyValuePairs = new Array();
  if(q) 
  {
    for(var i=0; i < this.q.split("&").length; i++) 
    {
      this.keyValuePairs[i] = this.q.split("&")[i];
    }   
  }
  
  this.getKeyValuePairs = function() 
  { 
    return this.keyValuePairs; 
  }
  
  this.getValue = function(s) 
  {
    for(var j=0; j < this.keyValuePairs.length; j++) 
    {
      if(this.keyValuePairs[j].split("=")[0] == s)
      return this.keyValuePairs[j].split("=")[1];
    }
    return false;
  }
  this.getParameters = function() 
  {
    var a = new Array(this.getLength());
    for(var j=0; j < this.keyValuePairs.length; j++) 
    {
      a[j] = this.keyValuePairs[j].split("=")[0];
    }
    return a;
  }
  
  this.getLength = function() { return this.keyValuePairs.length; }
}

function queryString(key)
{
  var page = new PageQuery(window.location.search);
  return unescape(page.getValue(key));
}

///Inizializza il video a seconda della query string
function InitVideo()
{
  var existsQueryStringValue = queryString("videoID");
  var videoNumberID = parseInt(queryString("videoID")); 
  
  if(existsQueryStringValue == 'false')
  {  
    SetActiveVideoButton('CosVideo1', 1);
    SetPlayerVideo(playlistslot[0], 'costituzioneleftcolumnvideocontainer');
    SetTellToFriendVideoUrl(1);
  }
  else
  {
    if(videoNumberID > 0 && videoNumberID <=5)
    {  
      SetActiveVideoButton('CosVideo'+videoNumberID, videoNumberID);
      
      SetPlayerVideo(playlistslot[videoNumberID-1], 'costituzioneleftcolumnvideocontainer');
      SetTellToFriendVideoUrl(videoNumberID);
    }
    else
    {
      SetActiveVideoButton('CosVideo1', 1);
      SetPlayerVideo(playlistslot[0], 'costituzioneleftcolumnvideocontainer');
      SetTellToFriendVideoUrl(1);
    }
  }
}

function SetActiveVideoButton(videoID, videoNumber)
{ 
  var objVideoLink = getObj(videoID);
  
  ///Imposta lo stile per il video attivo
  objVideoLink.setAttribute("class","costituzionevideolinkactive"+videoNumber);
  objVideoLink.className = "costituzionevideolinkactive"+videoNumber;

  ///Imposta i restanti video come inattivi
  
  for(i=1; i<= 5; i++)
  {
      var objVideoLinkUnActive = getObj("CosVideo"+i);
      ///Cambia lo stile tranne che per il video attivo
      if(i!=videoNumber)
      {    
        ///Imposta lo stile per il video attivo
        objVideoLinkUnActive.setAttribute("class","costituzionevideolink"+i);
        objVideoLinkUnActive.className = "costituzionevideolink"+i;
      }
  }
  
  ///Imposta il link dillo ad un amico
  SetTellToFriendVideoUrl(videoNumber);
  
  ///Imposta il pulsante download
  SetDownloadButtonUrl(videoNumber);

}



function SetPlayerVideo(videoUrl, playervideocontainer)
{
  ///Individua il container video del playyer
  var objPlayervideocontainer = getObj(playervideocontainer);
  
  ///Imposta il video da riprodurre
 
  var stringPlayVideo = '';
  
  stringPlayVideo+= '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="433" height="382">';
  stringPlayVideo+='<param name="allowScriptAccess" value="sameDomain" />';
  stringPlayVideo+='<param name="movie" value="'+videoUrl+'" />';
  stringPlayVideo+='<param name="quality" value="high" />';
  stringPlayVideo+='<param name="bgcolor" value="#ffffff" />';
  stringPlayVideo+='<param name="wmode" value="transparent" />';
  stringPlayVideo+='<param name="base" value="/images/flash/" />';
  stringPlayVideo+='<embed src="'+videoUrl+'" base="/images/flash/" wmode="transparent" quality="high" bgcolor="#ffffff" width="433" height="382" name="banner_10" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
  stringPlayVideo+='</object>';
  
  objPlayervideocontainer.innerHTML = stringPlayVideo;
  
  
}

function SetTellToFriendVideoUrl(videoNumber)
{
  ///Individua il container del link dillo a un amico
  var objJCTellToFriendLink = getObj('CostituzioneTellToFriendLink');
  
  objJCTellToFriendLink.setAttribute("onclick","showRules('popup-inviaamico.asp" + "?videoID="+videoNumber+"');");
  
  ///Per IE è necessario aggiunge il listener per l'evento (a causa del bug sulla setAttribute)
  objJCTellToFriendLink.onclick = function()
  {
    showRules("popup-inviaamico.asp?videoID="+videoNumber);
  };

}

function SetDownloadButtonUrl(videoNumber)
{
  ///Individua il container del Download
  var objDownloadLink = getObj('CostituzioneDownloadLink');

  ///Imposta la url
  objDownloadLink.setAttribute("href",playlistslotdownload[videoNumber-1]);
  objDownloadLink.href = playlistslotdownload[videoNumber-1];

}






