<?php
// Register widgetized areas
if ( function_exists('register_sidebar') ) {
	 register_sidebars(1,array('name' => 'Front content left','before_widget' => '<div class="widget">','after_widget' => '</div>','before_title' => '<h3><span>','after_title' => '</span></h3>'));
	 register_sidebars(1,array('name' => 'Front content right','before_widget' => '<div class="widget">','after_widget' => '</div>','before_title' => '<h3><span>','after_title' => '</span></h3>'));
	 
	 register_sidebars(1,array('name' => 'Front content','before_widget' => '<div class="widget">','after_widget' => '</div>','before_title' => '<h3><span>','after_title' => '</span></h3>'));
	 register_sidebars(1,array('name' => 'Front Sidebar','before_widget' => '<div class="widget">','after_widget' => '</div>','before_title' => '<h3><span>','after_title' => '</span></h3>'));
	  register_sidebars(1,array('name' => 'Content Page Sidebar','before_widget' => '<div class="widget">','after_widget' => '</div>','before_title' => '<h3><span>','after_title' => '</span></h3>'));
	
	 register_sidebars(1,array('name' => 'Event  Listing -> Sidebar','before_widget' => '<div class="widget">','after_widget' => '</div>','before_title' => '<h3><span>','after_title' => '</span></h3>'));
	 register_sidebars(1,array('name' => 'Add Event  Listing Sidebar','before_widget' => '<div class="widget">','after_widget' => '</div>','before_title' => '<h3><span>','after_title' => '</span></h3>'));
	 
	 	register_sidebars(1,array('name' => 'Event  Detail Page Content Banner','before_widget' => '<div class="widget">','after_widget' => '</div>','before_title' => '<h3><span>','after_title' => '</span></h3>'));
	 register_sidebars(1,array('name' => 'Event  Detail -> Sidebar','before_widget' => '<div class="widget">','after_widget' => '</div>','before_title' => '<h3><span>','after_title' => '</span></h3>'));
	  register_sidebars(1,array('name' => 'Blog Listing -> Sidebar','before_widget' => '<div class="widget">','after_widget' => '</div>','before_title' => '<h3><span>','after_title' => '</span></h3>'));
	   register_sidebars(1,array('name' => 'Blog Detail -> Sidebar','before_widget' => '<div class="widget">','after_widget' => '</div>','before_title' => '<h3><span>','after_title' => '</span></h3>'));
	   register_sidebars(1,array('name' => 'Blog Detail Page Content Banner','before_widget' => '<div class="widget">','after_widget' => '</div>','before_title' => '<h3><span>','after_title' => '</span></h3>'));
	 
	 register_sidebars(1,array('name' => 'Main Navigation','before_widget' => '<div class="widget">','after_widget' => '</div>','before_title' => '<h3><span>','after_title' => '</span></h3>'));
	  register_sidebars(1,array('name' => 'Top Navigation','before_widget' => '<div class="widget">','after_widget' => '</div>','before_title' => '<h3><span>','after_title' => '</span></h3>'));
}
	
// Check for widgets in widget-ready areas http://wordpress.org/support/topic/190184?replies=7#post-808787
// Thanks to Chaos Kaizer http://blog.kaizeku.com/
function is_sidebar_active( $index = 1){
	$sidebars	= wp_get_sidebars_widgets();
	$key		= (string) 'sidebar-'.$index;
 
	return (isset($sidebars[$key]));
}


// =============================== Login Widget ======================================
class loginwidget extends WP_Widget {
	function loginwidget() {
	//Constructor
		$widget_ops = array('classname' => 'Loginbox', 'description' => 'Loginbox Widget' );		
		$this->WP_Widget('widget_loginwidget', 'PT &rarr; Loginbox', $widget_ops);
	}
	function widget($args, $instance) {
	// prints the widget
		extract($args, EXTR_SKIP);
		$title = empty($instance['title']) ? '&nbsp;' : apply_filters('widget_title', $instance['title']);
		$desc1 = empty($instance['desc1']) ? '&nbsp;' : apply_filters('widget_desc1', $instance['desc1']);
		 ?>						
			
            <div class="widget login_widget">
       		
 	       
          <?php
			global $current_user;
			if($current_user->ID)
			{
			?>
			<h3><?php _e(MY_ACCOUNT_TEXT);?></h3>
			<ul class="xoxo blogroll">
				<li><a href="<?php echo get_author_link($echo = false, $current_user->data->ID);?>"><?php echo DASHBOARD_TEXT;?></a></li>
				<li><a href="<?php echo get_option('siteurl');?>/?ptype=profile"><?php echo EDIT_PROFILE_PAGE_TITLE;?></a></li>
				<li><a href="<?php echo get_option('siteurl');?>/?ptype=profile"><?php echo CHANGE_PW_TEXT;?></a></li>
                <li><a href="<?php echo get_option('siteurl');?>/?ptype=login&amp;action=logout" class="signin"><?php echo LOGOUT_TEXT;?></a></li>
			</ul>
			<?php
			}else
			{
			?>
			<h3><?php echo $title; ?> </h3>
		    <form name="loginform" id="loginform1" action="<?php echo get_settings('home').'/index.php?ptype=login'; ?>" method="post" >
           		<div class="form_row"><label><?php _e('Username');?>  <span>*</span></label>  <input name="log" id="user_login1" type="text" class="textfield" /> <span id="user_loginInfo"></span> </div>
                <div class="form_row"><label><?php _e('Password');?>  <span>*</span></label>  <input name="pwd" id="user_pass1" type="password" class="textfield" /><span id="user_passInfo"></span>  </div>
                
               	<input type="hidden" name="redirect_to" value="<?php echo $_SERVER['HTTP_REFERER']; ?>" />
				<input type="hidden" name="testcookie" value="1" />
                
                <input type="submit" name="submit" value="<?php _e(SIGN_IN_BUTTON);?>" class="b_signin" /> 
             </form> 
            <p class="forgot_link">   <a href="<?php echo get_option('siteurl'); ?>/?ptype=login&amp;page1=sign_up"><?php _e(NEW_USER_TEXT);?></a>  <br /> <a href="<?php echo get_option('siteurl'); ?>/?ptype=login&amp;page1=sign_in"><?php _e(FORGOT_PW_TEXT);?></a> </p>            
            <?php }?>
            </div>
        
 	<?php
	}
	function update($new_instance, $old_instance) {
	//save the widget
		$instance = $old_instance;		
		$instance['title'] = strip_tags($new_instance['title']);
		$instance['desc1'] = ($new_instance['desc1']);
		return $instance;
	}
	function form($instance) {
	//widgetform in backend
		$instance = wp_parse_args( (array) $instance, array( 'title' => '', 't1' => '', 't2' => '', 't3' => '',  'img1' => '', 'desc1' => '' ) );		
		$title = strip_tags($instance['title']);
		$desc1 = ($instance['desc1']);
?>
		<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Widget Title');?>: <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo attribute_escape($title); ?>" /></label></p>
<?php
	}}
register_widget('loginwidget');
	
