PlayerController = function (playerTagName)
{
 	this.adRefreshTimer=null;
	
	this.os = dojo.render.os;
 	this.browser = dojo.render;
    this.config = new ConfigController();
    this.adManager = new AdController(this.config);
 	    
 	this.loaded = false;
 	this.flashLoaded = false;
	this.hasTimeStarted = false;
	
    this.playerControl = document.getElementById(playerTagName);
	this.playerControl.style.display = "block"; //firefox happy 
	this.playerControl.style.visibility = "hidden";
	
	if (this.os.win)
	{
	    this.playerControl.uiMode = "invisible"; 
	    this.playerControl.windowlessVideo = (parseInt(this.playerControl.versionInfo) >= 10) ? true : false;
	}
	
	this.playIntro = false;
	this.fullScreenOK = false;
	this.introHasStarted = false;
	this.failureTimer = null;  
	this.showVideoTimer = null;  
	this.hideVideoTimer = null;  
	this.adCount = 0; 
	this.adPlaying = false; 
	
	this.live = false; 
	 
	//this.playlist = false; 
	this.videoEvent = {};  
	this.videoEvent.content = {type:"",id:""}; 

	//attach the event handlers
	if (this.os.win && this.playerControl)
	{
	    //only attach if exteranl stubs exist
	    if (onPlaystateChange)
	        dojo.event.connect(this.playerControl,"onPlaystateChange", this, "handleNewState");
	
		if (onBuffering)
		    dojo.event.connect(this.playerControl, "onBuffering", this, "handleBuffering");
	    
	    if (onCurrentItem)
	        dojo.event.connect(this.playerControl, "onCurrentItem", this, "handleCurrentItem");
	    
	    if (onPosition)
	        dojo.event.connect(this.playerControl, "onPosition", this, "handlePosition");
	    
	    if (onOpenstate)
	        dojo.event.connect(this.playerControl, "onOpenstate", this, "handleOpenState");
	    
   	    if (onMediaError)
	        dojo.event.connect(this.playerControl, "onMediaError", this, "handleMediaError");
	    
	    if (onMouseDown)
	        dojo.event.connect(this.playerControl, "onMouseDown", this, "handleMouseDown");

	}
	
	this.startFresh();
	if (!this.config.fullScreen.message) this.fullScreenOK = true;
	if (this.config.intro)
	    this.playIntro = true;
	else
	    this.playIntro = false; 
	this.channelName = (typeof this.config.channelName=="undefined") ? "undefined" : this.config.channelName;

	if (this.adManager.maxTime>-1)
	{
		this.clock = {videoTime:0,adTime:0,offset:100,timer:false};
		var thisObj = this;
		var timefunc = function() { thisObj.updateClock(); };
		this.clock.timer = setInterval(timefunc,this.clock.offset); 
	}

	if (window.addEventListener)
	{    
		window.addEventListener("unload",this.finish,false);
	}
	else
	{   
		window.attachEvent("onbeforeunload",this.finish)
	}
	
	this.loaded = true;
	
	if (this.flashLoaded) this.playNextElement();

};

dojo.lang.extend(PlayerController,
                    {
                       //***************startFresh********************
                       startFresh: function()
                       {
                       	    this.stopAdCountTimer();
	                        this.asxLock = false; 
	                        this.adPlaying = false;
	                        this.onFlashEvent("Video.ADPLAY","false");
	                        this.kickstartLoop = 0;   
                       },
                       //***************updateClock********************
                       updateClock: function()
                       {
	                        try
	                        { //in case of unload
		                        if (this.playerControl.playState==3)
		                        {  
			                        var n = this.clock.offset/1000;
                                     /* look for live video type . if it is a live video, then it is def. NOT an ad  */
                                     try
                                     {
                                        if (this.playerControl.currentMedia.getItemInfo("vidType") == "live")
                                        {
                                            this.adPlaying = false;
	                                        this.onFlashEvent("Video.ADPLAY","false");
                                        }
                                     }
                                     catch(e)
                                     {
                                        dojo.debug("EXCEPTION: updateClock() " + e.message);
                                     } 

			                         if (!this.adPlaying)
			                         {
				                            this.clock.videoTime += n; 
				                            this.evalMark(); 
			                         }
	                            }
	                        }
	                        catch(e)
	                        {
	                            dojo.debug("EXCEPTION: updateClock() " + e.message);
	                        }
                       },
                       //***************showVideo********************
                       showVideo: function()
                       {
                            clearTimeout(this.hideVideoTimer);
    	                    if (this.os.win)
                                this.playerControl.uiMode = "none";
    	                    this.playerControl.style.visibility = "visible"; 
    	                    this.onFlashEvent('Video.VIDEODISPLAY', 'visible');
							this.onShowVideo(this.live);
                        },
                       //***************delayShowVideo********************
                       delayShowVideo: function(n)
                       {
	                        clearTimeout(this.showVideoTimer);
	                        clearTimeout(this.hideVideoTimer);
	                        var thisObj = this;
                            //var  timefunc = function() { thisObj.showVideo() }; 
	                        this.showVideoTimer = setTimeout(function() { thisObj.showVideo() },n);
                        },
                       //***************hideVideo********************
                       hideVideo: function()
                       {
	                        try 
	                        {//in case of unload
		                        if (this.playerControl.playState==3) return; 
		                        clearTimeout(this.showVideoTimer);
                        		
		                        if (!this.playerControl.fullScreen)
		                        { 
			                        this.playerControl.style.visibility = "hidden"; 
			                        this.onFlashEvent('Video.VIDEODISPLAY','hidden');
									this.onHideVideo();
		                        }
	                        }
	                        catch(e)
	                        {
	                            dojo.debug("EXCEPTION: hideVideo() " + e.message);
	                        }
	                   },
                       //***************delayHideVideo********************
                       delayHideVideo: function(n)
                       {
	                        try
	                        {
	                            clearTimeout(this.showVideoTimer);
	                            clearTimeout(this.hideVideoTimer);
	                            if (this.os.win && this.playerControl.playState!=3)
	                            {
    	                            var thisObj = this;
                                    //var timefunc = function() { thisObj.hideVideo() }; 
		                            this.hideVideoTimer = setTimeout(function() { thisObj.hideVideo() },n);
	                            }
	                        }
	                        catch (e)
	                        {
	                            dojo.debug("EXCEPTION: delayHideVideo() " + e.message);
	                        }
	                        
                        }
                     }
                 );
                 
