/**
         * Function to render video player.
         * 
         * @param $matches - input arguments.
         * @return player code.
         * @author Praveen Rajan
         */
        function CVGVideo_Render($matches)
        {
            global $post, $wpdb;
            $output = '';
            $thumbexists = false;
            $setathumb = false;
            preg_match_all('/([\\.\\w]*)=(.*?) /i', $matches[1], $attributes);
            $arguments = array();
            $arguments = CoolVideoGallery::splitargs($matches[1]);
            $video_details = videoDB::find_video($arguments['videoId']);
            if (!is_array($video_details)) {
                return __('[Video not found]');
            }
            $video = array();
            $video['filename'] = site_url() . '/' . $video_details[0]->path . '/' . $video_details[0]->filename;
            $video['thumb_filename'] = $video_details[0]->path . '/thumbs/' . $video_details[0]->thumb_filename;
            $video['title'] = $video_details[0]->description;
            $video['name'] = $video_details[0]->name;
            if (!array_key_exists('filename', $video)) {
                return '<div style="background-color:#f99; padding:10px;">Error: Required parameter "filename" is missing!</div>';
                exit;
            }
            if (file_exists($video['thumb_filename'])) {
                $thumbexists = true;
            } else {
                $thumbexists = false;
            }
            $options_player = get_option('cvg_player_settings');
            $options = get_option('cvg_settings');
            $thumb_width = $options['cvg_preview_width'];
            $thumb_height = $options['cvg_preview_height'];
            $cv_zc = $options['cvg_zc'];
            $thumb_quality = $options['cvg_preview_quality'];
            if (isset($arguments['width'])) {
                $player_width = $arguments['width'];
            } else {
                $player_width = $options_player['cvgplayer_width'];
            }
            if (isset($arguments['height'])) {
                $player_height = $arguments['height'];
            } else {
                $player_height = $options_player['cvgplayer_height'];
            }
            if (!file_exists(ABSPATH . '/' . $video['thumb_filename'])) {
                $video['thumb_filename'] = WP_CONTENT_URL . '/plugins/' . dirname(plugin_basename(__FILE__)) . '/images/default_video.png';
            } else {
                $video['thumb_filename'] = site_url() . '/' . $video['thumb_filename'];
            }
            if (isset($arguments['mode'])) {
                $video_preview = $video_details[0]->path . '/thumbs/thumbs_' . $video_details[0]->alttext . '_preview.png';
                if (!file_exists(ABSPATH . '/' . $video_preview)) {
                    $video_preview = WP_CONTENT_URL . '/plugins/' . dirname(plugin_basename(__FILE__)) . '/images/default_video.png';
                } else {
                    $video_preview = site_url() . '/' . $video_preview;
                }
                if ($options_player['cvgplayer_autoplay'] == 1) {
                    $autoplay = "true";
                } else {
                    $autoplay = "false";
                }
                if ($options_player['cvgplayer_fullscreen'] == 1) {
                    $full_screen = "true";
                } else {
                    $full_screen = "false";
                }
                if ($options_player['cvgplayer_mute'] == 1) {
                    $mute = "true";
                } else {
                    $mute = "false";
                }
                ?>
	
				<script type='text/javascript' src='<?php 
                echo $this->plugin_url;
                ?>
cvg-player/swfobject.js'></script>
				<div>
				<?php 
                $video_display = '<div id="mediaplayer_vid_' . $arguments['videoId'] . '"><object width="' . $options_player['cvgplayer_width'] . '" height="' . $options_player['cvgplayer_height'] . '" style="" id="playerID_Video' . $arguments['videoId'] . '" data="' . $this->plugin_url . 'cvg-player/player.swf" type="application/x-shockwave-flash">';
                $video_display .= '<param value="' . $full_screen . '" name="allowfullscreen">';
                $video_display .= '<param value="transparent" name="wmode">';
                $video_display .= '<param value="file=' . $video['filename'] . '&amp;image=' . $video_preview . '&amp;height=' . $options_player['cvgplayer_height'] . '&amp;width=' . $options_player['cvgplayer_width'] . '&amp;autostart=' . $autoplay . '&amp;controlbar=' . $options_player['cvgplayer_controlbar'] . '&amp;backcolor=0x000000&amp;frontcolor=0xCCCCCC&amp;lightcolor=0x557722&amp;skin=' . $this->video_player_url . 'skins/' . $options_player['cvgplayer_skin'] . '.swf' . '&amp;volume=' . $options_player['cvgplayer_volume'] . '&amp;mute=' . $mute . '&amp;stretching=' . $options_player['cvgplayer_stretching'] . '" name="flashvars">';
                $video_display .= '<embed width="' . $options_player['cvgplayer_width'] . '" height="' . $options_player['cvgplayer_height'] . '" flashvars="file=' . $video['filename'] . '&amp;image=' . $video_preview . '&amp;skin=' . $this->video_player_url . 'skins/' . $options_player['cvgplayer_skin'] . '.swf&amp;volume=' . $options_player['cvgplayer_volume'] . '&amp;mute=' . $mute . '&amp;controlbar=' . $options_player['cvgplayer_controlbar'] . '&amp;stretching=' . $options_player['cvgplayer_stretching'] . '" lightcolor="0x557722" frontcolor="0xCCCCCC" backcolor="0x000000" wmode="transparent" autostart="' . $autoplay . '" allowscriptaccess="always" allowfullscreen="' . $full_screen . '" quality="high" name="playerID_Video' . $arguments['videoId'] . '" id="playerID_Video' . $arguments['videoId'] . '" style="" src="' . $this->plugin_url . 'cvg-player/player.swf" type="application/x-shockwave-flash">';
                $video_display .= '</object></div>';
                echo $video_display;
                ?>
				<div style="float:left;width:<?php 
                echo $options_player['cvgplayer_width'];
                ?>
px;height:auto;margin-bottom:20px;" >
					<div style="float:left;">
						<input type="image" src="<?php 
                echo $this->plugin_url;
                ?>
images/video-button-embed.png" onclick="generate_embed('<?php 
                echo $arguments['videoId'];
                ?>
');"/>
					</div>
					<div id="embed_content_<?php 
                echo $arguments['videoId'];
                ?>
" style="float:left;display:none;padding-left:5px;padding-top: 3px;width: 85%;">
						<textarea id="embed_text_<?php 
                echo $arguments['videoId'];
                ?>
" style="border:medium none;width:<?php 
                echo $options_player['cvgplayer_width'] - 85;
                ?>
px;"></textarea>
					</div>
				</div>
				</div>
				<br clear="all" />
				<?php 
                return;
            }
            $output .= '<a href="' . $video['filename'] . '" title="' . $video['title'] . '"  rel="shadowbox[' . $video['name'] . '];height=' . $player_height . ';width=' . $player_width . '">';
            $output .= '<img src="' . $video['thumb_filename'] . '" style="width:' . $thumb_width . 'px;height:' . $thumb_height . 'px;" ';
            $output .= 'alt="' . htmlspecialchars('Click to Watch Video') . '"/></a>';
            return $output;
        }
        /**
         * Function to render video player.
         * 
         * @param $matches - input arguments.
         * @return player code.
         * @author Praveen Rajan
         */
        function CVGVideo_Render($matches)
        {
            global $post, $wpdb;
            $output = '';
            preg_match_all('/([\\.\\w]*)=(.*?) /i', $matches[1], $attributes);
            $arguments = array();
            $arguments = CoolVideoGallery::splitargs($matches[1]);
            $video_details = videoDB::find_video($arguments['videoId']);
            if (!is_array($video_details)) {
                return __('[Video not found]');
            }
            $options = get_option('cvg_settings');
            $video = array();
            if ($video_details[0]->video_type == $this->video_type_upload) {
                // Upload file type
                $video['filename'] = site_url() . '/' . $video_details[0]->path . '/' . $video_details[0]->filename;
                $video['thumb_filename'] = $video_details[0]->path . '/thumbs/' . $video_details[0]->thumb_filename;
                if (!file_exists(ABSPATH . '/' . $video['thumb_filename'])) {
                    $video['thumb_filename'] = WP_CONTENT_URL . '/plugins/' . dirname(plugin_basename(__FILE__)) . '/images/default_video.png';
                } else {
                    $video['thumb_filename'] = site_url() . '/' . $video['thumb_filename'];
                }
            } else {
                if ($video_details[0]->video_type == $this->video_type_youtube) {
                    // Youtube file type
                    $video['filename'] = $video_details[0]->filename;
                    $video['thumb_filename'] = $video_details[0]->thumb_filename;
                } else {
                    if ($video_details[0]->video_type == $this->video_type_media) {
                        // Media file type
                        $video['filename'] = $video_details[0]->filename;
                        $video['thumb_filename'] = $video_details[0]->path . '/thumbs/' . $video_details[0]->thumb_filename;
                        if (!file_exists(ABSPATH . '/' . $video['thumb_filename'])) {
                            $video['thumb_filename'] = WP_CONTENT_URL . '/plugins/' . dirname(plugin_basename(__FILE__)) . '/images/default_video.png';
                        } else {
                            $video['thumb_filename'] = site_url() . '/' . $video['thumb_filename'];
                        }
                    } else {
                        // Upload file type
                        $video['filename'] = site_url() . '/' . $video_details[0]->path . '/' . $video_details[0]->filename;
                        $video['thumb_filename'] = $video_details[0]->path . '/thumbs/' . $video_details[0]->thumb_filename;
                        if (!file_exists(ABSPATH . '/' . $video['thumb_filename'])) {
                            $video['thumb_filename'] = WP_CONTENT_URL . '/plugins/' . dirname(plugin_basename(__FILE__)) . '/images/default_video.png';
                        } else {
                            $video['thumb_filename'] = site_url() . '/' . $video['thumb_filename'];
                        }
                    }
                }
            }
            if ($options['cvg_description'] == 1) {
                $video['title'] = $video_details[0]->description;
            } else {
                $video['title'] = '';
            }
            $video['name'] = $video_details[0]->name;
            if (!array_key_exists('filename', $video)) {
                return '<div style="background-color:#f99; padding:10px;">Error: Required parameter "filename" is missing!</div>';
                exit;
            }
            $options_player = get_option('cvg_player_settings');
            $thumb_width = $options['cvg_preview_width'];
            $thumb_height = $options['cvg_preview_height'];
            if (isset($arguments['width'])) {
                $player_width = $arguments['width'];
            } else {
                $player_width = $options_player['cvgplayer_width'];
            }
            if (isset($arguments['height'])) {
                $player_height = $arguments['height'];
            } else {
                $player_height = $options_player['cvgplayer_height'];
            }
            if ($options_player['cvgplayer_autoplay'] == 1) {
                $autoplay = "true";
            } else {
                $autoplay = "false";
            }
            if ($options_player['cvgplayer_mute'] == 1) {
                $mute = "true";
            } else {
                $mute = "false";
            }
            if ($options_player['cvgplayer_share_option'] == 1) {
                $player_swf = "player-share.swf";
            } else {
                $player_swf = "player.swf";
            }
            //Embed section for a video
            if (isset($arguments['mode']) && $arguments['mode'] == "playlist") {
                $video_display = '<div id="mediaplayer_vid_' . $arguments['videoId'] . '">';
                $video_display .= '</div>';
                ?>
					<script type="text/javascript">
					jQuery(document).ready(function(){
						
						jwplayer("<?php 
                echo "mediaplayer_vid_" . $arguments['videoId'];
                ?>
").setup({
							"autostart" : "<?php 
                echo $autoplay;
                ?>
",
							"controlbar" : "<?php 
                echo $options_player['cvgplayer_controlbar'];
                ?>
",
							"file" : "<?php 
                echo $video['filename'];
                ?>
",
							"flashplayer" : "<?php 
                echo $this->plugin_url . "cvg-player/" . $player_swf;
                ?>
",
							"volume" : "<?php 
                echo $options_player['cvgplayer_volume'];
                ?>
",
							"width" : "<?php 
                echo $options_player['cvgplayer_width'];
                ?>
",
							"height" : "<?php 
                echo $options_player['cvgplayer_height'];
                ?>
",
							"image" : "<?php 
                echo $video['thumb_filename'];
                ?>
",
							"mute" : "<?php 
                echo $mute;
                ?>
",
							"stretching" : "<?php 
                echo $options_player['cvgplayer_stretching'];
                ?>
",
							"skin" : "<?php 
                echo $this->video_player_url . 'skins/' . $options_player['cvgplayer_skin'] . '-skin/' . $options_player['cvgplayer_skin'] . '.xml';
                ?>
"
						});
					});
					</script>
				<?php 
                $video_display .= '<div><br clear="all" /> </div>';
                return $video_display;
            } else {
                if (isset($arguments['mode']) && $arguments['mode'] == "list_items") {
                    //List of videos section for a gallery
                    $videoDetails = videoDB::find_video($arguments["videoId"]);
                    $gallery_id = $videoDetails[0]->galleryid;
                    $output .= '<a href="' . $video['filename'] . '" title="' . stripslashes($video['title']) . '"  rel="fancy_cvg_gallery_' . $gallery_id . '_' . $arguments['placeholder'] . '" style="float:left;height:' . $thumb_height . 'px !important;">';
                    $output .= '<img src="' . $video['thumb_filename'] . '" style="width:' . $thumb_width . 'px;height:' . $thumb_height . 'px;max-width:100% !important;" ';
                    $output .= 'alt="' . htmlspecialchars('Click to Watch Video') . '" /><div style="width:' . $thumb_width . 'px;"></div></a>';
                } else {
                    if (isset($arguments['mode']) && $arguments['mode'] == "slide_show") {
                        //List of videos section for a gallery
                        $videoDetails = videoDB::find_video($arguments["videoId"]);
                        $gallery_id = $videoDetails[0]->galleryid;
                        $output .= '<a href="' . $video['filename'] . '" title="' . stripslashes($video['title']) . '"  rel="fancy_cvg_gallery_slide_' . $gallery_id . '_' . $arguments['placeholder'] . '">';
                        $output .= '<img  src="' . $video['thumb_filename'] . '" style="width:' . $thumb_width . 'px;height:' . $thumb_height . 'px;max-width:100% !important;" ';
                        $output .= 'alt="' . htmlspecialchars('Click to Watch Video') . '" /></a>';
                    } else {
                        //Single video display
                        $output .= '<a href="' . $video['filename'] . '" title="' . stripslashes($video['title']) . '"  rel="fancy_cvg_video_' . $arguments['videoId'] . '">';
                        $output .= '<img src="' . $video['thumb_filename'] . '" style="width:' . $thumb_width . 'px;height:' . $thumb_height . 'px;" ';
                        $output .= 'alt="' . htmlspecialchars('Click to Watch Video') . '" id="fancy_cvg_video_preview_' . $arguments["videoId"] . '"  /><div style="width:' . $thumb_width . 'px;"></div></a>';
                        ?>
				
				<script type="text/javascript">
					jQuery(document).ready(function() {
		
						jQuery("a[rel=fancy_cvg_video_<?php 
                        echo $arguments['videoId'];
                        ?>
]").fancybox({
							'titlePosition' : 'outside',
							'transitionIn' : 'none',
							'transitionOut' : 'none',
							'autoScale' : true,
							'titleFormat' : function(title, currentArray, currentIndex, currentOpts) {
								
								if(title.length != 0)
									return '<span id="fancybox-title-over">' + (title.length ?  title : '') + '</span>';
								else
									return '';
							},
							'content' : '<div id="video_fancy_cvg_video_<?php 
                        echo $arguments['videoId'];
                        ?>
" style="overflow:hidden;"></div>',
	
							'autoDimensions' : false,
							'width' : parseInt("<?php 
                        echo $options_player['cvgplayer_width'];
                        ?>
"),
							'height' : parseInt("<?php 
                        echo $options_player['cvgplayer_height'];
                        ?>
") + 6,
							'onComplete' : function() {
								
								jwplayer('video_fancy_cvg_video_<?php 
                        echo $arguments['videoId'];
                        ?>
').setup({
									'file' : this.href,
									"autostart" : "<?php 
                        echo $autoplay;
                        ?>
",
									"controlbar" : "<?php 
                        echo $options_player['cvgplayer_controlbar'];
                        ?>
",
									"flashplayer" : "<?php 
                        echo $this->plugin_url . "cvg-player/" . $player_swf;
                        ?>
",
									"volume" : "<?php 
                        echo $options_player['cvgplayer_volume'];
                        ?>
",
									"width" : "<?php 
                        echo $options_player['cvgplayer_width'];
                        ?>
",
									"height" : "<?php 
                        echo $options_player['cvgplayer_height'];
                        ?>
",
									"image" :  jQuery('#fancy_cvg_video_preview_<?php 
                        echo $arguments["videoId"];
                        ?>
').attr('src') ,
									"mute" : "<?php 
                        echo $mute;
                        ?>
",
									"stretching" : "<?php 
                        echo $options_player['cvgplayer_stretching'];
                        ?>
",
									"skin" : "<?php 
                        echo $this->video_player_url . 'skins/' . $options_player['cvgplayer_skin'] . '-skin/' . $options_player['cvgplayer_skin'] . '.xml';
                        ?>
"
									
								});
								
								jwplayer('video_fancy_cvg_video_<?php 
                        echo $arguments['videoId'];
                        ?>
').onComplete(function() {
									
									<?php 
                        $options_player = get_option('cvg_player_settings');
                        if ($options_player['cvgplayer_auto_close_single']) {
                            ?>
											jQuery.fancybox.close();
										<?php 
                        }
                        ?>
								});
							}
		
						});
					});

				</script>
				<?php 
                    }
                }
            }
            return $output;
        }