// =============================== Feedburner Subscribe widget ======================================
class subscribeWidget extends WP_Widget {
	function subscribeWidget() {
	//Constructor
		$widget_ops = array('classname' => 'widget Subscribe', 'description' => 'Subscribe' );		
		$this->WP_Widget('widget_subscribeWidget', 'PT &rarr; Subscribe', $widget_ops);
	}
	function widget($args, $instance) {
	// prints the widget
		extract($args, EXTR_SKIP);
		$id = empty($instance['id']) ? '' : apply_filters('widget_id', $instance['id']);
		$title = empty($instance['title']) ? '' : apply_filters('widget_title', $instance['title']);
		$text = empty($instance['text']) ? '' : apply_filters('widget_text', $instance['text']);
		$twitter = empty($instance['twitter']) ? '' : apply_filters('widget_twitter', $instance['twitter']);
		$facebook = empty($instance['facebook']) ? '' : apply_filters('widget_facebook', $instance['facebook']);
		$digg = empty($instance['digg']) ? '' : apply_filters('widget_digg', $instance['digg']);
		$feeurl = empty($instance['feeurl']) ? '' : apply_filters('widget_feeurl', $instance['feeurl']);
		$rss = empty($instance['rss']) ? '' : apply_filters('widget_rss', $instance['rss']);
?>
	
     
		 
	 
    	<div class="subscribe clearfix" >
      <h3><?php echo $title; ?>  <a href="<?php if($feeurl){echo $feeurl;}else{bloginfo('rss_url');} ?>" ><img  src="<?php bloginfo('template_directory'); ?>/images/i_rss.png" alt="" class="i_rss"  /> </a> </h3>
      
      
          	<?php if ( $text <> "" ) { ?>	 
         		 <p><?php echo $text; ?> </p>
            <?php } ?>
        
		 
		<form class="subscribe_form"  action="http://feedburner.google.com/fb/a/mailverify" method="post" target="popupwindow"  onsubmit="window.open('http://feedburner.google.com/fb/a/mailverify?uri=<?php echo $id; ?>', 'popupwindow', 'scrollbars=yes,width=550,height=520');return true">    
     <input type="text" class="field" value="Your Email Address" onfocus="if (this.value == 'Your Email Address') {this.value = '';}" onblur="if (this.value == '') {this.value = 'Your Email Address';}" name="email"/>
     <input type="hidden" value="<?php echo $id; ?>" name="uri"/><input type="hidden" name="loc" value="en_US"/>
     <input class="btn_submit" type="submit" name="submit" value="Submit" /> 
     </form>
		  </div>  <!-- #end -->
      

<?php
	}
	function update($new_instance, $old_instance) {
	//save the widget
		$instance = $old_instance;		
		$instance['id'] = strip_tags($new_instance['id']);
		$instance['title'] = ($new_instance['title']);
		$instance['text'] = ($new_instance['text']);
		$instance['twitter'] = ($new_instance['twitter']);
		$instance['facebook'] = ($new_instance['facebook']);
		$instance['digg'] = ($new_instance['digg']);
		$instance['feeurl'] = ($new_instance['feeurl']);
		
		return $instance;
	}
	function form($instance) {
	//widgetform in backend
		$instance = wp_parse_args( (array) $instance, array( 'title' => '', 'advt1' => '','text' => '','twitter' => '','facebook' => '','digg' => '','myspace' => '' ) );		
		$id = strip_tags($instance['id']);
		$title = strip_tags($instance['title']);
		$text = strip_tags($instance['text']);
		$twitter = strip_tags($instance['twitter']);
		$facebook = strip_tags($instance['facebook']);
		$digg = strip_tags($instance['digg']);
		$feeurl = strip_tags($instance['feeurl']);

 ?>
 <p><label for="<?php echo $this->get_field_id('title'); ?>">Widget Title: <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo attribute_escape($title); ?>" /></label></p>
 <p><label for="<?php echo $this->get_field_id('id'); ?>">Feedburner ID (ex :- templatic): <input class="widefat" id="<?php echo $this->get_field_id('id'); ?>" name="<?php echo $this->get_field_name('id'); ?>" type="text" value="<?php echo attribute_escape($id); ?>" /></label></p>
  <p><label for="<?php echo $this->get_field_id('feeurl'); ?>">RSS URL : <input class="widefat" id="<?php echo $this->get_field_id('feeurl'); ?>" name="<?php echo $this->get_field_name('feeurl'); ?>" type="text" value="<?php echo attribute_escape($feeurl); ?>" /></label></p>
      
  <p><label for="<?php echo $this->get_field_id('text'); ?>">Short Description <textarea class="widefat" rows="6" cols="20" id="<?php echo $this->get_field_id('text'); ?>" name="<?php echo $this->get_field_name('text'); ?>"><?php echo attribute_escape($text); ?></textarea></label></p>
<?php
	}}
register_widget('subscribeWidget');

// =============================== Sidebar Advt second  ======================================
class advtwidget extends WP_Widget {
	function advtwidget() {
	//Constructor
		$widget_ops = array('classname' => 'widget Advertise', 'description' => 'common advertise widget in sidebar, bottom section' );		
		$this->WP_Widget('advtwidget', 'PT &rarr; Advertise', $widget_ops);
	}
	function widget($args, $instance) {
	// prints the widget
		extract($args, EXTR_SKIP);
		$title = empty($instance['title']) ? '&nbsp;' : apply_filters('widget_title', $instance['title']);
		$desc1 = empty($instance['desc1']) ? '&nbsp;' : apply_filters('widget_desc1', $instance['desc1']);
		 ?>						
 	 
  		<?php /*?><h3><?php echo $title; ?> </h3><?php */?>
          
        <div class="advt_single">    
        <?php if ( $desc1 <> "" ) { ?>	
         <?php echo $desc1; ?> 
         <?php } ?>
        </div>
	<?php
	}
	function update($new_instance, $old_instance) {
	//save the widget
		$instance = $old_instance;		
		$instance['title'] = strip_tags($new_instance['title']);
		$instance['desc1'] = ($new_instance['desc1']);
		return $instance;
	}
	function form($instance) {
	//widgetform in backend
		$instance = wp_parse_args( (array) $instance, array( 'title' => '', 't1' => '', 't2' => '', 't3' => '',  'img1' => '', 'desc1' => '' ) );		
		$title = strip_tags($instance['title']);
		$desc1 = ($instance['desc1']);
?>
        <p><label for="<?php echo $this->get_field_id('desc1'); ?>">Advt code (ex.google adsense etc.) <textarea class="widefat" rows="6" cols="20" id="<?php echo $this->get_field_id('desc1'); ?>" name="<?php echo $this->get_field_name('desc1'); ?>"><?php echo attribute_escape($desc1); ?></textarea></label></p>
       
<?php
	}}
register_widget('advtwidget');



