function FlashInstalled()
{
	result = false;
	if (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"])
	{
		result = navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin;
	}
	else if (document.all && (navigator.appVersion.indexOf("Mac")==-1))
	{
		// IE Windows only -- check for ActiveX control, have to hide code in eval from Netscape (doesn't like try)
		eval ('try {var xObj = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");if (xObj)	result = true; xObj = null;	} catch (e)	{}');
	}
	return result;
}

function GetFlashHTML(url,width,height)
{
	var htm = '<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"';
	htm += '  codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" ';
	htm += ' WIDTH=' + width + ' HEIGHT=' + height + '>';
	htm += ' <PARAM NAME=movie VALUE="' + url + '"> <PARAM NAME=quality VALUE=high> <PARAM NAME=bgcolor VALUE=#FFFFFF>  ';
	htm += ' <EMBED src="' + url + '" quality=high bgcolor=#FFFFFF  ';
	htm += ' swLiveConnect=FALSE WIDTH=' + width + ' HEIGHT=' + height;
	htm += ' TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash">';
	htm += ' </EMBED></OBJECT>';
	return htm;
}

function BannerMgr_Switch(imageObj,kind,criteria)
{
	var banObj = this.GetBanner(kind,criteria);
	if (banObj != null)
	{
		imageObj.src = banObj.imgSrc;
		this.SetAnchorRef(imageObj.name+"Ref",banObj.ref);
	}
}

function BannerMgr_SetAnchorRef(name,ref)
{
	for (var i=0;i<document.anchors.length;i++)
	{
		if (document.anchors[i].name == name)
		{
			document.anchors[i].href = ref;
			break;
		}
	}
}

function BannerMgr_GetBanner(kind, criteriaStr)
{
	var banArray = this.banners[kind];
	var possibles = new Array();
	var result = null;

	for (var i=0;i<banArray.length;i++)
	{
		var criteria = criteriaStr.split(",");

		var matches = false;
		for (var j=0;j<criteria.length;j++)
		{
			if ((criteria[j]=="all") || (banArray[i].keywords.indexOf(criteria[j]) >= 0))
			{
				matches = true;
			}
			else
				matches = false;
		}
		if (matches)
			possibles[possibles.length] = banArray[i];
	}


	if (possibles.length > 0)
	{
		var choice = Math.floor(Math.random()*possibles.length);
		result = possibles[choice];
	}

	return result;
}

function BannerMgr_Add(kind, keywords, imgSrc, altText, ref, flashSrc)
{
	var banArray = this.banners[kind];
	var banObj = new Object();
	banObj.name = "ban" + banArray.length;
	banObj.keywords = keywords;
	banObj.imgSrc = imgSrc;
	banObj.altText = altText;
	banObj.ref = ref;

	if (arguments.length > 5)
		banObj.flashSrc = flashSrc;
	else
		banObj.flashSrc = null;

	banArray[banArray.length] = banObj;
}

function BannerMgr_WriteBanner(kind,criteria)
{
	var htm = this.GetBannerHTML(kind,criteria);
	document.write(htm);

}

function BannerMgr_GetBannerHTML(kind,criteria)
{
	var banObj = this.GetBanner(kind,criteria);
	var wh = this.GetWidthHeight(kind);

	var htm = '';
	if (banObj.flashSrc && FlashInstalled())
	{
		htm = GetFlashHTML(banObj.flashSrc+"?link="+banObj.ref,wh.width,wh.height);
	}
	else
	{
		htm += '<a name="' + banObj.name + 'Ref" href="' + banObj.ref + '" target="_blank">';
		htm += '<img name="' + banObj.name + '" src="' + banObj.imgSrc + '" width=';
		htm += wh.width + ' height=' + wh.height + ' onerror="gBannerMgr.Switch(this,' + kind + ',\'local,' + criteria + '\')" ';
		htm += 'alt="' + banObj.altText + '" border=0></a>';

		// support for airplane banner
		if (kind==BannerMgr.BAN)
		{
			gBannerName = banObj.name;
			gBannerLinkName = banObj.name;
			gBannerLinkURL = banObj.ref;
		}
	}

	return htm;
}

function BannerMgr_GetWidthHeight(kind)
{
	var returnObj = new  Object();
	switch(kind)
	{
		case 0:
			returnObj.width = 468;
			returnObj.height = 60;
			break;
		case 1:
			returnObj.width = 88;
			returnObj.height = 31;
			break;
		case 2:
			returnObj.width = 120;
			returnObj.height = 60;
			break;
	}
	return returnObj;
}



function BannerMgr()
{
	this.banners = new Array( new Array(), new Array(),new Array() );
	// Methods
	this.GetWidthHeight = BannerMgr_GetWidthHeight;
	this.WriteBanner = BannerMgr_WriteBanner;
	this.Add = BannerMgr_Add;
	this.GetBanner = BannerMgr_GetBanner;
	this.SetAnchorRef = BannerMgr_SetAnchorRef;
	this.Switch = BannerMgr_Switch;
	this.GetBannerHTML = BannerMgr_GetBannerHTML;
}
BannerMgr.BAN = 0;
BannerMgr.BTN = 1;
BannerMgr.BTN2X = 2;

var gBannerMgr = new BannerMgr();

//CURRENT BANNERS
gBannerMgr.Add(BannerMgr.BAN, "local", "http://www.doom-metal.com/pictures/ads/mar.gif", "Metalheads against Racism", "http://www.metalheadsagainstracism.org"); // free and NEVER TO BE DELETED

gBannerMgr.Add(BannerMgr.BAN, "local", "http://www.doom-metal.com/pictures/ads/crymadnessbanner.jpg", "Cryptic Madness", "http://www.crypticmadness.com"); // free for the moment

gBannerMgr.Add(BannerMgr.BAN, "local", "http://www.doom-metal.com/pictures/ads/stygcrypbanner.gif", "Stygian Crypt Productions", "http://www.stygiancrypt.com"); // free for the moment

gBannerMgr.Add(BannerMgr.BAN, "local", "http://www.doom-metal.com/pictures/ads/atihbanner1.gif", "All That is Heavy", "http://www.allthatisheavy.com/"); // free for the moment

gBannerMgr.Add(BannerMgr.BAN, "local", "http://www.doom-metal.com/pictures/ads/solprodbanner.jpg", "Solitude Productions", "http://solitude-prod.com"); // free for the moment

gBannerMgr.Add(BannerMgr.BAN, "local", "http://www.doom-metal.com/pictures/ads/eol.gif", "Evening of Light - (Dark) Ambient & (Neo-) Folk Reviews", "http://www.eveningoflight.nl"); // free for the moment

gBannerMgr.Add(BannerMgr.BAN, "local", "http://www.doom-metal.com/pictures/ads/shadowkingdomok.jpg", "Shadow Kingdom", "http://shadowkingdomrecords.com"); // free for the moment

gBannerMgr.Add(BannerMgr.BAN, "local", "http://www.doom-metal.com/pictures/ads/nulllbanner.jpg", "Nulll Records", "http://nulll-void.com"); // free for the moment

gBannerMgr.Add(BannerMgr.BAN, "local", "http://www.doom-metal.com/pictures/ads/psychedoomelicrecords.jpg", "PsycheDOOMelic Records", "http://shop.psychedoomelic.com/"); // free for the moment

//END CURRENT BANNERS

//

// Regular Size Banner Examples
//gBannerMgr.Add(BannerMgr.BAN, "local,swdev,general,flashexample", "images/aboutbanner2.gif", "Go to JavaScript on About!", "http://javascript.about.com", "images/aboutbanner.swf");
//gBannerMgr.Add(BannerMgr.BAN, "local,swdev", "http://www.angusog.com/images/booklistbanner.gif", "Find the best development books!", "http://www.angusog.com/redir.asp?url=http://www.angusog.com/dev/devbooks.htm");

//PAST BANNERS

//gBannerMgr.Add(BannerMgr.BAN, "local", "http://www.doom-metal.com/pictures/ads/bib.jpg", "Born in Blood - Helping Unsigned Metal Talent", "http://www.borninblood.co.uk"); // 12 euro until Jan 12 2008 -discount for staffy :-)

//gBannerMgr.Add(BannerMgr.BAN, "local", "http://www.doom-metal.com/pictures/ads/burntoak1.gif", "Burnt Oak Productions", "http://www.burntoakproductions.com"); // $25 until Jan 26 2008

//gBannerMgr.Add(BannerMgr.BAN, "local", "http://www.doom-metal.com/pictures/ads/solprod.gif", "Solitude Productions", "http://www.solitude-prod.com"); // $20 until Jan 29 2008 (discount for waiting)
//gBannerMgr.Add(BannerMgr.BAN, "local", "http://www.doom-metal.com/pictures/ads/worship1.gif", "New Worship Album - Out Soon", "http://www.EndzeitElegies.com"); // $20 until Feb 07 2008 (discount for waiting)
//gBannerMgr.Add(BannerMgr.BAN, "local", "http://www.doom-metal.com/pictures/ads/fireeuro.gif", "Firebox Europe Mailorder", "http://www.fireboxmagyarorszag.hu"); // ~13 euro in natura until Mar 26 2008 (discount for waiting)
//gBannerMgr.Add(BannerMgr.BAN, "local", "http://www.doom-metal.com/pictures/ads/foreshadow1.gif", "Foreshadow Productions", "http://www.foreshadow.pl"); // $20 until Mar 26 2008 (discount for waiting)
//gBannerMgr.Add(BannerMgr.BAN, "local", "http://www.doom-metal.com/pictures/adds/pantheist.jpg", "Pantheist", "http://www.pantheist.co.uk");
//gBannerMgr.Add(BannerMgr.BAN, "local", "http://www.doom-metal.com/pictures/adds/oak-knoll-banner.gif", "Oak Knoll Productions - Extreme metal label", "http://www.oak-knoll.com"); // since 01/2004 - 1 year//
//gBannerMgr.Add(BannerMgr.BAN, "local", "http://www.doom-metal.com/pictures/adds/bannerLOT.jpg", "Labyrinth of Thoughts - Mailorder", "http://www.labyrinthofthoughts.gr/"); // Feb 2005 - one month free (hack issue)
//gBannerMgr.Add(BannerMgr.BAN, "local", "http://www.doom-metal.com/pictures/adds/cos_ad.gif", "Chamber of Sorrow", "http://www.chamberofsorrows.com/"); // Feb 2005 - free tmp (hack issue)
//gBannerMgr.Add(BannerMgr.BAN, "local", "http://www.doom-metal.com/pictures/adds/lifesdecaybanner.gif", "Life's Decay", "http://www.lifesdecay.com/"); // Feb 2005 - 1 month free tmp (hack issue)
//gBannerMgr.Add(BannerMgr.BAN, "local", "http://www.doom-metal.com/pictures/adds/tlfbanner.gif", "Living Fields", "http://www.thelivingfields.com/"); // Feb 2005 - 1 month free tmp (hack issue)
//gBannerMgr.Add(BannerMgr.BAN, "local", "http://www.doom-metal.com/pictures/adds/sobbanner.gif", "Shroud of Bereavement", "http://www.shroud-of-bereavement.com/"); // Montly subscription - extra 6 months free after canceling imho (hack issue)

// Button Size Banner Examples
//gBannerMgr.Add(BannerMgr.BTN, "local,general", "http://www.angusog.com/images/FreeMarklet.gif", "Slowmomusic: Doom-metal webstore", "http://www.slowmomusic.com");
