
// these values are always the same
//var google_ad_client = "pub-3221643274784913";
//var google_ad_type = "text_image";
//var google_ad_channel ="8979238199";

// declare ad vars
//var google_ad_format;
//var google_ad_width;
//var google_ad_height;
//var google_color_border;
//var google_color_bg; 
//var google_color_link;
//var google_color_url;
//var google_color_text;

var google_ad_client = "pub-3867839607390295";
var google_ad_slot;
var google_ad_width;
var google_ad_height;

function revads_display(options) {

	var debugReturn = {
		mode: null,
		internalAdName: null,
		divisionName: null,
		googleAdSlot: null,
		googleAdPalette: null
	};

	var hostnameToDivisionMap = {
		"the3rdage.net": "t3a",
		"iceforge.net": "if",
		"petrolution.net": "petro",
		"cncguild.net": "cnc"
	}
	
	if (!options) options = {};

	// define formats
	var					KEY_WIDTH = 0,	KEY_HEIGHT = 1;
	var formats = {
			"468x60":	[468,			60],
			"728x90":	[728,			90],
			"120x600":	[120,			600],
			"160x600":	[160,			600]
	};

	// pick a format
	var fmt;
	var format = options.format;
	if (format && format != null) {
	} else {
		format = "728x90";
	}
	fmt = formats[format];
	
	// choose ad type
	var choice = Math.random();
	
	// INTERNAL ADS
	if ((options.forceInteral || choice < 0.3) && format == "728x90") {

		debugReturn.mode = "internal";

		var KEY_CHANCE = 0,	KEY_NAME = 1,		KEY_IMG = 2,									KEY_LINK = 3;
		var internalAds = [
			[2,		"donate",		"http://ads.revora.net/static/banners/donate.png",				"http://revora.net/donate"]
		//	[1,		"dwarfholds",		"http://ads.revora.net/static/banners/tdh-release.jpg",				"http://tdh.the3rdage.net"],
		//	[1,		"mandalorians", 	"http://ads.revora.net/static/banners/riseofthemandalorians_4_banner.jpg",	"http://forums.revora.net/index.php?showtopic=77407"]
		]

		var img;
		var lnk;

		// sum up total chances of ads
		var totalChoice = 0;
		for (var i in internalAds) {
			totalChoice += internalAds[i][KEY_CHANCE];
		}

		// determine ad choice
		choice = Math.random() * totalChoice;
		var c = 0;
		for (var i in internalAds) {
			var ad = internalAds[i];
			c+=ad[KEY_CHANCE];
			if (choice <= c) {
				debugReturn.internalAdName = ad[KEY_NAME];
				img = ad[KEY_IMG];
				lnk = ad[KEY_LINK];
				break;
			}
		}

		// write ad
		document.write('<div style="width: '+fmt[KEY_WIDTH]+'px; height: '+fmt[KEY_HEIGHT]+'px;"><a href="'+lnk+'"><img style="border: 0;" src="'+img+'" /></a></div>');
	}

	// GOOGLE ADS
	else {

		debugReturn.mode = "google";

		// define Google Ad Types
		var googleAdTypes = [
			["120x600",		"cnc",		"seaside",	"1933425150"],
			["160x600",		"cnc",		"seaside",	"9127782000"],
			["468x60",		"cnc",		"seaside",	"0055021998"],
			["728x90",		"cnc",		"seaside",	"9857297639"],
			["120x600",		"if",		"seaside",	"4307887995"],
			["160x600",		"if",		"seaside",	"2199656823"],
			["468x60",		"if",		"seaside",	"8471957581"],
			["728x90",		"if",		"seaside",	"8011812308"],
			["120x600",		"petro",	"seaside",	"1156974296"],
			["160x600",		"petro",	"seaside",	"3116963183"],
			["468x60",		"petro",	"seaside",	"4788484796"],
			["728x90",		"petro",	"seaside",	"9993408356"],
			["120x600",		"revora",	"seaside",	"0526777153"],
			["160x600",		"revora",	"seaside",	"7321579445"],
			["468x60",		"revora",	"seaside",	"5796220972"],
			["728x90",		"revora",	"seaside",	"0789266461"],
			["120x600",		"t3a",		"seaside",	"6484438937"],
			["160x600",		"t3a",		"seaside",	"7625491066"],
			["468x60",		"t3a",		"seaside",	"7053218462"],
			["728x90",		"t3a",		"seaside",	"2381019310"]
		];

		google_ad_width = fmt[KEY_WIDTH];
		google_ad_height = fmt[KEY_HEIGHT];

		if (options.googleAdSlot) {
			google_ad_slot = options.googleAdSlot;
		} else {

			var division;
			if (options.division) {
				division = options.division;
				if (division != "t3a" && division != "cnc" && division != "petro" && division != "if") division = "revora";
			} else {
				division = "revora";
				var hn = window.location.hostname;
				for (var d in hostnameToDivisionMap) {
					if (hn.length < d.length) continue;
					if (hn.substr(hn.length - d.length) == d) {
						division = hostnameToDivisionMap[d];
						break;
					}
				}
			}

			debugReturn.divisionName = division;

			var adType = null;
			for (var i in googleAdTypes) {
				var typ = googleAdTypes[i];
				if (typ[0] == format && typ[1] == division) {
					adType = typ;
					break;
				}
			}

			if (adType != null) {
				google_ad_slot = adType[3];
				debugReturn.googleAdPalette = adType[2];
			}

		}

		debugReturn.googleAdSlot = google_ad_slot;

		// show google ads
		document.write('<scr'+'ipt type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></scr'+'ipt>');

	}

	return debugReturn;

	/*
	// AMAZON
	else if (choice < 0.4 && (format == "728x90" || format == "120x600")) {
	
		if (format == "120x600") {
			document.write('<iframe src="http://rcm.amazon.com/e/cm?t=revora-20&o=1&p=29&l=ur1&category=game_downloads&banner=1R7B1N4E97Z234TK4G82&f=ifr" width="120" height="600" scrolling="no" border="0" marginwidth="0" style="border:none;" frameborder="0"></iframe>');
		} else {
			document.write('<iframe src="http://rcm.amazon.com/e/cm?t=revora-20&o=1&p=48&l=ur1&category=game_downloads&banner=07YBAJRZ4ZYJNPDJS3G2&f=ifr" width="728" height="90" scrolling="no" border="0" marginwidth="0" style="border:none;" frameborder="0"></iframe>');
		}

	}
	*/
   

}

