function _el(obj){
	return document.getElementById(obj);
}

/* ------------------------ DETECT PLUGINS FUNCTIONS STARTS ------------------------ */
// initialize a variable to test for JavaScript 1.1.
// which is necessary for the window.location.replace method
var javascriptVersion1_1 = false;


javascriptVersion1_1 = true;


// initialize global variables
var detectableWithVB = false;
var pluginFound = false;


function goURL(daURL) {
    // if the browser can do it, use replace to preserve back button
    if(javascriptVersion1_1) {
	window.location.replace(daURL);
    } else {
	window.location = daURL;
    }
    return;
}

function redirectCheck(pluginFound, redirectURL, redirectIfFound) {
    // check for redirection
    if( redirectURL && ((pluginFound && redirectIfFound) || 
	(!pluginFound && !redirectIfFound)) ) {
	// go away
	goURL(redirectURL);
	return pluginFound;
    } else {
	// stay here and return result of plugin detection
	return pluginFound;
    }	
}

function canDetectPlugins() {
    if( detectableWithVB || (navigator.plugins && navigator.plugins.length > 0) ) {
	return true;
    } else {
	return false;
    }
}

function detectFlash(redirectURL, redirectIfFound) {
    pluginFound = detectPlugin('Shockwave','Flash'); 
    // if not found, try to detect with VisualBasic
    if(!pluginFound && detectableWithVB) {
	pluginFound = detectActiveXControl('ShockwaveFlash.ShockwaveFlash.1');
    }
    // check for redirection
    return redirectCheck(pluginFound, redirectURL, redirectIfFound);
}

function detectDirector(redirectURL, redirectIfFound) { 
    pluginFound = detectPlugin('Shockwave','Director'); 
    // if not found, try to detect with VisualBasic
    if(!pluginFound && detectableWithVB) {
	pluginFound = detectActiveXControl('SWCtl.SWCtl.1');
    }
    // check for redirection
    return redirectCheck(pluginFound, redirectURL, redirectIfFound);
}

function detectQuickTime(redirectURL, redirectIfFound) {
    pluginFound = detectPlugin('QuickTime');
    // if not found, try to detect with VisualBasic
    if(!pluginFound && detectableWithVB) {
	pluginFound = detectQuickTimeActiveXControl();
    }
    return redirectCheck(pluginFound, redirectURL, redirectIfFound);
}

function detectReal(redirectURL, redirectIfFound) {
    pluginFound = detectPlugin('RealPlayer');
    // if not found, try to detect with VisualBasic
    if(!pluginFound && detectableWithVB) {
	pluginFound = (detectActiveXControl('rmocx.RealPlayer G2 Control') ||
		       detectActiveXControl('RealPlayer.RealPlayer(tm) ActiveX Control (32-bit)') ||
		       detectActiveXControl('RealVideo.RealVideo(tm) ActiveX Control (32-bit)'));
    }	
    return redirectCheck(pluginFound, redirectURL, redirectIfFound);
}

function detectWindowsMedia(redirectURL, redirectIfFound) {
    pluginFound = detectPlugin('Windows Media');
    // if not found, try to detect with VisualBasic
    if(!pluginFound && detectableWithVB) {
	pluginFound = detectActiveXControl('MediaPlayer.MediaPlayer.1');
    }
    return redirectCheck(pluginFound, redirectURL, redirectIfFound);
}

