#!/usr/bin/perl
require "weblib.lib";
use List::Util 'shuffle';
&getparams(0,"float");
$param{float}="none" if $param{float} eq "-1";
$param{float}="none" unless $param{float};
if($param{asin}){push(@ASIN,$param{asin});}
else{
	open(ASIN,"/home/todd/private/AmazonASINs");
	while(<ASIN>){
		chop;
		next if /#/ && $param{html} ne "all";
		push(@ASIN,$_);
	}
	close ASIN;
	@ASIN=shuffle(@ASIN) unless $param{html} eq "all";
}
if($param{html}){
	$style=<<EOF;
style=div.item {font: 8pt/9pt Verdana; display: inline-block; text-align: center;}
div.collection {display: inline-block; border: 5px ridge grey; margin: 5px; padding: 5px;}
iframe {width:122px; height:242px; overflow:hidden; margin:0px; border:0px; float:$param{float};}
EOF
	&htmlopen("Amazon $param{html}|",$style);
	if($param{html} eq "all"){
		print qq{<div style="display: inline-block;"><h1>Amazon Todd Rundgren Products</h1>};
		print "Purchasing these products through these links helps the TR Connection\n";
		foreach $ASIN(@ASIN){
			if($ASIN=~s/#//){
				print qq{</div><div class="collection"><h2>$ASIN</h2>\n};
				next;
			}
			print qq{<div class="item">$ASIN<br>};
			print &AmazonAd($ASIN,$param{float});
			print "</div>\n";
		}
		print "</div>\n";
	}
	else{
		print qq{<script src="$weblib::URL/$param{float}"></script>\n};
	}
	&htmlclose;
}
else{
	print "Content-type: text/javascript\n\n";
	print qq{document.write("},&AmazonAd(shift(@ASIN),$param{float}),qq{");};
}
sub AmazonAd{
	local($ASIN,$position)=@_;
	if($param{html}){
	return qq{<iframe src='http://rcm-na.amazon-adsystem.com/e/cm?t=thetoddrundgrenc&amp;o=1&amp;p=8&amp;l=as1&amp;asins=$ASIN&amp;fc1=000000&amp;IS2=1&amp;lt1=_blank&amp;m=amazon&amp;lc1=0000FF&amp;bc1=000000&amp;bg1=FFFFFF&amp;f=ifr' frameborder='0'></iframe>};
	}
else{
	return qq{<iframe src='http://rcm-na.amazon-adsystem.com/e/cm?t=thetoddrundgrenc&amp;o=1&amp;p=8&amp;l=as1&amp;asins=$ASIN&amp;fc1=000000&amp;IS2=1&amp;lt1=_blank&amp;m=amazon&amp;lc1=0000FF&amp;bc1=000000&amp;bg1=FFFFFF&amp;f=ifr' style='width:122px;height:242px;overflow:hidden;margin:0px;border:0px;float:$position;' frameborder='0'></iframe>};
	}
}
