#!/usr/bin/perl


$dirname = '.';
&lower_url("$dirname");


sub lower_url {
	local $this_dir = shift;
	chdir "$this_dir";
	opendir(DIR, '.');
	local (@filename) = readdir(DIR);
	closedir(DIR);
	foreach $file (@filename) {
		next if ($file eq "." || $file eq "..");
		
		if( -d $file) { 
			
			local $dirnew = $file;
			&lower_url("$dirnew");
			chdir ".." unless ($dirnew eq ".");
		}
		if($file =~ /\.html$/) {
			open(HTMLFILE, "<$file") || die "could not open $file";
			open(OUTPUT, ">$file.backup");
			print $file . "\n";
			while(<HTMLFILE>) {
					
				if(/HREF/) {
					
					if(/HREF/ && /SRC/) {
						
						/(HREF=\".*)(\".*)(SRC=\".*)(\".*)/;
						$one = $1; $three = $3;				
						$one =~ tr/A-Z/a-z/;
						$three =~ tr/A-Z/a-z/;
						#print $file . "\n";
						#print "one =" . $one . "\n";
						#print "three = " . $three . "\n";
						#print "1 =" . $1 . "\n";
						#print "3 =" . $3 . "\n";
						$x = $1;
						$y=$3;
						s/$x/$one/g;
						s/$y/$three/g;
						}
					elsif(/HREF/) {
						/(HREF=\".*)(\".*)/;
						$one = $1; 				
						$one =~ tr/a-z/A-Z/;
						print $file . "\n";
						print "one =" . $one . "\n";
						print "1 =" . $1 . "\n";
						$x = $1;
						s/$x/$one/g;
						}
					elsif(/SRC/) {
						/(SRC=\".*)(\".*)/;
						$one = $1; 			
						$one =~ tr/A-Z/a-z/;
						#print $file . "\n";
						#print "one =" . $one . "\n";
						#print "1 =" . $1 . "\n";
						$x = $1;
						s/$x/$one/g;
						}
					
				}
				print OUTPUT $_;
				}
	 		
			close(HTMLFILE);
			close(OUTPUT);
			`mv $file.backup $file`;
			}}}
		
					
				