dojo.lang.extend(PlayerController,
                    {
                       //***************playVideo********************
                       playVideo: function()
                       {
	                        var previousVideoEvent = this.videoEvent;  

	                        var args = playVideo.arguments;	 	
	                        this.videoEvent = this.makeVideoObject(args[0].item0,previousVideoEvent);
                        	
						    if (args[0].item1 != null)
	                            this.preBuffEvent = this.makeVideoObject(args[0].item1);   
	                        if (this.videoEvent.takesTrailingAd)
	                        {
		                        this.videoEvent.takesTrailingAd = !this.ifKillTrailingAd(false); //check pBE
	                        }
                        	
	                        if (!this.isValidURL(this.videoEvent.url)) {
		                        this.handleInvalidVideo(this.videoEvent.id);
		                        return;
	                        } 
                        	
	                        if (this.loaded) {  
		                        if (!this.adPlaying) this.playNextElement(); 
	                        } else {
		                        this.flashLoaded = true;
	                        }
                       },                       
                       //***************playNextElement********************
                       playNextElement: function()
                       {
                            this.startFresh(); 
	                        this.cued = false;	
	                        
	                        if (this.os.mac)
	                        {
								this.playNextElementMac();
								return;
	                        } 
 			
	                        if (this.playlist) this.playlist.index++; 
	                        if (this.playIntro && this.introHasStarted) this.playIntro = false; //intro interrupt
	
	                        this.startPlayNextElement();

	                        if (this.ifAdInsertion()) {    
		                        this.adPlaying = true; 
		                        this.onFlashEvent("Video.ADPLAY","true");
                        		
		                        try
		                        { 
			                        if (!this.playlist) {}
			                        else if (this.playlist.items.length<=this.playlist.index) return;
			                        else if (this.playlist.items[this.playlist.index].isAd)
			                        { 
				                        if (this.playlist.items[this.playlist.index-1].isAsx && !this.playlist.items[this.playlist.index-1].mediaEnded)
				                        {
				                        }	
				                        else if (!this.playlist.items[this.playlist.index-1].mediaEnded)
				                        {//interrupt & play
					                        this.cued = true; 
					                        this.playerControl.controls.playItem(this.root_playlist.item(this.playlist.index)); 
					                        this.removeCuedItems(this.playlist.index+1); 
				                        }
				                        else
				                        { //playing already 
					                        this.cued = true; 
					                        this.play(); 
				                        } 
			                        } 
		                        }
		                        catch(e)
		                        {
       	                            dojo.debug("EXCEPTION: playNextElement() " + e.message);
		                        }
                        		
		                        if (this.cued)
		                            this.delayHideVideo(200);
		                        else
		                        {  
			                        this.hideVideo();  
			                        this.stopFailureTimer(); 
			                        this.createNewPlaylist(); 
			                        this.insertAd(true);
			                        this.addToPlaylist(this.makeAdObj(true));
			                        this.playlist.items[this.playlist.items.length-1].isAd = true;  
    	                            var thisObj = this;
                                    //var timefunc = function() { thisObj.play(); } ;
			                        setTimeout(function() { thisObj.play(); },30); 
		                        }   
		                        if (this.playlist.index== this.playlist.items.length-1)
		                        {//no items after ad
    	                            var thisObj = this;
                                    //var timefunc = function() { thisObj.switchCuedItem(); };
			                        setTimeout(function() { thisObj.switchCuedItem(); },100);
		                        }
                        		
		                        this.clock.videoTime = 0; 
	                        } 
	                        else
	                        {      
		                        try
		                        {
			                        if (!this.playlist) {} 
			                        else if (this.playlist.items.length<=this.playlist.index) return;
			                        else if (this.stripAuthToken(this.playlist.items[this.playlist.index].url)==this.stripAuthToken(this.videoEvent.url))
			                        {//cued 
				                        if (this.playlist.items[this.playlist.index-1].isAsx && !this.playlist.items[this.playlist.index-1].mediaEnded)
				                        {
				                        }	
				                        else if (!this.playlist.items[this.playlist.index-1].mediaEnded)
				                        {//interrupt & play  
					                        this.cued = true; 
					                        this.playerControl.controls.playItem(this.root_playlist.item(this.playlist.index)); 
				                        }
				                        else
				                        { //playing already 
					                        this.cued = true; 
					                        this.play(); 
				                        }
			                        }   
		                        } catch(e)
		                        {
      	                            dojo.debug("EXCEPTION: playNextElement() " + e.message);
		                        }
                        		
		                        try
		                        {
			                        if (this.cued)
			                        {
				                        this.delayHideVideo(200);
				                        if (this.videoEvent.takesTrailingAd) this.videoEvent.takesTrailingAd = !this.ifKillTrailingAd(false); //check pBE
           	                            var thisObj = this;
                                        //var timefunc = function() { thisObj.addPrebufferItem(); }; 
				                        setTimeout(function() { thisObj.addPrebufferItem(); },100);
			                        }
			                        else
			                        { 
				                        this.hideVideo();  
				                        this.stopFailureTimer();	 
				                        this.createNewPlaylist();
				                        if (this.playIntro)
				                        {//so buff_url doesn't add twice
					                        if (!this.isValidURL(this.config.intro)) this.playIntro = false;
					                        else
					                        { 
						                        this.introHasStarted = true; 
						                        var introObj = {url:this.config.intro};
						                        this.addToPlaylist(introObj); 	
						                        this.playlist.items[this.playlist.items.length-1].id = "intro";
                   	                            var thisObj = this;
                                                //var timefunc = function() { thisObj.play(); } ;
						                        setTimeout(function() { thisObj.play(); },20); 
						                        this.addToPlaylist(this.videoEvent);   
					                        }
				                        }
				                        if (!this.playIntro) {  
					                        this.addToPlaylist(this.videoEvent);	 
              	                            var thisObj = this;
                                            //var timefunc = function() { thisObj.play(); } ;
					                        setTimeout(function() { thisObj.play(); },30); 
                                            //var timefunc2 = function() { thisObj.addPrebufferItem(); }; 
					                        setTimeout(function() { thisObj.addPrebufferItem(); },100);
				                        } 
			                        }  
		                        } catch(e)
		                        {
      	                            dojo.debug("EXCEPTION: playNextElement() " + e.message);
		                        }
		                        this.onVideoReporting(this.videoEvent, this.preBuffEvent);
								this.live = this.videoEvent.live; 
		                        if (!this.playIntro) this.startAdCountTimer();
	                        } 
                        	
	                        this.endPlayNextElement();
                       },
                       //***************playNextElement********************
                       playNextElementMac: function()
                       {
							//this.hideVideo();
							//dojo.byId("Player").style.visibility = "hidden";
							dojo.html.hide(dojo.byId("Player"));
							var mmsStr = this.videoEvent.url;
							//var mmsStr = "mms://a180.v89244.c8924.g.vm.akamaistream.net/7/180/8924/44ce8bb3/fs6.insinc.com/akamai/ctv/discovery/911/disc_911_tomcanavan_pt1.wmv";
							var embedPlayer = '<object id="Player" classid="clsid:6BF52A52-394A-11d3-B153-00C04F79FAA6" >';
							//embedPlayer += '	<param name="uiMode" value="">';
							embedPlayer += '	<param name="autoStart" value="true">';
							embedPlayer += '	<param name="volume" value="90";>';
							embedPlayer += '	<param name="AllowChangeDisplaySize" value="false">';
							embedPlayer += '	<param name="enableContextMenu" value="true">';
							embedPlayer += '	<param name="stretchToFit" value="false">';
							embedPlayer += '	<param name="URL" value="' + mmsStr + '">';
							embedPlayer += '	<embed TYPE="application/x-mplayer2" ';
							embedPlayer += '		pluginspage="http://www.microsoft.com/Windows/MediaPlayer/en/download/" ';
							embedPlayer += '		src="' + mmsStr + '"';
							embedPlayer += '		AutoStart="1" ';
							embedPlayer += '		Name="Player"';
							embedPlayer += '		ID="Player"';
							embedPlayer += '		AnimationAtStart="1"';
							embedPlayer += '		transparentAtStart="1"';
							embedPlayer += '		ShowStatusBar="1"';
							embedPlayer += '		ShowControls="1" ';
							embedPlayer += ' 		showpositioncontrols="1"  ';
							embedPlayer += '		autoSize="0" ';
							embedPlayer += '		allowchangedisplaysize="1" ';
							embedPlayer += '		enablefullscreencontrols="1" ';
							embedPlayer += '		displaySize="0" ';
							embedPlayer += '	</embed>';
							embedPlayer += '</object>';
							
							nodeHolder = dojo.byId("PlayerHolder");
							newNodes = dojo.html.createNodesFromText(embedPlayer, true)
							dojo.dom.replaceChildren(nodeHolder, newNodes[0]);

							dojo.html.show(newNodes[0]);
							//dojo.byId("Player").style.visibility = "visible";
							
						
							//reporting_manager.reportPlayVideo(videoEvent, preBuffEvent);
                       },
                       //***************startPlayNextElement********************
                       startPlayNextElement: function()
                       {
                            if (this.playIntro) return;
	                        if (!this.videoEvent.newContainer) return;
							
	                        try
	                        { //videoEvent starts new container 
		                        if (this.ifAdInsertion())
		                        { //trailing ad
			                        if (this.ifKillTrailingAd(true))
			                        {
				                        this.adCount = this.adManager.maxEls - this.adManager.maxElsOnReset;
				                        this.playlist.items[this.playlist.index].isAd = false; //kill existing ad  
			                        }
			                        return;
		                        } 
                        		
		                        if (this.videoEvent.forceLeadingAd)
		                        { //leading ad
			                        if (this.ifKillLeadingAd()|| this.leadingAdPlayed()) {
				                        this.adCount = 0;
				                        return;
			                        } 
		                        } 
                        		
		                        this.resetAdCount(); //no trailing or leading ad
	                        } 
	                        catch(e)
	                        {
                                dojo.debug("EXCEPTION: startPlayNextElement() " + e.message);
	                        }                        
                       },
                       //***************endPlayNextElement********************
                       endPlayNextElement: function()
                       {
	                        try
	                        { 	 
		                        if (this.adPlaying)
		                        { 
			                        this.adManager.container.adsPlayed++;
			                        this.adCount = 0; 
			                        return;
		                        }
		                        //video played 
		                        if (this.videoEvent.newContainer)
		                        { 
			                        if (this.playIntro && this.videoEvent.forceLeadingAd)
			                        { 
           	                            var thisObj = this;
                                        //var timeoutFunc = function () { thisObj.insertAd(true); };
				                        setTimeout(function () { thisObj.insertAd(true); },100);
			                        }
			                        if (!this.playIntro && this.videoEvent.forceCoAd) this.setCoAd(this.videoEvent.forceCoAd);
			                        if (!this.playIntro && this.videoEvent.forceTrailingAd)
			                        {
				                        this.adCount = this.adManager.maxEls; 
           	                            var thisObj = this;
                                        //var timeoutFunc = function () { thisObj.insertAd(true); };
				                        setTimeout(function () { thisObj.insertAd(true); },200); //after pbE added 
			                        }   
		                        }
		                        if (this.preBuffEvent && this.preBuffEvent.forceLeadingAd)
		                        { 
                                    var thisObj = this;
                                    //var timeoutFunc = function () { thisObj.insertAd(); };
			                        setTimeout(function () { thisObj.insertAd(); },200); 
		                        }
	                        } catch(e)
	                        {
                                dojo.debug("EXCEPTION: endPlayNextElement() " + e.message);
	                        }                        
                       },
                       //***************makeVideoObject********************
                       makeVideoObject: function(obj, previousVideoEvent)
                       {
	                        try { 
		                        if (!obj.url)
									obj.url = this.config.asxGen+ "?vid=" + obj.id;
								else if (typeof this.config.asxGen !="undefined" && obj.url.indexOf(".asx")==-1 && obj.url.indexOf(".wmv")==-1) obj.url = this.config.asxGen+ "?vid=" + obj.id;		
		                        
		                        if (obj.content.type=="") obj.content.type = "playlist"; 
		                        if (obj.content.id == 0) obj.content.id = obj.content.type; 
		                        obj.previousEvent = previousVideoEvent ? previousVideoEvent : this.videoEvent;     
		                        obj.newContainer = (eval("obj."+this.adManager.resetSwitch)!=eval("obj.previousEvent."+this.adManager.resetSwitch));    
		                        obj.forceCoAd = this.adManager.ifForceCoAd(obj.content.id); 
		                        obj.takesAds = this.adManager.ifTakesAds(obj.content.id); 
		                        obj.takesLeadingAd = this.adManager.ifTakesLeadingAd(obj.takesAds, obj.type);  
		                        obj.forceLeadingAd = this.adManager.ifForceLeadingAd(obj.newContainer, obj.takesLeadingAd); 
		                        obj.takesTrailingAd = this.adManager.ifTakesTrailingAd(obj.takesAds, obj.type); 
		                        obj.forceTrailingAd = this.adManager.ifForceTrailingAd(obj.takesAds, obj.type);
								if (obj.content.typeid == 14) //live 
		                        	obj.live = true;
								else
									obj.live = false;
									
		                        if (!this.config.scriptBasedBanner)
		                        {
									var adZone = this.config.bannerZone;
									if (true)
									{
										var contentType = obj.content.type;
										var pos = contentType.indexOf("##");
										if (pos > 0)
										{
											var tmpStr = contentType.substring(pos+2);
											pos = tmpStr.indexOf("##");
											if (pos > 0)
											{
												tmpStr = tmpStr.substring(0,pos);
											}
											adZone = tmpStr.toUpperCase();
											adZone = "VIDEOLB_" + adZone + ";";
										}									
									}
									
									obj.bannerUrl = this.config.bannerUrl + adZone + this.config.bannerOtherValue; 
								}
								else
									obj.bannerUrl = this.config.scriptBasedBanner; 
									

		                        return obj; 
	                        } catch(e) {
                                dojo.debug("EXCEPTION: makeVideoObject() " + e.message);
	                        }
                       },
                       //***************handleInvalidVideo********************
                       handleInvalidVideo: function(ivid)
                       {
                           	this.stopFailureTimer();
	
	                        if (this.adPlaying && ivid) {//while ad is playing
		                        this.requestItem();
		                        return;
	                        }
                        	
	                        if (!ivid) ivid = this.adPlaying ? "ad" : this.playlist.items[this.playlist.index].id;
                        	
	                        if (ivid == "intro") {
		                        this.playIntro = false;
		                        this.playNextElement();
	                        } else if (ivid == "ad") { 
		                        this.adCount = 0; 
		                        this.onFlashEvent("Video.PLAYSTATE", 1001);//PLAYSTATE_FAILURE
		                        this.playNextElement();
	                        } else {  
		                        this.onFlashEvent("Video.PLAYSTATE", 1001);//PLAYSTATE_FAILURE
                                var thisObj = this;
                                //var timeoutFunc = function () { thisObj.requestItem(); };
		                        setTimeout(function () { thisObj.requestItem(); }, 3000);
	                        }
                       },
                       //***************kickstartNextVideo********************
                       kickstartNextVideo: function()
                       {
                            this.stopFailureTimer();
                            this.hideVideo();

                            if (this.playerControl.playState != 3)
                            {
                                this.kickstartLoop++;
                                this.playerControl.fullscreen = false;
                                if (this.kickstartLoop==1)
                                {
                                    this.play();
                                    this.onFlashEvent("Video.PLAYSTATE", 1000);//PLAYSTATE_CONGESTION 
                                    this.startFailureTimer(true);
                                }
                                else if (this.playerControl.currentMedia.getItemInfo("vidType") != "live")
                                {
                                    this.adCount = 0; 
                                    this.startFresh();
                                    if (this.adPlaying)
                                    { 
                                        this.playNextElement();
                                    }
                                    else
                                    {
                                        this.onFlashEvent("Video.PLAYSTATE", 1001);//PLAYSTATE_FAILURE
                                        var thisObj = this;
                                        //var timeoutFunc = function () { thisObj.requestItem(); };
                                        setTimeout(function () { thisObj.requestItem(); },3000);
                                    }
                                }
                            } 
	                    },
                        //***************findNextElement********************
                        findNextElement: function ()
                        {
	                        try
	                        {
		                        this.playlist.items[this.playlist.index].mediaEnded = true;
	                        }
	                        catch(e)
	                        {
                                dojo.debug("EXCEPTION: findNextElement() " + e.message);
	                        } 
                        	
	                        if (this.playIntro)
	                        { 
		                        this.playIntro = false;
		                        this.playNextElement();  
	                        } 
	                        else if (this.adPlaying)
	                        { 
		                        this.playNextElement();
	                        }
	                        else
	                        {  
		                        this.requestItem();
	                        }
                       },
                       //***************requestItem********************
                       requestItem: function ()
                       {
	                        this.onFlashEvent("Video.PLAYSTATE", 8);
                       },
                       //***************requestItem********************
                       switchCuedItem:function ()
                       {
	                        if (this.isValidURL(this.videoEvent.url)) this.addToPlaylist(this.videoEvent);	
                       },
                       //***************requestItem********************
                       removeCuedItems: function (pos)
                       { 
	                        try
	                        {
		                        this.playlist.items.splice(pos,this.playlist.items.length-pos);  
		                        for (var i=pos;i<=this.root_playlist.count;i++) {
			                        this.root_playlist.removeItem(this.root_playlist.item(i));
		                        } 
	                        }
	                        catch(e)
	                        {
                                dojo.debug("EXCEPTION: removeCuedItems() " + e.message);
	                        }
                        }
                     }
                 );
                 