// =============================== Sidebar - Event Search section  ======================================
class eventsearch extends WP_Widget {
	function eventsearch() {
	//Constructor
		$widget_ops = array('classname' => 'widget Event search', 'description' => 'common Event search' );		
		$this->WP_Widget('eventsearch', 'PT &rarr; Event search', $widget_ops);
	}
	function widget($args, $instance) {
	// prints the widget
		extract($args, EXTR_SKIP);
		$title = empty($instance['title']) ? '&nbsp;' : apply_filters('widget_title', $instance['title']);
		$desc1 = empty($instance['desc1']) ? '&nbsp;' : apply_filters('widget_desc1', $instance['desc1']);
		 ?>						
 	 <script  type="text/javascript" language="javascript">var rootfolderpath = '<?php echo bloginfo('template_directory');?>/images/';</script>
	<script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/library/js/dhtmlgoodies_calendar.js"></script>
    <script type="text/javascript">
    function set_search()
	{
		var sr = '';
		if(document.getElementById('skw').value=='<?php _e('Search for');?>')
		{
			document.getElementById('skw').value = '';
		}else
		{
			sr = sr + document.getElementById('skw').value+'-';
		}
		if(document.getElementById('scat').value)
		{
			sr = sr + document.getElementById('scat').options[document.getElementById('scat').selectedIndex].text; + '-';
		}
		if(document.getElementById('sdate').value)
		{
			sr = sr + document.getElementById('sdate').value+ '-';
		}
		if(document.getElementById('saddress').value)
		{
			sr = sr + document.getElementById('saddress').value+ '-';
		}
		if(sr)
		{
			document.getElementById('sr').value = sr;
		}else
		{
			document.getElementById('sr').value = ' ';
		}
	}
    </script>
     <form action="<?php echo site_url();?>/" id="srchevent" name="srchevent" method="get"> 
     <input type="hidden" name="s" value="" id="sr" />
     <input type="hidden" name="t" value="event" />
      <div class="widget event_search">
  		 <h3><?php echo $title; ?> </h3> 
          
          <div class="row">
          <?php if($_REQUEST['skw'])
		  {
			$skw = $_REQUEST['skw'];  
		  }else
		  {
			$skw = __('Search for');
		  }?>
          	<input type="text" onblur="if (this.value == '') {this.value = '<?php _e('Search for');?>';}" onfocus="if (this.value == '<?php _e('Search for');?>') {this.value = '';}" class="textfield xl" id="skw" name="skw" value="<?php echo $skw;?>" />
          	<span><?php _e('Search for (e.g.festival,event name)');?></span>
          </div>
          
          <div class="row">
          <?php echo get_category_dl_options($_REQUEST['scat']);?>
          	<span><?php _e('Select a Category');?></span>
          </div>
          
           <div class="row">
           <input type="text" name="sdate" id="sdate" value="<?php echo $_REQUEST['sdate'];?>" class="textfield tsmall"  size="25"  />
			&nbsp;<img src="<?php echo bloginfo('template_directory');?>/images/cal.gif" alt="Calendar" onclick="displayCalendar(document.srchevent.sdate,'yyyy-mm-dd',this)"  class="calendar_link"  />
            <span><?php _e('Event start date');?></span>
          </div>
          
           <div class="row">
           <input name="saddress" id="saddress" type="text" value="<?php echo $_REQUEST['saddress'];?>" class="textfield xl"  />
          	<span><?php _e('Zip code or Address');?></span>
          </div>
         
         
          <input name="search" type="submit" value="<?php _e('Search Events');?>" class="b_search_event" onclick="set_search();" />
         
	 </div>
     </form>
	<?php
	}
	function update($new_instance, $old_instance) {
	//save the widget
		$instance = $old_instance;		
		$instance['title'] = strip_tags($new_instance['title']);
		$instance['desc1'] = ($new_instance['desc1']);
		return $instance;
	}
	function form($instance) {
	//widgetform in backend
		$instance = wp_parse_args( (array) $instance, array( 'title' => '', 't1' => '', 't2' => '', 't3' => '',  'img1' => '', 'desc1' => '' ) );		
		$title = strip_tags($instance['title']);
		$desc1 = ($instance['desc1']);
?>
		<p><label for="<?php echo $this->get_field_id('title'); ?>">Widget Title: <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo attribute_escape($title); ?>" /></label></p>
<?php
	}}
register_widget('eventsearch');



// =============================== categories  ======================================
class catewidget extends WP_Widget {
	function catewidget() {
	//Constructor
		$widget_ops = array('classname' => 'widget categories', 'description' => 'categories with post count' );		
		$this->WP_Widget('catewidget', 'PT &rarr; Categories', $widget_ops);
	}
	function widget($args, $instance) {
	// prints the widget
		extract($args, EXTR_SKIP);
		$title = empty($instance['title']) ? '&nbsp;' : apply_filters('widget_title', $instance['title']);
		$catid = empty($instance['catid']) ? '&nbsp;' : apply_filters('widget_catid', $instance['catid']);
		 ?>						
 	 
  	 <h3><?php echo $title; ?> </h3> 
         <ul class="categories"> 
       	<?php
		$variable = wp_list_categories('echo=0&show_count=1&title_li=&exclude='.$catid);
		$variable = str_replace(array('(',')'), array('<span class="count">','</span>'), $variable);
		echo $variable;
		?>
	</ul>
         
	 
             
	<?php
	}
	function update($new_instance, $old_instance) {
	//save the widget
		$instance = $old_instance;		
		$instance['title'] = strip_tags($new_instance['title']);
		$instance['catid'] = ($new_instance['catid']);
		return $instance;
	}
	function form($instance) {
	//widgetform in backend
		$instance = wp_parse_args( (array) $instance, array( 'title' => '', 'catid' => '' ) );		
		$title = strip_tags($instance['title']);
		$catid = ($instance['catid']);
?>
		<p><label for="<?php echo $this->get_field_id('title'); ?>">Widget Title: <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo attribute_escape($title); ?>" /></label></p>
     
         <p><label for="<?php echo $this->get_field_id('catid'); ?>">Categories Exclude ID : <input class="widefat" id="<?php echo $this->get_field_id('catid'); ?>" name="<?php echo $this->get_field_name('catid'); ?>" type="text" value="<?php echo attribute_escape($catid); ?>" /></label></p>
       
<?php
	}}
register_widget('catewidget');


// =============================== Latest news posts Widget (particular category) ======================================
class news2columns extends WP_Widget {
	function news2columns() {
	//Constructor
		$widget_ops = array('classname' => 'widget Latest News', 'description' => 'List of Latest Post List View' );
		$this->WP_Widget('news2columns', 'PT &rarr; Latest Post List View', $widget_ops);
	}

