function aichevideoplayer () 
{

try
  {
    var aicheVideoContainer = document.getElementById('aichevideoblock');

    if (aicheVideoContainer!=null) // page must have a div with ID=aichevideoblock to embed videos
    {
	var baseUrl=aicheVideoContainer.getAttribute('url');
	var videopath=aicheVideoContainer.getAttribute('videopath');
	var width=aicheVideoContainer.getAttribute('playerwidth');
	var height=aicheVideoContainer.getAttribute('playerheight');

	height = parseInt(height)+25; // player-specific; to account for player controls' height

	aicheVideoContainer.style.width = width+'px';
	aicheVideoContainer.style.height = height+'px';
	aicheVideoContainer.style.align = 'center';
	aicheVideoContainer.style.verticalAlign = 'middle';

	// include video player specific script file -- flowplayer
	//var playerJSfile = "/includes/flowplayer/flowplayer-3.0.3.min.js"

	// include video player specific script file -- jwplayer
	if (videopath.toLowerCase().indexOf('.wmv')>0) {
		var script1 = document.createElement("script");
		script1.setAttribute("type", "text/javascript");
		var playerJSfile ="/includes/jwplayer/silverlight.js";
		script1.setAttribute("src", playerJSfile);
		document.getElementsByTagName("head")[0].appendChild(script1);

		var script2 = document.createElement("script");
		script2.setAttribute("type", "text/javascript");
		var playerJSfile ="/includes/jwplayer/wmvplayer.js";
		script2.setAttribute("src", playerJSfile);
		document.getElementsByTagName("head")[0].appendChild(script2);
	}
	else {
		var noFlashMssg = document.createElement("a");
		noFlashMssg.href="http://www.macromedia.com/go/getflashplayer";
		noFlashMssg.appendChild (document.createTextNode("Flash Player is required to view this video."));
		aicheVideoContainer.appendChild(noFlashMssg ); 

		var playerJSfile ="/includes/jwplayer/swfobject.js";
		var script = document.createElement("script");
		script.setAttribute("type", "text/javascript");
		script.setAttribute("src", playerJSfile);
		document.getElementsByTagName("head")[0].appendChild(script);

	}

/****** JWPlayer ****/

	// Player-specific script is NOT available immediately for (needs a few milli-seconds)
	// So execute any video player-specific code that needs to reference the script after a time delay (eg 1000 milisecs)
	var timerID = setInterval(
		function() {

			if (videopath.toLowerCase().indexOf('.wmv')>0) {
			 	var src = "/includes/jwplayer/wmvplayer.xaml";
		 		var cfg = {file:"mms://aice.wmod.llnwd.net/a3559/o33/"+videopath};
			 	var ply = new jeroenwijering.Player(aicheVideoContainer,src,cfg);
			} else {
				var jwplayer = new SWFObject("/includes/jwplayer/player.swf","ply",width,height,"9","#FFFFFF");
				jwplayer.addParam("allowfullscreen","true");
				jwplayer.addParam("allowscriptaccess", "always");
				jwplayer.addVariable("streamer", baseUrl);
				if (videopath.toLowerCase().indexOf('.flv')>0 || videopath.toLowerCase().indexOf('.mp3')>0 || videopath.toLowerCase().indexOf('.mp4')>0) 
					jwplayer.addVariable("file", videopath);
				else
					jwplayer.addVariable("file", videopath+".flv");

				jwplayer.write("aichevideoblock");
			}
			clearInterval(timerID);
		}, 1500);

/****** flowplayer: REMOVED 03/04/09 due to inconsistent performance if network connection is poor

	// create video player specific container (e.g flowplayer wants a <a> tag)
	var playerVideoContainer = document.createElement("a");
	playerVideoContainer.style.display = "block";
	playerVideoContainer.style.width = width+"px";
	playerVideoContainer.style.height = height+"px";
	playerVideoContainer.style.border = "1px solid gray";
	playerVideoContainer.setAttribute("id","playerVideoContainer");
	aicheVideoContainer.appendChild(playerVideoContainer); 

	// Player-specific script is NOT available immediately for (needs a few milli-seconds)
	// So execute any video player-specific code that needs to reference the script after a time delay (eg 1000 milisecs)
	var timerID = setInterval(
		function() {
			if (document.getElementById("playerVideoContainer")!=null) {
	    			$f("playerVideoContainer", "/includes/flowplayer/flowplayer-3.0.3.swf", { 
					clip: {    
						url: videopath,  
						provider: 'cdn', autoPlay: false, scaling: 'fit' 
					},
					plugins:{
						cdn: { 
							url: '/includes/flowplayer/flowplayer.rtmp-3.0.2.swf', 
							netConnectionUrl: baseUrl
						} 
					}
		    		}); 
			};
			clearInterval(timerID);
		}, 1000);
**********/

    }
  }
  catch(e){}
  return;
}

aichevideoplayer();

// ****************************  TRACK GOOGLE ANALYTICS **********************
function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function setGoogleVars() {


	if (typeof pageTracker=='object') {

		var aicheLoginCookie = readCookie('AIChEMemberInfo');

		var userType="NOT-Logged-In";
		if (aicheLoginCookie!=null) {
			userType="Logged-In";
		};

		pageTracker._setCustomVar( 
			1,             // This custom var is set to slot #1 
			"UserType",   // The name of the custom varaible 
			userType,      // Sets the value of "User Type" 
			1             // scope = visitor
		); 

		var aicheMembershipCookie = readCookie('CURRENT-MEMBERSHIPS');
		var memberType="NON-MEMBER";
 
		if (aicheMembershipCookie!=null) {
			var membershipRecords = aicheMembershipCookie.split('#');
			memberType = 'OTHER';
			for(var i=0;i < membershipRecords.length;i++) {
				memRec = membershipRecords[i].split('~');
				var memProdID=memRec[4];

				if (memProdID==9 && memberType == 'OTHER')
					memberType='AIChE-MEMBER';
				else if (memProdID==4 || memProdID==3)
					memberType='AIChE-YP-MEMBER';
				else if (memProdID==2 || memProdID==1)
					memberType='AIChE-STUD-MEMBER';
				else if (memProdID==13 || memProdID==12)
					memberType='AIChE-GRADSTUD-MEMBER';
				else if (memProdID==1666 || memProdID==1667)
					memberType='AIChE-INTLSTUD-MEMBER';
				else if (memProdID==497)
					memberType='AIChE-SPONSORED-MEMBER';
				else if (memProdID==15)
					memberType='AIChE-FELLOW';
				else if (memProdID==14 || memProdID==409)
					memberType='AIChE-SR-MEMBER';
				else if (memProdID==14 || memProdID==409)
					memProdName='AIChE-SR-MEMBER';
				else if (memProdID==212)
					memberType='SBE-IND-MEMBER';
				else if (memProdID==319)
					memberType='CCPS-CORP-MEMBER';
			}
		}
 
		if (userType=="Logged-In"){
			pageTracker._setCustomVar( 
				2,             // This custom var is set to slot #2 
				"MemberType",   // The name of the custom varaible 
				memberType,      // Sets the value of "User Type" 
				1             // scope = visitor
			); 
		}

		pageTracker._trackPageview();
    	}
}

setGoogleVars();

// **************************** END SET GOOGLE CUSTOM VARIABLES **********************

