﻿// JScript File
// <script language="javascript">

var videoWidth=640;
var videoHeight=376;
var imgWidth = 640; 
var imgHeight = 390;     

var fase=7;
var imgsize=600;
var stopfase=fase*imgsize;
var stopslide=false;

function sscroll()
{
   if (stopslide){return;}
   stopslide=true;
   ClosePanel();
   //document.getElementById("Label1").innerHTML="";
   btOpacity(50)
   var appList = document.getElementById("movies"); 
   var amov=appList.scrollLeft - imgsize; 
   intsval=setInterval("slide(-10," + amov + ")", 1)
}

function dscroll()
{
   if (stopslide){return;}
   stopslide=true;
   ClosePanel();
   //document.getElementById("Label1").innerHTML="";
   btOpacity(50)
   var appList = document.getElementById("movies");
   var amov=appList.scrollLeft + imgsize; 
   intsval=setInterval("slide(10," + amov + ")", 1)
}

function slide(astep,amov)
{
   var appList = document.getElementById("movies"); 
   
   appList.scrollLeft = appList.scrollLeft + astep;
   var hpos=appList.scrollLeft;
   var hver=hpos % imgsize;
   //var hver;
   //if (astep<0){hver=(hpos<=amov);}else{hver=(hpos>=amov);}
   if (hver==0 || hpos<=0 || hpos>=stopfase){clearInterval(intsval);appList.scrollLeft=amov;stopslide=false;btOpacity(100);}
}

function btOpacity(opacity)
{
   var appList = document.getElementById("movies"); 
   var hpos=appList.scrollLeft;
   var btnum=hpos/imgsize;
   eval("var obj = document.getElementById(\"bt" + btnum + "\");") 

   // IE/Win
   obj.style.filter = "alpha(opacity:"+opacity+")";
   // Safari<1.2, Konqueror
   obj.style.KHTMLOpacity = opacity/100;
   // Older Mozilla and Firefox
   obj.style.MozOpacity = opacity/100;
   // Safari 1.2, newer Firefox and Mozilla, CSS3
   obj.style.opacity = opacity/100;
}

function jmove(amov)
{
   if (stopslide){return;}
   stopslide=true;
   
   ClosePanel();
   //document.getElementById("Label1").innerHTML="";
   btOpacity(40)
   var appList = document.getElementById("movies");
   amov=amov*imgsize;

   var hstep;
   var hpos=appList.scrollLeft;

   if (hpos > amov){hstep=-30;}else{hstep=30;}
   intjval=setInterval("jslide("+ hstep + ","+ amov + ")", 1)
}

function startmove(amov)
{
   if (stopslide){return;}
   stopslide=true;
   
   btOpacity(40)
   var appList = document.getElementById("movies");
   amov=amov*imgsize;

   var hstep;
   var hpos=appList.scrollLeft;

   if (hpos > amov){hstep=-30;}else{hstep=30;}
   intjval=setInterval("jslide("+ hstep + ","+ amov + ")", 1)
}

function jslide(astep,amov)
{
   var appList = document.getElementById("movies"); 
   appList.scrollLeft = appList.scrollLeft + astep;

   var hpos=appList.scrollLeft;
   var hver;
   if (astep<0){hver=(hpos<=amov);}else{hver=(hpos>=amov);}
    
   if (hver|| hpos<=0 || hpos>=stopfase){clearInterval(intjval);appList.scrollLeft=amov;stopslide=false;btOpacity(100);}
   
}

function ClosePanel()
{
        document.getElementById("pannello").innerHTML="";
        document.getElementById("pannello").style.width="0px";  
        document.getElementById("pannello").style.height="0px";   
        document.getElementById("pannello").style.position="absolute";
        document.getElementById("pannello").style.left="1px";
        document.getElementById("pannello").style.top="1px";
        document.getElementById("pannello").style.visibility="hidden"; 
        
} 

function OpenPanel(playfunction,mp4,ytcode)
{
    ClosePanel();
    //document.getElementById("Label1").innerHTML="";
    var cw = getClientWidth()
    var ch = getClientHeight()
    
    var panelWidth=videoWidth+2;
    var panelHeight=videoHeight+40;    
    
    var mw=(cw/2)-(panelWidth/2);
    //var mh=(ch/2)-(panelHeight/2);
    //if (mh < 70) {mh=70;} 
    var mh=70;
    
    document.getElementById("pannello").style.width=panelWidth+"px";  
    document.getElementById("pannello").style.height=panelHeight+"px";
    document.getElementById("pannello").style.visibility="visible"; 
    document.getElementById("pannello").style.position="absolute";
    document.getElementById("pannello").style.left=mw+"px";
    document.getElementById("pannello").style.top=mh+"px";   
    codice="<div><img border=\"0\" src=\"images/loading.gif\" style=\"position:absolute;top: 150px; left:290px;\" /></div>"
    document.getElementById("pannello").innerHTML=codice;
    setTimeout(playfunction + "('" + mp4 + "','" + ytcode + "')", 1000)       
} 

function getClientWidth() {
  return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientWidth:document.body.clientWidth;
}

function getClientHeight() {
  return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight:document.body.clientHeight;
} 

function getPageWidth() {
	if (window.innerHeight && window.scrollMaxY) {  
		xScroll = window.innerWidth + window.scrollMaxX;  
	}else if (document.body.scrollHeight > document.body.offsetHeight){  
		xScroll = document.body.scrollWidth;  
		}else{  
		xScroll = document.body.offsetWidth;  
	}  
	return xScroll;
}