	function widget($args, $instance) {
	// prints the widget

		extract($args, EXTR_SKIP);
		echo $before_widget;
		$title = empty($instance['title']) ? '' : apply_filters('widget_title', $instance['title']);
 		$category = empty($instance['category']) ? '' : apply_filters('widget_category', $instance['category']);
		$post_number = empty($instance['post_number']) ? '3' : apply_filters('widget_post_number', $instance['post_number']);
		$post_link = empty($instance['post_link']) ? '&nbsp;' : apply_filters('widget_post_link', $instance['post_link']);
		$character_cout = empty($instance['character_cout']) ? '15' : apply_filters('widget_character_cout', $instance['character_cout']);
		
		 ?>
          <div class="tabber">
          		<ul class="tab">
                	<li class="active" id="li_upcomming_events"> <a href="javascript:void(0);" onclick="show_hide_tabs('upcoming');"><?php _e('Upcoming Events')?></a></li>
                    <li id="li_index_past_events"> <a href="javascript:void(0);" onclick="show_hide_tabs('past');"><?php _e('Past Events')?></a></li>
                </ul>
           </div>
          
          <script type="text/javascript">
			function show_hide_tabs(type)
			{
				if(type=='upcoming')
				{
					document.getElementById('widget_index_upcomming_events_id').style.display='';
					document.getElementById('widget_index_past_events_id').style.display='none';
					document.getElementById('li_upcomming_events').className='active';
					document.getElementById('li_index_past_events').className='';
				}else if(type=='past')
				{
					document.getElementById('widget_index_upcomming_events_id').style.display='none';
					document.getElementById('widget_index_past_events_id').style.display='';	
					document.getElementById('li_upcomming_events').className='';
					document.getElementById('li_index_past_events').className='active';
				}
			}
			</script>
          <ul class="category_list_view" id="widget_index_upcomming_events_id">
				<?php 
			        global $post,$wpdb;
					$today = date('Y-m-d H:i');
					global $post,$wpdb;
					if($category)
					{
						$category = "'".str_replace(",","','",$category)."'";
						$sqlsql = "and p.ID in (select tr.object_id from $wpdb->term_relationships tr join $wpdb->term_taxonomy t on t.term_taxonomy_id=tr.term_taxonomy_id where t.term_id in ($category)  )";
					}
					$today = date('Y-m-d H:i');
					$sqlsql .= " AND p.ID in (select $wpdb->postmeta.post_id from $wpdb->postmeta where $wpdb->postmeta.meta_key='end_date' and date_format($wpdb->postmeta.meta_value,'%Y-%m-%d %H:%i')>='".$today."') ";
					$orderbysql = " (select $wpdb->postmeta.meta_value from $wpdb->postmeta where $wpdb->postmeta.meta_key='st_date' and $wpdb->postmeta.post_id=p.ID) asc, ";
				  $sql = "select p.* from $wpdb->posts p where p.post_type='".CUSTOM_POST_TYPE1."' and p.post_status='publish' $sqlsql order by $orderbysql p.post_title asc limit $post_number";
					$latest_menus = $wpdb->get_results($sql);
					if($latest_menus)
					{
                    foreach($latest_menus as $post) :
                    setup_postdata($post);
			    ?>
                 <?php $post_images = bdw_get_images($post->ID);?>
           		
               <li class="clearfix">
                   
                    <a class="post_img" href="<?php the_permalink(); ?>">
                    <?php if(get_post_meta($post->ID,'is_featured',true)){?> <span class="featured_img"></span><?php }?>
                   <?php 
					if(get_the_post_thumbnail( $post->ID, array())){?>
					 <?php echo get_the_post_thumbnail( $post->ID, array(90,70),array('class'	=> "",));?>
					<?php }else if($post_images[0]){ global $thumb_url;	 
						$thumb_url1 = $thumb_url.get_image_cutting_edge($args);
					?>
                    <img src="<?php echo bloginfo('template_url'); ?>/thumb.php?src=<?php echo $post_images[0];?>&amp;w=124&amp;h=75&amp;zc=1&amp;q=80<?php echo $thumb_url1;?>" alt="<?php the_title(); ?>" title="<?php the_title(); ?>"  />
                    <?php
                    } else { ?> 
                     <span class="img_not_available"> <b> <?php _e('image not available');?> </b> </span>
                    <?php }?>
                    </a>
                     <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>  </h3> 
                     <?php
                     if(get_post_meta($post->ID,'address',true))
					{
						$from_add = get_post_meta($post->ID,'address',true);
					}
					if($from_add){
					 ?>
                    <p class="timing"> <span><?php _e('Start Date');?> :</span> <?php echo get_formated_date(get_post_meta($post->ID,'st_date',true));?><br />  
    <span><?php _e('End Date');?> :</span><?php echo get_formated_date(get_post_meta($post->ID,'end_date',true));?> <br />
    <span><?php _e('Time');?> :</span> <?php 
	if(get_post_meta($post->ID,'st_time',true) && get_post_meta($post->ID,'end_time',true))
	{
	echo get_formated_time(get_post_meta($post->ID,'st_time',true))?> <?php _e('to');?> <?php echo get_formated_time(get_post_meta($post->ID,'end_time',true));
	}else
	{
		echo ' - ';	
	}?> </p>
     
                     <p class="address"> <span> <?php _e('Location');?> :</span> <br /> <?php echo get_post_meta($post->ID,'address',true);?></p>
                     <?php }?>
                      
                     
                   <p class="bottom"><span class="fl"><?php _e('Listed in')?> <?php the_taxonomies(array('before'=>'','sep'=>'','after'=>'')); ?></span> 
                   <a href="<?php the_permalink(); ?>" class="read_more" > <?php _e('Read More');?> </a>   </p>
                   
            	 </li>   
				<?php endforeach; ?>
                <?php }else{
					_e('<p>Not a single Upcoming Event is there.</p>');
				}
					?>
			</ul>
            
            <ul class="category_list_view" id="widget_index_past_events_id" style="display:none;">
            <?php
			$sqlsql = '';
			$sql = '';
			if($category)
			{
				$category = "'".str_replace(",","','",$category)."'";
				$sqlsql = " and p.ID in (select tr.object_id from $wpdb->term_relationships tr join $wpdb->term_taxonomy t on t.term_taxonomy_id=tr.term_taxonomy_id where t.term_id in ($category)  )";
			}
			$today = date('Y-m-d H:i');
			$sqlsql .= " AND p.ID in (select $wpdb->postmeta.post_id from $wpdb->postmeta where $wpdb->postmeta.meta_key='end_date' and date_format($wpdb->postmeta.meta_value,'%Y-%m-%d %H:%i')<='".$today."') ";
			$sql = "select p.* from $wpdb->posts p where p.post_type='".CUSTOM_POST_TYPE1."' and p.post_status='publish' $sqlsql order by p.post_date desc,p.post_title asc limit $post_number";
			$latest_menus = $wpdb->get_results($sql);
			if($latest_menus)
			{
			foreach($latest_menus as $post) :
			setup_postdata($post);
			$post_images = bdw_get_images($post->ID);
			?>
            <li class="clearfix">
                   
                    <?php if(get_post_meta($post->ID,'is_featured',true)){?> <span class="featured_img"></span><?php }?>
                   <?php 
					if(get_the_post_thumbnail( $post->ID, array())){?>
					 <a class="post_img" href="<?php the_permalink(); ?>">
					 <?php echo get_the_post_thumbnail( $post->ID, array(90,70),array('class'	=> "",));?>
					 </a>
					<?php }else if($post_images[0]){ global $thumb_url;	 
						$thumb_url1 = $thumb_url.get_image_cutting_edge($args);
					?>
                      <a class="post_img" href="<?php the_permalink(); ?>">
                    <img src="<?php echo bloginfo('template_url'); ?>/thumb.php?src=<?php echo $post_images[0];?>&amp;w=124&amp;h=75&amp;zc=1&amp;q=80<?php echo $thumb_url1;?>" alt="<?php the_title(); ?>" title="<?php the_title(); ?>"  />  </a>
                    <?php
                    } else { ?> 
                        <a class="post_img" href="<?php the_permalink(); ?>"><span class="img_not_available"> <b> <?php _e('image not available');?> </b> </span></a>
                    <?php }?>
                    
                     <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>  </h3> 
                     <?php
                     if(get_post_meta($post->ID,'address',true))
					{
						$from_add = get_post_meta($post->ID,'address',true);
					}
					if($from_add){
					 ?>
                    <p class="timing"> <span><?php _e('Start Date');?> :</span> <?php echo get_formated_date(get_post_meta($post->ID,'st_date',true));?><br />  
    <span><?php _e('End Date');?> :</span><?php echo get_formated_date(get_post_meta($post->ID,'end_date',true));?> <br />
    <span><?php _e('Time');?> :</span> <?php echo get_formated_time(get_post_meta($post->ID,'st_time',true))?> <?php _e('to');?> <?php echo get_formated_time(get_post_meta($post->ID,'end_time',true))?> </p>
     
                     <p class="address"> <span> <?php _e('Location');?> :</span> <br /> <?php echo get_post_meta($post->ID,'address',true);?></p>
                     <?php }?>
                      
                     
                   <p class="bottom"><span class="fl"><?php _e('Listed in')?> <?php the_taxonomies(array('before'=>'','sep'=>'','after'=>'')); ?></span> 
                   <a href="<?php the_permalink(); ?>" class="read_more" > <?php _e('Read More');?> </a>   </p>
                   
            	 </li>   
			<?php endforeach; ?>
            <?php }else{
                _e('<p>Not a single Past Event is there.</p>');
            }
            ?>
            </ul>
			<?php
		    echo $after_widget;
	}

	function update($new_instance, $old_instance) {
	//save the widget
		$instance = $old_instance;
		$instance['title'] = strip_tags($new_instance['title']);
		$instance['category'] = strip_tags($new_instance['category']);
		$instance['post_number'] = strip_tags($new_instance['post_number']);
		$instance['post_link'] = strip_tags($new_instance['post_link']);
		$instance['character_cout'] = strip_tags($new_instance['character_cout']);
		return $instance;

	}

	function form($instance) {
	//widgetform in backend
		$instance = wp_parse_args( (array) $instance, array( 'title' => '', 'category' => '', 'post_number' => '','character_cout' => '' ) );
		$title = strip_tags($instance['title']);
		$category = strip_tags($instance['category']);
		$post_number = strip_tags($instance['post_number']);
		$post_link = strip_tags($instance['post_link']);
		$character_cout = strip_tags($instance['character_cout']);

?>
<p>
  <label for="<?php echo $this->get_field_id('title'); ?>">Title:
    <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo attribute_escape($title); ?>" />
  </label>
</p>
<p>
  <label for="<?php echo $this->get_field_id('category'); ?>">Categories (<code>IDs</code> separated by commas):
  <input class="widefat" id="<?php echo $this->get_field_id('category'); ?>" name="<?php echo $this->get_field_name('category'); ?>" type="text" value="<?php echo attribute_escape($category); ?>" />
  </label>
</p>
<p>
  <label for="<?php echo $this->get_field_id('post_number'); ?>">Number of posts:
  <input class="widefat" id="<?php echo $this->get_field_id('post_number'); ?>" name="<?php echo $this->get_field_name('post_number'); ?>" type="text" value="<?php echo attribute_escape($post_number); ?>" />
  </label>
</p>

<?php
	}

}

