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

function tigu_banner_660x90_load_widgets(){
		register_widget("Tigu_Banner_660x90_Widget");
}

class Tigu_Banner_660x90_Widget extends WP_widget{

	function Tigu_Banner_660x90_Widget(){
	    $widget_ops = array(
       'classname' => 'tigu_banner_660x90_widget', 
       'description' => 'Display a 660x90 banner on Homepage.');

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

		$this->WP_Widget(
       'tigu_banner_660x90_widget', 
       'GAMELEON: 660x90 banner', 
        $widget_ops, 
        $control_ops);
		
	}
	/* User selected settings. */
	function widget($args,$instance){
		extract($args);
		echo $before_widget;
		$link = $instance['link'];
		$alt = $instance['alt'];
		$image = $instance['image'];
		$code = $instance['code'];
		?>
		<?php
		if($image) {	
		?>				
			<div class="banner660x90"><a href="<?php echo $link; ?>"><img src="<?php echo $image; ?>" alt="<?php echo $alt; ?>" /></a></div>
		<?php
		}
		else {
		?>
			<div class="banner660x90"><?php echo stripslashes($code); ?></div>
		<?php
		}
		echo $after_widget;
	}
	
	function update($new_instance, $old_instance){
		$instance = $old_instance;
		
		$instance['link'] = $new_instance['link'];
		$instance['alt'] = $new_instance['alt'];
		$instance['image'] = $new_instance['image'];
		$instance['code'] = $new_instance['code'];
		
		return $instance;
	}
	
	function form($instance){
		$defaults = array(
        'link' => '', 
        'alt' => 'banner', 
        'image' => '', 
        'code' => '');
		$instance = wp_parse_args((array) $instance, $defaults); ?>
		<h4>USING IMAGE</h4>
		
		<p>
			<label for="<?php echo $this->get_field_id('image'); ?>">Image Url:</label>
			<input class="widefat" style="width: 216px;" id="<?php echo $this->get_field_id('image'); ?>" name="<?php echo $this->get_field_name('image'); ?>" value="<?php echo $instance['image']; ?>" />
		</p>
	    <p>
			<label for="<?php echo $this->get_field_id('link'); ?>">Target Url:</label>
			<input class="widefat" style="width: 216px;" id="<?php echo $this->get_field_id('link'); ?>" name="<?php echo $this->get_field_name('link'); ?>" value="<?php echo $instance['link']; ?>" />
		</p>
        <p>
			<label for="<?php echo $this->get_field_id('alt'); ?>">Image alt attribute:</label>
			<input class="widefat" style="width: 216px;" id="<?php echo $this->get_field_id('alt'); ?>" name="<?php echo $this->get_field_name('alt'); ?>" value="<?php echo $instance['alt']; ?>" />
         An imagine element must have an alt attribute, useful for markup validation.
	    </p>
		<h4 style='margin-top: 40px;'>OR USING CUSTOM CODE</h4>
		<p>
			<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

	}
}
?>