function detectPlugin() {
    // allow for multiple checks in a single pass
    var daPlugins = detectPlugin.arguments;
    // consider pluginFound to be false until proven true
    var pluginFound = false;
    // if plugins array is there and not fake
    if (navigator.plugins && navigator.plugins.length > 0) {
	var pluginsArrayLength = navigator.plugins.length;
	// for each plugin...
	for (pluginsArrayCounter=0; pluginsArrayCounter < pluginsArrayLength; pluginsArrayCounter++ ) {
	    // loop through all desired names and check each against the current plugin name
	    var numFound = 0;
	    for(namesCounter=0; namesCounter < daPlugins.length; namesCounter++) {
		// if desired plugin name is found in either plugin name or description
		if( (navigator.plugins[pluginsArrayCounter].name.indexOf(daPlugins[namesCounter]) >= 0) || 
		    (navigator.plugins[pluginsArrayCounter].description.indexOf(daPlugins[namesCounter]) >= 0) ) {
		    // this name was found
		    numFound++;
		}   
	    }
	    // now that we have checked all the required names against this one plugin,
	    // if the number we found matches the total number provided then we were successful
	    if(numFound == daPlugins.length) {
		pluginFound = true;
		// if we've found the plugin, we can stop looking through at the rest of the plugins
		break;
	    }
	}
    }
    return pluginFound;
} // detectPlugin


// Here we write out the VBScript block for MSIE Windows
if ((navigator.userAgent.indexOf('MSIE') != -1) && (navigator.userAgent.indexOf('Win') != -1)) {
    document.writeln('<script language="VBscript">');

    document.writeln('\'do a one-time test for a version of VBScript that can handle this code');
    document.writeln('detectableWithVB = False');
    document.writeln('If ScriptEngineMajorVersion >= 2 then');
    document.writeln('  detectableWithVB = True');
    document.writeln('End If');

    document.writeln('\'this next function will detect most plugins');
    document.writeln('Function detectActiveXControl(activeXControlName)');
    document.writeln('  on error resume next');
    document.writeln('  detectActiveXControl = False');
    document.writeln('  If detectableWithVB Then');
    document.writeln('     detectActiveXControl = IsObject(CreateObject(activeXControlName))');
    document.writeln('  End If');
    document.writeln('End Function');

    document.writeln('\'and the following function handles QuickTime');
    document.writeln('Function detectQuickTimeActiveXControl()');
    document.writeln('  on error resume next');
    document.writeln('  detectQuickTimeActiveXControl = False');
    document.writeln('  If detectableWithVB Then');
    document.writeln('    detectQuickTimeActiveXControl = False');
    document.writeln('    hasQuickTimeChecker = false');
    document.writeln('    Set hasQuickTimeChecker = CreateObject("QuickTimeCheckObject.QuickTimeCheck.1")');
    document.writeln('    If IsObject(hasQuickTimeChecker) Then');
    document.writeln('      If hasQuickTimeChecker.IsQuickTimeAvailable(0) Then ');
    document.writeln('        detectQuickTimeActiveXControl = True');
    document.writeln('      End If');
    document.writeln('    End If');
    document.writeln('  End If');
    document.writeln('End Function');

    document.writeln('</scr' + 'ipt>');
}
/* ------------------------ DETECT PLUGINS FUNCTIONS ENDS ------------------------ */


/* ####################################################################################### */

//Create vPlayer Object
//var vPlayer			=	new Object();


///////////////// VPLAYER CONFIG VALUES /////////////////
//--------------------------------------------------------	
//Set Video Player Container
var vPlayerContainerId	=	"video_container";

//Set Video Player Width & Height
var vPlayerWidth =	"370"; var vPlayerHeight =	"265";

//Set FLV Video Player Path
var vPlayerPath_flv		=	"video/FlowPlayer.swf";
	vPlayerPath_flv		=	"/video/flvplayer.swf";

//Set the HTML code for embeding FLV Video Player
var vPlayerCode_flv		=	"<!--[if !IE]> <--><object type='application/x-shockwave-flash' width='"+vPlayerWidth+"' height='"+vPlayerHeight+"' data='"+vPlayerPath_flv+"'><!--><![endif]-->"+
							"<!--[if IE]> <object type='application/x-shockwave-flash' width='"+vPlayerWidth+"' height='"+vPlayerHeight+"' classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0'> <![endif]-->"+
							"<param name='movie' value='"+vPlayerPath_flv+"' />"+
							"<param name='allowScriptAccess' value='sameDomain' />"+
							"<param name='quality' value='high' />"+
							"<param name='FlashVars' value='baseURL=%baseURL%&videoFile=%videoFile%&autoPlay=true&bufferLength=5&loop=true' />"+
							"</object>";
	vPlayerCode_flv		=	'<embed type="application/x-shockwave-flash" src="'+vPlayerPath_flv+'" style="" id="single" name="single" quality="high" allowfullscreen="true" flashvars="file=%video_file%&image=preview.jpg&width='+vPlayerWidth+'&amp;height='+vPlayerHeight+'&autostart=true" height="'+vPlayerHeight+'" width="'+vPlayerWidth+'">';

