﻿///<reference path="main.js" />
function getWindowSize(popupWindow){
 var obj = (popupWindow)? popupWindow: window;
 var w = 0;
 var h = 0;
	if(obj.innerWidth){
		w=obj.innerWidth;
		h=obj.innerHeight;
	}
 	else{
		var docElement = (obj.document.documentElement && obj.document.documentElement.clientWidth && obj.document.documentElement.clientWidth != 0);
	w=(docElement)?obj.document.documentElement.clientWidth:obj.document.getElementsByTagName('body')[0].clientWidth;
	h=(docElement)?obj.document.documentElement.clientHeight:obj.document.getElementsByTagName('body')[0].clientHeight;
 	}
return {width:w,height:h};
}

function determineContents(width,height){
    if(AddScroll()){
    return true;   
    }
    else{
    return false;
    }
    function AddScroll(){
    //If the browser height is less than the video height
    return (height > getWindowSize().height);
    }
}

function popDownload(t)
{
    //t:training title, u:UId
    var popupWindow = (window.open('/download?t='+t,'11any_download','height=1,width=1,menubar=0,resizable=1,location=0,directories=0,toolbar=0,scrollbars=0,status=0'));
}

function request(url, userCaptionPreference, hasCaption, w, h) 
{
    var width=w;
    var height = h;
	if(userCaptionPreference != "")
	{
		if(typeof(hasCaption) == "undefined")
		{
			hasCaption = false;
		}
		if(userCaptionPreference == "yes" && hasCaption)
		{
			width = width - 96;
		}
	}

    var popupWindow = popupVideo('/files/movie?f='+url+'&cap='+hasCaption+'&userCap='+userCaptionPreference,'11any',width,height);
}

function popupVideo(url,popup,width,height)
{
    var popupWindow;
    if(determineContents(880,600))//standard ie6 676-76
    {
	    width += 17;
	    height += 20;
	    popupWindow = (window.open(url,popup,'height=' + height + ',width=' + width + ',menubar=0,resizable=1,location=0,directories=0,toolbar=0,scrollbars=1,status=0'));
    }
    else
    {
        popupWindow = (window.open(url,popup,'height=' + height + ',width=' + width + ',menubar=0,resizable=1,location=0,directories=0,toolbar=0,scrollbars=0,status=0'));
    }
    return popupWindow;	
}

//use the popup menu
var snap;
function ShowSnap(uid, controlID, isCaptioned)
{
    //keep the same thumb WIDTH, but actually the two kind of movie have the same HEIGHT
    var heightOffset = 195;//194 + 1
    var middleHeight = 152;
    if(isCaptioned == 'True')
    {
        heightOffset = 211;//194 + 16 + 1
        middleHeight = 168;//155 + 16
    }
    
    var control = document.getElementById(controlID);      
    if(control != null)
    {
        var divSnapLeft = GetOffsetLeft(control);
        var divSnapTop = GetOffsetTop(control);
        var html= 
                "<div class='bg'>"
                    +"<div class='top'></div>"
                    +"<div class='middle' style='height:" + middleHeight + "px'></div>"
                    +"<div class='bottom'></div>"
             +"</div>"
             +"<div class='content'>"
                    +"<div class='header'><strong>视频截图</strong></div>" 
                    +"<div>"
                        +"<img class='snapImg' src='/Images/Snap/" + uid + ".jpg' />"  
                    +"</div>"
             +"</div>" ; 
     
        if(snap == null)
        {
            var snapDiv = document.getElementById("snapDiv");
            snapDiv.innerHTML = html;
            snap = new PopupMenu(snapDiv,divSnapLeft+20,divSnapTop-heightOffset ,228,0,false,false, null);
            snap.SetZIndex(100);  
            snap.Show();      
        }
        else
        {
            snap.Div.innerHTML = html;
            snap.Left = divSnapLeft+20;
            snap.Top = divSnapTop-heightOffset;
            snap.Show();         
        }
    }
}

function HideSnap()
{
    if(snap != null)
    {
        snap.Hide();
    }
}



