function findObj(theObj, theDoc)
{
  var p, i, foundObj;
  
  if(!theDoc) theDoc = document;
  if( (p = theObj.indexOf("?")) > 0 && parent.frames.length)
  {
    theDoc = parent.frames[theObj.substring(p+1)].document;
    theObj = theObj.substring(0,p);
  }
  if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
  for (i=0; !foundObj && i < theDoc.forms.length; i++) 
    foundObj = theDoc.forms[i][theObj];
  for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++) 
    foundObj = findObj(theObj,theDoc.layers[i].document);
  if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);
  
  return foundObj;
}
function showHideLayers()
{ 
  var i, visStr, obj, args = showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3)
  {
    if ((obj = findObj(args[i])) != null)
    {
      visStr = args[i+2];
      if (obj.style)
      {
        obj = obj.style;
        if(visStr == 'show') visStr = 'visible';
        else if(visStr == 'hide') visStr = 'hidden';
      }
      obj.visibility = visStr;
    }
  }
}
function moveLayerToMouseLoc(theLayer, offsetH, offsetV)
{
  var obj;
  if ((findObj(theLayer))!=null)
  {
    if (document.all)//IE

    {
		document.getElementById(theLayer).style.pixelLeft = Math.max(0,mLoc.x +offsetH);
		document.getElementById(theLayer).style.pixelTop = Math.max(0,mLoc.y +offsetV);
    }
	else
	  {
		document.getElementById(theLayer).style.left =Math.max(0,mLoc.x +offsetH);
		document.getElementById(theLayer).style.top =Math.max(0,mLoc.y +offsetV);
	  }
    showHideLayers(theLayer,'','show');
  }
}
function Point(x,y) {  this.x = x; this.y = y; }

mLoc = new Point(-500,-500);
function mouseCoords(evt){
	if(evt.pageX || evt.pageY){
		mLoc.x = evt.pageX;
		mLoc.y = evt.pageY;
	}
	else{
		mLoc.x = evt.clientX + document.body.scrollLeft - document.body.clientLeft;
		mLoc.y = evt.clientY + document.body.scrollTop  - document.body.clientTop;
	};
}

//HMPlayer: status of hmplayer
function HMPlayerStatus(filename,filetype,playerpath,player,divname,divstatus,offsetX,offsetY)
{
	this.filename=filename;		this.filetype=filetype;
	this.playerpath=playerpath;	this.player=player;
	this.divname=divname;		this.divstatus=divstatus;
	this.offsetX=offsetX;		this.offsetY=offsetY;
}

//HMPlayer:create hongen media player layer and flash object. 
function HMCreatLayer(theLayer,thePlayer)
{
	if ((findObj(theLayer))==null)
	{

			document.write("<div style='position:absolute;z-index:1;visibility:hidden;width:114px; height:24px;' id=" + theLayer + ">");
			document.write("<object width='114' height='24' id=" + thePlayer +" classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0'>");
			document.write("<param name='salign' value='lt'><param name='scale' value='noscale'><param name='transparent' value='true'>");
			document.write("<param name='quality' value='high'><param name='bgcolor' value='#DFDEDE'/>");
			document.write("<param name='movie' value='" + gHMPlayer.playerpath + "player.swf'>");
			document.write("<embed name=" + thePlayer +" src='" + gHMPlayer.playerpath + "player.swf' quality='high' bgcolor='#DFDEDE' width='114' height='24' scale='noscale' name='../../dev/cri/Site/english/player/player' transparent='true' wmode='opache' salign='lt' allowScriptAccess='sameDomain' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' />");
			document.write("</object>");
			document.write("</div>");
	}
}

function HMGetUrlPath()
{
	return (location.pathname.substring(0,location.pathname.lastIndexOf('/')+1));
}
function getFlashMovieObject(movieName)
{
  if (window.document[movieName]) 
  {
      return window.document[movieName];
  }
  if (navigator.appName.indexOf("Microsoft Internet")==-1)
  {
    if (document.embeds && document.embeds[movieName])
      return document.embeds[movieName]; 
  }
  else
  {
    return document.getElementById(movieName);
  }
}
function HMPlayGO(event,filename,filetype)
{
	evt = event || window.event;
	mouseCoords(evt);
	if(filename==gHMPlayer.filename && filetype==gHMPlayer.filetype)
	{
		if( gHMPlayer.divstatus == "show" )
		{
			showHideLayers(gHMPlayer.divname,'','hide');
			gHMPlayer.divstatus = "hide";
		}
		else
		{
			showHideLayers(gHMPlayer.divname,'','show');
			gHMPlayer.divstatus = "show";
		}
	}
	else
	{
		gHMPlayer.filename = filename;
		gHMPlayer.divstatus = "show";
		
		objSwf = getFlashMovieObject(gHMPlayer.player);
		objSwf.TGotoLabel("/","idle");
		objDiv = findObj(gHMPlayer.divname); 

		if( filetype != gHMPlayer.filetype )
		{
			gHMPlayer.filetype = filetype;
			var w,h;
			switch(filetype)
			{
			case "mp3":
				w = 114; 
				h=24; 
				gHMPlayer.offsetX=-13; 
				gHMPlayer.offsetY=-35; 
				//objDiv.style.borderWidth='0px';
				break;
			case "swf":
				w = 200; h=150; gHMPlayer.offsetX=0; gHMPlayer.offsetY=-175;
				objDiv.style.borderStyle='ridge';
				objDiv.style.backgroundColor = 'white';
				objDiv.style.padding = '1px';
				objDiv.style.borderWidth='2px';
				break;
			case "flv":
				var s=location.href;
				if( s.indexOf("french")!=-1)
				{
					w = 200; h=150; gHMPlayer.offsetX=10; gHMPlayer.offsetY=-175;
				}
				else
				{
					w = 240; h=196; gHMPlayer.offsetX=10; gHMPlayer.offsetY=-220;
				}
				objDiv.style.borderStyle='ridge';
				objDiv.style.backgroundColor = 'white';
				objDiv.style.padding = '1px';
				objDiv.style.borderWidth='2px';
				break;
			}
			objSwf.width=w;
			objSwf.height=h;
		}
		objSwf.SetVariable("style",gHMPlayer.filetype);
		objSwf.SetVariable("skinName", gHMPlayer.playerpath + "flvskin");
		objSwf.SetVariable("streamName",HMGetUrlPath() + gHMPlayer.filename+"."+filetype);
		objSwf.SetVariable("pName",	gHMPlayer.playerpath + gHMPlayer.filetype + "player.swf");


		objSwf.TGotoLabel("/",gHMPlayer.filetype);
		moveLayerToMouseLoc(gHMPlayer.divname,gHMPlayer.offsetX,gHMPlayer.offsetY);
		showHideLayers(gHMPlayer.divname,'','show');
	}

	return false;
}

gHMPlayer=new HMPlayerStatus("0","0","../player/","HMPlayer","HMDiv","hide",0,0);
HMCreatLayer(gHMPlayer.divname,gHMPlayer.player);
