<?php 

add_action('widgets_init','random_posts');

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

class random_posts extends WP_Widget {
	function random_posts() {
			
		$widget_ops = array('classname' => 'tweets','description' =>__('Widget Display Latest Posts','lioit'));		
		$this->WP_Widget('random-posts',__('( LioIT ) Latest Posts','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="lioLatestPosts">
<?php query_posts(array( 'showposts' => $count)); ?>
	<?php global $post; if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
	<div class="lioLatestPost">
    <?php $type_badge = get_post_meta($post->ID, 'lioit_post_type', true);?>
    <h1><a href="<?php the_permalink(); ?>"><div class="<?php echo $type_badge; ?> articleType"></div><?php the_title(); ?></a></h1>
    <div class="liopostThumb">
       <?php $img = catch_that_image($post->ID); ?>
        <a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title(); ?>">
        <img src="<?php echo Lioit_URI; ?>/scripts/timthumb.php?src=<?php echo $img ?>&amp;w=62&amp;h=62&amp;zc=1" alt="<?php the_title(); ?>" title="<?php the_title(); ?>" />
        </a>
    </div><!--End Post Thumb-->
    
    <div class="lioPosMeta">
    	<span class="postAuthor"><?php the_author_posts_link(); ?></span>
        <span class="postDate"><?php the_time('F d, Y'); ?></span>
        <span class="postComments"><a href="<?php comments_link();?>"><?php comments_number(__('No comments', 'lioit'), __('1 Comment', 'lioit'), __('% Comments', 'lioit'));?></a></span>
    </div>
    </div>
	<?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 Posts', 
			'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' ); ?>" 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' ); ?>" value="<?php echo $instance['count']; ?>" class="widefat" />
		</p>
        
        
	
		

   <?php 
}
	} //end class