//Help functions
dojo.lang.extend(PlayerController,
                    {
                       //***************isValidURL********************
                       isValidURL: function(testUrl)
                       {
                        	if (typeof testUrl == "undefined"||testUrl==null||testUrl==""||testUrl=="undefined") return false;
                            else return true;
                       },
                       //***************isValidURL********************
                       isAsx: function(url)
                       {
	                        return (url.substring(0,7)=="http://"||url.substring(0,1)=="/");
                       },
                       //***************safeString********************
                       safeString: function(s)
                       {
                           try
                           {
                              s = unescape(s);
                              s = s.replace(/\W+/gi,"_").toLowerCase();
                              s = s.replace(/\s+/gi,"_").toLowerCase();
                              s = s.replace(/_+/g,"_");
                           }
                           catch(e)
                           {
                              return s;
                           }
                           return s;
                       },
                       //***************stripAuthToken********************
                       stripAuthToken: function(testURL)
                       {
	                        var u = testURL.substring(0, testURL.indexOf("?"));
	                        var query = testURL.substring(testURL.indexOf("?"), testURL.length);
	                        var sq = "";
	                        if (query.length>0)
	                        {
		                        var nvp = query.split("&");
		                        if (nvp.length > 0)
		                        {
			                        for (var i=0;i<nvp.length;i++)
			                        {
				                        if (nvp[i].indexOf("auth=")<0 && nvp[i].indexOf("aifp=")<0)
				                        {
					                        n = (sq=="") ? "" : "&";
					                        sq += n + nvp[i];
				                        }
			                        }
		                        }
	                        }
	                        return u+sq;
                        },
                       //***************startFailureTimer********************
                       startFailureTimer: function()
                       {
	                        try {
		                        var t = eval("this.config.failureTime."+(this.adPlaying?"ad":"video")+"."+(this.kickstartLoop==0?"congestion":"kickstart"));  
		                        var thisObj = this;
                                //var  timefunc = function() { thisObj.kickstartNextVideo(); } ;
		                        this.failureTimer = setTimeout(function() { thisObj.kickstartNextVideo(); },t);
	                        } catch(e)
	                        {
                                dojo.debug("EXCEPTION: startFailureTimer() " + e.message);
	                        }
	                   },
                       //***************stopFailureTimer********************
                       stopFailureTimer: function()
                       {
                       	    try
                       	    {
		                        clearTimeout(this.failureTimer);
	                        } catch(e)
	                        {
                                dojo.debug("EXCEPTION: stopFailureTimer() " + e.message);
	                        }
                       }
                     }
                 );

