<?php

function gfxbucket_video_func( $atts, $content ) {
	extract(shortcode_atts( array(
        'id'   => '',
        'type' => 'youtube',
        'autoplay'   => '',
        'loop'   => '',
	), $atts ));

	$return = '';

	/* Options */

	$options = '';

	if( $autoplay == 'true' || $autoplay == '1' ) {
		$options .= '&autoplay=1';
	}


	if( $loop == 'true' || $loop == '1' ) {
		$options .= '&loop=1';

		if( $type == 'youtube' ) {
			$options .= '&playlist=' . $id;
		}
	}

	if( $options != '' ) {
		$options = '?' . substr($options, 1);
	}

	if( $type == 'youtube' ) {
		$return = '<iframe src="https://www.youtube.com/embed/' . $id . $options . '" frameborder="0" allowfullscreen="allowfullscreen"></iframe>';
	} else if( $type == 'vimeo' ) {
		$return = '<iframe src="https://player.vimeo.com/video/' . $id . $options . '" frameborder="0" allowfullscreen="allowfullscreen"></iframe>';
	}

	return '<div class="video-wrapper">' . $return .  '</div>';
}
add_shortcode( 'gfxbucket_video', 'gfxbucket_video_func' );