oTime = 1;
oTime2 = 2;



////////////////////////////////////////////////////////////////
// Given an image and the width/height of the containing frame, 
// resizes the image
// NON USIAMO QUESTO 
////////////////////////////////////////////////////////////////
function SetMultimediaSize(container,img,maxWidth,maxHeight,marginTop,marginLeft){
    
    if(container==null || img==null)
        return;
           
    var imageFrameHeight=maxHeight;
    var imageFrameWidth=maxWidth;
    var imageHeight=imageFrameHeight;
    var imageWidth=imageFrameWidth;
    var imageThumbHeight=0;
    var imageThumbWidth=0;
    //carico l'immagine per stabilire le dimensioni	
    var documento;
    //documento=System.Gadget.document;
    //var temp=documento.createElement("img");
   
    var temp=document.createElement("img");
    temp.src = img.src;
    imageThumbWidth = temp.width;
    imageThumbHeight = temp.height;
     
    var color="none";
    var ratio=1;
    var style="";
    var applyHeight=false;
    //verifico se l'immagine č pių grande del campo.Si verificano entrambe le dimensioni
    if ((imageThumbHeight>imageFrameHeight) ||(imageThumbWidth>imageFrameWidth)){
        //ottengo la dimensione maggiore
        if (imageThumbWidth>=imageThumbHeight){ 
            ratio=imageThumbHeight/imageThumbWidth;
            var compr=imageThumbWidth/imageFrameWidth;    
            imageWidth=imageFrameWidth;  
            //imageHeight=imageFrameHeight*ratio;
            imageHeight=imageThumbHeight/compr;  
            color="red";
        }
        else
        {   
            ratio=imageThumbHeight/imageThumbWidth;   
            var compr= imageThumbHeight/imageFrameHeight;
            //imageWidth=imageFrameWidth/ratio;
            imageWidth=imageThumbWidth/compr;  
            
            imageHeight=imageFrameHeight;   
            color="blue";
        }
    }
    else
    {
        imageWidth=imageThumbWidth;
        imageHeight=imageThumbHeight;
        color="black";
    }
    var x=Math.round(imageWidth);
    var y=Math.round(imageHeight);
    //determino il margin da dare...
    var deltax=Math.round((imageFrameWidth-x)/2);
   //
    if (marginLeft)
        deltax+=marginLeft;
        
    var deltay=Math.round((imageFrameHeight-y)/2);
    if (marginTop)
        deltay+=marginTop;
    //var style="style=\"width:"+x+"px;heigth:"+y+"px;border:1px solid "+color+";margin-top:"+deltay+"px;margin-left:"+deltax+"px;\"";
   // var style="style=\"width:"+x+"px;heigth:"+y+"px;margin-top:"+deltay+"px;margin-left:"+deltax+"px;\"";
    var style="style=\"width:"+x+"px;heigth:"+y+"px;margin-top:"+deltay+"px;margin:auto;\"";
    img.style.width=x.toString()+'px';
    img.style.height=y.toString()+'px';
    img.style.marginTop=deltay.toString()+'px';
    //img.style.marginLeft=deltax.toString()+'px';
    img.style.margin='auto';
    //img.style.border="1px solid "+color;
    container.appendChild(img);
}


function VerticalSlide(sD, sDD, iShiftY, iSpeed, sUp, sDown)
{	
	if (sD == "" || sDD == "" || sUp == "" || sDown == "")
		return;

    var	oD = eval("document.getElementById('"+ sD +"')");  //div interno scorrevole
	var oDD = eval("document.getElementById('"+ sDD +"')"); //div esterno
	var	btnUp = eval("document.getElementById('"+ sUp +"')");
	var	btnDown = eval("document.getElementById('" + sDown + "')");

//	if (oD == null || oDD == null || btnUp == null || btnDown == null)
//		return;
	
	if (!document.layers)
	{
		oD = oD.style;
		oDD = oDD.style;
		oUp = btnUp.style;
		oDown = btnDown.style;
	}
	
	var iTopBorderPosition = parseInt(oD.left);
	var iContainerHeight = parseInt(oDD.width), iSlidingObjectHeight =  parseInt(oD.width);
	if (iContainerHeight - iSlidingObjectHeight >= 0)
		return;
	
	var iMaxTop = iContainerHeight - iSlidingObjectHeight;
	
	//iTopBorderPosition = iTopBorderPosition + iShiftY;
	iTopBorderPosition = iTopBorderPosition + iShiftY;
	
		
	if (iTopBorderPosition >= 0)
	{
		eval("oUp.cursor = 'default'");
		//eval("oDown.cursor = 'hand'");
		eval("oDown.cursor = 'pointer'");
		iShiftY = -parseInt(oD.left);
		SlowSliding(sD,iShiftY,iSpeed);
	}
	else if(iTopBorderPosition <= iMaxTop)
	{	
//		eval("oUp.cursor = 'hand'");
        eval("oUp.cursor = 'pointer'");
		eval("oDown.cursor = 'default'");
		iShiftY = iMaxTop - parseInt(oD.left);
		SlowSliding(sD,iShiftY,iSpeed);		
	}
	else
	{
//		eval("oUp.cursor = 'hand'");
//		eval("oDown.cursor = 'hand'");
        eval("oUp.cursor = 'pointer'");
		eval("oDown.cursor = 'pointer'");
		SlowSliding(sD,iShiftY,iSpeed);	
	}
	
	var sFunction = "VerticalSlide('" + sD + "','" + sDD + "'," + iShiftY + "," + iSpeed + ",'" + sUp + "','" + sDown + "')";
	oTime2 = setTimeout(sFunction,500);
}

function SlowSliding(sD,iShiftY,iSpeed)
{
	if (sD == "")
		return;
//	var	oD = eval("FindObject('" + sD + "')");
var	oD = eval("document.getElementById('" + sD + "')");


	if (oD == null)
		return;
	if (!document.layers)
		oD = oD.style;
			
	if (oTime != null)
		{clearTimeout(oTime);}
		
	
	var iTopBorderPosition = parseInt(oD.left);
	var iFinalY = iTopBorderPosition + iShiftY;
		
	if (iTopBorderPosition != iFinalY)
	{		
		var iMY = ((iFinalY - iTopBorderPosition) / iSpeed);  
		iMY = (iMY > 0) ? Math.ceil(iMY) : Math.floor(iMY);
		iFinalY = iTopBorderPosition + iMY;
		
		var sS = "";
		if ((parseInt(navigator.appVersion)>4 || navigator.userAgent.indexOf("MSIE")>-1) && (!window.opera))
			{sS="px";}
					
		if (iMY != 0)	//effettivo assegnamento dello spostamento in verticale
		{			
			eval("oD.left = '" + iFinalY + sS + "'");
		}
		
		var iY = iShiftY - iMY;
		var sFunction = "SlowSliding('" + sD + "'," + iY + "," + iSpeed + ")";
				
		oTime = setTimeout(sFunction,10);
	}
}

function StopSlide()
{
	if (oTime2 != null)
		{clearTimeout(oTime2);}
}