//Player controls
dojo.lang.extend(PlayerController,
                    {
                       //***************play********************
                       play: function()
                       {
                            try {this.playerControl.controls.play();}
                            catch(e)
                            {
                                dojo.debug("EXCEPTION: play() " + e.message);
                            }
                       },
                       //***************pause********************
                       pause: function()
                       {
                            try {this.playerControl.controls.pause();}
                            catch(e)
                            {
                                dojo.debug("EXCEPTION: pause() " + e.message);
                            }
	                   },
                       //***************stop********************
                       stop: function()
                       {
                            try {this.playerControl.controls.stop();}
                            catch(e)
                            {
                                 dojo.debug("EXCEPTION: stop() " + e.message);
                            }
                       },
                       //***************finish********************
                       finish: function()
                       {
							try
	                        { 
								//configManager.finish();
		                        if (this.playerControl != null)
		                        {
									this.stop();
			                        this.playerControl.close();   
		                        }
								ReporterHBX.reportEndVideo();
		                        //var nodeHolder = dojo.byId("PlayerHolder");
								//var newNodes = dojo.html.createNodesFromText("<div></div>", true)
								//dojo.dom.replaceChildren(nodeHolder, newNodes[0]);
	                        }
	                        catch(e)
	                        {
                                 dojo.debug("EXCEPTION: finish() " + e.message);
	                        }
                       },
                       //***************setVolume********************
                       setVolume: function(val)
                       {
                            try
                            {
								
                                if (val != 0)
                                    this.volume = val;
                                this.playerControl.settings.volume = val;
                            }
                            catch(e)
                            {
                                 dojo.debug("EXCEPTION: setVolume() " + e.message);
                            }
                       },
                       //***************mute********************
                       mute: function(val)
                       {
                            try
                            {
                                if (val == 1)
                                    this.setVolume(this.volume);
                                else
                                    this.setVolume(0);
                            }
                            catch(e)
                            {
                                 dojo.debug("EXCEPTION: mute() " + e.message);
                            }
                       },
                       //***************setFullscreen********************
                       setFullscreen: function()
                       {
                       	    try
                       	    {
		                        if (this.playerControl.playState == 3)
		                        { 
		                            if (this.fullScreenOK)
		                            {
			                            this.playerControl.fullscreen = true; 
		                            }
		                            else
		                            {
			                            if (confirm(this.config.fullScreen.message))
			                            {
				                            this.fullScreenOK = true;
				                            this.playerControl.fullscreen = true;
				                        }
				                    } 
			                    }
	                        } catch(e)
	                        {
                                 dojo.debug("EXCEPTION: setFullscreen() " + e.message);
	                        }
                       },
                       //***************setPosition********************
                       setPosition: function (val)
                       {
                       	    try
                       	    {
	                            this.playerControl.controls.currentPosition = (val/1000);
	                        }
	                        catch(e)
	                        {
                                 dojo.debug("EXCEPTION: setPosition() " + e.message);
	                        }
                       },
                       //***************getPosition********************
                       getPosition: function ()
                       {
                       	    try
                       	    {
		                        var pos = this.playerControl.controls.currentPosition;
	                            if ((this.playerControl.style.display=="none"||this.playerControl.style.visibility=="hidden") && pos > 0) this.showVideo();
	                            this.onFlashEvent("Video.POSITION", pos);
								ReporterHBX.reportProgressVideo();
	                            return pos 
	                        } catch(e)
	                        {
	                            return 0;
	                        }
                       }
                     }
                 );