register_widget('news2columns');



// =============================== Featured Post slider (particular category) ======================================
class featuredslider extends WP_Widget {
	function featuredslider() {
	//Constructor
		$widget_ops = array('classname' => 'widget featured post slider', 'description' => 'List of featured slider post in particular category or latest posts' );
		$this->WP_Widget('featuredslider', 'PT &rarr; Featured Slider', $widget_ops);
	}

	function widget($args, $instance) {
	// prints the widget

		extract($args, EXTR_SKIP);
		echo $before_widget;
		$title = empty($instance['title']) ? '&nbsp;' : apply_filters('widget_title', $instance['title']);
 		$category = empty($instance['category']) ? '' : apply_filters('widget_category', $instance['category']);
		$post_number = empty($instance['post_number']) ? '5' : apply_filters('widget_post_number', $instance['post_number']);
		$post_link = empty($instance['post_link']) ? '&nbsp;' : apply_filters('widget_post_link', $instance['post_link']);
		$character_cout = empty($instance['character_cout']) ? '15' : apply_filters('widget_character_cout', $instance['character_cout']);
		
	global $post,$wpdb;
	 if($category)
	   {
			$category = "'".str_replace(",","','",$category)."'";
			$sqlsql = "and p.ID in (select tr.object_id from $wpdb->term_relationships tr join $wpdb->term_taxonomy t on t.term_taxonomy_id=tr.term_taxonomy_id where t.term_id in ($category)  )";   
	   }
		$sql = "select p.* from $wpdb->posts p where p.post_type='".CUSTOM_POST_TYPE1."' and p.post_status='publish' $sqlsql and p.id in (select $wpdb->postmeta.post_id from $wpdb->postmeta where $wpdb->postmeta.post_id=p.ID and $wpdb->postmeta.meta_key like \"is_featured\") order by  p.post_date desc  limit $post_number";
		$latest_menus = $wpdb->get_results($sql);
		if($latest_menus)
		{
		 ?>
          
 <script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/library/js/jquery-1.4.2.js"></script>
<script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/library/js/jquery.pikachoose.js"></script>

<script language="javascript" type="text/javascript">
			$(document).ready(
				function (){
					$("#pikame").PikaChoose();
			});
		</script>
        <div class="pikachoose">
<span class="h_featured"><?php echo $title; ?> </span>
 	<ul id="pikame" class="jcarousel-skin-pika">
        <?php 
			foreach($latest_menus as $post) :
			setup_postdata($post);
	    ?>
         <?php $post_images = bdw_get_images($post->ID,'large');?>
		<li> 
        <a href="<?php the_permalink(); ?>">
                  	  <?php 
 							if(get_the_post_thumbnail( $post->ID, array())){
 							echo get_the_post_thumbnail( $post->ID, array(615,400),array('class'	=> "",));
							}else if($post_images[0]){ global $thumb_url;
							 
								$thumb_url1 = $thumb_url.get_image_cutting_edge($args);
							?>
							<img src="<?php echo bloginfo('template_url'); ?>/thumb.php?src=<?php echo $post_images[0];?>&amp;w=570&amp;h=400&amp;zc=1&amp;q=80<?php echo $thumb_url1;?>" alt="<?php the_title(); ?>" title="<?php the_title(); ?>"  /> 
							<?php
							} else { ?><?php }?>  
                  </a>
         <span><?php the_title(); ?> <br /> <small><?php echo get_formated_date(get_post_meta($post->ID,'st_date',true));?> <?php echo get_formated_time(get_post_meta($post->ID,'st_time',true))?> </small> </span>
        </li>
<?php endforeach; ?>
<?php
   echo '</ul></div>';
}
		echo $after_widget;
	}

	function update($new_instance, $old_instance) {
	//save the widget
		$instance = $old_instance;
		$instance['title'] = strip_tags($new_instance['title']);
		$instance['category'] = strip_tags($new_instance['category']);
		$instance['post_number'] = strip_tags($new_instance['post_number']);
		$instance['post_link'] = strip_tags($new_instance['post_link']);
		$instance['character_cout'] = strip_tags($new_instance['character_cout']);
		return $instance;

	}

	function form($instance) {
	//widgetform in backend
		$instance = wp_parse_args( (array) $instance, array( 'title' => '', 'category' => '', 'post_number' => '','character_cout' => '' ) );
		$title = strip_tags($instance['title']);
		$category = strip_tags($instance['category']);
		$post_number = strip_tags($instance['post_number']);
		$post_link = strip_tags($instance['post_link']);
		$character_cout = strip_tags($instance['character_cout']);

?>
<p>
  <label for="<?php echo $this->get_field_id('title'); ?>">Title:
    <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo attribute_escape($title); ?>" />
  </label>
</p>
<p>
  <label for="<?php echo $this->get_field_id('category'); ?>">Categories (<code>IDs</code> separated by commas):
  <input class="widefat" id="<?php echo $this->get_field_id('category'); ?>" name="<?php echo $this->get_field_name('category'); ?>" type="text" value="<?php echo attribute_escape($category); ?>" />
  </label>
</p>
<p>
  <label for="<?php echo $this->get_field_id('post_number'); ?>">Number of posts:
  <input class="widefat" id="<?php echo $this->get_field_id('post_number'); ?>" name="<?php echo $this->get_field_name('post_number'); ?>" type="text" value="<?php echo attribute_escape($post_number); ?>" />
  </label>
</p>
 
<?php
	}

}

register_widget('featuredslider');







// =============================== Latest news posts Widget (particular category) ======================================

class eventwidget extends WP_Widget {
	function eventwidget() {
	//Constructor
		$widget_ops = array('classname' => 'widget Latest News', 'description' => 'List of latest posts in particular category ( Sidebar or Footer content )' );
		$this->WP_Widget('eventwidget', 'PT &rarr; Latest News', $widget_ops);
	}

	function widget($args, $instance) {
	// prints the widget

		extract($args, EXTR_SKIP);
		echo $before_widget;
		$title = empty($instance['title']) ? '&nbsp;' : apply_filters('widget_title', $instance['title']);
 		$category = empty($instance['category']) ? '&nbsp;' : apply_filters('widget_category', $instance['category']);
		$post_number = empty($instance['post_number']) ? '5' : apply_filters('widget_post_number', $instance['post_number']);
		$post_link = empty($instance['post_link']) ? '&nbsp;' : apply_filters('widget_post_link', $instance['post_link']);

		// if ( !empty( $title ) ) { echo $before_title . $title . $after_title; };
		echo '';
		 ?>
          <h3> <?php echo $title; ?> </h3>
          <ul>
                
				<?php 
			        global $post;
			        $latest_menus = get_posts('numberposts='.$post_number.'postlink='.$post_link.'&category='.$category.'');
                    foreach($latest_menus as $post) :
                    setup_postdata($post);
			    ?>
                 <?php $post_images = bdw_get_images($post->ID,'large');?>
           
           		<li class="clearfix"> 
                    <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>  <br />
                   <span class="date"><?php the_time('j F Y') ?> at <?php the_time('H : s A') ?>  </span> 
               </li>
    
<?php endforeach; ?>
<?php

	    echo '</ul>';

		echo $after_widget;
	}

	function update($new_instance, $old_instance) {
	//save the widget
		$instance = $old_instance;
		$instance['title'] = strip_tags($new_instance['title']);
		$instance['category'] = strip_tags($new_instance['category']);
		$instance['post_number'] = strip_tags($new_instance['post_number']);
		$instance['post_link'] = strip_tags($new_instance['post_link']);
		return $instance;

	}

