function getParameter ( queryString, parameterName ) {
   // Add "=" to the parameter name (i.e. parameterName=value)
   var parameterName = parameterName + "=";
   if ( queryString.length > 0 ) {
      // Find the beginning of the string
      begin = queryString.indexOf ( parameterName );
      // If the parameter name is not found, skip it, otherwise return the value
      if ( begin != -1 ) {
         // Add the length (integer) to the beginning
         begin += parameterName.length;
         // Multiple parameters are separated by the "&" sign
         end = queryString.indexOf ( "&" , begin );
      if ( end == -1 ) {
         end = queryString.length
      }
      // Return the string
      return unescape ( queryString.substring ( begin, end ) );
   }
   // Return "null" if no parameter has been found
   return "null";
   }
}

$(document).ready(function() 
		{
			var adCatName = []; var adDomain = []; var adFb = []; var adHost = [];
			adCatName[5646] = 'Announcements'; adDomain[5646] = '/Announcements/browse.aspx'; adFb[5646] = '87';
			adCatName[6247] = 'Apparel'; adDomain[6247] = '/Apparel/browse.aspx';	adFb[6247] = '89';
			adCatName[5960] = 'Automotive & Boating'; adDomain[5960] = '/Automotive-and-Boating/browse.aspx'; adFb[5960] = '90';
			adCatName[5961] = 'Books & Magazines'; adDomain[5961] = '/Books-and-Magazines/browse.aspx'; adFb[5961] = '91';
			adCatName[1020] = 'Camera & Photo'; adDomain[1020] = '/Camera-and-Photo/browse.aspx'; adFb[1020] = '92';
			adCatName[1021] = 'Computer'; adDomain[1021] = '/Computer/browse.aspx'; adFb[1021] = '93';
			adCatName[1022] = 'Electronics'; adDomain[1022] = '/Electronics/browse.aspx'; adFb[1022] = '94';
			adCatName[940] = 'Employment'; adDomain[940] = '/Employment/browse.aspx'; adFb[940] = '95';
			adCatName[942] = 'Entertainment & Party'; adDomain[942] = '/Entertainment-and-Party/browse.aspx'; adFb[942] = '96';
			adCatName[1024] = 'Flowers & Gifts'; adDomain[1024] = '/Flowers-and-Gifts/browse.aspx'; adFb[1024] = '97';
			adCatName[943] = 'Groceries'; adDomain[943] = '/Groceries/browse.aspx'; adFb[943] = '98';
			adCatName[944] = 'Health & Personal Care'; adDomain[944] = '/Health-and-Personal_Care/browse.aspx'; adFb[944] = '99';
			adCatName[1026] = 'Home & Garden'; adDomain[1026] = '/Home-and-Garden/browse.aspx'; adFb[1026] = '100';
			adCatName[1027] = 'Jewelry & Watches'; adDomain[1027] = '/Jewelry-and-Watches/browse.aspx'; adFb[1027] = '101';
			adCatName[5962] = 'Merchandise'; adDomain[5962] = '/Merchandise/browse.aspx'; adFb[5962] = '102';
			adCatName[1029] = 'Office Products'; adDomain[6247] = '/Office_Products/browse.aspx'; adFb[6247] = '103';
			adCatName[1030] = 'Pets & Animals'; adDomain[1030] = '/Pets-and-Animals/browse.aspx'; adFb[1030] = '104';
			adCatName[948] = 'Real Estate'; adDomain[948] = '/Real_Estate/browse.aspx'; adFb[948] = '105';
			adCatName[1031] = 'Services'; adDomain[1031] = '/Services/browse.aspx'; adFb[1031] = '106';
			adCatName[949] = 'Sports & Recreation'; adDomain[949] = '/Sports-and-Recreation/browse.aspx'; adFb[949] = '107';
			adCatName[1033] = 'Tools & Building Products'; adDomain[1033] = '/Tools-and-Building_Products/browse.aspx'; adFb[1033] = '108';
			adCatName[950] = 'Toys'; adDomain[950] = '/Toys/browse.aspx'; adFb[950] = '109';
			adCatName[1034] = 'Travel & Luggage'; adDomain[1034] = '/Travel-and-Luggage/browse.aspx'; adFb[1034] = '110';
			
			adHost[67] = 'daytondailynews';
			adHost[69] = 'middletownjournal';
			adHost[70] = 'springfieldnewssun';
			adHost[68] = 'journalnews';
			adHost[72] = 'pulsejournal';
			adHost[73] = 'westernstar';
			adHost[74] = 'oxfordpress';
			adHost[71] = 'fairfieldecho';
			
			var adGet = window.top.location.search.substring(1);
			var adCat = getParameter(adGet,'categoryid');
			var adChannel = getParameter(adGet,'channelid');
			if (adChannel == '67')
			{
				var adTitle = $("table > tbody > tr > td > span:first").text();
				var publishDate = $("table > tbody > tr > td > span:last").text();
				var adLinks = $("div.item-buttons:eq(1)").html();
				var adImg = $("td.itemdisplay:eq(0)").html();
				var adImgHeight = $("td.itemdisplay:eq(0) > img").height()-20;
				var adImgWidth = $("td.itemdisplay:eq(0) > img").width();
				var adFeedWidth = 775-adImgWidth;
				
				var adInfo = $("td.itemdisplay:eq(1)").html();
				$("div.item-buttons:eq(0)").before('<div id="start-ad-page" style="text-align:left;"><div style="font-size:20pt;color:#2e2e2e;font-weight:bold;">'+adTitle+'</div><div style="font-size:9pt;color:#2e2e2e;">&nbsp;<a href="http://'+adHost[adChannel]+'.shopmountain.com/Shopping/Shop'+adDomain[adCat]+'" style="color:#0079c8;">'+adCatName[adCat]+'</a>&nbsp;|&nbsp;'+publishDate+'</div><div style="border-bottom: 1px solid #bbb;"></div><div style="margin-bottom:20px;margin-top:20px;float:left;">'+adImg+'</div><div class="feedbotAd" style="margin-bottom:20px;;margin-top:20px;margin-left:20px;float:left;"><div style="border-bottom: 1px solid #bbb;margin-bottom:5px;font-weight:bold;color:#2e2e2e;">Related Ads...<a href="http://'+adHost[adChannel]+'.shopmountain.com/Shopping/Shop'+adDomain[adCat]+'" style="color:#0079c8;font-size:9pt;">show more</a></div><iframe src="http://www.feedbotapp.com/widget/html/'+adFb[adCat]+'?harvestdealchannel='+adChannel+'" height="250px" width="450px" scrolling="auto" frameborder="0"></iframe></div><div style="clear:both;"><div style="border-bottom: 1px solid #bbb;"></div><div class="ad-link-list" style="float:left;width:15%;margin-top:8px;">'+adLinks+'</div><div style="float:left;font-size:9pt;width:80%;">'+adInfo+'</div><div style="clear:both;"></div></div>');
				$("div.item-buttons:eq(0)").empty();
				$("div.item-buttons:eq(0)").remove();
			}
			
		});