//Events Section
dojo.lang.extend(PlayerController,
                    {
                       //***************onFlashEvent********************
                       onFlashEvent: function(eventName, param)
                       {
                       },
                       //***************onSetCoAd********************
                       onSetCoAd: function(adTag)
                       {
                       },
                       //***************onVideoReporting********************
                       onVideoReporting: function(videoEvent, preBuffEvent)
                       {
                       },
					   //***************onNewState********************
                       onNewState: function(newState)
                       {
                       },
					   onCurrentItem: function()
                       {
                       },
					   onShowVideo: function(live)
                       {
                       },
					   onHideVideo: function()
                       {
                       },
                       //***************onPlaystateEvent********************
                       handleNewState: function (newState)
                       { 	
                            debug.debugEvent("<< handleNewState() ");

							this.onNewState(newState);
	                        this.stopFailureTimer();
	
	                        switch (newState)
	                        {
		                        case 10: // Ready		
			                        this.delayHideVideo(100);
		                        case 0: // Undefined
		                        case 7: // Waiting
		                        case 9: // Transitioning
		                        case 11: // Reconnecting 
			                        this.startFailureTimer();
			                        break;
	                        }
	                        
	                        //dojo.debug("handleNewState(): " + newState);	


	                        if (newState == 3)
	                        { // playing

		                        try
		                        {
			                        this.onFlashEvent("Video.DURATION", this.playerControl.currentMedia.duration);
			                        this.onFlashEvent("Video.POSITION", this.playerControl.controls.currentPosition);
			                        this.onFlashEvent("Video.BITRATE", this.playerControl.network.bitRate);
			                        this.onFlashEvent("Video.MAXBITRATE", this.playerControl.network.maxBitRate);
			                        this.delayShowVideo( 500 );	
		                        } catch(e)
		                        {
                                    dojo.debug("EXCEPTION: handleNewState() " + e.message);
		                        }
                        		
		                        // added for live stream start time. 
		                        try {  
			                        if (this.useStartTime && !this.hasTimeStarted)
			                        { 
				                        this.hasTimeStarted = true;
				                        this.playerControl.controls.currentPosition = this.getStartTime(liveOffsetDate);
			                        }
			                        else
			                        {
				                        this.hasTimeStarted = false;
			                        }
		                        }
		                        catch(e)
		                        {
                                    dojo.debug("EXCEPTION: handleNewState() " + e.message);
		                        }
	                        }
	
	                        if (newState==8 && this.playerControl.currentPlaylist.isIdentical(this.root_playlist))
	                        { //media ended
		                        this.findNextElement();
		                        ReporterHBX.videoState8();
	                        } else if (newState==8)
	                        {  
		                        this.asxLock = true;
								ReporterHBX.videoState8(); 
	                        }
	
	                        if (newState!=8) this.onFlashEvent("Video.PLAYSTATE", newState);
                            
                            debug.debugEvent("handleNewState() >>");
                        },
                        //***************onOpenstateEvent********************
                        handleOpenState: function(newState)
                        {
                            debug.debugEvent("<< handleOpenState() ");

	                        if (newState==7)
	                        {//PlaylistChanged
		                        if (this.asxLock && this.playerControl.currentPlaylist.isIdentical(this.root_playlist))
		                        {
			                        if (this.loaded) this.findNextElement();
		                        }
	                        }
                            debug.debugEvent("handleOpenState() >>");
                        },
                        //***************onBufferingEvent********************
                        handleBuffering: function (start)
                        {
                            debug.debugEvent("<< handleBuffering()");

	                        if (start)
	                        { 
		                        if ( !(this.playerControl.controls.currentPosition > 0) )
		                        {
			                        this.stopAdCountTimer();
			                        this.hideVideo();
		                        }
	                        } 
	                        else
	                        { 
		                        if (this.playerControl.controls.currentPosition==0 && !this.adPlaying)
		                        {
			                        this.startAdCountTimer(); 
		                        }
		                        this.delayShowVideo( 50 );
	                        }
                            debug.debugEvent("handleBuffering() >>");
                        },
                        //***************onCurrentItemEvent********************
                        handleCurrentItem: function ()
                        {
                            debug.debugEvent("<< handleCurrentItem()");
	                        try
	                        { //error-handling
								this.onCurrentItem();
								 
								 if (this.adPlaying && this.playerControl.currentMedia.sourceURL == this.playlist.items[this.playlist.index+1].url)
		                         {
			                        this.playNextElement();
		                         }
	                        } catch(e)
	                        {
                                    dojo.debug("EXCEPTION: onCurrentItemEvent() " + e.message);
	                        }
 
	                        var coAdLink;
	                        try
	                        { //in case of unload
		                        var e = false; 
		                        var type = this.playerControl.currentMedia.getItemInfo("vidType").toLowerCase();
		                        var coAd = this.playerControl.currentMedia.getItemInfo("coAd");
		                        var expired = this.playerControl.currentMedia.getItemInfo("vidExpired"); 
		                        var vid = this.playerControl.currentMedia.getItemInfo("vid");
								coAdLink = this.playerControl.currentMedia.getItemInfo("coAdLink");
		                        this.setCoAdLink(coAdLink); // null is a valid value.
	                        } catch(e)
	                        {
		                        var e = true;
	                        }
	
	                        if (!e)
	                        {
		                        this.onFlashEvent("Video.VIDEOLIVE", type);  
		                        if (coAd != "") {
									clearTimeout(this.adRefreshTimer);
									this.setCoAd(coAd);
								}
		                        else if (vid != "" && this.playerControl.currentMedia.duration > 60)
		                        {
		                        	clearTimeout(this.adRefreshTimer);
									var thisObj = this;
									this.adRefreshTimer = setTimeout(function() { thisObj.setCoAd(thisObj.videoEvent.bannerUrl); },40000); 
									//this.setCoAd(this.videoEvent.bannerUrl)
		                        }  
		                        if (expired) this.onFlashEvent("Video.VIDEOEXPIRED", expired);
	                        }
	
	                        // Jump into a Live Stream.
	                        try
	                        {
		                        var vidTime = this.playerControl.currentMedia.getItemInfo("vidTime").toLowerCase();
		                        if (vidTime != "" )
		                        {
			                        this.liveOffsetDate = vidTime;
			                        this.useStartTime = true;
			                        this.hasTimeStarted = false;
		                        }
		                        else
		                        {
			                        this.useStartTime = false;
		                        }
	                        }
	                        catch(e)
	                        {
                                    dojo.debug("EXCEPTION: onCurrentItemEvent() " + e.message);
	                        }
                            debug.debugEvent("handleCurrentItem() >>");
                        },
                        //***************onPositionEvent********************
                        handlePosition: function (oldPosition, newPosition)
                        {
	                        this.clearAdEvalMark();
                        },
                        //***************onMediaErrorEvent********************
                        handleMediaError:function ()
                        {
                            debug.debugEvent("<< handleMediaError()");
                         
	                        try
	                        {
		                        if (!this.playlist.items[this.playlist.index].isError)
		                        {
			                        this.playlist.items[this.playlist.index].isError = true;
			                        this.handleInvalidVideo();
		                        }
	                        } catch(e)
	                        {
                                    dojo.debug("EXCEPTION: onMediaErrorEvent() " + e.message);
	                        }
                            debug.debugEvent("handleMediaError() >>");
                        }, 
                        //***************onMouseDownEvent********************
                        handleMouseDown: function (nButton,nShiftState,fX,fY)
                        {
                            debug.debugEvent("<< handleMouseDown() ");
	                        try
	                        {
		                        if (this.playerControl.fullscreen == false)
		                        {
			                        // When an Ad is Playing.
			                        if (this.adPlaying)
			                        {
				                        // If the coAdLive is in the ASX
				                        if (this.getCoAdLink())
				                        {
					                        // Open the Url in a new window.
					                        window.open(this.getCoAdLink());
				                        }
				                        else
				                        {
					                        this.setFullscreen();
				                        }
			                        }
			                        else
			                        {
				                        this.setFullscreen();
			                        }
		                        }
		                        else
		                            this.playerControl.fullscreen == false;
	                        }
	                        catch(e)
	                        {
                                    dojo.debug("EXCEPTION: onMouseDown() " + e.message);
	                        }
                            debug.debugEvent("handleMouseDown() >>");
                        }                         
                     }
                  );
                  