//Set Video Player Width & Height
vPlayerWidth =	"370"; vPlayerHeight =	"300";

//Set the HTML code for embeding WMV Video Player
var vPlayerCode_wmv		=	"<!--[if !IE]> <--><object type='application/x-mplayer2' width='"+vPlayerWidth+"' height='"+vPlayerHeight+"' data='%video_file%'><!--> <![endif]-->"+
							"<!--[if IE]><object type='application/x-oleobject' width='"+vPlayerWidth+"' height='"+vPlayerWidth+"' classid='clsid:6BF52A52-394A-11d3-B153-00C04F79FAA6' ><![endif]-->"+
							"<param name='src' value='%video_file%' />"+
							"<param name='URL' value='%video_file%' />"+
							"<param name='animationatStart' value='true' />"+
							"<param name='transparentatStart' value='true' />"+
							"<param name='autoStart' value='true' />"+
							"<param name='showControls' value='true' />"+
							"<param name='loop' value='true' />"+
							"</object>";

	vPlayerCode_wmv		=	"<OBJECT ID='MediaPlayer' WIDTH='"+vPlayerWidth+"' HEIGHT='"+vPlayerHeight+"' CLASSID='CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95' STANDBY='Loading Windows Media Player components...' TYPE='application/x-oleobject'><param name='uiMode' value='full'><PARAM NAME='FileName' VALUE='%video_file%'><PARAM name='autostart' VALUE='true'><PARAM name='ShowControls' VALUE='true'><param name='ShowStatusBar' value='false'><PARAM name='ShowDisplay' VALUE='false'><EMBED TYPE='application/x-mplayer2' SRC='%video_file%' NAME='MediaPlayer' WIDTH='"+vPlayerWidth+"' HEIGHT='"+vPlayerHeight+"'  allowchangedisplaysize='1' autosize='1' displaysize='1' showcontrols='1'showstatusbar='1' autorewind='1' autostart='1' type='video/x-ms-wmv-plugin' ></EMBED></OBJECT>";

//Set Video Player Width & Height
vPlayerWidth =	"352"; vPlayerHeight =	"300";

//Set the HTML code for embeding MOV Video Player
var vPlayerCode_mov		=	"<!--[if !IE]> <--><object type='video/quicktime' width='"+vPlayerWidth+"' height='"+vPlayerHeight+"' data='%video_file%'><!--> <![endif]-->"+
							"<!--[if IE]><object classid='clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B' codebase='http://www.apple.com/qtactivex/qtplugin.cab' width='"+vPlayerWidth+"' height='"+vPlayerHeight+"' scale='tofit' ><![endif]-->"+
							"<param name='src' value='%video_file%' />"+
							"<param name='AUTOPLAY' value='true' />"+
							"<param name='KIOSKMODE' value='false' />"+
							"</object>";

//Set Video Player Width & Height
vPlayerWidth =	"370"; vPlayerHeight =	"265";