	function form($instance) {
	//widgetform in backend
		$instance = wp_parse_args( (array) $instance, array( 'title' => '', 'category' => '', 'post_number' => '' ) );
		$title = strip_tags($instance['title']);
		$category = strip_tags($instance['category']);
		$post_number = strip_tags($instance['post_number']);
		$post_link = strip_tags($instance['post_link']);

?>
<p>
  <label for="<?php echo $this->get_field_id('title'); ?>">Title:
    <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo attribute_escape($title); ?>" />
  </label>
</p>
<p>
  <label for="<?php echo $this->get_field_id('category'); ?>">Categories (<code>IDs</code> separated by commas):
  <input class="widefat" id="<?php echo $this->get_field_id('category'); ?>" name="<?php echo $this->get_field_name('category'); ?>" type="text" value="<?php echo attribute_escape($category); ?>" />
  </label>
</p>
<p>
  <label for="<?php echo $this->get_field_id('post_number'); ?>">Number of posts:
  <input class="widefat" id="<?php echo $this->get_field_id('post_number'); ?>" name="<?php echo $this->get_field_name('post_number'); ?>" type="text" value="<?php echo attribute_escape($post_number); ?>" />
  </label>
</p>
<?php
	}

}
register_widget('eventwidget');


 






// =============================== Category wise Widget (particular category) ======================================

class onecolumnslist extends WP_Widget {
	function onecolumnslist() {
	//Constructor
		$widget_ops = array('classname' => 'widget category List View', 'description' => 'List of latest posts in particular category - ( Front content )' );
		$this->WP_Widget('onecolumnslist', 'PT &rarr; Category List View', $widget_ops);
	}

	function widget($args, $instance) {
	// prints the widget

		extract($args, EXTR_SKIP);
		echo $before_widget;
		$title = empty($instance['title']) ? '&nbsp;' : apply_filters('widget_title', $instance['title']);
 		$category = empty($instance['category']) ? '' : apply_filters('widget_category', $instance['category']);
		$post_number = empty($instance['post_number']) ? '5' : apply_filters('widget_post_number', $instance['post_number']);
		$post_link = empty($instance['post_link']) ? '&nbsp;' : apply_filters('widget_post_link', $instance['post_link']);
		$more_link = empty($instance['more_link']) ? '&nbsp;' : apply_filters('widget_more_link', $instance['more_link']);
		$character_cout = empty($instance['character_cout']) ? '15' : apply_filters('widget_character_cout', $instance['character_cout']);
		 ?>
          <h3 class="clearfix"><?php echo $title; ?> </h3>
          <ul class="listingview clearfix">
                
				<?php 
			        global $post,$wpdb;
					if($category)
					{
						$category = "'".str_replace(",","','",$category)."'";
						$sqlsql = " and p.ID in (select tr.object_id from $wpdb->term_relationships tr join $wpdb->term_taxonomy t on t.term_taxonomy_id=tr.term_taxonomy_id where t.term_id in ($category)  )";
					}
					$sql = "select p.* from $wpdb->posts p where p.post_type='".CUSTOM_POST_TYPE1."' and p.post_status='publish' $sqlsql order by p.post_date desc,p.post_title asc limit $post_number";
					$latest_menus = $wpdb->get_results($sql);
                    $pcount=0;
					if($latest_menus)
					{
					foreach($latest_menus as $post) :
                    setup_postdata($post);
					$pcount++;
			    ?>
                 <?php $post_images = bdw_get_images($post->ID);?>
           
           		<li class="clearfix"> 
                
               
                     <a class="post_img" href="<?php the_permalink(); ?>">
                      <?php if(get_post_meta($post->ID,'is_featured',true)){?> <span class="featured_img_s"></span><?php }?>
					<?php if(get_the_post_thumbnail( $post->ID, array())){?>
					<?php echo get_the_post_thumbnail( $post->ID, array(80,55),array('class'	=> "",));?>
					<?php }else if($post_images[0]){ global $thumb_url;	 
						$thumb_url1 = $thumb_url.get_image_cutting_edge($args);
					?>
					 <img src="<?php echo bloginfo('template_url'); ?>/thumb.php?src=<?php echo $post_images[0];?>&amp;w=80&amp;h=55&amp;zc=1&amp;q=80<?php echo $thumb_url1;?>" alt="<?php the_title(); ?>" title="<?php the_title(); ?>"  />
					<?php
					} else { ?> 
					 <span class="img_not_available"> <b> <?php _e('Image Not Available ');?></b> </span>
					<?php }?>
                    </a>

            		<h3> <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3> 
                    <p> <span> <?php echo get_formated_date(get_post_meta($post->ID,'st_date',true));?> <?php _e('at');?> <?php echo get_formated_time(get_post_meta($post->ID,'st_time',true))?></span> <br /> 
                    <?php echo get_post_meta($post->ID,'address',true);?> </p>
            	 </li>
				<?php endforeach; ?>
                 <?php }else{
				  _e('<p>Not a single Event is there.</p>');
			 		}
				 ?>
<?php

	    echo '</ul>';

		echo $after_widget;
	}

	function update($new_instance, $old_instance) {
	//save the widget
		$instance = $old_instance;
		$instance['title'] = strip_tags($new_instance['title']);
		$instance['category'] = strip_tags($new_instance['category']);
		$instance['post_number'] = strip_tags($new_instance['post_number']);
		$instance['post_link'] = strip_tags($new_instance['post_link']);
		$instance['more_link'] = strip_tags($new_instance['more_link']);
		$instance['character_cout'] = strip_tags($new_instance['character_cout']);
		return $instance;

	}

	function form($instance) {
	//widgetform in backend
		$instance = wp_parse_args( (array) $instance, array( 'title' => '', 'category' => '', 'post_number' => '','character_cout' => '','more_link' => '' ) );
		$title = strip_tags($instance['title']);
		$category = strip_tags($instance['category']);
		$post_number = strip_tags($instance['post_number']);
		$post_link = strip_tags($instance['post_link']);
		$more_link = strip_tags($instance['more_link']);
		$character_cout = strip_tags($instance['character_cout']);

?>
<p>
  <label for="<?php echo $this->get_field_id('title'); ?>">Title:
    <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo attribute_escape($title); ?>" />
  </label>
</p>
<p>
  <label for="<?php echo $this->get_field_id('category'); ?>">Categories (<code>IDs</code> separated by commas):
  <input class="widefat" id="<?php echo $this->get_field_id('category'); ?>" name="<?php echo $this->get_field_name('category'); ?>" type="text" value="<?php echo attribute_escape($category); ?>" />
  </label>
</p>
<p>
  <label for="<?php echo $this->get_field_id('post_number'); ?>">Number of posts:
  <input class="widefat" id="<?php echo $this->get_field_id('post_number'); ?>" name="<?php echo $this->get_field_name('post_number'); ?>" type="text" value="<?php echo attribute_escape($post_number); ?>" />
  </label>
</p>

<?php
	}

}

register_widget('onecolumnslist');





 // =============================== Videos Widget (particular category) ======================================

class spotlightpost extends WP_Widget {
	function spotlightpost() {
	//Constructor
		$widget_ops = array('classname' => 'widget Featured Video', 'description' => 'List of In Featured Video in particular category' );
		$this->WP_Widget('spotlight_post', 'PT &rarr; Featured Video', $widget_ops);
	}