//Ads Section
dojo.lang.extend(PlayerController,
                    {
                        //***************ifAdInsertion********************
                        ifAdInsertion: function()
                        {
                        	if (this.playIntro) return false;
	                        if (this.adCount >= this.adManager.maxEls) return true;
	                        return false;
                        },
                        //***************resetAdCount********************
                        resetAdCount: function ()
                        {
	                        try { 
		                        this.adCount = (this.videoEvent.takesAds&&this.videoEvent.takesLeadingAd) ? this.adManager.maxEls-this.adManager.maxElsOnReset : 0;	
		                        this.adManager.container.id = eval("this.videoEvent."+this.adManager.resetSwitch);
		                        this.adManager.container.adsPlayed = 0;  
	                        } catch(e) {
		                        dojo.debug("EXCEPTION: resetAdCount() " + e.description);
	                        }
                        },
                        //***************ifKillTrailingAd********************
                        ifKillTrailingAd: function (wo)
                        { 
	                        try
	                        {
		                        if (this.adManager.killTrailingAds == 0) return false; //never
		                        if (this.adManager.killTrailingAds == 2) return true;  //always
		                        var obj = wo ? "this.videoEvent" : "this.preBuffEvent";  
		                        return eval(obj+".forceLeadingAd"); //only if no leading ad
	                        } catch(e) {
		                        dojo.debug("EXCEPTION: ifKillTrailingAd() " + e.description);
		                        return false; 
	                        }
                        },
                        //***************ifKillLeadingAd********************
                        ifKillLeadingAd: function ()
                        { 
                            try
                            {
	                            if (!this.playlist) return false;
	                            if (this.adManager.killTrailingAds==1 && this.playlist.items[this.playlist.index-1].isAd) return true;
	                            if (this.adManager.killTrailingAds==1 && this.playlist.length>2)
	                            {
		                            if (this.playlist.items[this.playlist.index-2].isAd && this.playerControl.controls.currentPosition<2)
		                            {
			                            return true;
		                            }
	                            }
	                            return false; 
                            } catch(e)
                            {
		                        dojo.debug("EXCEPTION: ifKillLeadingAd() " + e.description);
	                            return false; 
                            }
                        },
                        //***************leadingAdPlayed********************
                        leadingAdPlayed: function ()
                        { 
	                        try
	                        { 
		                        if (!this.config.startServeAds)
								{
									this.config.startServeAds = true;
									return true; //so leading ad won't play
								}
								return (this.adManager.container.id == eval("this.videoEvent."+this.adManager.resetSwitch))  
	                        }
	                        catch(e)
	                        {
		                        dojo.debug("EXCEPTION: leadingAdPlayed() " + e.description);
	                        }	
                        },
                        //***************evalMark********************
                        evalMark: function ()
                        { 
	                        try
	                        {
		                        //if isidentical
		                        if (!this.playlist.items[this.playlist.index].forceTrailingAd && this.playlist.items[this.playlist.index].takesTrailingAd)
		                        { 
			                        if (this.clock.videoTime>= this.adManager.maxTime)
			                        {
				                        this.adCount = this.adManager.maxEls;
				                        this.insertAd(true);
				                        this.playlist.items[this.playlist.index].forceTrailingAd = true;
			                        } 
		                        }
	                        }
	                        catch(e)
	                        {
		                        dojo.debug("EXCEPTION: evalMark() " + e.description);
	                        }
                        },
                        //***************clearAdEvalMark********************
                        clearAdEvalMark: function ()
                        {
	                        clearTimeout(this.adManager.adCountTimer); 
							try
							{
	                        	if (this.playlist.items[this.playlist.index].forceTrailingAd) return;
							}
							catch (err1)
							{
								return;
							}
							
							try
							{
	                        	if (!this.playlist.items[this.playlist.index].takesAds||!this.playlist.items[this.playlist.index].takesTrailingAd) return; //scrub calls
                        	}
							catch (err2)
							{
								return;	
							}
	                        try
	                        {    
		                        if (!this.playlist.items[this.playlist.index].tenSec && this.playerControl.controls.currentPosition>10)
		                        {
			                        this.adCount++;
			                        this.playlist.items[this.playlist.index].tenSec = true;
			                        if (this.adCount >= this.adManager.maxEls)
			                        {
				                        this.insertAd(true);
				                        this.playlist.items[this.playlist.index].forceTrailingAd = true;
			                        }
		                        }
		                        else if (this.playerControl.controls.currentPosition < 10)
		                        {
			                        var thisObj = this;
			                        //var timefunc = function() { thisObj.clearAdEvalMark(); };
			                        this.adManager.adCountTimer = setTimeout(function() { thisObj.clearAdEvalMark(); },1000);
		                        }
	                        }
	                        catch(e)
	                        {
		                        dojo.debug("EXCEPTION: clearAdEvalMark() " + e.description);
	                        }  
                        },
                        //***************stopAdCountTimer********************
                        stopAdCountTimer: function()
                        {
                            clearTimeout(this.adManager.adCountTimer);
                        },
                        //***************startAdCountTimer********************
                        startAdCountTimer: function()
                        {
	                        this.stopAdCountTimer(); 
	                        var thisObj = this;
	                        //var timefunc = function() { thisObj.clearAdEvalMark(); };
	                        this.adManager.adCountTimer = setTimeout(function() { thisObj.clearAdEvalMark(); }, this.adManager.adEvalMark); 
	                    },
	                    insertAd: function (wo)
	                    {  
	                        try 
	                        { 
		                        this.addToPlaylist(this.makeAdObj(wo),this.playlist.index+1);   
		                        this.playlist.items[this.playlist.index+1].isAd = true;  
	                        }
	                        catch(e)
	                        {
		                        dojo.debug("EXCEPTION: insertAd() " + e.description);
	                        }
                        },
                        //***************makeAdObj********************
                        makeAdObj: function (wo)
                        { 
	                        try
	                        { 
		                        var slate = wo ? ((this.adManager.container.adsPlayed<1) ? true : false) : true;	
 		                        var obj = wo ? this.videoEvent : this.preBuffEvent; 
		                        var adObj = {}; 
		                        var adZone = this.config.adCall.zone;
								var contentType = obj.content.type;
								var pos = contentType.indexOf("##");
								if (pos > 0)
								{
									var tmpStr = contentType.substring(pos+2);
									pos = tmpStr.indexOf("##");
									if (pos > 0)
									{
										tmpStr = tmpStr.substring(0,pos);
									}
									adZone = tmpStr.toUpperCase();
								}
								adObj.url = this.config.adCallUrl + this.adManager.dartCommand + "/" + this.config.adCall.site + "/" + adZone + ";";
                                
								if(typeof(this.config.adCallOtherValues) != 'undefined')
									adObj.url += this.config.adCallOtherValues + ";";
								
								var targetingVals = "";
		                        targetingVals += "gateway=" + this.safeString(obj.gateway.name) + ";";
		                        targetingVals += "section_1=" + this.safeString(obj.content.type) + ";";
		                        targetingVals += "section_2=" + this.safeString(obj.content.title) + ";";
		                        targetingVals += "video_id=" + this.safeString(obj.id) + ";";
		                        targetingVals += "mode=live;";
		                        targetingVals += this.config.adCallSize;
		                        targetingVals += "slate="+slate+";";

                                try
                                {
                                     if(typeof this.config.adsetup_additionalValues != 'undefined')
                                     {
                                        for (i in this.config.adsetup_additionalValues)
                                        {
                                           if(this.config.adsetup_additionalValues[i] != "")
                                           {
                                              if(i == "launchedFrom")
                                              {
                                                 if(this.firstrun)
                                                 {
                                                    targetingVals += i + "=" + this.config.adsetup_additionalValues[i] + ";";
                                                    if(adManager.container.adsPlayed > 0)
                                                    {
                                                       this.firstrun = false;
                                                    }
                                                 }
                                              }
                                              else
                                              {
                                                targetingVals += i + "=" + this.config.adsetup_additionalValues[i] + ";";
                                              }
                                           }
                                        }
                                     }
                                }
                                catch(e)
                                {
       		                        dojo.debug("EXCEPTION: makeAdObj() " + e.description);
                                }

                                if(window.location.search.indexOf("testmode")!=-1)
                                {
                                     targetingVals += "testmode=on;";
                                }


	                            try
	                            { 
                                     if(typeof obj.content.title != 'undefined')
                                     {
          	                            if(this.safeString(obj.content.title).indexOf('daily_show') != -1)
          	                            {
                                            targetingVals += "!category=sens;";
                                        }
                                     }
                                }
                                catch(e)
                                {
       		                        dojo.debug("EXCEPTION: makeAdObj() " + e.description);
                                }

                                adObj.url += targetingVals;

                                try 
                                {
                                    var uvalues = "u=|" + targetingVals.split("=").join("-").split(";").join("|"); 
                                    adObj.url += uvalues + ";";
                                }
                                catch(e)
                                {
       		                        dojo.debug("EXCEPTION: makeAdObj() " + e.description);
                                }


		                        adObj.url += "ord="+ Math.floor(Math.random() * 100000000000) + "?";
		                        adObj.id = "ad"; 
		                        return adObj; 
	                        }
	                        catch(e)
	                        {
       		                    dojo.debug("EXCEPTION: makeAdObj() " + e.description);
	                        }
                        },
                        //***************setCoAd********************
                        setCoAd: function (adTag)
                        {
	                        try
	                        { 		
                                 this.onSetCoAd(adTag);

	                        } catch(e) {
       		                    dojo.debug("EXCEPTION: makeAdObj() " + e.description);
	                        } 
                        },
                        //***************getOrd********************
                        getOrd: function(url)
                        {
                             if(url.match(/(ord=)([0-9]+)/))
                             {
                                return RegExp.$2;
                             }else
                             {
                                return -1;
                             }
                        },
                        //***************setCoAdLink********************
                        setCoAdLink: function (url)
                        {
	                        this.coAdLink = url;
                        },
                        //***************getCoAdLink********************
                        getCoAdLink: function ()
                        { 
	                        return this.coAdLink;
                        }
                    }
                );
                
