
var TimeOut = 25;
var animate = 0;
var RunStatus = 0;
var Running = 0;
var CheckBufferRun = false;
var DIVStatus = 'hide';
var BufferStatus = 0;
var actWidth = 0;
var newWidth = 0;
var VideoDisplay = 0;
var Movie;


function getPlayer(playerName, PlayerWidth, PlayerHeight)
{

    var VIDEO_TAG = '<OBJECT ID="' + playerName + '" width=' + PlayerWidth + ' height=' + PlayerHeight + ' ';

	if ( - 1 != navigator.userAgent.indexOf("MSIE"))
    {
        VIDEO_TAG = VIDEO_TAG + 'classid="clsid:6BF52A52-394A-11d3-B153-00C04F79FAA6">';
    }
    else if ( - 1 != navigator.userAgent.indexOf("Firefox"))
    {
        VIDEO_TAG = VIDEO_TAG + 'type="application/x-ms-wmp">';
    }



    VIDEO_TAG = VIDEO_TAG + 
	'<PARAM NAME="autoStart" VALUE="True">'+
//	'<PARAM NAME="URL" VALUE="mms://stream.wmv.n-tv.de/ntvlive">'+
//	'<PARAM NAME="src"value="mms://stream.wmv.n-tv.de/ntvlive">'+
 	'<PARAM NAME="URL" VALUE="http://www.ehf-euro.com/fileadmin/ehfeuro/video/DAILY.wmv">'+
	'<PARAM NAME="src"value="http://www.ehf-euro.com/fileadmin/ehfeuro/video/DAILY.wmv">'+
	'<param value="true" name="AutoStart"/>'+
	'<param value="0" name="CurrentPosition"/>'+
	'<param value="4" name="DisplaySize"/>'+
	'<param value="true" name="AutoSize"/>'+
	'<param value="true" name="AllowChangeDisplaySize"/>'+
	'<param value="true" name="stretchToFit"/>'+
	'<param value="true" name="maintainAspectRatio"/>'+
	'<param value="none" name="uiMode"/>'+
	'<param value="0" name="ShowControls"/>'+
	'<param value="0" name="ShowPositionControls"/>'+
	'<param value="false" name="ShowStatusBar"/>'+
	'<PARAM NAME="windowlessVideo" VALUE="True">'+
'</object>'+
'<SCRIPT for="mediaplayer" event="Buffering(bStart)">'+
'	show_hide_buffer(bStart);'+
'</SCRIPT>';								

    return VIDEO_TAG;
}

function VideoGO(VideoWidth, VideoHeight, VideoDIV)
{
	
	if (VideoDisplay == 0)
	{

		VideoDisplay = 1;
	 	document.getElementById('Player').innerHTML = getPlayer('mediaplayer', 294, 220);
		Movie = document.getElementById('mediaplayer');

	};

    if (DIVStatus == 'hide')
    {

        DIVStatus = 'show';

    }
    else
    {

        DIVStatus = 'hide';

    }

    if (Running == 0)
    {

        ProzessMovment(VideoWidth, VideoHeight, VideoDIV);

		if (animate == 1) {

	        Running = 1;
			
		}

    }

}

function ProzessMovment(VideoWidth, VideoHeight, VideoDIV)
{

	if (animate == 1) {

		breake = false;
	
		OBJVideoDIV = document.getElementById(VideoDIV);
	
		if (DIVStatus == 'show')
		{
	
			if (VideoWidth > actWidth)
			{
	
				newWidth = actWidth + 20;
	
			}
	
			if (newWidth > VideoWidth)
			{
	
				newWidth = VideoWidth;
	
				ControlPlayer('Player', 'play', VideoWidth, VideoHeight, VideoDIV);
	
				breake = true 
	
			}
	
		}
		else
		{
	
			if (actWidth > 0)
			{
	
				newWidth = actWidth - 20;
	
			}
	
			if (newWidth < 0)
			{
	
				newWidth = 0;
	
			}
	
		}
		if (newWidth == 0)
		{
	
			breake = true;
	
		}
	
		if (actWidth == VideoWidth && newWidth < actWidth)
		{
	
			ControlPlayer('Player', 'stop', VideoWidth, VideoHeight, VideoDIV);
	
		}
	
		actWidth = newWidth;
	
		OBJVideoDIV.style.width = newWidth + 'px';
	
		if (breake)
		{
	
			Running = 0;
	
		}
		else
		{
	
			setTimeout("ProzessMovment(" + VideoWidth + "," + VideoHeight + ",'" +
				VideoDIV + "')", TimeOut);
	
		}

	} else {
		
		if (DIVStatus == 'show') {
			
			ControlPlayer('Player', 'play', VideoWidth, VideoHeight, VideoDIV);
			
		} 
		
		if (DIVStatus == 'hide') {
			
			ControlPlayer('Player', 'stop', VideoWidth, VideoHeight, VideoDIV);
			
		}

	}

}