	function widget($args, $instance) {
	// prints the widget

		extract($args, EXTR_SKIP);
		echo $before_widget;
		$title = empty($instance['title']) ? '&nbsp;' : apply_filters('widget_title', $instance['title']);
		$category = empty($instance['category']) ? '&nbsp;' : apply_filters('widget_category', $instance['category']);
		$post_number = empty($instance['post_number']) ? '5' : apply_filters('widget_post_number', $instance['post_number']);
		$post_link = empty($instance['post_link']) ? '&nbsp;' : apply_filters('widget_post_link', $instance['post_link']);
		$video_link = empty($instance['video_link']) ? '&nbsp;' : apply_filters('widget_video_link', $instance['video_link']);

		// if ( !empty( $title ) ) { echo $before_title . $title . $after_title; };
		echo ' <div class="featured_video">';?>
        		
                <h3 class="clearfix"> <span class="fl"><?php echo $title; ?> </span>
                 
                  <?php if ( $video_link <> "" ) { ?>	 
                   <span class="more"><a href="<?php echo $video_link; ?>"> <?php _e('View All');?></a> </span> 
          		<?php } ?>
                 
                 </h3>
        		
				<?php 
			        global $post;
			        $latest_menus = get_posts('numberposts='.$post_number.'postlink='.$post_link.'&category='.$category.'');
                    foreach($latest_menus as $post) :
                    setup_postdata($post);
 			    ?>
                
                
              		 
                <?php if(get_post_meta($post->ID,'video',true)){?>
                     <div class="video">
                    <?php echo get_post_meta($post->ID,'video',true);?>
                    	<h4><a class="widget-title" href="<?php the_permalink(); ?>"><?php the_title(); ?> </a></h4>
                    </div>
                    <?php }?>
                    
			       
                     
                 <?php endforeach; ?>
                <?php

	    echo '</div>';
		

		echo $after_widget;
	}

	function update($new_instance, $old_instance) {
	//save the widget
		$instance = $old_instance;
		$instance['title'] = strip_tags($new_instance['title']);
		$instance['category'] = strip_tags($new_instance['category']);
		$instance['post_number'] = strip_tags($new_instance['post_number']);
		$instance['post_link'] = strip_tags($new_instance['post_link']);
		$instance['video_link'] = strip_tags($new_instance['video_link']);
		return $instance;

	}

	function form($instance) {
	//widgetform in backend
		$instance = wp_parse_args( (array) $instance, array( 'title' => '', 'category' => '', 'post_number' => '','video_link' => '' ) );
		$title = strip_tags($instance['title']);
		$category = strip_tags($instance['category']);
		$post_number = strip_tags($instance['post_number']);
		$post_link = strip_tags($instance['post_link']);
		$video_link = strip_tags($instance['video_link']);

?>
<p>
  <label for="<?php echo $this->get_field_id('title'); ?>">Title:
    <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo attribute_escape($title); ?>" />
  </label>
</p>
<p>
  <label for="<?php echo $this->get_field_id('category'); ?>">Categories (<code>IDs</code> separated by commas):
    <input class="widefat" id="<?php echo $this->get_field_id('category'); ?>" name="<?php echo $this->get_field_name('category'); ?>" type="text" value="<?php echo attribute_escape($category); ?>" />
  </label>
</p>
<p>
  <label for="<?php echo $this->get_field_id('post_number'); ?>">Number of posts:
    <input class="widefat" id="<?php echo $this->get_field_id('post_number'); ?>" name="<?php echo $this->get_field_name('post_number'); ?>" type="text" value="<?php echo attribute_escape($post_number); ?>" />
  </label>
</p>
<p>
  <label for="<?php echo $this->get_field_id('video_link'); ?>">Videos category listing page manual link full url :
    <input class="widefat" id="<?php echo $this->get_field_id('video_link'); ?>" name="<?php echo $this->get_field_name('video_link'); ?>" type="text" value="<?php echo attribute_escape($video_link); ?>" />
  </label>
</p>
<?php
	}

}

register_widget('spotlightpost');








// =============================== Flickr widget ======================================

class flickrWidget extends WP_Widget {
	function flickrWidget() {
	//Constructor
		$widget_ops = array('classname' => 'widget Flickr Photos ', 'description' => 'Flickr Photos' );
		$this->WP_Widget('widget_flickrwidget', 'PT &rarr; Flickr Photos', $widget_ops);
	}

	function widget($args, $instance) {
	// prints the widget

		extract($args, EXTR_SKIP);
		echo $before_widget;
		$id = empty($instance['id']) ? '&nbsp;' : apply_filters('widget_id', $instance['id']);
		$number = empty($instance['number']) ? '&nbsp;' : apply_filters('widget_number', $instance['number']);

?>
		
        <h3 ><span>Photo Gallery</span> </h3>
<div class="flickr clearfix">
			
 		  <script type="text/javascript" src="http://www.flickr.com/badge_code_v2.gne?count=<?php echo $number; ?>&amp;display=latest&amp;size=s&amp;layout=x&amp;source=user&amp;user=<?php echo $id; ?>"></script>
 		 
</div>
</div>	

<?php
	}

	function update($new_instance, $old_instance) {
	//save the widget
		$instance = $old_instance;
		$instance['id'] = strip_tags($new_instance['id']);
		$instance['number'] = strip_tags($new_instance['number']);
		return $instance;

	}

	function form($instance) {
	//widgetform in backend
		$instance = wp_parse_args( (array) $instance, array('title' => '',  'id' => '', 'number' => '') );
		$id = strip_tags($instance['id']);
		$number = strip_tags($instance['number']);
?>

<p>
  <label for="<?php echo $this->get_field_id('id'); ?>">Flickr ID (<a href="http://www.idgettr.com">idGettr</a>):
    <input class="widefat" id="<?php echo $this->get_field_id('id'); ?>" name="<?php echo $this->get_field_name('id'); ?>" type="text" value="<?php echo attribute_escape($id); ?>" />
  </label>
</p>
<p>
  <label for="<?php echo $this->get_field_id('number'); ?>">Number of photos:
    <input class="widefat" id="<?php echo $this->get_field_id('number'); ?>" name="<?php echo $this->get_field_name('number'); ?>" type="text" value="<?php echo attribute_escape($number); ?>" />
  </label>
</p>
<?php
	}

}

register_widget('flickrWidget');

 
// =============================== Popular Posts Widget ======================================

function PopularPostsSidebar()
{

    $settings_pop = get_option("widget_popularposts");

	$name = $settings_pop['name'];
	$number = $settings_pop['number'];
	if ($name <> "") { $popname = $name; } else { $popname = 'Popular Posts'; }
	if ($number <> "") { $popnumber = $number; } else { $popnumber = '10'; }

?>
 
	<div  class="popular_post">
	<h3 class="popular" ><span><?php echo $popname; ?></span></h3>
	
		<ul>
 			<?php
			global $wpdb;
            $now = gmdate("Y-m-d H:i:s",time());
            $lastmonth = gmdate("Y-m-d H:i:s",gmmktime(date("H"), date("i"), date("s"), date("m")-12,date("d"),date("Y")));
            $popularposts = "SELECT ID, post_title, COUNT($wpdb->comments.comment_post_ID) AS 'stammy' FROM $wpdb->posts, $wpdb->comments WHERE comment_approved = '1' AND $wpdb->posts.ID=$wpdb->comments.comment_post_ID AND post_status = 'publish' AND post_date < '$now' AND post_date > '$lastmonth' AND comment_status = 'open' GROUP BY $wpdb->comments.comment_post_ID ORDER BY stammy DESC LIMIT $popnumber";
            $posts = $wpdb->get_results($popularposts);
            $popular = '';
            if($posts){
                foreach($posts as $post){
	                $post_title = stripslashes($post->post_title);
		               $guid = get_permalink($post->ID);
					   
					      $first_post_title=substr($post_title,0,26);
            ?>
             <?php $post_images = bdw_get_images($post->ID,'large');?>
            
		        <li class="clearfix">
                    <a href="<?php echo $guid; ?>" title="<?php echo $post_title; ?>"><?php echo $post_title; ?></a>  
                     </li>
            <?php } } ?>

		</ul>
 
 </div>

<?php
}
function PopularPostsAdmin() {

	$settings_pop = get_option("widget_popularposts");

	// check if anything's been sent
	if (isset($_POST['update_popular'])) {
		$settings_pop['name'] = strip_tags(stripslashes($_POST['popular_name']));
		$settings_pop['number'] = strip_tags(stripslashes($_POST['popular_number']));

		update_option("widget_popularposts",$settings_pop);
	}

	echo '<p>
			<label for="popular_name">Title:
			<input id="popular_name" name="popular_name" type="text" class="widefat" value="'.$settings_pop['name'].'" /></label></p>';
	echo '<p>
			<label for="popular_number">Number of popular posts:
			<input id="popular_number" name="popular_number" type="text" class="widefat" value="'.$settings_pop['number'].'" /></label></p>';
	echo '<input type="hidden" id="update_popular" name="update_popular" value="1" />';

}