//Playlist functions
dojo.lang.extend(PlayerController,
                    {
                        //***************createNewPlaylist********************
                        createNewPlaylist: function()
                        {
	                        this.stop();
	                        if (this.os.win)
	                        {
	                            this.root_playlist = this.playerControl.newPlaylist("","");
	                            this.playerControl.currentPlaylist = this.root_playlist;
	                        }  
	                        this.playlist = new Object();
	                        this.playlist.items = new Array(); 
	                        this.playlist.index = 0;
	                        debug.debugPlaylist("Playlist created.");
	                   },
                        //***************addToPlaylist********************
                        addToPlaylist: function(obj, pos)
                        {
                            debug.debugPlaylist("Adding playlist: - " + obj.url); 
	                        obj.tenSec = false;
	                        obj.mediaEnded = false;
	                        obj.isAd = false;
	                        obj.isAsx = this.isAsx(obj.url); 
	                        obj.isError = false;   
	                        try {   
		                        if (pos)
		                        {   
			                        this.playlist.items.splice(pos,0,obj);
			                        if (this.os.win)
			                        {
			                            var media = this.playerControl.newMedia(obj.url);
			                            this.root_playlist.insertItem(pos,media);
			                        }
		                        }
		                        else
		                        {  
			                        this.playlist.items.push(obj); 
			                        if (this.os.win)
			                        {
			                            var media = this.playerControl.newMedia(obj.url);
			                            this.root_playlist.appendItem(media);
			                        }
		                        }
		                        debug.debugPlaylist("Added playlist: - " + obj.url); 
	                        } catch(e)
	                        {
		                        dojo.debug("EXCEPTION addToPlaylist(): " + e.description);
	                        }  
	                   },
                        //***************addPrebufferItem********************
                        addPrebufferItem: function()
                        {
	                        try
	                        {
		                        if (this.os.win && this.playerControl.playState!=3) this.play();
		                        if (this.preBuffEvent && this.isValidURL(this.preBuffEvent.url)) this.addToPlaylist(this.preBuffEvent);	
	                        }
	                        catch(e)
	                        {
		                        dojo.debug("EXCEPTION addPrebufferItem(): "+ e.description);
	                        }
                        }
                    }
                );

                    




