function loadVideo(xmlURL, width, height, autoplay, preroll, targetdiv, preview, thumbUrl)
{
	if(preview == 'true')
	{
		XML2Player(xmlURL, width, height, autoplay, preroll,targetdiv, preview, thumbUrl);
	}
	else
	{
		var xmlhttp;
		if(window.ActiveXObject)
		{
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		else
		{
			xmlhttp=new XMLHttpRequest();
		}
		
		var date = new Date();
		
		if (xmlhttp)
		{
			if (xmlURL.indexOf('?') == -1) xmlURL = xmlURL + "?";
			xmlhttp.open("GET",xmlURL,true);
			xmlhttp.onreadystatechange=function()
			{  
				if (xmlhttp.readyState==4){
				  try{
					var response = xmlhttp.responseXML;
					XML2Player(response, width, height, autoplay, preroll,targetdiv, preview);
				  }
				  catch(e){};
				}
			}
			xmlhttp.send(null)
		  }		
	}
}

function XML2Player(response, width, height, autoplay, preroll, targetdiv, preview, thumbUrl)
{
	//First get the dimensions, source, etc for the movie that's being played
	if(preview == 'true')
	{
		var flashfile = response;
		var thumbnailobject = '';
		var thumbnail = thumbUrl;

		if(width != null)
		{
			var videoWidth = width;
		}
		else
		{
			var videoWidth = '416';
		}

		if(height != null)
		{
			var videoHeight = height;
		}
		else
		{
			var videoHeight = '234';	
		}
	}
	else
	{
		var flashfile = response.getElementsByTagName("flashfile")[0].firstChild.data;		

		var thumbnailobject = response.getElementsByTagName("thumbnail")[0];
		var thumbnail = '';
	
		if (thumbnailobject.firstChild != null) 
		{
			thumbnail = thumbnailobject.firstChild.data;
		}

		if(width != null)
		{
			var videoWidth = width;
		}
		else
		{
			var videoWidth = response.getElementsByTagName("width")[0].firstChild.data;
		}
		
		if(response.getElementsByTagName("height")[0].firstChild.data != null && height < 400)
		{
			var videoHeight = response.getElementsByTagName("height")[0].firstChild.data;
		}
		else
		{
			if(height != null)
			{
				var videoHeight = height;
			}
			else
			{
				var videoHeight = response.getElementsByTagName("height")[0].firstChild.data;
			}
		}
	}
	
	if(autoplay != null)
	{
		autostart = autoplay;
	}
	else
	{
		autostart = 'true';
	}

	//Get the dimensions of the player
	var playerWidth = videoWidth;
	var playerHeight = videoHeight;
	
	//The div where the player is placed
	var targetDiv = '#'+targetdiv;

	//Create an unique ID for the player
	var uniqueNr = Math.round(1000 * Math.random());
	var uniqueDiv = 'mediaplayer_'+uniqueNr;

	html5Player = '<video controls id="'+uniqueDiv+'" poster="'+thumbnail+'" src="'+flashfile+'" type="video/mp4"></video>';
	$(targetDiv).empty();
	$(targetDiv).append(html5Player);

	lastPlayer = uniqueDiv;

	if(preroll == 'true')
	{
		//Create a player with preroll
		
		if (typeof(et_ord)=='undefined')
		{
			et_ord=Math.floor(Math.random()*10000000000000000);
				if (typeof(et_tile)=='undefined') et_tile=1;
		} 

		//This is the url which returns the preroll movie
		var ovaTag = 'http://ad.uk.doubleclick.net/adx/inlineplayer.rtl.vi/vicontent;sz=62x90;pos=preroll_1;tile=1;ord='+ et_ord + ';dcmt=text/xml?';
		
		jwplayer(uniqueDiv).setup({
			'id': uniqueDiv,
			'width': playerWidth,
			'height': playerHeight,
			'file': flashfile,
			'image': thumbnail,
			'autostart': autostart,
			'plugins': 'http://static.openvideoads.org/qa/latest/ova.jwplayer.5x/dist/swf/ova-jw.js,gapro-1',
			'config': '/static/vi/xml/ova-config.xml',
			'ova.tag': ovaTag,
			'gapro.trackingobject': 'pageTracker',
			'gapro.accountid': 'UA-8932537-1',
			'gapro.trackstarts': true,
			'gapro.trackpercentage': true,
			'gapro.trackseconds': true,
			'skin': '/static/vi/assets/glow/glow.zip',
			'modes': [
			{type: 'flash', src: '/static/vi/swf/player.swf'},
			{type: 'html5', config: {'autostart': false}}
			]
		 });
	}
	else
	{
		//Create a player without a preroll
		jwplayer(uniqueDiv).setup({
			'id': uniqueDiv,
			'width': playerWidth,
			'height': playerHeight,
			'file': flashfile,
			'image': thumbnail,
			'autostart': autostart,
			'skin': '/static/vi/assets/glow/glow.zip',
			'plugins': 'gapro-1',
			'gapro.trackingobject': 'pageTracker',
			'gapro.accountid': 'UA-8932537-1',
			'gapro.trackstarts': true,
			'gapro.trackpercentage': true,
			'gapro.trackseconds': true,
			'modes': [
			{type: 'flash', src: '/static/vi/swf/player.swf'},
			{type: 'html5', config: {'autostart': false}}
			]
		 });	
	}
}

function include(file){   
  var script  = document.createElement('script');   
  script.src  = file;   
  script.type = 'text/javascript';   
  script.defer = true;   
  document.getElementsByTagName('head').item(0).appendChild(script);   
}
include('/static/vi/scripts/swfobject_source.js');
