initvideoedit();

function initvideoedit(args)
{
	var hMainWnd = dcvideoedit.GetHandle();
	var hPreviewWnd = dcvideoedit.staticvideopreview.GetHandle();
	g_dvdcreator.InitVideoEditClass(	hMainWnd, 
						hPreviewWnd);
						
	dcvideoedit.slidervideotime.setfrommid(5);
	dcvideoedit.slidervideotime.SetRange(0, 100);
	dcvideoedit.slidervideotime.reset();
	dcvideoedit.slidervideotime.SetMidText("00:00:00");
	dcvideoedit.slidervideotime.SetPos(0);
	
	dcvideoedit.buttonctrlplay.SetEnable(false);
	dcvideoedit.buttonctrlstop.SetEnable(false);
	dcvideoedit.buttonctrlgobeg.SetEnable(false);
	dcvideoedit.buttonctrlgoend.SetEnable(false);
						
}

function dcvideoedit_onmove(args)
{
	g_dvdcreator.VideoEditMove();
}

var arrayvideorange = new Array();
var arraybreviarypos = new Array();
var tmpbreviarypos = -1;

var dcvideoedit_curritem = -1;
var dcvideoedit_dvdplaystatus = 0;

var dcvideoedit_oldsize = 0;
var dcvideoedit_newsize = 0;

function dcvideoedit_play(args)
{
/*
	var str1 = dcvideoedit.slidervideotime.getmax();
	var str2 = dcvideoedit.slidervideotime.getmin();
	var str3 = dcvideoedit.slidervideotime.GetPos();
	var str4 = dcvideoedit.slidervideotime.GetSelectRange();
	Msg(str1+"\r\n"+str2+"\r\n"+str3+"\r\n"+str4);
*/	
	var str = g_dvdcreator.GetCurrVideo();
	if(str.length <= 0)
	{
		return 1;
	}

	if(dcvideoedit_dvdplaystatus==0)
	{
		dcvideoedit.buttonctrlplay.SetImage("pause.png");
		dcvideoedit.buttonctrlplay.SetTipText("_btn_pause");
		dcvideoedit_dvdplaystatus=1;
		
		g_dvdcreator.VideoEditPlay();
	}
	else
	{
		dcvideoedit.buttonctrlplay.SetImage("play.png");
		dcvideoedit.buttonctrlplay.SetTipText("_btn_play");
		dcvideoedit_dvdplaystatus=0;

		g_dvdcreator.VideoEditPause();
	}
	
	dcvideoedit.buttonctrlplay.SetEnable(true);
	dcvideoedit.buttonctrlstop.SetEnable(true);
	dcvideoedit.buttonctrlgobeg.SetEnable(true);
	dcvideoedit.buttonctrlgoend.SetEnable(true);
}

function dcvideoedit_stop(args)
{
	g_dvdcreator.VideoEditStop();

	dcvideoedit_dvdplaystatus=0;

	dcvideoedit.slidervideotime.SetMidText("00:00:00");
	dcvideoedit.slidervideotime.SetPos(0);
	
	dcvideoedit.staticvideopreview.SetImage("Skin\\black.png");
	dcvideoedit.buttonctrlplay.SetImage("play.png");
	dcvideoedit.buttonctrlplay.SetTipText("_btn_play");
	
	dcvideoedit.buttonctrlplay.SetEnable(true);
	dcvideoedit.buttonctrlstop.SetEnable(false);
	dcvideoedit.buttonctrlgobeg.SetEnable(false);
	dcvideoedit.buttonctrlgoend.SetEnable(false);
	
}

function dcvideoedit_dvdprevious(args)
{
	g_dvdcreator.VideoEditPrevious();
}

function dcvideoedit_dvdnext(args)
{
	g_dvdcreator.VideoEditNext();
}

function dcvideoedit_sliderchange(args)
{
	var pos = dcvideoedit.slidervideotime.GetPos();
	
	g_dvdcreator.VideoEditSeek(pos);
}

function dcvideoedit_reset()
{
	tmpbreviarypos = -1;
	dcvideoedit.slidervideotime.reset();
}

function dcvideoedit_setbeg()
{
	var pos = dcvideoedit.slidervideotime.GetPos();
	dcvideoedit.slidervideotime.setstartpos(pos);
}

function dcvideoedit_setend()
{
	var pos = dcvideoedit.slidervideotime.GetPos();
	dcvideoedit.slidervideotime.setendpos(pos);
}

function dcvideoedit_setbreviary()
{
	tmpbreviarypos = dcvideoedit.slidervideotime.GetPos();
}

function dcvideoedit_confirm()
{
	var tmprange = dcvideoedit.slidervideotime.GetSelectRange();
	if(tmprange==null || tmprange.length<=0)
	{
		tmprange = new Array();
		tmprange[0] = 0;
	}
	arrayvideorange[dcvideoedit_curritem] = tmprange;
	arraybreviarypos[dcvideoedit_curritem] = tmpbreviarypos;
	
	var str = g_dvdcreator.GetCurrVideo();
	if(str.length > 0)
	{
		dcvideoedit_newsize = getlengthfromrange(str);
		dcmain.progresscontent.curdisksize -= dcvideoedit_oldsize;
		dcmain.progresscontent.curdisksize += dcvideoedit_newsize;
		updateprogress(dcmain.progresscontent.curdisksize);
		
		var tmplen = dcvideoedit.slidervideotime.geteditlen();
		tmplen = tmplen * 1;
		if(tmplen > 100)
		{
			var timestr = g_dvdcreator.ConvertTimeToString(tmplen);
			dcmain.listctrlfiles.SetValue(dcvideoedit_curritem, 5, timestr);
		}
	}
	
	dcvideoedit_close();
}

function dcvideoedit_close()
{
	dcvideoedit_dvdplaystatus = 0;

	dcvideoedit_stop();
	
	g_dvdcreator.VideoEditClose();
	
	var cutstr = "skin\\";
	var skin = dcsetting.tabbasic.comboshow.GetCurSel();
	var skinstr = dcsetting.tabbasic.comboshow.GetData(skin);
	
	cutstr += skinstr;
	cutstr += "\\";
	cutstr += "pen.png";
	
	if(arrayvideorange[dcvideoedit_curritem][0] > 0)
	{
		dcmain.listctrlfiles.SetValue(dcvideoedit_curritem, 0, cutstr);
	}
	else
	{
		dcmain.listctrlfiles.SetValue(dcvideoedit_curritem, 0, "");
	}

	dcvideoedit.slidervideotime.reset();
	dcvideoedit.Close();
}
