function do_album_navigator($parent, $page, $skip, $propclass, $extraclause = '')
    {
        global $wpdb;
        static $level;
        static $ca;
        if (!$level) {
            $level = '1';
            if (isset($_REQUEST['wppa-album'])) {
                $ca = $_REQUEST['wppa-album'];
            } elseif (isset($_REQUEST['album'])) {
                $ca = $_REQUEST['album'];
            } else {
                $ca = '0';
            }
            $ca = wppa_force_numeric_else($ca, '0');
            if ($ca && !wppa_album_exists($ca)) {
                //				wppa_log('dbg', 'Non-existent album '.$ca.' in url. Referrer= '.$_ENV["HTTP_REFERER"].', Request uri= '.$_ENV["REQUEST_URI"]);
                $ca = '0';
            }
        } else {
            $level++;
        }
        $slide = wppa_opt('album_navigator_widget_linktype') == 'slide' ? '&wppa-slide=1' : '';
        $w = $this->get_widget_id();
        $p = $parent;
        $result = '';
        $albums = $wpdb->get_results($wpdb->prepare("SELECT * FROM `" . WPPA_ALBUMS . "` WHERE `a_parent` = %s " . $extraclause . wppa_get_album_order(max('0', $parent)), $parent), ARRAY_A);
        if (!empty($albums)) {
            wppa_cache_album('add', $albums);
            $result .= '<ul>';
            foreach ($albums as $album) {
                $a = $album['id'];
                $treecount = wppa_treecount_a($a);
                if ($treecount['albums'] || $treecount['photos'] > wppa_opt('min_thumbs') || $skip == 'no') {
                    $result .= '
						<li class="anw-' . $w . '-' . $p . $propclass . '" style="list-style:none; display:' . ($level == '1' ? '' : 'none') . ';">';
                    if (wppa_has_children($a)) {
                        $result .= '
							<div style="cursor:default;width:12px;float:left;text-align:center;font-weight:bold;" class="anw-' . $w . '-' . $a . '-" onclick="jQuery(\'.anw-' . $w . '-' . $a . '\').css(\'display\',\'\'); jQuery(\'.anw-' . $w . '-' . $a . '-\').css(\'display\',\'none\');" >' . ($a == $ca ? '&raquo;' : '+') . '</div>
							<div style="cursor:default;width:12px;float:left;text-align:center;font-weight:bold;display:none;" class="anw-' . $w . '-' . $a . '" onclick="jQuery(\'.anw-' . $w . '-' . $a . '-\').css(\'display\',\'\'); jQuery(\'.anw-' . $w . '-' . $a . '\').css(\'display\',\'none\'); jQuery(\'.p-' . $w . '-' . $a . '\').css(\'display\',\'none\');" >' . ($a == $ca ? '&raquo;' : '-') . '</div>';
                    } else {
                        $result .= '
							<div style="width:12px;float:left;" >&nbsp;' . ($a == $ca ? '&raquo;' : '') . '</div>';
                    }
                    $result .= '
							<a href="' . wppa_encrypt_url(wppa_get_permalink($page) . '&amp;wppa-album=' . $a . '&amp;wppa-cover=0&amp;wppa-occur=1' . $slide) . '">' . wppa_get_album_name($a) . '</a>
						</li>';
                    $newpropclass = $propclass . ' p-' . $w . '-' . $p;
                    $result .= '<li class="anw-' . $w . '-' . $p . $propclass . '" style="list-style:none;" >' . $this->do_album_navigator($a, $page, $skip, $newpropclass, $extraclause) . '</li>';
                }
            }
            $result .= '</ul>';
            if ($level == '1' && $ca) {
                // && $parent != '-1' ) {
                $result .= '<script type="text/javascript" >';
                while ($ca != '0' && $ca != '-1') {
                    $result .= '
								jQuery(\'.anw-' . $w . '-' . $ca . '\').css(\'display\',\'\'); jQuery(\'.anw-' . $w . '-' . $ca . '-\').css(\'display\',\'none\');';
                    $ca = wppa_get_parentalbumid($ca);
                }
                $result .= '</script>';
            }
        }
        $level--;
        return str_replace('<ul></ul>', '', $result);
    }
    /** @see WP_Widget::form */
    function form($instance)
    {
        global $wpdb;
        //Defaults
        $instance = wp_parse_args((array) $instance, array('title' => __('Thumbnail Albums', 'wppa'), 'parent' => '0', 'name' => 'no', 'skip' => 'yes'));
        $parent = $instance['parent'];
        $name = $instance['name'];
        $skip = $instance['skip'];
        $widget_title = $instance['title'];
        ?>
		<p><label for="<?php 
        echo $this->get_field_id('title');
        ?>
"><?php 
        _e('Title:', 'wppa');
        ?>
</label> <input class="widefat" id="<?php 
        echo $this->get_field_id('title');
        ?>
" name="<?php 
        echo $this->get_field_name('title');
        ?>
" type="text" value="<?php 
        echo $widget_title;
        ?>
" /></p>
		<p><label for="<?php 
        echo $this->get_field_id('parent');
        ?>
"><?php 
        _e('Album selection or Parent album:', 'wppa');
        ?>
</label> 
			<select class="widefat" id="<?php 
        echo $this->get_field_id('parent');
        ?>
" name="<?php 
        echo $this->get_field_name('parent');
        ?>
" >

				<option value="all" <?php 
        if ($parent == 'all') {
            echo 'selected="selected"';
        }
        ?>
><?php 
        _e('--- all albums ---', 'wppa');
        ?>
</option>
				<option value="0"  <?php 
        if ($parent == '0') {
            echo 'selected="selected"';
        }
        ?>
><?php 
        _e('--- all generic albums ---', 'wppa');
        ?>
</option>
				<option value="-1" <?php 
        if ($parent == '-1') {
            echo 'selected="selected"';
        }
        ?>
><?php 
        _e('--- all separate albums ---', 'wppa');
        ?>
</option>
				<option value="last" <?php 
        if ($parent == 'last') {
            echo 'selected="selected"';
        }
        ?>
><?php 
        _e('--- most recently added albums ---', 'wppa');
        ?>
</option>
				<?php 
        $albs = $wpdb->get_results("SELECT * FROM `" . WPPA_ALBUMS . "` ORDER BY `name`", ARRAY_A);
        if ($albs) {
            foreach ($albs as $alb) {
                echo '<option value="' . $alb['id'] . '" ';
                if ($parent == $alb['id']) {
                    echo 'selected="selected" ';
                }
                if (!wppa_has_children($alb['id'])) {
                    echo 'disabled="disabled" ';
                }
                echo '>' . __(stripslashes($alb['name'])) . '</option>';
            }
        }
        ?>

			</select>
		</p>
		<p>
			<?php 
        _e('Show album names:', 'wppa');
        ?>
			<select id="<?php 
        echo $this->get_field_id('name');
        ?>
" name="<?php 
        echo $this->get_field_name('name');
        ?>
">
				<option value="no" <?php 
        if ($name == 'no') {
            echo 'selected="selected"';
        }
        ?>
><?php 
        _e('no.', 'wppa');
        ?>
</option>
				<option value="yes" <?php 
        if ($name == 'yes') {
            echo 'selected="selected"';
        }
        ?>
><?php 
        _e('yes.', 'wppa');
        ?>
</option>
			</select>
		</p>
		<p>
			<?php 
        _e('Skip "empty" albums:', 'wppa');
        ?>
			<select id="<?php 
        echo $this->get_field_id('skip');
        ?>
" name="<?php 
        echo $this->get_field_name('skip');
        ?>
">
				<option value="no" <?php 
        if ($skip == 'no') {
            echo 'selected="selected"';
        }
        ?>
><?php 
        _e('no.', 'wppa');
        ?>
</option>
				<option value="yes" <?php 
        if ($skip == 'yes') {
            echo 'selected="selected"';
        }
        ?>
><?php 
        _e('yes.', 'wppa');
        ?>
</option>
			</select>
		</p>

		<p><?php 
        _e('You can set the sizes in this widget in the <b>Photo Albums -> Settings</b> admin page.', 'wppa');
        ?>
</p>
<?php 
    }