public static function addHotReloadScript(&$gallery_list, $width, $height, &$videolist_row, &$theme_row)
    {
        $vs = array();
        //'youtube','vimeo','break','own3dtvlive','own3dtvvideo','google','yahoo','collegehumor','dailymotion','.flv','presentme');
        foreach ($gallery_list as $g) {
            $v = $g['videosource'];
            if (!in_array($v, $vs)) {
                $vs[] = $v;
            }
        }
        $document = JFactory::getDocument();
        //
        $hotrefreshscript = '
<!-- Youtube Gallery Hot Video Switch -->
<script type="text/javascript">
//<![CDATA[
	var YoutubeGalleryVideoSources' . $videolist_row->id . ' = ["' . implode('", "', $vs) . '"];
	var YoutubeGalleryPlayer' . $videolist_row->id . ' = new Array;
';
        $i = 0;
        foreach ($vs as $v) {
            $player_code = '<!-- ' . $v . ' player -->' . YoutubeGalleryLayoutRenderer::ShowActiveVideo($gallery_list, $width, $height, '****youtubegallery-video-id****', $videolist_row, $theme_row, $v);
            $hotrefreshscript .= '
	YoutubeGalleryPlayer' . $videolist_row->id . '[' . $i . ']=\'' . $player_code . '\';';
            $i++;
        }
        $hotrefreshscript .= '
	
	for (var i=0;i<YoutubeGalleryPlayer' . $videolist_row->id . '.length;i++)
	{
		var player_code=YoutubeGalleryPlayer' . $videolist_row->id . '[i];
		';
        //player_code=player_code.replace(/\*\/scr/g,\'</scr\');
        //player_code=player_code.replace(/\*quote\*/g,\'\\\'\');
        $hotrefreshscript .= '
		player_code=player_code.replace(\'*quote*\',\'\\\'\');
		YoutubeGalleryPlayer' . $videolist_row->id . '[i]=player_code;
	}
	
	function YoutubeGalleryCleanCode' . $videolist_row->id . '(playercode)
	{
		do{
			var b=playercode.indexOf("***code_begin***");
			var e=playercode.indexOf("***code_end***");
			if(b!=-1 && e!=-1)
				playercode=playercode.substr(0,b) + playercode.substr(e+14);
		}while(b!=-1 && e!=-1)
		return playercode;
	}
	
	function YoutubeGalleryHotVideoSwitch' . $videolist_row->id . '(videoid,videosource,id)
	{
		var i=YoutubeGalleryVideoSources' . $videolist_row->id . '.indexOf(videosource);
		if(i==-1)
			playercode="";
		else
			playercode=YoutubeGalleryPlayer' . $videolist_row->id . '[i];
			
		playercode=playercode.replace("****youtubegallery-video-id****",videoid);
		
		var title=document.getElementById("YoutubeGalleryThumbTitle' . $videolist_row->id . '_"+id).innerHTML
		var description=document.getElementById("YoutubeGalleryThumbDescription' . $videolist_row->id . '_"+id).innerHTML
		var link=document.getElementById("YoutubeGalleryThumbLink' . $videolist_row->id . '_"+id).innerHTML
		var startsecond=document.getElementById("YoutubeGalleryThumbStartSecond' . $videolist_row->id . '_"+id).innerHTML
		var endsecond=document.getElementById("YoutubeGalleryThumbEndSecond' . $videolist_row->id . '_"+id).innerHTML
		var customimage_obj=document.getElementById("YoutubeGalleryThumbCustomImage' . $videolist_row->id . '_"+id);
		
		ygApiStart' . $videolist_row->id . '=startsecond;
		ygApiEnd' . $videolist_row->id . '=endsecond;
		
		if(customimage_obj)
		{
			var customimage=customimage_obj.innerHTML;
			var n=customimage.indexOf("_small");
			if(n==-1)
			{
				playercode=playercode.replace("****youtubegallery-video-customimage****",customimage);
				for(i=0;i<2;i++)
				{
					playercode=playercode.replace("***code_begin***","");
					playercode=playercode.replace("***code_end***","");
				}
			}
			else
				playercode=YoutubeGalleryCleanCode' . $videolist_row->id . '(playercode);
		}
		else
			playercode=YoutubeGalleryCleanCode' . $videolist_row->id . '(playercode);
		
		playercode=playercode.replace("****youtubegallery-video-link****",link);
		playercode=playercode.replace("****youtubegallery-video-startsecond****",startsecond);
		playercode=playercode.replace("****youtubegallery-video-endsecond****",endsecond);
		playercode=playercode.replace("autoplay=0","autoplay=1");
		
		document.getElementById("YoutubeGallerySecondaryContainer' . $videolist_row->id . '").innerHTML=playercode;
		if(playercode.indexOf("<!--DYNAMIC PLAYER-->")!=-1)
			eval("youtubegallery_updateplayer_"+videosource+"_' . $videolist_row->id . '(videoid,true)");
		
		var tObj=document.getElementById("YoutubeGalleryVideoTitle' . $videolist_row->id . '");
		var dObj=document.getElementById("YoutubeGalleryVideoDescription' . $videolist_row->id . '");
		
		if(tObj)
		{
			tObj.innerHTML=title;
		}
		
		if(dObj)
		{
			dObj.innerHTML=description;
		}
		';
        if ($theme_row->openinnewwindow == 5) {
            //Jump to the player anchor:"youtubegallery"
            $hotrefreshscript .= '
		window.location.hash="youtubegallery";
';
        }
        /*
        		if($theme_row->playertype==2 or $theme_row->playertype==4)
        		{
        			$hotrefreshscript.='
        		if(videosource=="youtube")
        		{
        			
        			var toPlay="YGYouTubePlayerReady'.$videolist_row->id.'(true)";
        			setTimeout(toPlay, 750);
        			
        		}
        		';
        		
        		//youtubegallery_updateplayer_youtube_'.$videolist_row->id.'(videoid);
        		}*/
        $hotrefreshscript .= '
	}
//]]>	
</script>

';
        $document->addCustomTag($hotrefreshscript);
    }