<?php
add_action('widgets_init','tigu_seoblock_load_widgets');

function tigu_seoblock_load_widgets(){
	   register_widget("Tigu_seoblock_Widget");
}

class Tigu_seoblock_Widget extends WP_widget{
	
	function Tigu_seoblock_Widget(){
		$widget_ops = array(
       'classname' => 'tigu_seoblock_widget', 
       'description' => 'Display a SEO Text Block on your Home Page or Sidebar.');

		$control_ops = array(
       'id_base' => 'tigu_seoblock_widget');

		$this->WP_Widget(
        'tigu_seoblock_widget', 
        'GAMELEON: SEO Text Block', 
         $widget_ops, 
         $control_ops);
		
	}
	/* User selected settings. */
	function widget($args,$instance){
		extract($args);
        $title = apply_filters('widget_title', $instance['title']);
		$code = $instance['code'];
        echo $before_widget;
        if($title) {
        echo $before_title.$title.$after_title;
   }
            wp_register_script('mousewheel', get_template_directory_uri() . '/js/jquery.mousewheel.min.js', 'jquery');
            wp_register_script('jqueryuimin', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js', 'jquery');
            wp_register_script('scrollbar', get_template_directory_uri() . '/js/jquery.mCustomScrollbar.min.js', 'jquery');
            wp_enqueue_script('mousewheel');
            wp_enqueue_script('jqueryuimin');
            wp_enqueue_script('scrollbar');	 

		?>
 
<div id="content_1" class="seo-block">
<p style="height:192%;">
<?php echo stripslashes($code); ?>
</p>
</div>
	<script>
		(function($){
			$(window).load(function(){
				$("#content_1").mCustomScrollbar({
					scrollButtons:{
						enable:true
					}
				});
			});
		})(jQuery);
	</script>
	<?php
	 
		echo $after_widget;
	}
	
	function update($new_instance, $old_instance){
		$instance = $old_instance;
		$instance['title'] = strip_tags($new_instance['title']);
		$instance['code'] = $new_instance['code'];
		return $instance;
	}
	
	function form($instance){
		$defaults = array(
        'title' => 'SEO Block',
        'code' => '');
		$instance = wp_parse_args((array) $instance, $defaults); ?>
		  <p>
         <label for="<?php echo $this->get_field_id('title'); ?>">Title:</label>
         <input class="widefat" style="width: 216px;" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" value="<?php echo $instance['title']; ?>" />
      </p>

		     <p>
             <label for="<?php echo $this->get_field_id('code'); ?>">SEO Text:</label>
			<textarea class="widefat" rows="10" cols="10" id="<?php echo $this->get_field_id('code'); ?>" name="<?php echo $this->get_field_name('code'); ?>"><?php echo $instance['code']; ?></textarea>
            </p>
<?php }
}
?>