/**
 *	@author			Stewart Smith
 *	@email			stewart.smith@beamland.com
 *	@version		1.0
 *
 *	@history
 * 	04.24.2009		ssmith		Initial Version 
 *	
 *	embed code using swfobject v2.1
 */
	var VideoPlayer = {
		// variables for swfobject
		swfUrlStr		:'/_swf/VideoShell.swf',
		replaceElemIdStr:'flashModule',
		widthStr		:'640',
		heightStr		:'360',
		swfVersionStr	:'9.0.0',
		xiSwfUrlStr		:'/_swf/expressInstall.swf',
		flashvarsObj	:{
			sourceID			:'1',
			regStatus			:'false',
			trackAccount		:'none',
		playlistURL			:'',
		defaultVideoID		:'',
		autoPlayDefault		:'false',
			defaultPlaylistOpen	:'true',
			defaultCornersRound	:'false',
			trackNetPath		:'/_inc/video_tracking.php', 
			swfPath				:'/_swf/VideoPlayer.swf'
		},
		paramsObj		:{
			scale				:'noScale',
			salign				:'lt',
			menu				:'false',
			quality				:'high',
			bgcolor				:'#cccccc',
			wmode				:'transparent',
			allowFullScreen		:'true',
			allowScriptAccess	:'sameDomain'
		},
		attributesObj	:{
			id					:'videoPlayer',
			name				:'videoPlayer'
		},
		
		// functions
		embed:function()
		{
			// embed/re-embed the swf
			// this.widthStr = '640';
			// this.heightStr = '360';
		swfobject.embedSWF( this.swfUrlStr + '?rand=' + new Date().getTime(), this.replaceElemIdStr, this.widthStr, this.heightStr, this.swfVersionStr, this.xiSwfUrlStr, this.flashvarsObj, this.paramsObj, this.attributesObj );
		},
		embedDemo:function()
		{
			// embed/re-embed the swf
			this.widthStr = '850';
			this.heightStr = '520';
		swfobject.embedSWF( this.swfUrlStr + '?rand=' + new Date().getTime(), this.replaceElemIdStr, this.widthStr, this.heightStr, this.swfVersionStr, this.xiSwfUrlStr, this.flashvarsObj, this.paramsObj, this.attributesObj );
		},
		defaultPlaylistURL:function( $filePath )
		{
			// if param passed - update var
			if( $filePath != undefined ) this.flashvarsObj.playlistURL = $filePath;
			this.embed();
		},
		defaultPlaylistOpen:function( $bool )
		{
			// if called without a param - make it open at start
			if( $bool == undefined ) $bool = true;
			
			// update var
			if( $bool || $bool == 'true' )
			{
				this.flashvarsObj.defaultPlaylistOpen = 'true';
			}
			else if( !$bool || $bool == 'false' )
			{
				this.flashvarsObj.defaultPlaylistOpen = 'false';
			}
			
			// re-embed the swf
			this.embed();
		},
		defaultCornersRound:function( $bool )
		{
			// if called without a param - make rounded corners
			if( $bool == undefined ) $bool = true;
			
			bool = true;
			
			// update var
			if( $bool || $bool == 'true' )
			{
				this.flashvarsObj.defaultCornersRound = 'true';
			}
			else if( !$bool || $bool == 'false' )
			{
				this.flashvarsObj.defaultCornersRound = 'false';
			}
			
			// re-embed the swf
			this.embed();
		},
		// from swfaddress
		
		_swfChange:function()
		{
			for (var i = 0, id, obj, value = SWFAddress.getValue(), setter = 'setSWFAddressValue'; id = _ids[i]; i++)
			{
				obj = document.getElementById(id);
				if (obj)
				{
					if (obj.parentNode && typeof obj.parentNode.so != UNDEFINED)
					{
						obj.parentNode.so.call(setter, value);
					}
					else
					{
						if (!(obj && typeof obj[setter] != UNDEFINED))
						{
							var objects = obj.getElementsByTagName('object');
							var embeds = obj.getElementsByTagName('embed');
							obj = ((objects[0] && typeof objects[0][setter] != UNDEFINED) ? 
								objects[0] : ((embeds[0] && typeof embeds[0][setter] != UNDEFINED) ? 
									embeds[0] : null));
						}
						if (obj)
							obj[setter](value);
					} 
				}
				else if (obj = document[id])
				{
					if (typeof obj[setter] != UNDEFINED)
						obj[setter](value);
				}
			}
		}
	};
	
	

	loadFullReg = function( sourceID, videoID ) {	
		/* 
		alert( 'loadFullReg( ' + sourceID + ', ' + videoID + ' )' );
		VideoPlayer.flashvarsObj.regStatus = 'true';
		VideoPlayer.flashvarsObj.defaultVideoID = videoID;
		VideoPlayer.flashvarsObj.defaultCornersRound = 'false';
		VideoPlayer.embed();
		*/
	}
	
	loadDemoReg = function( sourceID, videoID ) {
		// check whether the users already registered
		// if yes, then show the demo
		if ($.cookie('revisit') || $.cookie('dfex')) {

			switch(sourceID) {
				case "47": // collector
					var vidID = "9";
					break;

				case "48": // clinicals
					var vidID = "10";
					break;
			}

			tb_show(null,'/video.php?vid='+vidID+'&height=545&width=840&TB_iframe=true',false);
		}
		// if no, then show the form
		else {

			switch(sourceID) {
				case "47": // collector
					var srcID = "49";
					break;

				case "48": // clinicals
					var srcID = "50";
					break;
			}
			
			tb_show(null,'leadform.php',false);
		}
			
		/*
		// The videoID could be null if the call is form a postroll 'Watch Demo' 
		if( VideoPlayer.flashvarsObj.regStatus != 'true' )
		{
			alert( 'loadDemoReg( ' + sourceID + ', ' + videoID + ' )' );
			VideoPlayer.flashvarsObj.regStatus = 'true';
		}
		if( videoID != undefined && videoID != '' )
		{
			VideoPlayer.flashvarsObj.defaultVideoID = videoID;
		}
		else
		{
			VideoPlayer.flashvarsObj.defaultVideoID = '';
			VideoPlayer.flashvarsObj.playlistURL = 'lang/en/playlist_demo.xml';
		}
		VideoPlayer.flashvarsObj.defaultCornersRound = 'true';
		VideoPlayer.embedDemo();
		*/
	}

	cancelDemo = function( sourceID ) {
		// alert( 'cancelDemo( ' + sourceID + ' )' );
		self.parent.tb_remove();
	}

	loadContactUs = function( sourceID ) {
		if ($('#lyr_video_demo').length > 0) {
			$('#lyr_video_demo').css({display:'none'});
			window.location.href = 'leadform.htm';
			self.parent.sizeThickboxToContact();
		}
		else if ($('#lyr_video').length > 0) {
			window.location.href = 'leadform.htm';
			self.parent.sizeThickboxToContact();
		}
		else {
			// alert( 'loadContactUs( ' + sourceID + ' )' );
			tb_show(null,'leadform.htm',false);
		}
	}
	
	
	sizeToVideo = function( videoID ) {
		VideoPlayer.flashvarsObj.defaultVideoID = videoID;
		VideoPlayer.flashvarsObj.defaultCornersRound = 'false';
		VideoPlayer.embed();
	}

	sizeToDemo = function( videoID ) {
		VideoPlayer.flashvarsObj.defaultVideoID = videoID;
		VideoPlayer.flashvarsObj.defaultCornersRound = 'true';
		VideoPlayer.embedDemo();
	}

	playVideo = function( videoID ) {
		document.getElementById('videoPlayer').playVideo( videoID );
		return false;
	}
