function CGMInitFinished(CGMPlayerObj) {
	CGMPlayer = CGMPlayerObj;
	CGMPlayer.SetZoomRange(30,2000);
	CGMLastSelectedHs = null;
	CGMClearTimeout();
	CGMBlink();
	CGMHintCache = new Array();
	CGMOpeningFile=true;
}

var xwert = -50;
var ywert = 50;

function CGMMoveHSInCanvas(hsName) { 
	if(CGMLastHS4Moving == hsName) return;
	
	if(CGMLastSelectedHs.split(",").length>1) {
		if(CGMPlayer.Viewsize != CGMInitZoomSize)
			CGMPlayer.Viewsize = CGMInitZoomSize;
		CGMPlayer.OffsetX=0;
		CGMPlayer.OffsetY=CGMPlayer.ExtentY;
	} else {

	  CGMPlayer.SetViewPort("$OBJ_"+hsName);
	  var x = CGMPlayer.OffsetX;
	  var y = CGMPlayer.OffsetY;
	  //alert("CGMPlayer.ExtentY: "+CGMPlayer.ExtentY+"\nCGMPlayer.ExtentX: "+CGMPlayer.ExtentX+
	  //"\nzFaktor: "+CGMPlayer.Viewsize+"\nCGMPlayer.OffsetY: "+CGMPlayer.OffsetY+"\nCGMPlayer.OffsetX: "+CGMPlayer.OffsetX);
	  var newx = x+xwert;// *(z/100);
	  var newy = y+ywert;// *(z/100);
	  CGMPlayer.Viewsize = 150;
	  if(newy>CGMPlayer.ExtentY)
	  	newy = CGMPlayer.ExtentY;
	  if(newy<0)
	  	newy = 0;
	  if(newx>CGMPlayer.ExtentX)
	  	newx = CGMPlayer.ExtentX;
	  if(newx<0)
	  	newx=0;
	  CGMPlayer.OffsetX=newx;
	  CGMPlayer.OffsetY=newy;
  	}
  	CGMLastHS4Moving = hsName;
}

function CGMFileHasChanged(fileName) {
	if(CGMCurrentFile != fileName) {
		CGMLastHS4Moving = null;
		CGMInitZoomSize = CGMPlayer.Viewsize;
		CGMLastSelectedHs = null;
		CGMHintCache = new Array();
		CGMCurrentFile = fileName
		fileName = fileName.substring(0,fileName.lastIndexOf("["));
		fileName += ".cgm";
		if(CGMOpeningFile==false)   {
			belenusHome.sendMessage("Table","ChangeImage","Label="+fileName);
		}
		CGMOpeningFile=false;
		if(CGMCurrentFile.indexOf("ueb") != -1) showReset2InitialView=false;
	} else {
		if(CGMCurrentFile!=null) {
			if(CGMCurrentFile.indexOf("ueb") != -1) showReset2InitialView=false;
			else showReset2InitialView=true;
		}
	}
	CGMDisposeMenu();
}

function CGMContextMenuItemHit(item,title) {
	if(showReset2InitialView==true) {
		if(item==1) 
			CGMPlayer.GoHome();
		else if(item==2) 
			belenusHome.eventHandler("AddSelectionToBasket", null);	
	} else {
		if(item==1) 
			belenusHome.eventHandler("AddSelectionToBasket", null);	
	}
}

var showReset2InitialView = false;
function CGMSetHome(a,b) {
	CGMPlayer.setHome(a,b);
	if(a.indexOf("ueb") != -1) showReset2InitialView=true;
	else showReset2InitialView=false;
	if(CGMCurrentFile!=null && CGMCurrentFile.indexOf("ueb") != -1) showReset2InitialView=false;
	CGMDisposeMenu();
}

function CGMCreateMenu() {
	CGMPlayer.DisposeContextMenu();
	if(showReset2InitialView)CGMPlayer.AddContextMenuItem( ""+belenusHome.ld['resetToInitialView'], true );
	CGMPlayer.AddContextMenuItem( ""+belenusHome.ld['orderCurrentPart'], true );
	CGMPlayer.CreateContextMenu();
}

function CGMDisposeMenu() {
	CGMPlayer.DisposeContextMenu();
	if(showReset2InitialView)CGMPlayer.AddContextMenuItem( ""+belenusHome.ld['resetToInitialView'], true );
	//CGMPlayer.AddContextMenuItem( ""+belenusHome.ld['orderCurrentPart'], true );
	CGMPlayer.CreateContextMenu();
}