// find page type
var queries=OAS_query.split('&'),page_type='';
for(var q=0;q<queries.length;q++){
  var query=queries[q].split('=');
  if(query[0]=='pagetype'){page_type=query[1];break;}
	}

// set page_type
if (page_type=='article_page'){
  var suffix='_article';
  }
  else if (page_type=='photo_gallery'){
  var suffix='_gallery';
  }
  else
  {
  var suffix='_other';
  }

//now find the section from oas: split the sitepage, then match the big list
var spsplit=OAS_sitepage.split('/');
if(spsplit.length>2) {var section=spsplit[1]+'_'+spsplit[2]}
else {var section=spsplit[1]}

// adjust a couple of names
if (section =='travel_NET') {section='travel_newengland'}
else if (spsplit[1]=='bostonworks') {spsplit[1]='jobs'}
else if (spsplit[2]=='redsox') {section='sports_baseball'}
else if (spsplit[2]=='patriots') {section='sports_football'}
else if (spsplit[2]=='celtics') {section='sports_basketball'}
else if (spsplit[2]=='bruins') {section='sports_hockey'}
else if (spsplit[2]=='hyperlocal') {section='yourtown'}
else if (spsplit[2]=='dining') {section='ae_restaurants'}
else if (spsplit[2]=='family') {section='lifestyle_moms'}
else if (spsplit[2]=='health') {section='news_health'}
else if (spsplit[1]=='yourlife') {section='lifestyle_'+spsplit[2];spsplit[1]='lifestyle';}
var validchannels = "news|news_local|news_globe|news_nation|news_health|news_science|news_world|news_politics|news_education|business|business_finance|business_technology|sports|sports_baseball|sports_football|sports_basketball|sports_hockey|sports_soccer|sports_college|sports_highschool|lifestyle|lifestyle_home|lifestyle_green|lifestyle_food|lifestyle_relationships|lifestyle_weddings|lifestyle_moms|lifestyle_fashion|lifestyle_photos|ae|ae_restaurants|ae_music|ae_movies|ae_celebrity|ae_tv|ae_books|ae_arts|thingstodo|travel|travel_newengland|travel_boston|travel_getaways|cars|cars_news|cars_research|jobs|realestate|realestate_news|yourtown";
var channel = validchannels.match(section);

//backup tries
if (channel==null) {channel = validchannels.match(spsplit[1])}
if (channel==null) {channel = 'other'}

var google_ad_channel=channel+suffix,google_hints='',ad_test='';

function google_ad_request_done(ads)
{
	var s='';
	if(ads.length==0)
		return;

	s += '<div id="adSenseContainer"><div id="adSenseHeaderGray"><div class="adsBy">Ads by Google</div><div class="whatIs"><a href="http://www.boston.com/help/linksqa_text/" onClick="window.open(\'\',\'popupad\',\'width=400,height=400,resizable=yes,scrollbars=yes,toolbar=no,location=no,menubar=no,status=no\')" target="popupad" class="et">what\'s this?</a></div></div><div id="adSenseActual">';

	for(var i=0;i<ads.length;++i)
	{
		s+='<div class="adWrap" ><a id="aw0" class="adUrl" target="_blank" href="'+ads[i].url+'"><b>'+ads[i].line1+'</b></a><br><div class="adBody" onClick="window.open(\'' + ads[i].url + '\',\'popupad\',\'\');">'+ads[i].line2+' '+ads[i].line3+'</div>'+'<a id="aw0" class="adUrl" target="_blank" href="' + ads[i].url + '">' + ads[i].visible_url+'</a></div>';
	}
	s+='</div></div>';
	document.write(s);
	return;
}
var google_ad_output='js',google_max_num_ads='3',google_ad_client='ca-boston_js',google_safe='high',google_ad_section='default';
//section-specific changes
switch(section){
    case 'sports_baseball':google_hints='MLB Merchandise, Red Sox,-Yankees';break;
    case 'lifestyle_moms':google_max_num_ads='5';break;
    case 'lifestyle_food':google_hints='recipes';
    }

//start test
if (location.href.search('/overdrive/') > 0 || location.href.search('/tv/blog') > 0)
	{if (Math.random() > .5)
	   {document.write('<style>.adWrap {background-color:#ffffff}</style>');
	   google_ad_channel +=', test3';
	   } else {
	   google_ad_channel +=', test4';
	   }
	}
//start test
if (section=='yourtown')
	{if (Math.random() > .5)
	   {google_hints=trustedTown + ', MA';
	   google_ad_channel +=', test5';
	   } 
	}
if (google_ad_channel=='lifestyle_food_article')
	{if (Math.random() > .5)
	   {google_ad_channel +=', test6';
	   } else {
	   google_ad_channel +=', test7';
	   ad_test='food';
	   }
	}
document.write('<!--s:'+section+' c:'+google_ad_channel+' h:'+google_hints+'-->');