//Set the HTML code for embeding RM Video Player
var vPlayerCode_rm		=	"<table border='0' cellpadding='0' align='center'><tr><td><object id='rvocx' classid='clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA' width='"+vPlayerWidth+"' height='"+vPlayerHeight+"'><param name='src' value='%video_file%'><param name='autostart' value='1'><param name='controls' value='imagewindow'><param name='console' value='video'><param name='loop' value='0'><param name='SHUFFLE' value='0'><param name='PREFETCH' value='0'><param name='NOLABELS' value='0'><param name='NUMLOOP' value='0'><param name='CENTER' value='0'><param name='MAINTAINASPECT' value='0'><param name='BACKGROUNDCOLOR' value='#000000'><embed src='%video_file%' width='"+vPlayerWidth+"' height='"+vPlayerHeight+"' loop='false' type='audio/x-pn-realaudio-plugin' controls='imagewindow' console='video' autostart='true'></embed></object></td></tr><tr><td><object id='rvocx' classid='clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA' width='"+vPlayerWidth+"' height='30'><param name='src' value='%video_file%'><param name='autostart' value='0'><param name='controls' value='ControlPanel'><param name='console' value='video'><param name='SHUFFLE' value='0'><param name='PREFETCH' value='0'><param name='NOLABELS' value='0'><param name='LOOP' value='0'><param name='NUMLOOP' value='0'><param name='CENTER' value='0'><param name='MAINTAINASPECT' value='0'><param name='BACKGROUNDCOLOR' value='#000000'><embed src='%video_file%' width='"+vPlayerWidth+"' height='30' controls='ControlPanel' type='audio/x-pn-realaudio-plugin' console='video' autostart='false'></embed></object></td></tr></table>";
//--------------------------------------------------------


///////////////// VPLAYER FUNCTIONALITIES /////////////////
//--------------------------------------------------------
function LoadVideoPlayer(videofile){	

	var vType					=	videofile.substr(videofile.lastIndexOf(".")+1, videofile.length);
	var baseURL					=	videofile.substr(0, videofile.lastIndexOf("/"));
	var videoFile				=	videofile.substr(videofile.lastIndexOf("/")+1, videofile.length);

	var vPlayerContainer		=	_el(vPlayerContainerId);

	switch(vType){
		case 'flv':
				//Check whether the system has the required Plug-in
				if (!detectFlash()){
					alert("Your browser do not support Shockwave Flash. Please install the required Plugin and Try.");
					return;
				}
				vPlayerCode_flv				=	vPlayerCode_flv.replace("%video_file%", videofile);	
				vPlayerCode_flv				=	vPlayerCode_flv.replace("%baseURL%", baseURL);	
				vPlayerCode_flv				=	vPlayerCode_flv.replace("%videoFile%", videoFile);	
				vPlayerContainer.innerHTML	=	vPlayerCode_flv;
			break;
		case 'wmv':
				//Check whether the system has the required Plug-in
				if (!detectWindowsMedia()){
					alert("Your browser do not support Windows Media Player. Please install the required Plugin and Try.");
					return;
				}
				vPlayerCode_wmv				=	vPlayerCode_wmv.replace("%video_file%", videofile);	
				vPlayerCode_wmv				=	vPlayerCode_wmv.replace("%video_file%", videofile);	
				vPlayerCode_wmv				=	vPlayerCode_wmv.replace("%video_file%", videofile);	
				vPlayerContainer.innerHTML	=	vPlayerCode_wmv;
			break;

		case 'mov':
				//Check whether the system has the required Plug-in
				if (!detectQuickTime()){
					alert("Your browser do not support QuickTime. Please install the required Plugin and Try.");
					return;
				}
				vPlayerCode_mov				=	vPlayerCode_mov.replace("%video_file%", videofile);	
				vPlayerCode_mov				=	vPlayerCode_mov.replace("%video_file%", videofile);	
				vPlayerContainer.innerHTML	=	vPlayerCode_mov;
			break;

		case 'rm':
				//Check whether the system has the required Plug-in
				if (!detectReal()){
					alert("Your browser do not support Real Player. Please install the required Plugin and Try.");
					return;
				}
				vPlayerCode_rm				=	vPlayerCode_rm.replace("%video_file%", videofile);	
				vPlayerCode_rm				=	vPlayerCode_rm.replace("%video_file%", videofile);	
				vPlayerCode_rm				=	vPlayerCode_rm.replace("%video_file%", videofile);	
				vPlayerCode_rm				=	vPlayerCode_rm.replace("%video_file%", videofile);	
				vPlayerContainer.innerHTML	=	vPlayerCode_rm;
			break;
	}
}
//--------------------------------------------------------


