<?php 

add_action('widgets_init','random_videos');

function random_videos() {
	register_widget('random_videos');
	
	}

class random_videos extends WP_Widget {
	function random_videos() {
			
		$widget_ops = array('classname' => 'tweets','description' =>__('Widget Display Latest Videos','lioit'));		
		$this->WP_Widget('random-videos',__('( LioIT ) Latest Videos','lioit'),$widget_ops);

		}
		
	function widget( $args, $instance ) {
		extract( $args );
		$title = apply_filters('widget_title', $instance['title'] );
		$count = $instance['count'];
		$type = $instance['type'];
		echo $before_widget;
		if ( $title )
			echo $before_title . $title . $after_title;
?>
<div class="lioLatestVideos">
<?php query_posts(array("ignore_sticky_posts" => 1, 'showposts' => $count,'post_type' => 'videos')); ?>
	<?php global $post; if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
	<div class="smallVideoitem">
                	<?php
					$video_type = get_post_meta($post->ID, 'lioit_video_type', true);
					$video_id = get_post_meta($post->ID, 'lioit_video_id', true);
					$video_thumb = get_post_meta($post->ID, 'lioit_video_thumb', true);
					$featured_image = get_post_meta($post->ID, 'featured_image', true);
					$video = get_post_meta($post->ID, 'video', true);
					?> 
					<?php if($video_thumb == 'video') { ?>
						<?php if($video_type == 'youtube') { ?>
						<iframe width="300" height="190" src="http://www.youtube.com/embed/<?php echo $video_id; ?>?rel=0" frameborder="0" allowfullscreen></iframe>
						<?php } elseif($video_type == 'vimeo') { ?>
						<iframe src="http://player.vimeo.com/video/<?php echo $video_id; ?>?title=0&amp;byline=0&amp;portrait=0&amp;color=ba0d16" width="300" height="190" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>
						<?php } elseif($video_type == 'dialymotion') { ?>
						<iframe frameborder="0" width="300" height="190" src="http://www.dailymotion.com/embed/video/<?php echo $video_id ?>?logo=0"></iframe>
						<?php } ?>
					<?php } elseif($video_thumb == 'featured_image') { ?>
                    <?php $img = catch_that_image($post->ID); ?>
						<div class="homeVThumb ThumbCover">
                        	<div class="cover" style="top: 100%;">
                                            <a class="postype prettyphoto" href="<?php echo $img ?>" rel="prettyPhoto"></a>
                                            <a class="detail" href="<?php the_permalink(); ?>" title="View detail"></a>										
                                        </div>
							
							<a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title(); ?>">
							<img src="<?php echo $img ?>" width="275" alt="<?php the_title(); ?>" />
							</a>
						</div><!--End HomeVideo Thumb-->
					<?php } ?>
                    <div class="listVideoContent">
                    <h3 class="videoTitle"><a href="<?php the_permalink(); ?>"><i class="icon-film"></i><?php the_title(); ?></a></h3>
                </div><!--End Video Content-->
                </div><!--End Small Video item-->
	<?php endwhile; ?>
	<?php  else:  ?>
	<!-- Else in here -->
	<?php  endif; ?>
	<?php wp_reset_query(); ?>
</div>			
<?php 
		
		echo $after_widget;
	}
	
	function update( $new_instance, $old_instance ) {
		$instance = $old_instance;

		
		$instance['title'] = strip_tags( $new_instance['title'] );
		$instance['count'] = $new_instance['count'];
		$instance['type'] = $new_instance['type'];

		return $instance;
	}
	
function form( $instance ) {

	
		$defaults = array( 'title' => 'Latest Videos', 
			'count' => 5
 			);
		$instance = wp_parse_args( (array) $instance, $defaults ); ?>
	
    	<p>
		<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e('Title : ' , 'lioit') ?></label>
		<input id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text"  value="<?php echo $instance['title']; ?>"  class="widefat" />
		</p>

		<p>
		<label for="<?php echo $this->get_field_id( 'count' ); ?>"><?php _e('Count : ' , 'lioit') ?></label>
		<input id="<?php echo $this->get_field_id( 'count' ); ?>" name="<?php echo $this->get_field_name( 'count' ); ?>" type="text"  value="<?php echo $instance['count']; ?>" class="widefat" />
		</p>
        
        
	
		

   <?php 
}
	} //end class