function getXMLHttpObj(){
	if(typeof(XMLHttpRequest)!='undefined')
		return new XMLHttpRequest();

	var axO=['Msxml2.XMLHTTP.6.0', 'Msxml2.XMLHTTP.4.0',
		'Msxml2.XMLHTTP.3.0', 'Msxml2.XMLHTTP', 'Microsoft.XMLHTTP'], i;
	for(i=0;i<axO.length;i++)
		try{
			return new ActiveXObject(axO[i]);
		}catch(e){}
	return null;
}

function loadScript(scriptpath, functions){
	var oXML = getXMLHttpObj();
	oXML.open('GET', scriptpath, false);
	oXML.send('');
	eval(oXML.responseText);
	for(var i=0; i<functions.length; i++)
		window[functions[i]] = eval(functions[i]);
}

function canPlayVorbis() {
    var v = document.createElement('video');
    return !!(v.canPlayType && v.canPlayType('video/ogg; codecs="theora, vorbis"').replace(/no/, ''));
}

function canPlayMP4() {
    var v = document.createElement('video');
    return !!(v.canPlayType && v.canPlayType('video/mp4; codecs="avc1.42E01E, mp4a.40.2"').replace(/no/, ''));
}

function canPlayWebM() {
    var v = document.createElement('video');
    return !!(v.canPlayType && v.canPlayType('video/webm; codecs="vp8, vorbis"').replace(/no/, ''));
}

var video_container_count = 0;
function startVideo(obj, file, width, height){
	video_container_count++;

	if (!!document.createElement('video').canPlayType){
		if (canPlayVorbis()){
			s =  '<video width="'+width+'" height="'+height+'" controls="true" autoplay="true" poster="'+obj.src+'">';
			s += '<source src="'+file+'.ogg" type=video/ogg>';
			s += '<source src="'+file+'.m4v" type=video/mp4>';
			s += 'Sorry, but your browser does not support the video tag. You can Donwload the Video <a href="'+file+'.m4v">here</a>.';
			s += '</video>';
		} else {
			s =  '<video src="'+file+'.m4v" width="'+width+'" height="'+height+'" controls="true" autoplay="true" poster="'+obj.src+'">';
			s += 'Sorry, but your browser does not support the video tag. You can Donwload the Video <a href="'+file+'.m4v">here</a>.';
			s += '</video>';	
		}
		//s += '<a href="'+file+'.m4v">here</a>';
		obj.parentNode.innerHTML = s;
	} else {
		file = file+".flv";
		
		s  = '<a href="'+file+'.m4v"  style="display:block;width:'+width+'px;height:'+height+'px"  id="player'+video_container_count+'">This content requires the Adobe Flash Player.</a>';
		obj.parentNode.innerHTML = s;
		if (video_container_count==1)
			loadScript('/videoPlayer/flowplayer-3.2.0.min.js', ['flowplayer']);	
		
		obj = document.getElementById("player"+video_container_count);
		obj.innerHTML = '';
		
		flowplayer("player"+video_container_count, "/videoPlayer/flowplayer-3.2.0.swf");
		//obj.parentNode.innerHTML = '<iframe src="/videoPlayer/flvplayer.html?flashvideo='+file+'&picture='+obj.src+'&autoplay=true&skinfile=./skins/ClearOverNoVol.swf&w='+width+'&h='+height+'" style="width:'+width+'px;height:'+height+'px;" frameborder="0" scrolling="no"></iframe>'
	}
}
