function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

addLoadEvent(function() {
});

var videoPlaying = false;

function writeVideo (videoUrl, width, height, autoplay, element) {

	var innerVideo = '<SCRIPT LANGUAGE = "JScript"  FOR ="MediaPlayer" EVENT = playStateChange(NewState)>stateChanged(NewState)</SCRIPT>';

	if (navigator.userAgent.indexOf("MSIE") != -1) {
		innerVideo = innerVideo + "<object ID=\"MediaPlayer\" width=\""+width+"\" height=\""+height+"\" classid=\"CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95\" CODEBASE=\"http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,5,715\" standby=\"Loading Video...\"  type=\"application/x-oleobject\">"
	} else {
		innerVideo = innerVideo + '<object type="application/x-ms-wmp" width="'+width+'" height="'+height+'" id="MediaPlayer" />'
	}

	if (autoplay == false) {
		innerVideo = innerVideo + "<param name=\"AutoStart\" value=\"False\"/>"
	} else {
		innerVideo = innerVideo + "<param name=\"AutoStart\" value=\"True\"/>"
	}

	innerVideo = innerVideo + "<param name=\"FileName\" value=\""+videoUrl+"\" />"
	innerVideo = innerVideo + "<param name=\"SendPlayStateChangeEvents\" value=\"true\" />"
	innerVideo = innerVideo + "<param name=\"ShowControls\" value=\"false\" />"
	innerVideo = innerVideo + "<param name=\"ShowStatusBar\" value=\"false\" />"
	innerVideo = innerVideo + "<param name=\"uiMode\" value=\"none\" />"
	innerVideo = innerVideo + "<param name=\"wmode\" value=\"transparent\" />"
	innerVideo = innerVideo + "<param name=\"fullscreen\" value=\"true\" />"

	if (autoplay == false) {
		innerVideo = innerVideo + "<embed showdisplay=\"1\" showstatusbar=\"0\" fullscreen=\"true\" showcontrols=\"0\" uiMode=\"none\" type=\"application/x-mplayer2\" pluginspage=\"http://www.microsoft.com/Windows/MediaPlayer/\" SRC=\""+videoUrl+"\" name=\"MediaPlayer\" width=\""+width+"\" height=\""+height+"\" autostart=\"0\">"
	} else {
		innerVideo = innerVideo + "<embed showdisplay=\"1\" showstatusbar=\"1\" fullscreen=\"true\" showcontrols=\"0\" uiMode=\"none\" type=\"application/x-mplayer2\" pluginspage=\"http://www.microsoft.com/Windows/MediaPlayer/\" SRC=\""+videoUrl+"\" name=\"MediaPlayer\" width=\""+width+"\" height=\""+height+"\" autostart=\"1\">"
	}
			
	innerVideo = innerVideo + "</embed></object>"

	if (element) {
		element.innerHTML = innerVideo;
	} else {
		document.write(innerVideo);
	}

	caricamente();
}

function stateChanged (newState) {

	switch (newState){

	case 3:
		//Playing
		document.getElementById('videoPauseButton').style.display = '';
		document.getElementById('videoPlayButton').style.display = 'none';
		document.getElementById('videoStopButton').style.display = '';

		videoPlaying = true;

		break;

	default: 
		break;
	}
}


function controlVideo(action) {

	switch (action){

    	case 1:
        	//Stop

		if (navigator.userAgent.indexOf("MSIE") != -1) {
			document.getElementById('MediaPlayer').stop();
		} else {
			document.getElementById('MediaPlayer').controls.stop();
		}

		document.getElementById('videoPauseButton').style.display = 'none';
		document.getElementById('videoPlayButton').style.display = 'none';
		document.getElementById('videoStopButton').style.display = 'none';

		document.getElementById('videoPane').innerHTML = '';

		break;
    	case 2:
		//Pause

		if (navigator.userAgent.indexOf("MSIE") != -1) {
			document.getElementById('MediaPlayer').pause();
		} else {
			document.getElementById('MediaPlayer').controls.pause();
		}

		document.getElementById('videoPauseButton').style.display = 'none';
		document.getElementById('videoPlayButton').style.display = '';
		document.getElementById('videoStopButton').style.display = '';

		break;
	case 3:
		//Play

		if (navigator.userAgent.indexOf("MSIE") != -1) {
			document.getElementById('MediaPlayer').Play();
		} else {
			document.getElementById('MediaPlayer').controls.play();
		}

		document.getElementById('videoPauseButton').style.display = '';
		document.getElementById('videoPlayButton').style.display = 'none';
		document.getElementById('videoStopButton').style.display = '';

		videoPlaying = true;

		break;

	default: 
		break;
	}
}

function caricamente() {

	var carica = document.getElementById('carica');

	if (videoPlaying == false) {

		if (carica.style.display == 'none') {
			carica.style.display = '';
		}

		var bgPos = document.getElementById('carica').style.backgroundPosition;

		if (bgPos == '0px 0px') {
			carica.style.backgroundPosition = '0px 51px';
		} else if (bgPos == '0px 51px') {
			carica.style.backgroundPosition = '0px 34px';
		} else if (bgPos == '0px 34px') {
			carica.style.backgroundPosition = '0px 17px';
		} else if (bgPos == '0px 17px') {
			carica.style.backgroundPosition = '0px 0px';
		}

		setTimeout('caricamente()', 1000);

	} else {
		carica.style.display = 'none';
	}
}

function hiddenSubMenu()
{
	document.getElementById('prodInf').style.display = 'none';
}

function showSubMenu()
{
	document.getElementById('prodInf').style.display = 'block';
}