register_sidebar_widget('PT &rarr; Popular Posts', 'PopularPostsSidebar');
register_widget_control('PT &rarr; Popular Posts', 'PopularPostsAdmin', 250, 200);




// =============================== Recent Comments Widget ======================================
class CommentsWidget extends WP_Widget {
	function CommentsWidget() {
	//Constructor
		$widget_ops = array('classname' => 'widget Recent Review', 'description' => 'Front Page Comments' );		
		$this->WP_Widget('widget_comment', 'PT &rarr; Recent Review', $widget_ops);
	}
	function widget($args, $instance) {
	// prints the widget
		extract($args, EXTR_SKIP);
		$title = empty($instance['title']) ? '' : apply_filters('widget_title', $instance['title']);
		$count = empty($instance['count']) ? '5' : apply_filters('widget_count', $instance['count']);
 		 ?>						
		
        
        <div class="widget recent_comments_section">
        
        <h3> <?php echo $title; ?> </h3>
       
       	<ul class="recent_comments">
		   <?php
 		  if(function_exists('recent_comments')) {
			recent_comments(30, $count, 100, false);
		  }
		?>
       </ul>
            
            </div> 
            
	<?php
	}
	function update($new_instance, $old_instance) {
	//save the widget
		$instance = $old_instance;		
		$instance['title'] = strip_tags($new_instance['title']);
		$instance['count'] = strip_tags($new_instance['count']);
 		return $instance;
	}
	function form($instance) {
	//widgetform in backend
		$instance = wp_parse_args( (array) $instance, array( 'title' => '', 't1' => '', 't2' => '', 't3' => '',  'img1' => '', 'count' => '' ) );		
		$title = strip_tags($instance['title']);
		$count = strip_tags($instance['count']);
 ?>
		<p><label for="<?php echo $this->get_field_id('title'); ?>">Widget Title: <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo attribute_escape($title); ?>" /></label></p>
        <p><label for="<?php echo $this->get_field_id('count'); ?>">Number of Reviews  <input class="widefat" id="<?php echo $this->get_field_id('count'); ?>" name="<?php echo $this->get_field_name('count'); ?>" type="text" value="<?php echo attribute_escape($count); ?>" /></label></p>
<?php
	}}
register_widget('CommentsWidget');



 


// =============================== Twitter widget ======================================
// Plugin Name: Twitter Widget
// Plugin URI: http://seanys.com/2007/10/12/twitter-wordpress-widget/
// Description: Adds a sidebar widget to display Twitter updates (uses the Javascript <a href="http://twitter.com/badges/which_badge">Twitter 'badge'</a>)
// Version: 1.0.3
// Author: Sean Spalding
// Author URI: http://seanys.com/
// License: GPL
class twitter extends WP_Widget {
	function twitter() {
	//Constructor
		$widget_ops = array('classname' => 'Twitter', 'description' => 'Twitter' );
		$this->WP_Widget('widget_Twidget', 'PT &rarr; Twitter', $widget_ops);
	}

	function widget($args, $instance) {
	// prints the widget

		extract($args, EXTR_SKIP);
		echo $before_widget;
		$title = empty($instance['title']) ? '&nbsp;' : apply_filters('widget_title', $instance['title']);
		$account = empty($instance['account']) ? '&nbsp;' : apply_filters('widget_account', $instance['account']);
		$show = empty($instance['show']) ? '&nbsp;' : apply_filters('widget_show', $instance['show']);
		$follow = empty($instance['follow']) ? '&nbsp;' : apply_filters('widget_follow', $instance['follow']);

		 // Output
		echo $before_widget ;

		// start
		echo '<div id="twitter"> <h3><a href="http://www.twitter.com/'.$account.'/" title="'.$follow.'">'.$title.' </a></h3>';              
		echo '<ul id="twitter_update_list"><li></li></ul>
		      <script type="text/javascript" src="http://twitter.com/javascripts/blogger.js"></script>';
		echo '<script type="text/javascript" src="http://twitter.com/statuses/user_timeline/'.$account.'.json?callback=twitterCallback2&amp;count='.$show.'"></script>';
		echo '</div> </div>';
			
				
		// echo widget closing tag
		echo $after_widget;
	}

	function update($new_instance, $old_instance) {
	//save the widget
		$instance = $old_instance;
		$instance['title'] = strip_tags($new_instance['title']);
		$instance['account'] = strip_tags($new_instance['account']);
		$instance['follow'] = strip_tags($new_instance['follow']);
		$instance['show'] = strip_tags($new_instance['show']);
		return $instance;

	}

	function form($instance) {
	//widgetform in backend
		$instance = wp_parse_args( (array) $instance, array('account'=>'rbhavesh', 'title'=>'Twitter Updates', 'show'=>'3' ) );
		$title = strip_tags($instance['title']);
		$show = strip_tags($instance['show']);
		$follow = strip_tags($instance['follow']);
		$account = strip_tags($instance['account']);
?>
<p>
  <label for="<?php echo $this->get_field_id('account'); ?>"><?php  _e('Twitter Account ID')?>:
    <input class="widefat" id="<?php echo $this->get_field_id('account'); ?>" name="<?php echo $this->get_field_name('account'); ?>" type="text" value="<?php echo attribute_escape($account); ?>" />
  </label>
</p>
<p>
  <label for="<?php echo $this->get_field_id('title'); ?>"><?php  _e('Title')?>:
    <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo attribute_escape($title); ?>" />
  </label>
</p>

<p>
  <label for="<?php echo $this->get_field_id('show'); ?>"><?php  _e('Show Twitter Posts')?>:
    <input class="widefat" id="<?php echo $this->get_field_id('show'); ?>" name="<?php echo $this->get_field_name('show'); ?>" type="text" value="<?php echo attribute_escape($show); ?>" />
  </label>
</p>

<?php
	}

}

register_widget('twitter');

// =============================== Event Calendar ======================================
class my_event_calender_widget extends WP_Widget {
	function my_event_calender_widget() {
	//Constructor
		$widget_ops = array('classname' => 'widget Event Listing calender.', 'description' => 'Event Listing calender' );		
		$this->WP_Widget('event_calendar', 'PT &rarr; Event Listing Calender', $widget_ops);
	}
	function widget($args, $instance) {
	// prints the widget
		global $post;
		extract($args, EXTR_SKIP);
		$title = empty($instance['title']) ? '' : apply_filters('widget_title', $instance['title']);
		include_once (TEMPLATEPATH . '/library/calendar/calendar.php');
		if($title)
		{
		echo '<h3>'.$title.'</h3>';	
		}
		get_my_event_calendar();
	}
	function update($new_instance, $old_instance) {
	//save the widget
		$instance = $old_instance;		
		$instance['title'] = strip_tags($new_instance['title']);
		return $instance;
	}
	function form($instance) {
	//widgetform in backend
		$instance = wp_parse_args( (array) $instance, array( 'title' => '') );		
		$title = strip_tags($instance['title']);
		?>
        
        
        
<p>
  <label for="<?php echo $this->get_field_id('title'); ?>"><?php  _e('Title')?>:
    <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo attribute_escape($title); ?>" />
  </label>
</p>
        <?php
	}}
register_widget('my_event_calender_widget');
?>