#-*-Perl-*-

$hof{"bobbins"} = 0;

# Bobbins online http://www.geocities.com/SoHo/Square/3506/bobbins/
sub bobbins {
    my $mytime = shift(@_);
    my @ltime = localtime($mytime);
    my ($ndays, %conv);
    my ($basedir, $basename);
    my $vday;
    
    # Quick Access to some values ...
    %conv = (907606800 => 1,  # Oct 5
             909421200 => 16, # Oct 26
             911235600 => 34, # Nov16
             911840400 => 41, # Nov 23
             913050000 => 53, # Dec 7
             913654800 => 60, # Dec 14
             920912400 => 132 # Mar 8
             );
    
    # Nothing before October 5th, 1998
    return undef if ($mytime < 907606800);
    
    #make sure we look for a correct amount of dates a week
    $basedir = "strips";
    $basename = "cart";
    if ($mytime < 915210000) { # Before 1999
        $_ = $ltime[7];
        if ($_ < 298) {
	    $ndays = 5;
	} elsif ($_ < 319) {
            $ndays = 6;
        } elsif ($_ < 326) {
	    $ndays = 7; 
        } elsif ($_ < 340) {
	    $ndays = 6;
        } elsif ($_ < 347) {
	    $ndays = 7;
	} else {
            $ndays = 6;
	}
    } else {
        $basedir = "1999" if ($ltime[7] >= 3); 
        $basename = "c" if ($mytime >= 916592400);
        if ($ltime[7] < 64) {
	    $ndays = 6;
	} else {
            $ndays = 5; # Supposedely staying at 5 strips a week
	}
    }

    foreach $val (sort bobbins_sort keys %conv) {
        $vday = $conv{$val} # quick access
            + ($ndays * int (($mytime - $val) / (3600 * 24 * 7))) #and week due
            if ($mytime >= $val);
    }

    # Day add
    if ($ltime[6] == 0) {
        return undef if ($ndays < 7);
        $vday += 6;
    } else {
        return undef if (($ltime[6] == 6) && ($ndays < 6));
        $vday += ($ltime[6] - 1);
    }


#    print "@ltime : $mytime : $basedir/$basename$vday\n";

    my $rec = {
        'name' => strftime("Bobbins-${date_fmt}.gif",@ltime),
        'base' => "http://www.geocities.com/SoHo/Square/3506/bobbins/",
        'page' => "$basedir/$basename$vday.gif"
        };
    return $rec;
}

sub bobbins_sort { $a <=> $b; } #sort numerically

1;