function ControlPlayer(PlayerDivID, type, VideoWidth, VideoHeight, VideoDIV)
{



    OBJPlayerDiv = document.getElementById(PlayerDivID);

    OBJPlayerButton = document.getElementById('PlayButton');

	bufferDiv = document.getElementById('buffer');


    if (type == 'play')
    {
		
		if (animate == 1) {

			OBJPlayerButton.className = 'pause';
	
			OBJPlayerDiv.style.display = 'block';
	
			setTimeout("Movie.controls.play();",1000);
		
		} else if (animate == 0) { 
		
			OBJPlayerButton.className = 'pause';
	
			OBJPlayerDiv.style.display = 'block';
	
			setTimeout("Movie.controls.play();",0);

			setTimeout("opacity('video_blende', 100, 0, 1000);",500)
			
		}

    }

    if (type == 'stop')
    {


		if (animate == 1) {
			
			OBJPlayerButton.className = 'play';
	
			OBJPlayerDiv.style.display = 'none';

			Movie.controls.stop();

			bufferDiv.style.display = 'none';
			
		} else if (animate == 0) {
			
			Movie.controls.pause();
			OBJPlayerButton.className = 'play';
			opacity('video_blende', 0, 100, 1000)

		}

    }

}

function show_hide_buffer(typ){

	bufferDiv = document.getElementById('buffer');

	if (typ)
	{
		bufferDiv.style.display = 'block';
		bufferDiv.innerHTML = 'buffering';
		CheckBufferRun = true;
		checkBufferStatus();
	}
	else
	{
		bufferDiv.style.display = 'none';
		CheckBufferRun = false;
	}

}

function checkBufferStatus(){

	if ( - 1 != navigator.userAgent.indexOf("MSIE"))
    {
		bufferDiv.innerHTML = 'buffering ... '+Movie.network.BufferingProgress + '%';
    }
    else if ( - 1 != navigator.userAgent.indexOf("Firefox"))
    {
		bufferDiv.innerHTML = 'buffering ... %';
		//'+Movie.Network.BufferingProgress+'
    }



	
	if (CheckBufferRun){
		setTimeout("checkBufferStatus();",500)
	}
	
}

function controls_opacity(type) {
	
	if (type == 'show') {
		
		opacity('video_onscreen_controls', 20, 100, 500)
		
	}else if (type == 'hide') {
		
		opacity('video_onscreen_controls', 100, 20, 500)

	}
}

function opacity(id, opacStart, opacEnd, millisec) {
	//speed for each frame
	var speed = Math.round(millisec / 100);
	var timer = 0;

	//determine the direction for the blending, if start and end are the same nothing happens
	if(opacStart > opacEnd) {
		for(i = opacStart; i >= opacEnd; i--) {
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	} else if(opacStart < opacEnd) {
		for(i = opacStart; i <= opacEnd; i++)
			{
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	}
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
	var object = document.getElementById(id).style; 
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
}

function shiftOpacity(id, millisec) {
	//if an element is invisible, make it visible, else make it ivisible
	if(document.getElementById(id).style.opacity == 0) {
		opacity(id, 0, 100, millisec);
	} else {
		opacity(id, 100, 0, millisec);
	}
}

function blendimage(divid, imageid, imagefile, millisec) {
	var speed = Math.round(millisec / 100);
	var timer = 0;
	
	//set the current image as background
	document.getElementById(divid).style.backgroundImage = "url(" + document.getElementById(imageid).src + ")";
	
	//make image transparent
	changeOpac(0, imageid);
	
	//make new image
	document.getElementById(imageid).src = imagefile;

	//fade in image
	for(i = 0; i <= 100; i++) {
		setTimeout("changeOpac(" + i + ",'" + imageid + "')",(timer * speed));
		timer++;
	}
}

function currentOpac(id, opacEnd, millisec) {
	//standard opacity is 100
	var currentOpac = 100;
	
	//if the element has an opacity set, get it
	if(document.getElementById(id).style.opacity < 100) {
		currentOpac = document.getElementById(id).style.opacity * 100;
	}

	//call for the function that changes the opacity
	opacity(id, currentOpac, opacEnd, millisec)
}