// ========================= Ajax ===================================
var component = "";
http =  getHTTPObject();


function getHTTPObject() 
{
  	var xmlhttp;
  
  /*@cc_on
  @if (@_jscript_version >= 5)
	try {
	  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
	  try {
	    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	  } catch (E) {
	    xmlhttp = false;
	  }
	}
  @else
  xmlhttp = false;
  @end @*/

  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') 
  {
	try 
	{
	  xmlhttp = new XMLHttpRequest();
	  xmlhttp.overrideMimeType("text/xml");
	} catch (e) 
	{
	  xmlhttp = false;
	}
  }
  return xmlhttp;
}


function handleHttpResponse() 
{  	
   	if(http.readyState == 4)
   	{
   		results = http.responseText;
  		document.getElementById(component).innerHTML = results;
   	}
}


function show_inner(com,url)
{	
	component = com;
	http.open("GET", url, true);   // open a connection to the server
	// setup a function for the server to run when it's done
	http.onreadystatechange = handleHttpResponse;	
	document.getElementById(component).innerHTML = 'loading....';	
	http.send(null);   // send the request
}

// =========================End of Ajax ===================================


function GetObj(objName)
{
	if(document.getElementById)
	{
		return eval('document.getElementById("' + objName + '")');
	}
	else
	{
		return eval('document.all.' + objName);
	}
}


function Mute()
{
	if(MediaPlayer.Mute.toString().toLowerCase()=='true')
	{
		MediaPlayer.Mute='False';
		document.images("muteControl").src = "http://image2.sina.com.cn/dongman/BN/images/vod026.gif";
		document.images("muteControl").alt = "";
	}
	else
	{
		MediaPlayer.Mute='True';
		document.images("muteControl").src = mutePic.src;
		document.images("muteControl").alt = "";
	}
}


function toPlay()
{
	if(document.MediaPlayer.Duration>0)
	{
		if(isPlayO)
		{
			toPause();
		}
		else
		{
			if(isStopO||isPauseO)
			{
				VolumeUp(3);
				openTime();
				document.MediaPlayer.Play();
				mouseMove();
				document.images("playControl").src = "images/bg/vod009.gif";
				document.images("stopControl").src = "images/bg/vod025.gif";
				isPlayO = true;
				pFlag = true;
				isStopO = false;
				isPauseO = false;
			}
		}
	}
	
	if(flag)
	{
		GetObj('hideScreen').style.display = 'none';
		GetObj('myScreen').style.display = 'block';
		flag = false;
	}
}


function clrTime() 
{
	if( timeObj != null ) 
	{
		window.clearInterval( timeObj );
		timeObj = null;
	}
}


function openTime() 
{
	clrTime();
	timeObj = window.setInterval( "mouseMove()", 1000 );
}


//back to ini video
function toStop()
{
		document.MediaPlayer.Stop();
		document.images("playControl").src = playPic.src;
		document.images("stopControl").src = stopPic.src;
		isPlayO = false;
		isStopO = true;
		flag = true;
		GetObj('myScreen').style.display = 'none';
		GetObj('hideScreen').style.display = 'block';
		clrTime();
		currPos = 0;
		show_inner("mydiv","includes/display_image.php");
}


function toPause()
{
	if(document.MediaPlayer.Duration>0)
	{
		if(isPlayO&&document.MediaPlayer.PlayState!=3)
		{
			document.MediaPlayer.Pause();
			document.images("playControl").src = playPic.src;
			isPlayO = false;
			isPauseO = true;
			clrTime();
		}
	}
}


function mouseDown(objSign)
{
	isPorV = objSign;
	
	if(isPorV==0)
	{
		if(document.MediaPlayer.Duration>0)
		{
			pFlag = true;
			if(window.event.srcElement.id!='pZone') GetObj('pBox').style.left = GetObj('pBox').offsetLeft;
			else GetObj('pBox').style.left = (window.event.x-9);
			currPos = parseInt(GetObj('pBox').style.left);
			mouseUp();
		}
	}
	else if(isPorV==1)
	{
		vFlag = true;
		if(window.event.srcElement.id!='vZone') GetObj('vBox').style.left = GetObj('vBox').offsetLeft;
		else GetObj('vBox').style.left = (window.event.x-4);
		mouseUp();
	}
}


function mouseMove()
{
	if(isPorV==0)
	{
		if(document.MediaPlayer.Duration>0)
		{
			if(pFlag) 
			{
				currPos += 79.5 / document.MediaPlayer.Duration;
				document.getElementById('pBox').style.left = parseInt(currPos);
			}
			
			if (parseInt(document.getElementById('pBox').style.left) > 70) 
			{
				clrTime();
				currPos = 0;
				document.getElementById('pBox').style.left = parseInt(currPos);
				document.MediaPlayer.Stop();
				document.images("playControl").src = playPic.src;
				document.images("stopControl").src = stopPic.src;
				isPlayO = false;
				isStopO = true;
				flag = true;
			}
			
			if (parseInt(document.getElementById('pBox').style.left) < 0) 
			{
				clrTime();
				currPos = 0;
				document.getElementById('pBox').style.left = parseInt(currPos);
				document.MediaPlayer.Stop();
				document.images("playControl").src = playPic.src;
				document.images("stopControl").src = stopPic.src;
				isPlayO = false;
				isStopO = true;
				flag = true;
			}
		}
	}
}


function mouseUp()
{
	if(isPorV==0)
	{
		if(document.MediaPlayer.Duration>0)
		{
			if (pFlag)
			{
				var duration = document.MediaPlayer.Duration;
				document.MediaPlayer.CurrentPosition=duration * (parseInt(document.getElementById('pBox').style.left)/70);
				openTime();
			}
		}
	}
	else if(isPorV==1)
	{
		if (vFlag)
		{
			tempVol = (10 - (parseInt(document.getElementById('vBox').style.left)/3.5))*(-100);
			document.MediaPlayer.Volume=Math.round(tempVol);
		}
		vFlag = false;
	}
}


function VolumeUp(vol)
{
	tempVol = (10 - vol)*(-100);
	document.MediaPlayer.Volume= tempVol;
	document.getElementById('vBox').style.left = vol/10*35;
}


var broadFile = 'http://aramis.sarge.com/video/Punk.mpeg';
var narrowFile = 'http://aramis.sarge.com/video/Punk.mpeg';
var iniPic = 'images/bg/gw_bn_278.jpg';
var iniText = '';
var curBroad = broadFile;
var curNarrow = narrowFile;
var curFile = broadFile;
var tempHTML;
var tempFile;
var isPorV = 0;
var currPos = 0;
var timeObj = null;
var isPlayO = false;
var isStopO = true;
var isPauseO = false;
var flag = true;
var fFlag= false;
var pFlag = false;
var vFlag = false;
var mutePic = new Image(29,29);
mutePic.src = "images/bg/vod022.gif";
var playPic = new Image(48,77);
playPic.src = "images/bg/vod008.gif";
var stopPic = new Image(24,35);
stopPic.src = "images/bg/vod025.gif";
var pausePic = new Image(28,77);
pausePic.src = "images/bg/vod024.gif";
