/****************
Static yahooHandler class
****************/

function yahooHandler () {}

//Static method to determine if referrer is yahoo
yahooHandler.isReferrer = function ()
{
	if (document.referrer && document.referrer.indexOf('http://www.yahoo.com/') == 0)
	{
		return true;	
	}
	
	return false;
}


//Validate a channel
yahooHandler.validateChannel = function (ch)
{
	//Init vars
	var valid = "www"; //Default to www
	var valid_channels = new Array (
		"auto", "computer", "electronics",
		"entertainment", "food", "health", "home",
		"mobiltravelguide", "money", "people",
		"recipes", "science", "travel", "www",
		"reference"
	);
	
	for (var chValue in valid_channels)
	{
		if (valid_channels[chValue] == ch)
		{
			valid = ch;
			break;
		}
	}

	return valid;
}

//Method to couple with isYahooReferred
yahooHandler.serveAd = function (adPosition)
{
	var adCode     = '';
	var client     = '';
	var googleCode = '';
	var googleData = null;

	switch (adPosition)
	{
		case 'Google1':
			client = 'howstuffworks';
			googleData = {
				google_ad_output   : "'js'",
				google_ad_client   : "'howstuffworks_rs_2_js'",
				google_ad_channel  : "ch",
				google_safe        : "'high'",
				google_max_num_ads : "'3'",
				google_skip        : 3,
				google_ad_type     : "'text'",
				google_ad_section  : "'content'"
			}
			adCode = "function google_ad_request_done(ads) {   	if (google_ads.length == 0) {   return;    	}    t = '<table cellpadding=\"0\" cellspacing=\"0\" style=\"width: 300px; font-family: verdana,sans-serif; font-size: 12px; color: #888888; text-align: left;\" ><tr><td>'					+'<div style=\"padding: 0px; font-weight: bold; padding-left: 7px; color: #666666;\" >&nbsp;Ads by Google</div>' 					+'<ul style=\"font-weight: normal; color: #686868;  list-style-type: none; margin-left: 5px; margin-bottom: 7px; margin-top: -8px; margin-right: 2px; padding-left: 5px; padding-right: 2px; list-style-image: none;\" >';				if ((google_ads.length == 1) && (google_ads.bidtype == \"CPM\")) {					t += '<li style=\"margin-top: 20px\"><a href=\"' + google_ads[0].url + '\" ' 					+ 'onmouseout=\"window.status=\\\'\\\'\" onmouseover=\"window.status=\\\'go to ' 					+ google_ads[0].visible_url + '\\\'; return true\" style=\"text-decoration:none\">' 					+ '<span style=\"text-decoration:underline;color:blue; font-size:14px\">' 					+ '<b>' + google_ads[0].line1 + '</b><br></span></a>' 					+ '<span style=\"color:#000000;font-size:14px\">' + google_ads[0].line2 + '&nbsp;' 					+ google_ads[0].line3 + '</span><br>' 					+ '<a href=\"' + google_ads[0].url + '\" ' 					+ 'onmouseout=\"window.status=\\\'\\\'\" onmouseover=\"window.status=\\\'go to ' 					+ google_ads[0].visible_url + '\\\'; return true\" style=\"text-decoration:none\"><span style=\"color:#888888;font-size:12px\">' 					+ google_ads[0].visible_url + '</span></a></li>';				} else {					for(i = 0; i < google_ads.length; ++i) {					    t += '<li style=\"margin-top: 10px\"><a target=\"gslp\" href=\"' + google_ads[i].url + '\" ' 					    + 'onmouseout=\"window.status=\\\'\\\'\" onmouseover=\"window.status=\\\'go to ' 					    + google_ads[i].visible_url + '\\\';return true\" style=\"text-decoration:none\">' 					    + '<span style=\"text-decoration:none;color:#181C80; font-weight: bold;\">' 					    + google_ads[i].line1 + '<br></span></a>' 					    + '<span style=\"color:#000000\">' + google_ads[i].line2 + '&nbsp;' 					    + google_ads[i].line3 + '</span><br><a target=\"gslp\" href=\"' + google_ads[i].url + '\" ' 					    + 'onmouseout=\"window.status=\\\'\\\'\" onmouseover=\"window.status=\\\'go to ' 					    + google_ads[i].visible_url + '\\\';return true\" style=\"text-decoration:none\"><span style=\"color: #181C80\">' 					    + google_ads[i].visible_url + '</span></a><br></li>';					}				}    				t += '</ul></div></td></tr>'					+ '<tr><td><div style=\"padding-left: 10px; padding-bottom: 25px; color: #666666;\" ><a href=\"https://adwords.google.com/select/OnsiteSignupLandingPage?client=ca-howstuffworks_rs_2_js&referringUrl=howstuffworks.com\">Advertise on this site</a></div></td></tr></table>';    				document.write(t);  				} 				var ads = new Array;";
			break;

		case 'Google2':
			client = 'howstuffworks';
			googleData = {
				google_ad_output    : "'js'",
				google_ad_client    : "'howstuffworks_rs_js'",
				google_ad_channel   : "ch",
				google_safe         : "'high'",
				google_max_num_ads  : "'3'",
				google_skip         : 0,
				google_ad_section   : "'content'",
				google_ad_type      : "'text'"
			}
			adCode = "function google_ad_request_done(ads) {    if (google_ads.length == 0) {       return;    }    t = '<table cellpadding=\"0\" cellspacing=\"0\" style=\"border-color: #686868; width: 430px; font-family: verdana,sans-serif; font-size: 12px; color: #000000; text-align: left;\" ><tr><td>'+'<div style=\"position: bottom; padding: 0px; font-weight: bold\">&nbsp;Ads by Google</div>' +'<hr color=\"blue\"><ul style=\"font-weight: normal; color: #686868;  list-style-type: none; margin-left: 2px; margin-bottom: 17px; margin-top: 2px; margin-right: 2px; padding-left: 1px; padding-right: 2px; list-style-image: none;\" >';     for(i = 0; i < google_ads.length; ++i) {        t += '<li style=\"margin-top: 10px;\"><a target=\"gslp\" href=\"' + google_ads[i].url + '\" ' +                            'onmouseout=\"window.status=\\\'\\\'\" ' +                            'onmouseover=\"window.status=\\\'go to ' +                            google_ads[i].visible_url + '\\\'; return true\" ' +                            'style=\"text-decoration:none\">' +                            '<span style=\"text-decoration:underline;color:blue\">' +                            '' + google_ads[i].line1 + '<br></span></a>' +                             '<span style=\"color:#000000\">' +                             google_ads[i].line2 + '&nbsp;' +                            google_ads[i].line3 + '</span><br>' +                            '<a target=\"gslp\" href=\"' + google_ads[i].url + '\" ' +                            'onmouseout=\"window.status=\\\'\\\'\" ' +                            'onmouseover=\"window.status=\\\'go to ' +                            google_ads[i].visible_url + '\\\'; return true\" ' +                            'style=\"text-decoration:none\"><span style=\"color:#888888\">' +                            google_ads[i].visible_url + '</span></a><br></li>';    }    t += '</ul></div></td></tr></table>';    document.write(t);  } var ads = new Array;";
			break;

		case 'MedRect':
		case 'MedRectHome':
			client = 'ca-howstuffworks_rs_300x250';
			googleData = {
				google_ad_client    : "'howstuffworks_rs_300x250'",
				google_ad_width     : 300,
				google_ad_height    : 250,
				google_ad_format    : "'300x250_pas_abgnc'",
				google_safe         : "'high'",
				google_ad_channel   : "ch",
				google_color_bg     : "'FFFFFF'",
				google_color_border : "'990000'",
				google_ad_section   : "'content'",
				google_ad_type      : "'image_flash'"
			}
			break;

		case 'Tower':
			client = 'ca-howstuffworks_rs_120x600';
			googleData = {
				google_ad_client    : "'ca-howstuffworks_rs_160x600'",
				google_ad_width     : 160,
				google_ad_height    : 600,
				google_ad_format    : "'160x600_pas_abgnc'",
				google_safe         : "'high'",
				google_ad_channel   : "ch",
				google_color_bg     : "'FFFFFF'",
				google_color_border : "'990000'",
				google_ad_type      : "'image_flash'"
			}
			break;

		case 'TopBanner':
		case 'TopHome':
		case 'BotBanner':
			client = 'ca-howstuffworks_rs_728x90';
			googleData = {
				google_ad_client    : "'ca-howstuffworks_rs_728x90'",
				google_ad_width     : 728,
				google_ad_height    : 90,
				google_ad_format    : "'728x90_pas_abgnc'",
				google_safe         : "'high'",
				google_ad_channel   : "ch",
				google_color_bg     : "'FFFFFF'",
				google_color_border : "'000099'",
				google_ad_type      : "'image_flash'",
				google_ad_section   : "'content'"
			}
			break;

		//Don't display anything.
		default:
			return;
			break;
	}

	//Build out google adsense code info.
	for (var key in googleData)
	{
		googleCode += key + " = " + googleData[key] + ";\n";
	}

	//Write google adsense client details and additional ad code.
	document.write(
		"<script type=\"text/javascript\" language=\"JavaScript\"><!--\n" +
		adCode + "\n\n" +
		"chRA=document.domain.split(\".\");\n" +
		"ch = yahooHandler.validateChannel(chRA[0]);\n" +
		googleCode + "\n" +
		"//--></script>"
	);

	//Write js/image inclusion
	document.write("<script type=\"text/javascript\" language=\"JavaScript\" src=\"http://pagead2.googlesyndication.com/pagead/show_ads.js\"></script>\n");
	document.write(
		"<noscript>\n" +
		"	<img height=1 width=1 border=0 src=\"http://pagead2.googlesyndication.com/pagead/imp.gif?client=" + client + "&event=noscript\"/>\n" +
		"</noscript>\n"
	);

}