var video_comm_frame = 0;
var video_comm_timer = null;
var video_comm_cnt = { left: -197, top:-70 , width:980 , height:440 ,cnt :null };

function ShowVideoCommBoxFrame()
{
    var cnt = video_comm_cnt.cnt;
    var offset_x = (video_comm_cnt.width/2)*((100-video_comm_frame)/100);
    var offset_y = (video_comm_cnt.height/2)*((100-video_comm_frame)/100);
 
    cnt.style.left = video_comm_cnt.left + offset_x + "px";
    cnt.style.top = video_comm_cnt.top + offset_y + "px";
    cnt.style.width = video_comm_cnt.width - 1.9*offset_x + "px";
    cnt.style.height = video_comm_cnt.height - 1.9*offset_y + "px";
    cnt.style.display = "block";
    SetOpacity(cnt,video_comm_frame / 120);
    video_comm_frame = MakeInc( video_comm_frame,0, 100, 10 );
    if( video_comm_frame >= 100 )
    {
        clearInterval(video_comm_timer);
        video_comm_timer = null;
        video_comm_frame = 0;
        cnt.style.left = video_comm_cnt.left + "px";
        cnt.style.top = video_comm_cnt.top + "px";
        cnt.style.width = video_comm_cnt.width +"px";
        cnt.style.height = video_comm_cnt.height + "px";
        $get("videopopupinner").style.display = "block";
    }
}

function HideVideoCommBoxFrame()
{
    SetOpacity(video_comm_cnt.cnt,(100-video_comm_frame) / 120);
    video_comm_frame = MakeInc( video_comm_frame,0, 100, 10 );
    if( video_comm_frame >= 100 )
    {
        clearInterval(video_comm_timer);
        video_comm_timer = null;
        video_comm_frame = 0;
        video_comm_cnt.cnt.style.display = "none";
    }

}

function CloseVideoComm()
{
    $get("videopopupinner").style.display = "none";
     $get("video_comm_out").innerHTML = "";
    video_comm_timer = setInterval( HideVideoCommBoxFrame , 30 ); // let's animate it //
}

function VideoComm(uid)
{
    var cnt = $get("videopopup");
    if($get("videopopupinner").style.display != "block")
    {
        video_comm_cnt.cnt = cnt;
        video_comm_timer = setInterval( ShowVideoCommBoxFrame , 30 ); // let's animate it //
    }
    $get("video_comm_out").innerHTML = "<img src='images/public/ajax-loader1.gif' width='66' height='66' style='margin-left:440px;margin-top:150px; filter:progid:DXImageTransform.Microsoft.Alpha(opacity=80);-moz-opacity:0.8;opacity:0.8;khtml-opacity:0.8' />";
    $get(hdn_video_id).value = uid;
    eval(video_comm_postback);
}

function MakeInc(ax,amin,amax,aspeed)
{
    if( ax < amax )
	{
		var t = ((ax-amin) / (amax - amin)) * (Math.PI / 2);
		if( t<0 ) 
		{
    		var t =(Math.PI / 8);
		}
	    	var amp = 2*Math.cos(  t  )*Math.sin(t )+ 0.2; // constant to start //
			ax += aspeed * amp; 
		}
	return ax;
}

// val in [0,1]
function SetOpacity(object,val)
{
    object.style.opacity = val;
    object.style.MozOpacity = val;
    object.style.KhtmlOpacity = val;
    object.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity="+val*100+")";
}