function getPageHeight() {
	if (window.innerHeight && window.scrollMaxY) {  
		yScroll = window.innerHeight + window.scrollMaxY;  
	}else if (document.body.scrollHeight > document.body.offsetHeight){  
		yScroll = document.body.scrollHeight;  
		}else{  
		yScroll = document.body.offsetHeight;  
	}  
	return yScroll;	
} 

function html5tag(xtag)
{
   var test=(!!document.createElement(xtag).canPlayType)  
   if (test) {test=(navigator.userAgent.indexOf("Firefox")==-1);}
   return test;
}

function mPlayVideo(mp4,ytcode)
{
    var srcfile="video/" + mp4

    var codice;

    //if (html5tag('video') && navigator.appName!="Microsoft Internet Explorer"){     
        //codice="<a href=\"#\" onclick=\"ClosePanel()\"><img border=\"0\" src=\"images/close.gif\" /></a>"
        //codice+="<div style=\"text-align: center;\">"    
        //codice+="<video controls preload autoplay=\"autoplay\" width=\"" + videoWidth + "\">"
        //codice+="<source src=\"" + srcfile + "\" type=\"video/mp4\"' />"
        //codice+="Your browser does not support this tag."
        //codice+="</video>"      
        //codice+="</div>"          
    //} else {
        codice="<a href=\"#\" onclick=\"ClosePanel()\"><img border=\"0\" src=\"images/close.gif\" /></a>"
        codice+="<div style=\"text-align: center;\">"
        //codice+="<OBJECT CLASSID=\"clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B\""
        //codice+=" CODEBASE=\"http://www.apple.com/qtactivex/qtplugin.cab\" WIDTH=\"" + videoWidth + "\" HEIGHT=\"" + videoHeight + "\" >"
        //codice+="<PARAM NAME=\"src\" VALUE=\"" + srcfile + "\" >"
        //codice+="<PARAM NAME=\"autoplay\" VALUE=\"true\" >"
        //codice+="<EMBED SRC=\"" + srcfile + "\" TYPE=\"image/x-macpaint\""
        //codice+="PLUGINSPAGE=\"http://www.apple.com/quicktime/download\" WIDTH=\"" + videoWidth + "\" HEIGHT=\"" + videoHeight + "\" AUTOPLAY=\"true\"></EMBED>"
        //codice+="</OBJECT>"
        codice+="<iframe width=\"640\" height=\"360\" src=\"http://www.youtube.com/embed/" + ytcode + "\" frameborder=\"0\" allowfullscreen></iframe>"
        codice+="</div>"      
    //}
    document.getElementById("pannello").innerHTML="";
    document.getElementById("pannello").innerHTML=codice;
 
}

    function viewImg(selimg)
    {
        ClosePanel();

        var pannello=document.getElementById("pannello")

        var cw = getClientWidth()
        var ch = getClientHeight()
        
        var panelWidth=imgWidth+2;
        var panelHeight=imgHeight+40;    
        
        var mw=(cw/2)-(panelWidth/2);
        //var mh=(ch/2)-(panelHeight/2);
        //mh=mh-50
        //if (mh < 50) {mh=50;} 
        var mh=50;
        pannello.style.width=panelWidth+"px";  
        pannello.style.height=panelHeight+"px";
        pannello.style.visibility="visible"; 
        pannello.style.position="absolute";
        pannello.style.left=mw+"px";
        pannello.style.top=mh+"px";  
        codice="<a href=\"#\" onclick=\"ClosePanel()\"><img border=\"0\" src=\"images/close.gif\" /></a><br>" 
        codice+="<img style='border:0px;' id='img1' src='/" + selimg + "' alt='' />"
        document.getElementById("pannello").innerHTML=codice; 
    }   



var montharray=new  Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")

function countdown(yr,m,d){
theyear=yr;themonth=m;theday=d
var today=new Date()
var todayy=today.getYear()
if (todayy < 1000)
todayy+=1900
var todaym=today.getMonth()
var todayd=today.getDate()
var todayh=today.getHours()
var todaymin=today.getMinutes()
var todaysec=today.getSeconds()
var todaystring=montharray[todaym]+" "+todayd+", "+todayy+" "+todayh+":"+todaymin+":"+todaysec
futurestring=montharray[m-1]+" "+d+", "+yr
dd=Date.parse(futurestring)-Date.parse(todaystring)
dday=Math.floor(dd/(60*60*1000*24)*1)
dhour=Math.floor((dd%(60*60*1000*24))/(60*60*1000)*1)
dmin=Math.floor(((dd%(60*60*1000*24))%(60*60*1000))/(60*1000)*1)
dsec=Math.floor((((dd%(60*60*1000*24))%(60*60*1000))%(60*1000))/1000*1)
if(dday==0&&dhour==0&&dmin==0&&dsec==1){
document.getElementById("countdown").innerHTML=current
return
}
else
document.getElementById("countdown").innerHTML="-" + dday + ":" + dhour + ":" + dmin + ":" + dsec
setTimeout("countdown(theyear,themonth,theday)",1000)
}

function posContainer()
{
    var container=document.getElementById("container");
    
    var cw = getClientWidth()
    var ch = getClientHeight()
    var posw=(cw-container.offsetWidth)/2;
    var posh=(ch-container.offsetHeight)/2;
    container.style.position="absolute";
    if (posw>0){container.style.left=posw+"px"};
    if (posh>0){container.style.top=posh+"px";}
    //if (cw > container.offsetWidth) {container.style.width=cw+"px";}
    //if (ch > container.offsetHeight) {container.style.height=ch"px";}
    container.style.visibility="visible";
 
} 
