Thumb

Pooflinger's Mousehuntizer

By Pooflinger Last update 6 hours ago — Installed 23,813 times. Daily Installs: 127, 163, 159, 172, 152, 129, 172, 132, 147, 120, 118, 149, 206, 150, 163, 137, 128, 108, 111, 140, 112, 119, 127, 106, 75, 120, 76, 121, 311, 411, 444, 319

There are 40 previous versions of this script.

the source is over 100KB, syntax highlighting in the browser is too slow

// ==UserScript==
// @name Pooflinger's Mousehuntizer
// @namespace		Pooflinger
// @description		Enhance Facebook with Mousehunt Experience!
// @include        	http://*.facebook.com/*
// @include        	http://furoma.com/*
// @author 		   Peter Limpiyawon - peter [at] furoma.com

// ==/UserScript==
//===============================================================================

//* normal version
var source_location = "http://userscripts.org/scripts/source/37906.user.js"; // "http://userscripts.org/scripts/show/37906"; 
var version_holder = "http://furoma.com/mousehuntizer/version.txt"; 
var CONFIG_URL='http://furoma.com/mousehuntizer';
var is_config_page = (
	document.location.href.indexOf('furoma.com/mousehuntizer')!=-1 && 
	document.location.href.indexOf('rev.html')==-1 &&
	document.location.href.indexOf('template.html')==-1);
//*/

/* beta version
var source_location = "http://furoma.com/mousehuntizer/mousehuntizer.user.js"; 
var version_holder = "http://furoma.com/mousehuntizer/betaversion.txt"; 
var CONFIG_URL='http://furoma.com/mousehuntizer/beta.html';
var is_config_page = (
	document.location.href.indexOf('furoma.com/mousehuntizer/beta')!=-1 	//beta
);
	
if (window.location.href=='http://furoma.com/mousehuntizer/' ||
	window.location.href.indexOf('http://furoma.com/mousehuntizer/?')==0)
	window.location.href='http://furoma.com/mousehuntizer/beta.html';
//*/

var your_version = '0.4.3';	

var usr_debug = GM_getValue('usr_debug', false);
var usr_chk_fr = GM_getValue('usr_chk_fr', false);
var usr_chk_pt = GM_getValue('usr_chk_pt', false);
var usr_chk_rk = GM_getValue('usr_chk_rk', false);
//var usr_chk_k = GM_getValue('usr_chk_k', true);
var usr_chk_k = true;
var usr_ld_msg = GM_getValue('usr_ld_msg', true);

var usr_chk_ls = GM_getValue('usr_chk_ls', false);
var usr_chk_lp = GM_getValue('usr_chk_lp', false);
var usr_chk_bs = GM_getValue('usr_chk_bs', false);
var usr_chk_cr = GM_getValue('usr_chk_cr', false);
var usr_chk_bl = GM_getValue('usr_chk_bl', false);
var usr_chk_tp = GM_getValue('usr_chk_tp', false);

var usr_chk_tm_mh = GM_getValue('usr_chk_tm_mh', true);
var usr_chk_tm_fb = GM_getValue('usr_chk_tm_fb', false);
var usr_chk_tm_pos = GM_getValue('usr_chk_tm_pos', 'float box');
var usr_rm_fb = GM_getValue('usr_rm_fb', true);
var usr_rm_pf = GM_getValue('usr_rm_pf', false);

var usr_mh_mn = GM_getValue('usr_mh_mn', true);
var usr_fb_mhz = GM_getValue('usr_fb_mhz', false);	//BETA
var usr_mh_sc = GM_getValue('usr_mh_sc', true);		//RETIRED
var usr_mh_ss = GM_getValue('usr_mh_ss', false);		//BETA	enable maid
var usr_mh_sm = GM_getValue('usr_mh_sm', false);		//BETA	smart maid
var usr_delay = GM_getValue('usr_delay', 5);

var usr_chk_tm_alarm = GM_getValue('usr_chk_tm_alarm', false);
var usr_chk_tm_alarm_file = GM_getValue('usr_chk_tm_alarm_file', 'dingdongmale.wav');
var usr_chk_tm_alarm_wmp = GM_getValue('usr_chk_tm_alarm_wmp', true);
var usr_chk_tm_alarm_vol = GM_getValue('usr_chk_tm_alarm_vol', 40);
var usr_chk_tm_alarm_cnfm = GM_getValue('usr_chk_tm_alarm_cnfm', true);
var usr_chk_tm_title = GM_getValue('usr_chk_tm_title', true);
var usr_chk_tm_update = GM_getValue('usr_chk_tm_update', 5);

function str2xml(strXML) { 
		//create a DOMParser
		var objDOMParser = new DOMParser();
		//create new document from string
		var objDoc = objDOMParser.parseFromString(strXML, "text/xml");
		return objDoc;
	}

function xfm_title(x)
{
if (x == 'lord' || x == 'lady')
	return 'lord/lady';
if (x == 'baron' || x == 'baroness')
	return 'baron/baroness';
return x;					
}

function xfm_cheese(x)
{
return x.replace(/Havarti - (.+) \((.+)\)/,'$1 Havarti')
	.replace(/Havarti - (.+)/,'$1 Havarti')
	.replace('SUPER|brie+','Super Brie');
}

//******************************************************
//The gup function is copied from http://www.netlobo.com/url_query_string_javascript.html
//******************************************************

function gup(str, name)
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( str );
  if( results == null )
    return "";
  else
    return results[1];
}

function xpathFirst(p, c) {
  return document.evaluate(p, c || document, null, XPathResult.ANY_UNORDERED_NODE_TYPE, null).singleNodeValue;
}

function xpath(query, element) {
  var element = (element == null) ? document : element;
  return document.evaluate(query, element, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
}

function setHTML(is_append, ele_id, text)
{
/*
	var allLinks;
	allLinks = document.evaluate(
    	'//*[@id='+ele_id+']',
    	document,
    	null,
    	XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
    	null);
	for (var i = 0; i < allLinks.snapshotLength; i++) 
    		allLinks.snapshotItem(i).innerHTML = text;
*/
	var tag2search = (ele_id.indexOf('fb_link')==-1)? 'span':'a';

	var obj = document.getElementsByTagName(tag2search); 
	// use document.getElementsByTagName('*'); also works but slower

	for (var i=0; i<obj.length; i++)
		if (obj[i].getAttribute('id')==ele_id)
			obj[i].innerHTML = (is_append)? obj[i].innerHTML+text:text;

}

function poo_link(link_objekt, objekt, fb_id, link_id)
	{

	for (i=0; i<link_id; i++)
		if (fb_id_array[i]==fb_id)
			return;

	var is_MHer;

	/**************************************************/
	// poo_objekt id="poo"+link_id (contains green links)

	// link_objekt id="fb_link"+fb_id (contains badge and name)
	// objekt id="mh"+fb_id (contains point and friend info)
	// id="mh_only"+fb_id (within poo_objekt) 
	/**************************************************/

setHTML (0, "mh_info"+fb_id, "");

//CASE 1: CHECK NOTHING*************************************************
if (!usr_chk_pt && !usr_chk_rk && !usr_chk_fr)
	return;

//CASE 2: CHECK FRIENDS ONLY*************************************************
else if (!usr_chk_pt && !usr_chk_rk && usr_chk_fr)
	GM_xmlhttpRequest({
    	method: 'GET',
    	url: 'http://www.facebook.com/addfriend.php?id='+fb_id,
   	 headers: {
        	'User-agent': 'Mozilla/4.0 (compatible) Greasemonkey',
        	'Content-type':'application/x-www-form-urlencoded',
    		},
    	onload: function(responseDetails) {
       		var res = responseDetails.responseText;

		if (res.indexOf('<h2 class="main_message" id="standard_error">')==-1)
			{
			
			setHTML (1, "mh_info"+fb_id, " <A href=http://www.facebook.com/addfriend.php?id="+fb_id+"><FONT color=grey>(not friend)</FONT></A>");
			setHTML (0, "mh_friend"+fb_id, ""); //CANNOT SEND SUPPLIES
				
			
			}
		else
			setHTML (1, "mh_info"+fb_id, " <FONT color=darkblue>(friend)</FONT>");

		}
	});


//CASE 3: CHECK POINTS OR RANK *************************************************
else
	GM_xmlhttpRequest({
    	method: 'GET',
    	url: 'http://apps.facebook.com/mousehunt/hunterprofile.php?snuid='+fb_id,
   	 headers: {
        	'User-agent': 'Mozilla/4.0 (compatible) Greasemonkey',
        	'Content-type':'application/x-www-form-urlencoded',
    		},
    	onload: function(responseDetails) {
       		var res = responseDetails.responseText;

		is_MHer = true;		
		
		//alert("displaying "+fb_name);

		if (res.indexOf("Hunting Since")==-1)
			{
			is_MHer = false;
			setHTML (0, "mh_info"+fb_id, " (<A href=http://apps.facebook.com/mousehunt/invite.php title=Invite><FONT color=red>not MHer</FONT></A>)");
			setHTML (0, "mh_only"+fb_id, "<A href=http://apps.facebook.com/mousehunt/invite.php>invite</A> | ");
			
			setHTML (0, "mh_friend"+fb_id, "");
			}
		else
			{
			//var mh_start_date = res.match(/<li><span class=["]label["]>Hunting Since<[/]span>: (.+)<[/]li>/)[1];
			var mh_title = res.match(/<li><span class=["]label["]>Hunter&rsquo;s Title<[/]span>: (.+)<[/]li>/)[1].replace(/ /g,"");
			var mh_pure_title = mh_title.match(/(.+)[(]/)[1].toLowerCase().replace('/','');

			var mh_point = res.match(/<li><span class=["]label["]>Points<[/]span>: (.+)<[/]li>/)[1];
			var mh_gold = res.match(/<li><span class=["]label["]>Gold<[/]span>: (.+)<[/]li>/)[1];

			if (usr_chk_rk)
			setHTML (0, "fb_link"+fb_id, "<IMG src=http://mousehunt.hitgrab.com/mousehunt/images/icons/titles/" +
						mh_pure_title+ ".gif alt=" +mh_pure_title+ " border=0> " + link_objekt.innerHTML);
			if (usr_chk_pt)
			setHTML (0, "mh_info"+fb_id, " ("+mh_point+" pts)");

			}
			

		
	///////////////////////////////// friend check

	if (usr_chk_fr)

	GM_xmlhttpRequest({
    	method: 'GET',
    	url: 'http://www.facebook.com/addfriend.php?id='+fb_id,
   	 headers: {
        	'User-agent': 'Mozilla/4.0 (compatible) Greasemonkey',
        	'Content-type':'application/x-www-form-urlencoded',
    		},
    	onload: function(responseDetails) {
       		var res = responseDetails.responseText;

		//if (res.indexOf("You are already friends with")==-1) only for English localizations
		
		if (res.indexOf('<h2 class="main_message" id="standard_error">')==-1)
			{
			if (is_MHer)
				{
				setHTML (1, "mh_info"+fb_id, " <A href=http://www.facebook.com/addfriend.php?id="+fb_id+"><FONT color=grey>(not friend)</FONT></A>");
				setHTML (0, "mh_friend"+fb_id, ""); //CANNOT SEND SUPPLIES
				}
			else // CANNOT INVITE!!!!!
				{
				setHTML (0, "mh_info"+fb_id, " (<FONT color=red>not MHer</FONT>) <A href=http://www.facebook.com/addfriend.php?id="+fb_id+"><FONT color=grey>(not friend)</FONT></A>");
				setHTML (0, "mh_only"+fb_id, "");
				}

			}
		else
			setHTML (1, "mh_info"+fb_id, " <FONT color=darkblue>(friend)</FONT>");

		}
	});

	//////////////////////////////

		}
	});

	
	}

var is_King;
var currentLocation = "";
var fb_id_array = new Array();
var mhzi=0;

function init_js_balloon()
{
if (typeof(unsafeWindow.disappeardelay)=='undefined')
	{
	var JS = document.createElement('script');
	JS.src = 'http://furoma.com/mousehuntizer/balloontip.js';
	JS.type = 'text/javascript';
	document.getElementsByTagName('head')[0].appendChild(JS);
	//document.body.appendChild(JS);
	//unsafeWindow.initalizetooltip();
	}
}

function js_balloon()
{
if (typeof(unsafeWindow.initalizetooltip)=='undefined')
	window.setTimeout(js_balloon, 100);
else
	unsafeWindow.initalizetooltip();
}

function poo_fb_mhz()
{
	

	if (!usr_fb_mhz)
		return;
		
	var ALINK = document.getElementsByTagName('a');
	/*
	var ALINK = document.evaluate(
		"//a[]",
		document,
		null,
		XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
		null); */
	
	
	var ALINK_found = false;
	
	//alert(document.location.href+' /  ' +ALINK.length);
	
	for (var i=0; i<ALINK.length /*snapshotLength*/; i++)
		{
		var fb_id;
		var fb_found=true;
		var this_link = ALINK[i];//ALINK.snapshotItem(i);
		
		//this_link.innerHTML=this_link.href;
		
		if (this_link.getAttribute('mhizer'))
			fb_found=false;
		else if (this_link.href.indexOf('facebook.com/profile.php?id=')!=-1)
			fb_id=gup(this_link.href,'id');
		else if (this_link.href.indexOf('facebook.com/mousehunt/hunterprofile.php?snuid=')!=-1)
			{
			if (this_link.getAttribute('where') && this_link.getAttribute('where')=='mhizer_menuFriends')
				fb_found=false;
			else
				fb_id=gup(this_link.href,'snuid');
			}
		else
			fb_found=false;
		
		
		if (!fb_found)
			continue;
			
			
			ALINK_found = true;
			this_link.setAttribute('rel','mhizer_balloon'+mhzi);
			//this_link.innerHTML+='+';
			
			var dd = document.createElement('div');
			dd.id='mhizer_balloon'+mhzi;
			
			
			
			dd.innerHTML=
			'<B>FB:</B> '+
			'<A mhizer=1 href=http://www.facebook.com/profile.php?id='+fb_id+'>profile</A>'+
			' | <A mhizer=1 href=http://www.facebook.com/inbox/?compose&id='+fb_id+'>message</A>'+
			' | <A mhizer=1 href=http://www.facebook.com/addfriend.php?id='+fb_id+'>add</A>'+
			' | <A mhizer=1 href=http://www.facebook.com/friends/?id='+fb_id+'>view friends</A>'+
			'<BR><B>MH:</B> '+
			'<A mhizer=1 href=http://apps.facebook.com/mousehunt/hunterprofile.php?snuid='+fb_id+'>profile</A>'+
			' | <A mhizer=1 href=http://apps.facebook.com/mousehunt/traderequest.php?snuid='+fb_id+'>trade SB</A>'+
			' | <A mhizer=1 href=http://apps.facebook.com/mousehunt/supplies.php?trade_recipient='+fb_id+'>give supplies</A>'+
			' | <A mhizer=1 href=javascript:; id=add_mh_friends'+mhzi+' add_mh='+fb_id+' add_mhn="'+
				((this_link.innerHTML.indexOf('<')==-1)? this_link.innerHTML:'') +'">add</A>'+
				
			
			'<BR><B>MH rank:</B> '+
			'<A mhizer=1 href=http://apps.facebook.com/mousehunt/scoreboard.php?seek='+fb_id+'&sort=points>point rank</A>'+
			' | <A mhizer=1 href=http://apps.facebook.com/mousehunt/scoreboard.php?seek='+fb_id+'&sort=gold>gold rank</A>'+
			' | <A mhizer=1 href=http://apps.facebook.com/mousehunt/scoreboard.php?seek='+fb_id+'&sort=mice>mice rank</A>';
			
			
			dd.setAttribute('class','balloonstyle');
			dd.style.width = '220px';
			
			// FIX for the NOTIFICATION AREA
			if(this_link.parentNode.getAttribute('class')=='UIImageBlock_Content UIImageBlock_ICON_Content')
				{
				dd.style.position = 'fixed';
				
				
				this_link.addEventListener("mouseover", function(){
					unsafeWindow.verticaloffset +=5;
					//$('arrowhead').style.position = 'fixed';
					}, false);
				
				this_link.addEventListener("mouseout", function(){
					unsafeWindow.verticaloffset -=5;
					//$('arrowhead').style.visibility='hidden';
					//$('arrowhead').style.position = 'absolute';
					}, false); 
				}
				
			document.body.appendChild(dd);
			
			// add click functionality to add mh friends
			//if (this_link.getAttribute('add_mh'))
				//{
				//Alll[i].id = 'add_mh'+i;
				//Alll[i].innerHTML = Alll[i].getAttribute('add_mh'); //DEBUG
				
				$('add_mh_friends'+mhzi).addEventListener("click", function(){
					
					//alert(mh_friends);
					
					var fb_id = this.getAttribute('add_mh');
					var nname = this.getAttribute('add_mhn');
					nname = dprompt('Give a nickname and add to your PF MH friend list.',nname);
					if (!nname)
						return;
					
					mh_friends.push(nname+'|'+fb_id);
					mh_friends.sort();
					GM_setValue('mh_friends',mh_friends.toString());
					
					display_mh_friends();
					
				
					}, false);
				

				//}

			
			
			mhzi++;
			
			
		}
	if (ALINK_found)
		init_js_balloon();
	//alert(currentLocation + ' *** ' + window.location.href);
	
	
	//if (currentLocation!="")
	js_balloon();


	currentLocation = window.location.href;
	

}

function is_forum_page()
{
//alert (document.location.href +' / '+ (document.location.href.indexOf('topic.php?') > document.location.href.indexOf('#')));

return (
(window.location.href.indexOf('/topic.php?') > window.location.href.indexOf('#'))
|| (window.location.href.indexOf('#/topic.php?')!=-1)
|| (window.location.href.indexOf('facebook.com/topic.php?') < window.location.href.indexOf('#post'))
|| (window.location.href.indexOf('facebook.com/topic.php?') < window.location.href.indexOf('#top'))
);

//document.location.href.indexOf('topic.php?')==-1 || 
}
function poo_party()
{

	if (window.location.href == currentLocation)
		return;

	
	if (!is_forum_page())
		{
		add_mh_friends();
		poo_fb_mhz();
		
			return;
		}

	
	
	currentLocation = window.location.href;
	show_rev();

	is_King = false; // King's reward check
	

	var newElement=document.createElement('style'); 
	newElement.innerHTML = ".poo {color:brown; display:none} .poo a {color:green}";
	document.body.appendChild(newElement);

	
	
	//************************* REMOVE FACEBOOK AJAX

	var allDivs;
	allDivs = document.evaluate(
	"//ul[@class='pagerpro']",
	document,
	null,
	XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
	null);

	if (allDivs.snapshotLength != 0)
		{
		allDivs = allDivs.snapshotItem(0);


		for (var i=1; i<allDivs.childNodes.length; i++)	
		allDivs.childNodes[i].innerHTML = allDivs.childNodes[i].innerHTML.replace(/onclick=(.+)[']>/g,'>');
		
		}
	
	
	//*/

	//************************ REPLY TO
	
	if ($('toggle_tabs_unused'))
	{
		var uid, topic, xid, app_id, sig, c_url, r_url;
		
		allDivs = $('toggle_tabs_unused').getElementsByTagName('a');
		for (var i=0; i<allDivs.length; i++)
			if (allDivs[i].innerHTML=='Topic View')
				{
				uid=gup(allDivs[i].href,'uid');
				topic=gup(allDivs[i].href,'topic');
				xid=gup(allDivs[i].href,'xid');
				app_id=gup(allDivs[i].href,'app_id');
				sig=gup(allDivs[i].href,'sig');
				c_url=gup(allDivs[i].href,'c_url');
				r_url=gup(allDivs[i].href,'r_url');
				break;
				}
	
		allDivs = xpath("//ul[@class='actionspro']");
		for (var i=0, txt; i<allDivs.snapshotLength; i++)
			{
			txt = allDivs.snapshotItem(i).innerHTML;
			if (txt.indexOf('Report')==-1)
				continue;
			
			allDivs.snapshotItem(i).innerHTML+=
			'<A class=actionspro_a href=http://www.facebook.com/edittopic.php?uid='+uid
			+'&topic='+topic
			+'&post=&reply_to='+allDivs.snapshotItem(i).parentNode.id.replace('post_data','')
			+'&xid='+xid
			+'&app_id='+app_id
			+'&c_url='+c_url
			+'&r_url='+r_url
			+'&sig='+sig
			+'&action=4>Reply To</A>';
			}
	//http://www.facebook.com/edittopic.php?xid=mm_tavern_1&app_id=79378246206&c_url=http%253A%252F%252Fapps.facebook.com%252Fmythmonger%252Fboards.php&r_url=http%253A%252F%252Fapps.facebook.com%252Fmythmonger%252Fboards.php&sig=acf231328f48884087db222a4d8dae13&topic=4464&action=1&post=44333
	//http://www.facebook.com/edittopic.php?uid=(board uid)&topic=(topic number)&post=&reply_to=(post number)&action=4
	}
	
	//************************* INSERT NODES

		allDivs = document.evaluate(
		//"//a[@class='author_post']",
		"//span[@class='author_header']",

		document,
		null,
		XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
		null);
		 

		for (var i=0; i<allDivs.snapshotLength; i++)
			{
			fb_id_array[i] = -99;

			if (allDivs.snapshotItem(i).childNodes.length<2)
				continue;

			var link_objekt = allDivs.snapshotItem(i).childNodes[0];
			var fb_id = gup(link_objekt.href,"id");
			
			if (fb_id=='')
				continue;
			
			fb_id_array[i] = fb_id;
			
			
			//tmp=allDivs.snapshotItem(i).innerHTML;



			var action_pt = ["loves", "kisses", "hugs", "winks at", "smiles sweetly at"];

			var load_msg;
			if (usr_ld_msg)
				load_msg= "<I><FONT color=grey>"+action_pt[Math.floor(Math.random()*action_pt.length)]+" you.</FONT></I>";
			else
				load_msg = "<I><FONT color=grey>loading...</FONT></I>";


			allDivs.snapshotItem(i).innerHTML = 
				allDivs.snapshotItem(i).innerHTML.replace(/(^<a)(.+)(<\/a> )(.+)/,"<a id=fb_link"+fb_id+" onmouseover=document.getElementById('poo"+i+"').style.display='inline';$2</a>" +
					" <span id=mh_info" +fb_id+">"+load_msg+"</span> $4<BR><span class=poo id=poo"+i+"></span>");
			

			//alert(allDivs.snapshotItem(i).childNodes.length+'\n'+allDivs.snapshotItem(i).innerHTML);
			//alert(tmp+"\n"+allDivs.snapshotItem(i).innerHTML);
			
			// ********** BUILD POO LINKS // FORMERLY POO OBJECT

			if (allDivs.snapshotItem(i).childNodes.length<5)
				continue;

			var newStr;

			
			var fb_name = link_objekt.innerHTML;


			newStr = "[ ";

			newStr += "<SPAN id=mh_only"+ fb_id +">";
			newStr += "<A href=http://apps.facebook.com/mousehunt/hunterprofile.php?snuid=";
			newStr += fb_id+">MH profile</A> | ";
			newStr += "<A href=http://apps.facebook.com/mousehunt/traderequest.php?snuid=";
			newStr += fb_id+">trade SB</A> | </SPAN>";

			newStr += "<SPAN id=mh_friend"+ fb_id +">";
			newStr += "<A href=http://apps.facebook.com/mousehunt/supplies.php?trade_recipient=";
			newStr += fb_id+">give supplies</A> | </SPAN>";
		
			newStr += "<A href=http://www.facebook.com/inbox/?compose&id=";
			newStr += fb_id+">message</A>";
			newStr += " | <A href=http://www.facebook.com/addfriend.php?id="+fb_id+">add friend</A>";
			newStr += " | <A href=javascript:; add_mh="+fb_id+" add_mhn='"+fb_name+"'>add MH friend</A>";
			//newStr += " | <A href=\"http://www.facebook.com/s.php?q="+ escape(fb_name) +"&a=4\">block</A>";
			newStr += " ]";

			$("poo"+i).innerHTML = newStr;
			

			//********** YELLOW BG MOUSEOVER

			var grandparent = allDivs.snapshotItem(i).parentNode;

			grandparent.setAttribute('onmouseover', 'style.backgroundColor="#FFFFAA";');
			grandparent.setAttribute('onmouseout', 'style.backgroundColor="inherit";');
			//grandparent.addEventListener("onmouseover", function () {this.style.backgroundColor="#FFFFAA";}, false);
			
			//grandparent.parentNode.setAttribute('onmouseout', '$("poo'+i+'").style.display="none";');



			}

	//************************* CHECK MH PROFILE

if (!usr_chk_k) // && usr_chk_fr)

	{
	for (var i=0; i<allDivs.snapshotLength; i++)
			{
			if (allDivs.snapshotItem(i).childNodes.length<5)
				continue;

			var link_objekt = allDivs.snapshotItem(i).childNodes[0];
			var fb_id = gup(link_objekt.href,"id");

			var objekt = allDivs.snapshotItem(i).childNodes[2];
			poo_link(link_objekt,objekt,fb_id,i);

			}
	}

else
	{
		
		for (var i=0; i<allDivs.snapshotLength; i++)
			{
			if (allDivs.snapshotItem(i).childNodes.length<5)
				continue;

			var link_objekt = allDivs.snapshotItem(i).childNodes[0];
			var fb_id = gup(link_objekt.href,"id");

			var objekt = allDivs.snapshotItem(i).childNodes[2];

			//********** KINGS REWARD
			if (is_King)
			objekt.innerHTML = "reminds ya to <A href=http://apps.facebook.com/mousehunt><FONT color=red>claim King&#039;s Reward</FONT></A>";


			//********** RUN BATCH CHECKS
			else
			poo_link(link_objekt,objekt,fb_id,i);

			}
		
		}


	//});

	// ADD MOUSEHUNT FRIENDS
	add_mh_friends();
	poo_fb_mhz(); //SUPER SLOW!
	
}

var mh_friends;

function add_mh_friends()
{	
	
	
	mh_friends = GM_getValue('mh_friends','');
	if (mh_friends=='')
		mh_friends = new Array();
	else
		mh_friends = mh_friends.split(',');
	
	display_mh_friends();
}

function dprompt(msg, df)
{
	var rt;
	
	rt=prompt(msg, df);
	if (!rt)
		return false;
			
	/*do
		{
		rt=prompt(msg, df);
		}
	while (!rt || rt==null || rt=='');*/
	
	return rt;
}

function display_mh_friends()
{
	var area;
	if (window.location.href.indexOf('facebook.com/mousehunt')==-1)
		area = 'fb_menu_friends_dropdown';
	else
		area = 'mhizer_menuFriends';
	
	if (!$(area))
		return;
	
	var aDiv = $(area).getElementsByTagName('div');
	for (var i=0; i<aDiv.length; i++)
		{
		if (aDiv[i].getAttribute('MHizer'))
			$(area).removeChild(aDiv[i--]);
		}
	
	if (!mh_friends || mh_friends.length==0)
		return;
		
	var tObj = document.createElement("div");
	tObj.setAttribute('class','fb_menu_separator');
	tObj.setAttribute('MHizer','1');
	$(area).appendChild(tObj);
	
	tObj = document.createElement("div");
	tObj.setAttribute('class','fb_menu_item');
	tObj.setAttribute('MHizer','1');
	tObj.innerHTML = "<A id=link_to_mh_friends class=fb_menu_item_link target=_blank "+
			"href=http://furoma.com/mousehuntizer/template.html?page=mh_friends><B>PF MH Friends Page</B></A>";
	$(area).appendChild(tObj);
	
	
	
	for (var i=0, nname, fb_id; i<mh_friends.length; i++)
		{
		nname = mh_friends[i].split('|')[0];
		fb_id = mh_friends[i].split('|')[1];
		
		tObj = document.createElement("div");
		//tObj.setAttribute('class','fb_menu_item');
		tObj.setAttribute('style','padding-left:5px;padding-bottom:3px;');
		tObj.setAttribute('MHizer','1');
		tObj.innerHTML = "[<A href=javascript:; title=Remove id=rm_mh_friends"+i+">X</A>|"+
			"<A href=javascript:; title=Rename id=rn_mh_friends"+i+">R</A>] "+
			"<A where="+area+" "+
			"href=http://apps.facebook.com/mousehunt/hunterprofile.php?snuid="+fb_id+
			">"+nname+"</A>";
		$(area).appendChild(tObj);
		//.insertBefore(tObj, $('fb_menubar_logo'));
		
		$('rm_mh_friends'+i).addEventListener("click", function () {
			//alert(mh_friends);
			mh_friends.splice(parseInt(this.id.replace('rm_mh_friends','')), 1);
			GM_setValue('mh_friends',mh_friends.toString());
			
			
			display_mh_friends();
			}, false);
		
		$('rn_mh_friends'+i).addEventListener("click", function () {
		
			var i= parseInt(this.id.replace('rn_mh_friends',''));
			var nname = mh_friends[i].split('|')[0];
			var fb_id = mh_friends[i].split('|')[1];
			
			var prompta = dprompt('Rename to...',nname);
			if (!prompta)
				return;
			mh_friends[i] = prompta+'|'+fb_id;
			
			mh_friends.sort();
			
			GM_setValue('mh_friends',mh_friends.toString());
			
			display_mh_friends();
			}, false);
		
		}
	//alert(	$('fb_menu_friends_dropdown').innerHTML);
		//<div class="fb_menu_separator"></div>
	
	//poo_fb_mhz(); //too slow
	
	if (window.location.href.indexOf('mousehuntizer/template.html?page=mh_friends')==-1)
		return;

	$('link_to_mh_friends').style.display = 'none';
	poo_fb_mhz();
	
}

//===============================================================================
//			- Weekly Auto-Update Check -
//===============================================================================
// CheckForUpdate() will verify if the time has come to look if an update is available.
// CheckVersion() will verify if this script version is the latest available.
// http://userscripts.org/scripts/show/22372
//===============================================================================

var script_title = "Pooflinger's Mousehuntizer";

var latest_version = " ";
var gm_updateparam = "pooflinger_lastupdatecheck";
var lastupdatecheck = GM_getValue(gm_updateparam, "never");





CheckForUpdate();



//Add a command to the menu in case someone wants to manually check for an update.
GM_registerMenuCommand("MH - Check for Pooflinger updates!", CheckVersion);

//Initiate the download of the new script version.
function GetNewVersion() {
        var today = new Date();
        GM_setValue(gm_updateparam, String(today));
        window.location.href = source_location;
}

//Verify if it's time to update
function CheckForUpdate()
{	
	var today = new Date();
	var one_day = 24 * 60 * 60 * 1000; //One day in milliseconds

	if(lastupdatecheck != "never")
	{
		today = today.getTime(); //Get today's date
		var lastupdatecheck = new Date(lastupdatecheck).getTime();
		var interval = (today - lastupdatecheck) / one_day; //Find out how much days have passed		

		//If a week has passed since the last update check, check if a new version is available
		if(interval >= 7)			
			CheckVersion();
	}
	else
		CheckVersion();
}

//Make sure we don't have the latest version
function CheckVersion()
{
	GM_xmlhttpRequest({
		    method: 'GET',
		    url: version_holder+'?'+Math.random(),
		    headers: {'Content-type':'application/x-www-form-urlencoded'},		    
		    onload: function(responseDetails)
			{
				var line = String(responseDetails.responseText.match(/version=[0-9].[0-9]?[0-9].[0-9]?[0-9]/));				
				//var line = responseDetails.responseText;//.match(/version=(.+) - Google Docs/)[1];
				
				if(line != null)
				{
					var strSplit = new Array();
					strSplit = line.split('=');					
					latest_version = strSplit[1];

					
					if(your_version != latest_version && latest_version != "undefined" && !is_config_page)
					{
						if(confirm("A more recent version of " + script_title + " (" + latest_version + ") has been found.\r\nWould you like to get it now?"))
							GetNewVersion();
						else
							AskForReminder();
					} 
					else if(your_version == latest_version && !is_config_page)
						alert("You have the latest version of " + script_title + ".");
					else if(is_config_page)
						{
						
						if (latest_version == your_version)
							{
							$('chk_latest_version').innerHTML = 'OK';
							//$('update_link').style.display='none';
							
							if ($('version') &&
								$('version').getAttribute('version')!=your_version &&	// config page is out of date
								gup(window.location.href,'rand')==''					// never been refreshed
								)
								{
								window.location.href+='?rand='+Date();	// refresh config page
								}
							}
						else
							{
							$('chk_latest_version').innerHTML = '';
							$('update_link').style.display='inline';
							
							//if (document.location.href.indexOf('beta')!=-1)
							$('update_link').href=source_location;
							}
						}
				}
				else
				{
					alert("Could not locate the version holder file.\r\nThis should be reported to the script author peter[at]furoma.com.\r\nThank you!");
					SkipWeeklyUpdateCheck();
				}
					
		    }
		});
}

//Ask the user to be reminded in 24 hours or only next week.
function AskForReminder()
{
	if(confirm("Would you like to be reminded in 24 hours ?\r\n(Cancel to be reminded next week only)"))
	{
		var today = new Date();
		today = today.getTime();		
		var sixdays_ms = 6 * 24 * 60 * 60 * 1000;
		var sda_ms = today - sixdays_ms;		
		var sixdaysago = new Date(sda_ms)

		//Since we check for updates after 7 days, just make it seem like the last check was 6 days ago.
		GM_setValue(gm_updateparam, String(sixdaysago));
	}
	else
		SkipWeeklyUpdateCheck();
}

//Set the next update check in seven days
function SkipWeeklyUpdateCheck()
{
	var today = new Date();
	//As if we've just updated the script, the next check will only be next week.
	GM_setValue(gm_updateparam, String(today));
}

//===============================================================================
//			START - Drag Objects -
//===============================================================================
function $(id) {
  return document.getElementById(id);
}

function soundAlarm(){
//http://www.phon.ucl.ac.uk/home/mark/audio/play.htm

if (!$('alarm'))
	{
	var alarm = document.createElement("span");
	alarm.id = 'alarm';
	document.body.appendChild(alarm);
	}
//alarm.innerHTML = "<iframe id=alarmframe></iframe>";
//alarm.innerHTML = "<embed enablejavascript=\"true\" src=\"http://furoma.com/mousehunt_horn_timer_"+usr_chk_tm_alarm_file+"\" autostart=true hidden=true />";



//window.open("http://furoma.com/mousehuntizer/alarm.php?file="+usr_chk_tm_alarm_file);
//$('alarmframe').src = "http://furoma.com/mousehuntizer/mousehuntizer_alarm.html?file="+usr_chk_tm_alarm_file;
//$('alarm').innerHTML = "<iframe  src=http://furoma.com/mousehuntizer/alarm.php?file="+usr_chk_tm_alarm_file+"></iframe>";
//$('alarm').innerHTML = "<embed hidden=true enablejavascript=true id=alarm src=\"http://furoma.com/mousehunt_horn_timer_"+usr_chk_tm_alarm_file+"\" autostart=true />";

//usr_chk_tm_alarm_wmp=false;
$('alarm').innerHTML = "<embed "+
	((usr_chk_tm_alarm_wmp)? "type=application/x-mplayer2":"") +
	" loop=false hiddren=true width=0 height=0 src=\"http://furoma.com/mousehunt_horn_timer_"+
	usr_chk_tm_alarm_file+"\" autostart=true volume="+
	usr_chk_tm_alarm_vol+" ></embed>";	//*/

	
/*
$('alarm').innerHTML =
'<object type="audio/x-wav" data="http://furoma.com/mousehunt_horn_timer_doorbell.wav" width="300" height="50">'+
'<param name="autoplay" value="true"><param name="autostart" value="true"></object>';
*/ //http://www.hardforum.com/showthread.php?t=1109736
//http://forums.mozillazine.org/viewtopic.php?t=206216

}

function setMin()
{

	if(HornTime==null)
		{
		if (MsgObj!=null)			// MsgObj==null --> Non MH pages
			sMsg = parseInt(MsgObj.value);
		else if (sMsg==null)
			return;
		
		var LoadTime = new Date();
		LoadTime = LoadTime.getTime();
		HornTime = LoadTime + (sMsg*1000);
		
		}
	var NowTime = new Date();
	NowTime = NowTime.getTime();
	sMsg = Math.ceil((HornTime - NowTime)/1000);
	
	var kr_success=false;
	
	if ($('app10337532241_contentcontainer') &&
		$('app10337532241_contentcontainer').innerHTML.indexOf('Reward claimed!')!=-1)
		{
		kr_success = true;
		usr_chk_tm_alarm = false;
		usr_chk_tm_alarm_cnfm = false;
		}
		
	if (!kr_success && document.title.indexOf('Claim a King\'s Reward!')!=-1) //king's reward
		{
		$('mh_min').innerHTML = 'King\'s Reward';
		if (usr_chk_tm_alarm)
			soundAlarm();
		}
	else if ($('app10337532241_hud') && $('app10337532241_hud').innerHTML.indexOf('None!')!=-1)
		{
		$('mh_min').innerHTML = '<a class=fb_menu_link href=http://apps.facebook.com/mousehunt/inventory.php>Out of cheese!</a>';
		if (!kr_success && usr_chk_tm_alarm)
			soundAlarm();
		}
	else if (sMsg<=0)
		{
		if (usr_chk_tm_pos=='fb_app_bar' && window.location.href.indexOf('facebook.com')!=-1)
			{
			$('mh_min').style.bottom = '20px';
			//$('mh_min').style.paddingTop = '5px';
			//$('presence_bar_right').style.paddingTop = '5px';
			}
		
		$('mh_min').innerHTML = '<a class=fb_menu_link href=http://apps.facebook.com/mousehunt/soundthehorn.php>Sound the horn!</a>';
		if (usr_chk_tm_title)
			document.title = 'Horn\'s ready! | ' + Doctitle;
		
		var usr_chk_tm_last = GM_getValue('usr_chk_tm_last',0);
		usr_chk_tm_last = (usr_chk_tm_last==0)? 0:Date.parse(usr_chk_tm_last);
		
		var todai = new Date();
		
		if (Date.parse(todai)-usr_chk_tm_last>120000) // last horn is older than 2 minutes ago
			{
			GM_setValue('usr_chk_tm_last',String(todai));
			
			if (!kr_success && usr_chk_tm_alarm)
				soundAlarm();
				
			if (!kr_success && usr_chk_tm_alarm_cnfm && confirm("It's time to sound the horn!\nDo you want to sound it now?\n\nNOTE: By clicking OK, the horn will be sounded on this tab, so please click cancel if you are in the middle of completing a form."))
				window.location.href = "http://apps.facebook.com/mousehunt/soundthehorn.php";
			
			}
		}
		
	else
		{var mh_min = Math.floor(sMsg/60);
		var mh_sec = sMsg%60;
		if (mh_sec<10)
			mh_sec = '0'+mh_sec;
		$('mh_min').innerHTML = 'MH timer <b style=font-size:14pt;>'+mh_min+':'+mh_sec+'</b>';
		
		if (usr_chk_tm_title)
			document.title = mh_min+':'+mh_sec+ ' | ' + Doctitle;
		
		setTimeout(setMin, usr_chk_tm_update*1000);
		}

	if (usr_debug)
		set_debug();
	
}

function set_debug()
{
	if (!$('mhtizer_debug'))
		{
		var deb = document.createElement("div");
		deb.id = 'mhtizer_debug';
		deb.style.bottom = '25px';
		deb.style.left = '25px';
		deb.style.position = 'fixed';
		deb.style.background = 'yellow';
		deb.style.zIndex = '100';
		document.body.appendChild(deb);
		}
		
	var last_horn;
	last_horn = GM_getValue('usr_chk_tm_last',0);
	last_horn = (last_horn == 0)? 'unknown': ((Date.parse(Date()) - Date.parse(last_horn))/1000) + ' seconds ago';//.toLocaleTimeString();
	
	
	var showHornTime = new Date();
	showHornTime.setTime(HornTime);
	
	$('mhtizer_debug').innerHTML= ("Last horn: "+last_horn) +
	' | <a href=javascript:; id=testalarm>test alarm</a>' +
	' | <a href=javascript:; id=resetalarm>reset last horn</a>' +
	' | <a href=javascript:; id=setalarm>last horn = now</a>' +
	' | <a href=javascript:; id=sim>simulate (next horn in 10 secs)</a>' +
	'<br>Current time is '+Date()+' | Horn time is '+showHornTime;

	$('testalarm').addEventListener("click", soundAlarm, false);
	$('resetalarm').addEventListener("click", function () {GM_setValue('usr_chk_tm_last', 0); set_debug(); }, false);
	$('setalarm').addEventListener("click", function () {GM_setValue('usr_chk_tm_last', Date()); set_debug(); }, false);
	$('sim').addEventListener("click", function () { 
	
	if (MsgObj!=null)
		{
		MsgObj.value = 10;
		sMsg=10;
		}
	var LoadTime = new Date();
	LoadTime = LoadTime.getTime();
	HornTime = LoadTime + (10*1000);
	
	set_debug();
	
	}, false);

	
}

var MsgObj, sMsg, HornTime;
var Doctitle = document.title;

function printMsg() {

/*
var alla = document.getElementsByTagName('a');
for (var i=0; i<alla.length; i++)
	{
	//if (alla[i].innerHTML.indexOf('Inbox')!=-1)
	if (alla[i].href=='http://apps.facebook.com/mythmonger/')
		{
		alert(alla[i].parentNode.parentNode.parentNode.innerHTML);
		break;
		}
	}//*/
//insertBefore(timer, $('fb_menubar_inbox

		
//if (document.location.href.indexOf("topic.php?")==-1 && document.location.href.indexOf("board.php?")==-1 && document.location.href.indexOf("apps.facebook.com/mousehunt")==-1 )
	//return;

if (MsgObj!=null)	
	return;

if (usr_chk_tm_mh)
	{
	var AllInputs = document.getElementsByTagName("input");
	for(i = 0; i< AllInputs.length; i++)
   
		{
		if(AllInputs[i].id.indexOf("hornWaitValue") !=-1)
			{MsgObj=AllInputs[i];
			break;}
		}
	}

	
	//var oDate = new Date();
	//var sWhen = oDate.toLocaleString() + "\n";
	
	if (usr_chk_tm_pos=='hide')
		{
		var tObj = document.createElement("span");
		tObj.setAttribute('id','mh_min');
		tObj.style.display = 'none';
		document.body.appendChild(tObj);
		setMin();
		}
	else if (usr_chk_tm_pos=='float box' || usr_chk_tm_pos=='fixed box' || window.location.href.indexOf('facebook.com')==-1)
		{
		var sCloseBtn = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABUAAAAVCAIAAAAmdTLBAAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH1gYKECMhBqiEGQAAADJ0RVh0Q29tbWVudABFcnN0ZWxsdCB2b24gRmxvcmlhbiBTY2hyZWllciBtaXQgVGhlIEdJTVCOHcWrAAADLUlEQVR42pWUPYhdRRiG32/OuTdZXTcas0n2ZiVVYBttLFLFQuNPZTQgiIIphGBAtNTC0lZBRRQVEYWoBAyk8ActRFCRLa3SpNH9icm699695+6Z+X5ei7Obtc1UH+/MM+/M9w4jJD0wnNi9czVuZ3iwSlKbQ5ohP3rzn+FGTBvmlqbUgpRgBQDdAbC0AOAepbV2ezI3v/Txd+nuQ0Jy4+3XqsMDqeqYjHxryJJRCiPgRneAMKU7rbBktlNrtoaj0WrvrpMXlxMAH29Kf5/0+6hqqXtS16h7SImpkqqSVCHVkipIQqq6NanuTdZXDs7VNQA2WzEZS12znTJvM2eWQi1UpSnDqQUgtcCVpnRHSqmqACQA1BKToY83oxnPPvz0/BvvR9OwaaKZeDOO8TC2NmP077FPfjzw/CvM23STlKTu3eKV04bbE+a8/8FTAI6+dTG00Aq00DK1LF78HcDs6bNwAwPcSaHjc5TCXKh6/fVz3cTggytwQzjc7vt6uRP/OrOEcGEAAXKHB8DcRm5pCvf1V5/pxGOf/kT64pd/7MBPnoArXEEXUrDLRztFyVCFOSMoXH35TMcsfvFrV6ycXUqJIiFwoUmYROz6mzK30LJ7Nwq5+tITt57a6rP3S6IIk0TqeBrC9/oXVhjOcGGIAAmDD7+/xQ+++jMl7PmHwlXC9vrHkqkFYWSQXHjvSkeun3+oK458tizdFjAJEytpz98KNdMK3Ri+8M43O/CFRwBef/EkALlj7sila4IQBlzFC013+bLjT9WFdy938NqFx0CCBHjj3AOdePjyqoSmDv7f+Qtzy9JS8/SXbwGsnT8NN3b5hzP8xnMnALQ/fI5wmkELzQAIyWun5qsD98jMbNq3X6oaAjAEAYRQJYpYFi+wgtKyFMtlPPWrW3zqatQAVEu020kqiZCqliQIh6CLOoXCi1iBFahRzdTVQh0A6pujaA4OuHkDyqqfUdWAgCFCYQi9gsNVwukqZjQ35UghC8cByDSTG3///MKjo7WVfq+mSEhCRJVEAKFXdAlPDPdAeMUozjh6/PFLv/UPDYRkVuzr3dbfh5sjv3OmmunjP4EhhHJu9NM9AAAAAElFTkSuQmCC";
		// here we generate a link which closes the message
		var sLinkClose = "<a href='#' onclick='document.getElementById(\"ttq_message\").parentNode.removeChild(document.getElementById(\"ttq_message\"));' class='ttq_close_btn'><img src='" +sCloseBtn+ "' border=0 alt='X' width=15px /></a>";
		var oMsgBox = document.createElement("div");
		
		//GM_setValue("MSG_POSITION", "50px_50px");
		var msgCoords = GM_getValue("MSG_POSITION", "45px_300px");
		msgCoords = msgCoords.split("_");
		oMsgBox.style.position = (usr_chk_tm_pos=='fixed box')? 'fixed':'absolute'; 
		oMsgBox.style.top = msgCoords[0];
		oMsgBox.style.left = msgCoords[1];

		oMsgBox.id = "ttq_message";
		oMsgBox.innerHTML = "<div id='ttq_draghandle_msg' style='position:absolute; z-index:100; border:1px solid black; padding:5px 5px; color:black; font:10pt Verdana; width:150px; background:white; cursor:move;'>" + sLinkClose + " <span id=mh_min></span></div>";
		
		document.body.appendChild(oMsgBox);


		makeDraggable($('ttq_draghandle_msg'));
		setMin();
		}
	else if (usr_chk_tm_pos=='fb_menu_bar')
		{
		var tObj = document.createElement("li");
		tObj.setAttribute('class','fb_menu');
		tObj.setAttribute('id','mh_min');
		tObj.style.color = 'white';
		$('fb_menubar_logo').parentNode.appendChild(tObj);
		setMin();
		}
	else if (usr_chk_tm_pos=='fb_app_bar')
		{
		set_app_garden();

		}

		
	//alert(msgCoords);
	//alert(oMsgBox.style.top); 
	
//var mh_start_date = res.match(/<li><span class=["]label["]>Hunting Since<[/]span>: (.+)<[/]li>/)[1];
		
}
var app_garden = 0;
function set_app_garden()
{
	/*	var ss= document.getElementsByTagName('div');
		var ww='';
		for (var w=0; w<ss.length; w++)
			{
			if (ss[w].id == '')
				continue;
				
			ww+=' / '+ss[w].id;
			}
		alert(ww);*/
if (app_garden++==100)
	{
	return;
	}
if ($('application_icon_garden_root')) //presence_applications_icon_garden application_icon_garden_root
	{
	var tObj = document.createElement("div");
		tObj.setAttribute('id','mh_min');
		//tObj.setAttribute('class', 'icon_garden_elem');
		tObj.style.position = 'relative';
		tObj.style.bottom = '25px';
		tObj.style.left = '160px';
		//tObj.style.marginTop = '0px'; //not work
		//tObj.style.paddingTop = '5px';
		//tObj.style.verticalAlign = 'center';
		//tObj.style.marginBottom = '-50px';
		//document.body.appendChild(tObj);
	$('application_icon_garden_root').appendChild(tObj);
	setMin();
	}
else
	setTimeout (set_app_garden, 100);
}



if (window.top!=null && document.location.href != window.top.location.href)
	{}
else if (usr_chk_tm_mh && document.location.href.indexOf("apps.facebook.com/mousehunt")!=-1)
	printMsg();
else if (usr_chk_tm_fb) // && document.location.href.indexOf("furoma.com")==-1)
	{
			
	GM_xmlhttpRequest({
		method: 'GET',
		url: 'http://apps.facebook.com/mousehunt/hunterprofile.php',
		headers: {
				'User-agent': 'Mozilla/4.0 (compatible) Greasemonkey',
				'Content-type':'application/x-www-form-urlencoded',
				},
			onload: function(responseDetails) {
			var res = responseDetails.responseText;
			if (MsgObj==null && sMsg==null)
				{
				sMsg = res.match(/<input type=["]hidden["] id=["].+hornWaitValue.+["] value=["](.+)["] fbcontext=["].+["] [/]>/);
				if (sMsg)
					{
					sMsg = parseInt(sMsg[1]);
					if (sMsg <0)
						sMsg=0;
					printMsg();
					}
				}
		}});

	}



/************************ Drag n drop*******************************/
var mouseOffset = null;
var iMouseDown  = false;
var lMouseState = false;
var dragObject  = null;
var curTarget   = null;

function mouseCoords(ev){
	return {x:ev.pageX, y:ev.pageY};
}

function makeClickable(object){
	object.onmousedown = function(){
		dragObject = this;
	}
}

function getMouseOffset(target, ev){
	var docPos    = getPosition(target);
	var mousePos  = mouseCoords(ev);
	return {x:mousePos.x - docPos.x, y:mousePos.y - docPos.y};
}

function getPosition(e){
	var left = 0;
	var top  = 0;
	while (e.offsetParent){
		left += e.offsetLeft + (e.currentStyle?(parseInt(e.currentStyle.borderLeftWidth)).NaN0():0);
		top  += e.offsetTop  + (e.currentStyle?(parseInt(e.currentStyle.borderTopWidth)).NaN0():0);
		e     = e.offsetParent;
	}
	left += e.offsetLeft + (e.currentStyle?(parseInt(e.currentStyle.borderLeftWidth)).NaN0():0);
	top  += e.offsetTop  + (e.currentStyle?(parseInt(e.currentStyle.borderTopWidth)).NaN0():0);
	return {x:left, y:top};
}

function mouseMove(ev){
	var target   = ev.target;
	var mousePos = mouseCoords(ev);

	if(dragObject){
		dragObject.style.position = (usr_chk_tm_pos=='fixed box')? 'fixed':'absolute'; 
		dragObject.style.top      = (mousePos.y - mouseOffset.y) +"px";
		dragObject.style.left     = (mousePos.x - mouseOffset.x) +"px";
	}
	lMouseState = iMouseDown;
	return false;
}

function mouseUp(ev){
	if(dragObject) {
		
	GM_setValue("MSG_POSITION", dragObject.style.top +"_"+ dragObject.style.left);
	}
	dragObject = null;
	iMouseDown = false;
}

function mouseDown(ev){	
var mousePos = mouseCoords(ev);
	var target = ev.target;
	iMouseDown = true;	
	if(target.getAttribute('DragObj')){
		return false;
	}	
}

function makeDraggable(item){
	if(!item) return;
	item.addEventListener("mousedown",function(ev){
		dragObject  = this.parentNode;
		mouseOffset = getMouseOffset(this.parentNode, ev);
		return false;
	}, false);
}

document.addEventListener("mousemove", mouseMove, false);
document.addEventListener("mousedown", mouseDown, false);
document.addEventListener("mouseup", mouseUp, false);

/************************************************************************************/


function test_mh(res)
{
	if(res.indexOf("Claim a King&#039;s Reward!</title>")!=-1)
		return "Please claim the King's reward and try again.";

	if(res.indexOf("Build Your First Mouse Trap")!=-1)
		return "Please log in to Facebook and try again.";
		
	if(res.indexOf("Error while loading page from")!=-1)
		return "MouseHunt server is down or in maintenance.";
	
	return '';
}

function to_summarizer()
{
/*
var oMsgBox = document.createElement("textarea");
oMsgBox.style.width = '500px';
oMsgBox.style.height = '500px';
document.body.appendChild(oMsgBox);*/



if ($('shit')==null)
	{
	alert('Error: could not find a pooflinging box in the log summarizer!');
	return;
	}
$('shit').value="importing data from facebook...";
var journal_entry = new Array();
var journal_cnt=0;


var fail=false;
var max_journal_cnt=10;
var journal_run=0;


for (var i=0;i<10;i++)
GM_xmlhttpRequest({
		    method: 'GET',
		    url: 'http://apps.facebook.com/mousehunt/index.php?p='+i,
		    headers: {'Content-type':'application/x-www-form-urlencoded'},		    
		    onload: function(responseDetails)
			{
			if(fail)
				return;
		
			if (responseDetails.status != 200)
				{
				alert('Error incurred. Please log in to MouseHunt and/or check Kings reward.');
				fail = true;
				return false;
				}
			
			var res = responseDetails.responseText.replace(/\n/g,'ZZZ');

	fail=test_mh(res);
	
	if(fail!='')
		{
		$('shit').value=fail;
		fail=true;
		return false;
		}
	else
		fail=false;
	
	if(i==0 && res.indexOf('journalbody')==-1)
		{
		fail = true;	
		$('shit').value="There are unknown problems downloading your data. Please try reloading the page.";
		return;
		}


	journal_run++;

	if (res.indexOf('journalbody')==-1)
		{
		journal_entry[i]='';
		}
	else
		{
		var k = res.match(/<li>\[ Page (.+) of (.+) \]<\/li>/)[1];
		max_journal_cnt= res.match(/<li>\[ Page (.+) of (.+) \]<\/li>/)[2];

		//alert(max_journal_cnt);

		res=res.match(/<div class="journalbody">(.+)<div class="journalbottom">/)[1];
		res=res.replace(/ZZZ/g,'\n').replace(/</g,'\n<').replace(/>/g,'>\n').replace(/\t/g,'');
	
		res=res.replace(/<div class="journaldate">/g,'ZZZ').replace(/<\/div>/g,' <\/div>');
		res=res.replace(/<.+>/g,'').replace(/\n/g,'');
		res=res.replace(/ZZZ/g,'\n');

		$('shit').value="importing data from facebook...\n"+ Math.floor((++journal_cnt)*100/max_journal_cnt) +' % complete';
		journal_entry [k-1]=res;
		}

	if (journal_run==10)
		{
		$('shit').value='';

		if (document.location.href.indexOf('furoma.com/mousehunt_log_summarizer')!=-1)
			for(var j=0;j<max_journal_cnt;j++)
				$('shit').value+='***from page '+(j+1)+'**'+journal_entry [j]+'\n\n';
		else
			for(var j=0;j<max_journal_cnt;j++)
				$('shit').value+=journal_entry [j]+'\n\n';
		
		}

			}
});


	

}


function show_rev()
{
	
	if (usr_rm_pf || $('rev')!=null || Math.random()>0.0999)
		return;
		
	//UIStandardFrame_Container clearfix
	//"//div[@class='adcolumn']",
	//"//div[@id='sidebar_ads']",

	var rev=document.createElement("div");
	rev.id = 'rev';
	var allDivs = xpathFirst("//div[@class='UIStandardFrame_SidebarAds']");
	
	if (!allDivs)
		return;
	/*if (allDivs==null)
		{
		allDivs = xpathFirst("//div[@class='right_column_container clearfix']");
		rev.innerHTML=
		'<span style=float:right;width:180px;height:0px;><span style="float:left;padding:5px 0px 0px 35px;"><iframe src=http://furoma.com/mousehuntizer/mousehuntizer_rev.html style="border: 0px none #ffffff;" width="140" height="620" scrolling="no" frameborder="0"></iframe></span></span>';
		//{float:right;width:180px} width:180px;font-size:11px;padding:47px 0 0 17px;text-align:left"
		}*/
	
	if (usr_rm_fb)
		{
		allDivs.style.visibility='hidden';
		allDivs.style.height='0px';
		}
	
	rev.innerHTML=
	//'<iframe src=http://furoma.com/mousehuntizer/mousehuntizer_rev.html style="border: 0px none #ffffff;" width="140" height="620" scrolling="no" frameborder="0"></iframe>';
	'<span style=margin-top:55px;margin-left:35px;><iframe src=http://furoma.com/mousehuntizer/mousehuntizer_rev.html style="border: 0px none #ffffff;" width="140" height="620" scrolling="no" frameborder="0"></iframe></span>';
	
	//allDivs.appendChild(rev); .childNodes[0]
	
	//alert(allDivs.parentNode.innerHTML);
	allDivs.parentNode.insertBefore(rev, allDivs);
	
}

function Remove_All_Facebook_Ads() // Credit: http://userscripts.org/scripts/review/13787
{
	/*
	var sidebar_ads = $('sidebar_ads');
	if (sidebar_ads && sidebar_ads.style.visibility != 'hidden') { //Prevents the visibility from being set multiple times unnecessarily
		//GM_log("Removing Facebook sidebar ads.");
		sidebar_ads.style.visibility = 'hidden';
	} */
	
	if ($('sidebar_ads'))
		{
		$('sidebar_ads').style.visibility='hidden';
		$('sidebar_ads').style.height='0px';
		}
  	var elements = document.evaluate(
		// "//div[contains(@class, 'ad_capsule')] | //div[contains(@class, 'social_ad_advert')] | //div[contains(@class, 'social_ad')] | //div[contains(@class, 'sponsor')] | //div[contains(@id, 'sponsor')]  | //div[contains(@class, 'banner_ad')] ",
		"//div[contains(@class, 'social_ad_advert')] | //div[contains(@class, 'banner_ad')] |  //div[contains(@class, 'social_ad_image')] | //div[contains(@id, 'adcolumn_advertise')] | //a[contains(@class, 'more_ads')] | //div[contains(@class, 'UIEMUASFrame_action')] | //div[contains(@class, 'UIEmuASIFrame')] ",
		document,
		null,
		XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
		null
	);

	for (var i = 0; i < elements.snapshotLength; i++) {
		var thisElement = elements.snapshotItem(i);
		//GM_log("Removing Facebook ad element with class='" + thisElement.className + "' and id='" + thisElement.id + "'.");
    	thisElement.parentNode.removeChild(thisElement);
	}

}

function to_best_setup()
{
	//alert($('input_area').innerHTML);
	GM_xmlhttpRequest({
		    method: 'GET',
		    url: 'http://apps.facebook.com/mousehunt/inventory.php',
		    headers: {'Content-type':'application/x-www-form-urlencoded'},		    
		    onload: function(responseDetails)
			{
				var res=responseDetails.responseText;
				var k=test_mh(res);
				if (k!='')
					{
					alert(k);
					return false;
					}

				var checkbox = document.getElementsByTagName('input');
				for (var i=0; i<checkbox.length; i++)
					if (checkbox[i].getAttribute('type')=='checkbox')
						checkbox[i].checked = false;
					
				
				// Lucky Shield
				if(res.indexOf('header_logo_donator.gif')!=-1)
					{
					if ($('shield_1'))	//best setup
						$('shield_1').checked=true;
					else if ($('shield')) //best location
						$('shield').selectedIndex=1;
					}
				else
					{
					if ($('shield_2'))
						$('shield_2').checked=true;
					}
					
				// Hunter's Title
				k = res.match(/Title:<\/span>&nbsp;&nbsp;(.+) \(/)[1].toLowerCase();
				var titleObj = ($('title'))? $('title'):$('huntertitle'); 
					//title for best setup; huntertitle for best location
				for (var i=0; i<titleObj.options.length; i++)
					{
					if(titleObj.options[i].text.toLowerCase().indexOf(k)!=-1)
						{
						titleObj.selectedIndex=i;
						unsafeWindow.your_title=i;
						unsafeWindow.changeRank();
						break;
						}
					}
				
					
				//alert(k+'///'+$('title').options[6].value);
				
				if (document.location.href.indexOf('best_setup')!=-1)
					{
					k = res.match(/<div class=\"itemname\">(.+)&nbsp;&nbsp;/g);
					var q = document.getElementsByTagName('label');
						// <input onclick="your_trap=18; genOutput();" 
						// name="form_trap" id="form_trap18" type="checkbox">Mouse Deathbot<br> 
					var cid, cname, qj;
					var test_cname=new Array(), x=0;
					
					
					for (var i=0; i<k.length; i++)
						{
						k[i] = k[i].replace(/<div class=\"itemname\">/,'').replace(/&nbsp;&nbsp;/,'').toLowerCase();
							for (var j=0; j<q.length; j++)
							{
							qj=q[j].innerHTML.toLowerCase();
							if (qj.indexOf('type="checkbox"')==-1)
								continue;
							cname = qj.match(/>(.+)<br>/)[1];
							
							// BEST SETUP ACRoNYM Trap
							//cname = cname.replace('acronym','arcane capturing rod of never yielding mystery');
							//q[j].innerHTML=cname+'<br>';
							
							if (cname!=k[i])
								continue;
							cid = qj.match(/id=\"(.+)\" type=/)[1];
							$(cid).checked=true;
							test_cname[x++]=cname;
							break;
							}
						}
					
					//alert(k);
					/*super brie,moon,radioactive blue,gnarled,glutter,susheese,gouda,brie,swiss,
					white cheddar,cheddar,digby drillbot,ambush,deathbot (chrome edition),snow barrage,
					ambrosial portal,sinister portal,explosive base,dehydration base,polar base,
					birthday cake base,stone base,wooden base with target,radioactive blue cheese curd potion,
					greater brie alchemy potion,greater radioactive blue cheese curd potion,brie alchemy potion,
					ambush trap blueprints,burroughs salmon,cheesy fluffs,coal,curds and whey,invisi-glu,
					ionized salt,master claw shard,nori,onyx stone,paint-brand paint,salt,scrap metal,
					splintered wood,stale cheese,token of the cheese belt,token of the cheese claw,
					token of the cheese fang,gnawnia map piece,burroughs laboratory map piece,
					key to the town of digby,tattered mousoleum map,shredded furoma map piece,
					furoma map stitch,ticket to the burroughs bazaar,gnarled tree map piece,
					whisker woods clearing map piece,map of the lagoon*/
					}
				else	// best location
					{
					$('ronza_traps').checked = true;
					$('ronza_bases').checked = true;
					
					
					k = res.match(/<div class=\"itemname\">(.+)&nbsp;&nbsp;/g);
					var q = document.getElementsByTagName('label');
						// <input onclick="your_trap=18; genOutput();" 
						// name="form_trap" id="form_trap18" type="checkbox">Mouse Deathbot<br> 
					var cid, cname;
					
					for (var i=0; i<k.length; i++)
						{
						k[i] = k[i].replace(/<div class=\"itemname\">/,'').replace(/&nbsp;&nbsp;/,'').toLowerCase();
						for (var j=0; j<q.length; j++)
							{							
							if (q[j].id.indexOf('_label')==-1)
								continue;
							if (q[j].id.indexOf('location_label')!=-1)
								continue;
							cname = q[j].innerHTML.toLowerCase();
							
							// BEST LOCATION CHANGE CHEESE NAMES
							cname = xfm_cheese(cname);
							cname = cname.toLowerCase();
							
							cname = cname.replace('*','');
							//q[j].innerHTML=cname;
								
							if (cname!=k[i])
								continue;
							cid = q[j].getAttribute('for'); //q[j].id.replace('_label','');
							$(cid).checked=true;//*/
							break;
							}
						}
					
					
					//alert(k);
					//alert(q[20].id);  location_label20
					//alert(q.length); //96
					}

			}
		}); //*/
}

function to_catch_rates() //and log summarizer
{
	
	
	GM_xmlhttpRequest({
		    method: 'GET',
		    url: 'http://apps.facebook.com/mousehunt/inventory.php',
		    headers: {'Content-type':'application/x-www-form-urlencoded'},		    
		    onload: function(responseDetails)
			{
				var res=responseDetails.responseText;
				var k=test_mh(res);
				if (k!='')
					{
					alert(k);
					return false;
					}
				var cid, cname, qj;
				
				
				// golden shield
				var q = document.getElementsByTagName('select');
				for (var i=0; i<q.length; i++)
					if (q[i].id.indexOf('shield')!=-1)
						{
						if (document.location.href.indexOf('/mousehunt_log_summarizer')==-1)
							{
							q[i].selectedIndex= (res.indexOf('header_logo_donator.gif')!=-1)? 1:0;
							unsafeWindow.your_shield[0] = q[i].selectedIndex;
							}
						else
							{
							q[i].selectedIndex= (res.indexOf('header_logo_donator.gif')!=-1)? 2:1;
							}
						}
				

				
				k = res.match(/<span class=\"hudstatlabel\">(.+):<\/span>&nbsp;&nbsp;(.+)<\/li>/g);
				for (var i=0; i<k.length; i++)
					{
					var kfield = k[i].match(/<span class=\"hudstatlabel\">(.+):<\/span>&nbsp;&nbsp;(.+)<\/li>/)[1].toLowerCase();
					k[i] = k[i].match(/<span class=\"hudstatlabel\">(.+):<\/span>&nbsp;&nbsp;(.+)<\/li>/)[2].toLowerCase();
					k[i] = k[i].replace(/ \((.+)\)/,'').replace('...','');
					
					
					k[i] = xfm_title(k[i]);
							
					var kfound=false;
					if (kfield=='points' || kfield=='gold' || kfield=='trap power')
						kfound=true;

								
					for (var j=0; j<q.length; j++)
						{
						
						for (var l=0; l<q[j].options.length; l++)
							{
							
							var cname = q[j].options[l].value;
							cname = xfm_cheese(cname);
							
							cname = cname.toLowerCase();
							if (cname.indexOf('acronym')!=-1)
								{
								cname='arcane capturing rod of never yielding mystery';
								}
							cname = cname.replace('super|brie+','super brie')
								.replace(/Havarti - (.+) \((.+)\)/,'$1 Havarti')
								.replace(/Havarti - (.+)/,'$1 Havarti');
								
								
							cname = cname.replace('ancient spear trap','ancient spear gun')
								.replace("hitgrab rockin' horse","hitgrab rockin'");
								
							cname = cname.replace('s.s. huntington ii','s.s. huntington');
							
							cname = cname.substr(0,16);
							
							/*for TESTING select input
							if (i==0)
								q[j].options[l].innerHTML = cname;
							//*/
							
							if (k[i]==cname)
								{
								kfound=true;
								q[j].selectedIndex=l;
								if (q[j].id.indexOf('traps')==0)
									unsafeWindow.your_trap[0] = l;
								else if (q[j].id.indexOf('bases')==0)
									unsafeWindow.your_base[0] = l;
								else if (q[j].id.indexOf('title')==0)
									unsafeWindow.your_title[0] = l;
								else if (q[j].id.indexOf('locations')==0)
									unsafeWindow.your_loc[0] = l;
								else if (q[j].id.indexOf('cheese')==0)
									unsafeWindow.your_cheese[0] = l;
								break;
								
								}
							}
						}
					
					if (!kfound)
						alert('URL: '+document.location.href+'\n'+
						'BUG: Cannot fill the form\n'+
						kfield+'='+k[i]+
						'\n\nPlease copy this message and report to peter[at]furoma.com');
					}
				
				if (document.location.href.indexOf('/mousehunt_log_summarizer')==-1)
					unsafeWindow.genOutput(0);
				//alert (k); // lagoon,hero,polar base,digby drillbot,4,352,59,556,7,921,435,gnarled
				//alert (q[0].options[10].value.toLowerCase().indexOf(k[3]));
				//alert(k); //lagoon,hero (41%),polar base,digby drillbot,4,352,45,624,7,761,450,gnarled (2)
				//alert(q[0].options[10].value); //Digby Drillbot

			}
		}); //*/
}

function to_travel_planner()
{
	
	GM_xmlhttpRequest({
		    method: 'GET',
		    url: 'http://apps.facebook.com/mousehunt/inventory.php?',
		    headers: {'Content-type':'application/x-www-form-urlencoded'},		    
		    onload: function(responseDetails)
			{
				var res=responseDetails.responseText;
				var k=test_mh(res);
				if (k!='')
					{
					alert(k);
					return false;
					}
				var cid, cname, titlefound=false;
				var q = document.getElementsByTagName('label');

				// TITLE 
				k = res.match(/Title:<\/span>&nbsp;&nbsp;(.+) \(/)[1].toLowerCase();
				var j=0;
				for (var i=0; i<q.length; i++)
					if (q[i].getAttribute('for').indexOf('form_rank')==0)
						{
						cid=q[i].getAttribute('for');
						if (q[i].innerHTML.toLowerCase()==xfm_title(k))
							{
							titlefound=true;
							
							$(cid).click();
							//$(cid).checked=true;
							//unsafeWindow.your_rank=j;
							
							//unsafeWindow.your_rank=q[i].getAttribute('for').replace('form_rank','');
							//alert(q[i].getAttribute('for'));
							break;
							}
						j++;
						}//*/
						
				//titlefound=false; //TESTFREEZE

				if (!titlefound) //higher than hero
					{
					$(cid).click();
					//$(cid).checked=true;
					//unsafeWindow.your_rank=j; //TESTFREEZE

					}

				
				unsafeWindow.change_rank(true); // TESTFREEZE
				
				
				// MAP
				var r=document.getElementsByTagName('input');
				for (var i=0; i<r.length; i++)
					if (r[i].id.indexOf('form_map')==0 && r[i].checked)
						{
						$(cid).disabled=false;
						r[i].checked=false;
						//r[i].click();
						}
				
				
				k = res.match(/<div class=\"itemname\">(.+)&nbsp;&nbsp;/g);
				/*/TESTFREEZE
				k[k.length] = 'Mousoleum Restoration Patch';
				k[k.length] = "Keeper's Candle";
				k[k.length] = 'S.S. Huntington II';
				k[k.length] = 'Ocean Navigation Kit'; //*/
				k.push('enable acolyte realm travel');	// enable by DEFAULT
				k.push('Ronza is back!');	// enable by DEFAULT
				
				for (var i=0; i<k.length; i++)
					{
					k[i] = k[i].replace(/<div class=\"itemname\">/,'').replace(/&nbsp;&nbsp;/,'').toLowerCase();
					
					if (k[i].indexOf('bazaar')!=-1)
						k[i]='bazaar ticket';
					else if (k[i].indexOf('whisker woods')!=-1)
						k[i]='whisker woods map';
					else if (k[i].indexOf('s.s. huntington')!=-1) //S.S. Huntington II
						k[i]='ship (rodentia)';

					
					
					for (var j=0; j<q.length; j++)
						{
						cid=q[j].getAttribute('for');
						
						if (cid.indexOf('form_map')!=0)
							continue;
						if (k[i].indexOf(q[j].innerHTML.toLowerCase())!=-1)
							{
							//$(cid).disabled=false;
							if (!$(cid).disabled)
								$(cid).checked=true;
							//$(cid).click();
							//alert(k[i]+'/'+q[j].innerHTML.toLowerCase());
							break;
							}
						}
					}//*/
				
				
				unsafeWindow.change_map(); // TESTFREEZE
				
				
				// WHERE_FROM LOCATION
				k = res.match(/Location:<\/span>&nbsp;&nbsp;(.+)<\/li>/)[1].replace('...','').toLowerCase();
				//k = 'elub shore'; //TESTFREEZE
				
				for (var i=0, j=0; i<q.length; i++)
					if (q[i].getAttribute('for').indexOf('form_source')==0)
						{
						cid=q[i].getAttribute('for');
						if (q[i].innerHTML.toLowerCase().indexOf(k)!=-1)
							{
							if (!$(cid).disabled)
								$(cid).click();
							//$(cid).checked=true;
							//unsafeWindow.source=j;
							
							//unsafeWindow.source=q[i].getAttribute('for').replace('form_source','');

							break;
							}
						j++;
						}//*/
				
				if (gup(window.location.href,'chauffeur')!='')
					{
					to_chauffeur();
					}
			}
		}); //*/
}

function to_chauffeur()
{

	var route = $('output_area').getElementsByTagName('blockquote');
	var cost = $('output_area').getElementsByTagName('b');
	if (route.length==0 || cost.length==0)
		{
		alert('Something went wrong. Iternary not calculated yet.')
		return;
		}
	
	route = route[0].innerHTML.replace(/ -&gt; /g,',');
	route = route.replace(/<font color=\"red\">/g,'').replace(/<\/font>/g,',Break');
	

	/*
	var route_destination = route.indexOf('</font>');
	if (route_destination!=-1)
		{
		route = route.substr(0,route_destination+7);
		route = route.replace('<font color="red">','').replace('</font>','');
		}*/
	
	cost = cost[0].innerHTML;
	
		
	window.location.href='http://apps.facebook.com/mousehunt/travel.php?cost='+cost+'&route=MHizer-'+route;

}

var MHizerSec=usr_delay;
var go_url;
function MHizer_travel_GO ()
{

	if(MHizerSec==-1)
		return;
	if(MHizerSec==0)
		{
		window.location.href=go_url;
		return;
		}
	
	$('MHizerSec').innerHTML = MHizerSec--;
	setTimeout(MHizer_travel_GO, 1000);
}

var asetup, asetup_b;
var mh_hash, ur_name, ur_fb_id;
var mloc, mweapon, mbase, mcheese, mcheese_cnt, mtitle, mtitlep;

function init_setup()	// this function is important - will be called by best location as well
{
	asetup = GM_getValue('asetup', '');

	if (asetup=='')
		{
		asetup = new Array();
		return;
		}
	asetup = asetup.split(',');
	asetup_b = new Array();
	for (var i=0; i<asetup.length; i++)
		{
		asetup_b.push(new Array());
		asetup_b[i] = asetup[i].split('/');
		}
}

function display_setup()
{
	init_setup();
	var setupTxt = '', locTxt = '';
	for (var i=0; i<asetup.length; i++)
		{

		setupTxt += '[<a href=javascript:; title="Remove this setup from the list." id=del_setup'+i+'><B>X</B></a>|' +
			'<a href=javascript:; title="Equip this setup." id=equip_setup'+i+'>Equip</a>] ' +
			((asetup_b[i][0]=='-')? '':
				'<a href="http://furoma.com/mousehunt_travel_planner.html?whereto='+
				asetup_b[i][0].replace('...','')+'" title="Travel with Travel Planner"><B>'+asetup_b[i][0]+'</B>:</a> '
				) +
			asetup_b[i][1]+'<B style=color:brown>+</B> '+asetup_b[i][2]+
			' <B style=color:brown>+</B> '+asetup_b[i][3]+'<br>';
		
		if (asetup_b[i][0]!='-')
			{
			locTxt +=
				'[<a href="http://furoma.com/mousehunt_travel_planner.html?whereto='
				+asetup_b[i][0].replace('...','')+'" title="Travel with Travel Planner">TP</a>'
				
				+	((usr_chk_tp)? '|<a href="http://furoma.com/mousehunt_travel_planner.html?chauffeur=1&whereto='
				+asetup_b[i][0].replace('...','')+'" title="Ask Chauffer to drive now (without stopovers)">Chffr</a>'
				:'')
				
				+'] '
				+asetup_b[i][0]
				+'<br>';
			}
		}
	

	$('setup_list').innerHTML = (setupTxt=='')? 'No setups saved' : setupTxt;
	$('loc_list').innerHTML = (locTxt=='')? 'No locations with favorite setup' : locTxt;
	
	for (var i=0; i<asetup.length; i++)
		{
		$('del_setup'+i).addEventListener("click", function(){
			
			asetup.splice( parseInt(this.id.replace('del_setup','')), 1); 
			GM_setValue('asetup', asetup.toString());
			display_setup();
			
			}, false);
		
		equip_setup ($('equip_setup'+i));
		/*$('equip_setup'+i).addEventListener("click", function(){
			
			equip_setup(this);
			
			}, false);*/
		
		}
		
	// INIT EQUIP WITH FAV SETUP - to display or not to display the link; if display, correct href
	var loc_found=false;
	for (var i=0; i<asetup.length; i++)
		if (asetup_b[i][0]==mloc)
			{
			loc_found=true;
			break;
			}
	if (loc_found)
		{
		/*$('equip_fav_setup').addEventListener("click", function(){
			equip_setup(this);
			}, false);*/
		$('equip_fav_setup_area').style.display = 'inline';
		equip_setup($('equip_fav_setup'));
		}
	else
		$('equip_fav_setup_area').style.display = 'none';
		
}
function save_setup ()
{
	//alert(asetup+'\n'+mweapon+'*'+mbase+'*'+mcheese);
	
	var sep = '/';	
	for (var i=0; i<asetup.length; i++)
		if (asetup_b[i][0]=='-'
			&& asetup_b[i][1]==mweapon
			&& asetup_b[i][2]==mbase
			&& asetup_b[i][3]==mcheese)
			return;	//duplicate entry
			

	asetup.push('-'+sep+mweapon+sep+mbase+sep+mcheese);
	asetup.sort();
	GM_setValue('asetup', asetup.toString());
	
	
	if(window.location.href.indexOf('facebook.com/mousehunt')!=-1)
		display_setup();
}
function save_setup_loc()
{
	var sep = '/';

	for (var i=0; i<asetup.length; i++)
		if (asetup_b[i][0]==mloc)
			{
			asetup.splice(i--,1);
			break;
			}
	asetup.push(mloc+sep+mweapon+sep+mbase+sep+mcheese);
	//asetup+=','+mloc+sep+mweapon+sep+mbase+sep+mcheese;
	asetup.sort();
	GM_setValue('asetup', asetup.toString());
	display_setup();
				
}
function equip_setup (obj)
{
	var setup_id;
	if (obj.id=='equip_fav_setup')
		{
		for (var i=0; i<asetup.length; i++)
			if (asetup_b[i][0]==mloc)
				{
				setup_id=i;
				break;
				}	
		}
	else
		setup_id = parseInt(obj.id.replace('equip_setup',''));
	
	//alert(obj.id + '*' + setup_id);// );
	
	var url_param = "";
	if (asetup_b[setup_id][1]!=mweapon)
		url_param += "&Weapon="+asetup_b[setup_id][1];
	if (asetup_b[setup_id][2]!=mbase)
		url_param += "&Base="+asetup_b[setup_id][2];
	if (asetup_b[setup_id][3]!=mcheese)
		url_param += "&Cheese="+asetup_b[setup_id][3];
	if (url_param=="")
		{
		obj.href = 'javascript:alert("This is your current setup. No need to equip.");';
		//obj.style.color = 'inherit';
		return;
		}
	obj.href = "http://apps.facebook.com/mousehunt/inventory.php?Mhizer=Setup"+url_param;
	//obj.style.color = 'blue';
	//obj.target = 'ifr';
	/*$('ifr').style.display = 'block';
	$('ifr').style.position = 'absolute';
	$('ifr').style.top = '0px';
	$('ifr').style.left = '0px';
	$('ifr').style.width = '100%';*/
	
	
}

function MHizer_setup_GO ()
{
	if(MHizerSec==-1)
		return;
	if(MHizerSec==0)
		{
		window.location.href=go_url;
		return;
		}
	
	$('MHizerSec').innerHTML = MHizerSec--;
	setTimeout(MHizer_setup_GO, 1000);
}

function setup_message(t)
{

	var cbox = document.createElement('div');
	//document.body.appendChild(JS);
	cbox.id = 'cbox';
	cbox.style.width = '100%';
	cbox.style.background = 'lightyellow';
	cbox.style.fontSize = '14pt';
	cbox.style.verticalAlign='center';
	cbox.style.textAlign='center';
	cbox.innerHTML = t+
	((MHizerSec==-1)? '<br><br><a id=MHizerStop href=javascript:;>Close this message</a>' :
		' in <span id=MHizerSec>'+usr_delay+'</span> seconds...'+
		'<br><br><a  href='+go_url+'>Now</a> | <a id=MHizerStop href=javascript:;>Cancel</a>');
	
	document.body.insertBefore(cbox, document.body.childNodes[0]);
	
	$('MHizerStop').addEventListener("click", function () {document.body.removeChild($('cbox'));MHizerSec=-1;}, true );
	MHizer_setup_GO();
}

function check_and_go ()
{
	var what = gup(window.location.href, 'Mhizer');

	if (what=='Cheese')
		{
		if ($('app10337532241_contentcontainer').innerHTML.indexOf('Trap bait changed.')==-1 &&
			$('app10337532241_contentcontainer').innerHTML.indexOf('Trap setup changed.')==-1)
			{
			go_url = window.location.href.replace('hash='+gup(window.location.href,'hash'),'hash='+mh_hash);
			var retry = gup(window.location.href,'retry');
			
			if (retry=='')
				{
				go_url += '&retry=1';
				}
			else
				{
				retry = parseInt(retry);
				if (retry<=3)
					{
					go_url = go_url.replace('retry='+retry,'&retry='+(++retry));
					setup_message('Failed to change your '+what+'.<br>Retrying..');
					}
				}
			}
		return;
		}

	if (what!='Setup')
		return;
	//what=='setup'
	//http://apps.facebook.com/mousehunt/inventory.php?Mhizer=Setup&Base=Polar%20Base&Cheese=Brie

	var tochange, tochange_full;
	var skipweapon=false, skipbase=false, skipcheese=false;

	do
		{
		if (!skipweapon && gup(window.location.href, 'Weapon')!='')
			what='Weapon';
		else if (!skipbase && gup(window.location.href, 'Base')!='')
			what='Base';
		else if (!skipcheese && gup(window.location.href, 'Cheese')!='')
			what='Cheese';
		else
			return;
		tochange_full = gup(window.location.href, what).replace(/%20/g,' ').replace(/%27/g,"'");
		tochange = tochange_full.replace('...','').substr(0,16).toLowerCase();
		
		if (what=='Weapon' && tochange==mweapon.replace('...','').toLowerCase())
			{what='Setup'; skipweapon=true;}
		else if (what=='Base' && tochange==mbase.replace('...','').toLowerCase())
			{what='Setup'; skipbase=true;}
		else if (what=='Cheese' && tochange==mcheese.replace('...','').toLowerCase())
			{what='Setup'; skipcheese=true;}
		
		//alert(what+'*'+mbase.replace('...','').toLowerCase()+'*'+tochange+'*'+(tochange==mbase.replace('...','').toLowerCase()));
		}
	while (what=='Setup')

	var allD = $('app10337532241_inv'+((what=='Cheese')? 'Cheese':'Traps')).getElementsByTagName('div');
		for (var i=0; i<allD.length; i++)
			if(allD[i].getAttribute('class')=='itemname')
				{		
				var inna = allD[i].innerHTML.substr(0, allD[i].innerHTML.indexOf('&nbsp;&nbsp;<span'));
				
				
				//alert(inna.substr(0,16).toLowerCase()+'*'+tochange);
				
				if (allD[i].parentNode.getElementsByTagName('a').length>0)
					go_url = allD[i].parentNode.getElementsByTagName('a')[0].href+'&'+
					window.location.href.substr(window.location.href.indexOf('Mhizer'),
						window.location.href.length)
					.replace('&'+what+'='+gup(window.location.href, what),'');
				else
					continue;
				
				/*if (skipweapon)
					go_url = go_url.replace('&Weapon='+gup(go_url,'Weapon'),'');
				if (skipbase)
					go_url = go_url.replace('&Base='+gup(go_url,'Base'),'');
				if  (skipcheese)
					go_url = go_url.replace('&Cheese='+gup(go_url,'Cheese'),'');//not necessary*/
					
				if (inna.substr(0,16).toLowerCase()==tochange)
					{
					setup_message('Attempting to change your '+what+' to "'+inna+'"');
					return;
					}
				}
	MHizerSec=-1;
	setup_message('<B style=color:red>Error:</B> The Maid cannot find "'+tochange_full+'" in your inventory.');

}

function shortenme(t)
{
	return t.substr(0,16) + ((t.length>16)? '...':'');
}

function xmlhttp(url, fn)
{
	try
		{
			GM_xmlhttpRequest({
				method: 'GET',
				url: url,
				headers: {
					'User-agent': 'Mozilla/4.0 (compatible) Greasemonkey',
					'Content-type':'application/x-www-form-urlencoded',
					},
				onload: function(responseDetails) {
					if (responseDetails.status != 200)
						{
						alert("Your internet connection or MH server is temporarily down.");
						return;
						}
					get_mh_hash(responseDetails.responseText);
					fn(responseDetails.responseText);
				}
			});
		}
	catch (e)
		{
		GM_log(e);
		}
}
function get_mh_hash(text)
{
	mh_hash = text.match (/_submithash = '([^;]+)';/)
	//mh_hash = unsafeWindow.a10337532241_submithash;
	if (!mh_hash)
		return;
	mh_hash = mh_hash[1];
}
function get_list()
{
	if (window.location.toString().indexOf('http://apps.facebook.com/mousehunt/inventory.php')==-1)
		{
		xmlhttp('http://apps.facebook.com/mousehunt/inventory.php', update_list);
		return;
		}
	update_list();
}
function update_list(t)
{
	var hid;
	if (window.location.toString().indexOf('http://apps.facebook.com/mousehunt/inventory.php')==-1)
		{
		hid = document.createElement('div');
		hid.style.display = 'none';
		hid.innerHTML = t;
		document.body.appendChild(hid);
		}
	
	mh_inventory = new Array();
	var allD = $('app10337532241_invCheese').getElementsByTagName('div');
	for (var i=0; i<allD.length; i++)
		if(allD[i].getAttribute('class')=='itemname')
			{
			
			var inna = allD[i].innerHTML.replace('&nbsp;&nbsp;<span class="itemstock">( ','&count=')
				.replace(/ piece[s]* \)<\/span>/,'').replace(/,/g,''); //.replace(/ /g,'&nbsp;');
			if (inna=='Need to buy more cheese?')
				continue;
			
			var idee;
			if (allD[i].parentNode.getElementsByTagName('a').length>0)
				idee = gup(allD[i].parentNode.getElementsByTagName('a')[0].href,'bait');
			
			mh_inventory.push('&type=Cheese&name='+inna+'&id='+idee);
			
			}
			
	
	allD = $('app10337532241_invTraps').getElementsByTagName('div');
	for (var i=0; i<allD.length; i++)
		if(allD[i].getAttribute('class')=='itemname')
			{
			var inna = allD[i].innerHTML.replace('&nbsp;&nbsp;<span class="itemstock">( ','&count=')
				.replace(' power )</span>',''); //.replace(/ /g,'&nbsp;');
			if (inna=='Need to upgrade your trap?')
				continue;
			
			var idee;
			if (allD[i].parentNode.getElementsByTagName('a').length>0)
				idee = gup(allD[i].parentNode.getElementsByTagName('a')[0].href,'equip');
			
			if (inna.indexOf('Base')==-1)	//This is a lazy way - better check class="inventorycomptype"
				mh_inventory.push('&type=Weapon&name='+inna+'&id='+idee);
			else
				mh_inventory.push('&type=Base&name='+inna+'&id='+idee);
			
			}
			
	allD = $('app10337532241_invPotions').getElementsByTagName('div');
	for (var i=0; i<allD.length; i++)
		if(allD[i].getAttribute('class')=='itemname')
			{
			
			var inna = allD[i].innerHTML.replace('&nbsp;&nbsp;<span class="itemstock">( ','&count=')
				.replace(/ potion[s]* \)<\/span>/,''); //.replace(/ /g,'&nbsp;');
			
			var idee = xpathFirst("//input[@name='curdy_potion_id']", allD[i].parentNode);

			mh_inventory.push('&type=Potions&name='+inna+'&id='+idee);
			}
			
	allD = $('app10337532241_invCrafting').getElementsByTagName('div');
	for (var i=0; i<allD.length; i++)
		if(allD[i].getAttribute('class')=='itemname')
			{
			
			var inna = allD[i].innerHTML.replace('&nbsp;&nbsp;<span class="itemstock">( x','&count=')
				.replace(' )</span>','').replace(/,/g,'');
			
			var idee = xpathFirst("//input[@name='curdy_potion_id']", allD[i].parentNode);

			mh_inventory.push('&type=Crafting&name='+inna+'&id='+idee);
			}
	
	allD = $('app10337532241_invMisc').getElementsByTagName('div');
	for (var i=0; i<allD.length; i++)
		if(allD[i].getAttribute('class')=='itemname')
			{
			
			var inna = allD[i].innerHTML.replace('&nbsp;&nbsp;<span class="itemstock">( x','&count=')
				.replace(' )</span>','').replace(/,/g,'');
			
			var idee;
			if (allD[i].parentNode.getElementsByTagName('a').length>0)
				idee = gup(allD[i].parentNode.getElementsByTagName('a')[0].href,'convertible');

			mh_inventory.push('&type=Misc&name='+inna+'&id='+idee);
			}
	
	if (hid)
		document.body.removeChild(hid);
			
	mh_inventory.sort();
				
	GM_setValue('mh_inventory', mh_inventory.toString());

	display_list();
}

function display_list()
{

if (!usr_mh_ss || !$('app10337532241_hud'))
	return;
	
	var mh_inventory_cheese_str = "", 
		mh_inventory_weapon_str = "",
		mh_inventory_base_str = "",
		mh_inventory_potion_str = "",
		mh_inventory_craft_str = "<TABLE border=0 cellspacing=0 cellpadding=0><COL width=200>",
		mh_inventory_map_str = "";
		mh_inventory_misc_str = "";
		
	var cheese_cnt=0, weapon_cnt=0, base_cnt=0, potion_cnt=0, craft_cnt=0, map_cnt=0, misc_cnt=0;
	
	for (var i=0; i<mh_inventory.length; i++)
		{	
		if (gup(mh_inventory[i],'type')=='Cheese')
			{
			cheese_cnt++;
			if (gup(mh_inventory[i],'name').substr(0,16)==mcheese.replace('...',''))
				{
				mh_inventory[i]=mh_inventory[i].replace(/&count=(.+)&id=/,'&count='+mcheese_cnt+'&id=');
				GM_setValue('mh_inventory', mh_inventory.toString());
				
				mh_inventory_cheese_str += mh_inventory[i].toString().replace(/&type=Cheese&name=(.+)&count=(.+)&id=(.+)/, '$1 ('+mcheese_cnt+')<br>');
				}
			else
				mh_inventory_cheese_str += mh_inventory[i].toString().replace(/&type=Cheese&name=(.+)&count=(.+)&id=(.+)/, '<A href=http://apps.facebook.com/mousehunt/inventory.php?Mhizer=Cheese&bait=$3&hash='+mh_hash+'&tab=invCheese>$1 ($2)</A><br>');
			}
		else if (gup(mh_inventory[i],'type')=='Weapon')
			{
			weapon_cnt++;
			if (gup(mh_inventory[i],'name').substr(0,16)==mweapon.replace('...',''))
				mh_inventory_weapon_str += mh_inventory[i].toString().replace(/&type=Weapon&name=(.+)&count=(.+)&id=(.*)/, '$1<br>');
			else
				mh_inventory_weapon_str += mh_inventory[i].toString().replace(/&type=Weapon&name=(.+)&count=(.+)&id=(.+)/, '<A href=http://apps.facebook.com/mousehunt/inventory.php?Mhizer=Weapon&equip=$3&hash='+mh_hash+'&tab=invTraps>$1</A><br>');
			}
		else if (gup(mh_inventory[i],'type')=='Base')
			{
			base_cnt++;
			if (gup(mh_inventory[i],'name').substr(0,16)==mbase.replace('...',''))
				mh_inventory_base_str += mh_inventory[i].toString().replace(/&type=Base&name=(.+)&count=(.+)&id=(.*)/, '$1<br>');
			else
				mh_inventory_base_str += mh_inventory[i].toString().replace(/&type=Base&name=(.+)&count=(.+)&id=(.+)/, '<A href=http://apps.facebook.com/mousehunt/inventory.php?Mhizer=Base&equip=$3&hash='+mh_hash+'&tab=invTraps>$1</A><br>');
		
			}
		else if (gup(mh_inventory[i],'type')=='Potions')
			{
			potion_cnt++;
			mh_inventory_potion_str += mh_inventory[i].toString().replace(/&type=Potions&name=(.+)&count=(.+)&id=(.+)/, '$1 ($2)<br>');
			}
		else if (gup(mh_inventory[i],'type')=='Crafting')
			{
			if (craft_cnt++%2==0)
				mh_inventory_craft_str +='<TR>';
			mh_inventory_craft_str += '<TD>'+mh_inventory[i].toString().replace(/&type=Crafting&name=(.+)&count=(.+)&id=(.+)/, '$1 ($2)');

			}
		else if (gup(mh_inventory[i],'type')=='Misc')
			{
			misc_cnt++;
			mh_inventory_misc_str += mh_inventory[i].toString().replace(/&type=Misc&name=(.+)&count=(.+)&id=(.+)/, '<A href=http://apps.facebook.com/mousehunt/inventory.php?tab=invMisc&convertible=$3&hash='+mh_hash+'>$1 ($2)</A><br>');
			}
		}
	mh_inventory_craft_str+='</TABLE>';
	
	$('mhizer_menuCheese').innerHTML =  
		'<B><A href=http://apps.facebook.com/mousehunt/cheeseshoppe.php>Visit Cheese Shoppe</A></B>'
		+ ' | <A id=rf_cheese href=javascript:;>Refresh list</A><hr>'
		+ ((cheese_cnt==0)? 'No cheese found': mh_inventory_cheese_str);
	$('mhizer_menuWeapon').innerHTML =  
		'<A href=http://apps.facebook.com/mousehunt/trapsmith.php><B>Visit TrapSmith</B></A>'
		+ ' | <A id=rf_weapon href=javascript:;>Refresh list</A><hr>'
		+ ((weapon_cnt==0)? 'No weapons found': mh_inventory_weapon_str);
	$('mhizer_menuBase').innerHTML =  
		'<A href=http://apps.facebook.com/mousehunt/trapsmith.php><B>Visit TrapSmith</B></A>'
		+ ' | <A id=rf_base href=javascript:;>Refresh list</A><hr>'
		+ ((base_cnt==0)? 'No bases found': mh_inventory_base_str);
	$('mhizer_menuPotions').innerHTML =  
		'<A id=rf_potion href=javascript:;>Refresh list</A><hr>'
		+ ((potion_cnt==0)? 'No potions found': mh_inventory_potion_str);
	$('mhizer_menuCrafting').innerHTML =  
		'<A id=rf_craft href=javascript:;>Refresh list</A><hr>'
		+ ((craft_cnt==0)? 'No crafting items found': mh_inventory_craft_str);
	$('mhizer_menuMisc').innerHTML =  
		'<A id=rf_misc href=javascript:;>Refresh list</A><hr>'
		+ ((misc_cnt==0)? 'No misc items found': mh_inventory_misc_str);

	
	var alist=['cheese', 'weapon', 'base', 'potion', 'craft', 'misc'];
	for (var i in alist)
		$('rf_'+alist[i]).addEventListener("click", get_list, true);

}

var mh_inventory = new Array();

function MAIN_PROGRAM ()
{

	if (false) //(usr_mh_sc)
		{
		var usr_chk_tm_last = GM_getValue('usr_chk_tm_last',0);
		usr_chk_tm_last = (usr_chk_tm_last==0)? 0:Date.parse(usr_chk_tm_last);
		
		var todai = new Date();
		
		if (Date.parse(todai)-usr_chk_tm_last>900000)
			{
			var ALINK = document.getElementsByTagName('a');
			for (var i=0; i<ALINK.length; i++)
				{
				if ((ALINK[i].href=="http://apps.facebook.com/mousehunt/" || ALINK[i].href=="http://apps.facebook.com/mousehunt/index.php"))
					ALINK[i].href="http://apps.facebook.com/mousehunt/soundthehorn.php";
				//else if (ALINK[i].href=="http://apps.facebook.com/mythmonger/")
					//ALINK[i].href="http://apps.facebook.com/mythmonger/turn.php";
				}
			}
		}

	if (document.location.href.indexOf("facebook.com")!=-1)
		{
		if (usr_rm_fb)
			{
			if ($('sidebar_ads'))
				{
				//$('sidebar_ads').style.display='none';
				$('sidebar_ads').style.visibility='hidden';
				$('sidebar_ads').style.height='0px';
				}
			/*if ($('profile_sidebar_ads'))
				{
				$('profile_sidebar_ads').style.visibility='hidden';
				$('profile_sidebar_ads').style.height='0px';
				}*/
			document.addEventListener("DOMNodeInserted", Remove_All_Facebook_Ads, true);
			
			}
		show_rev();
		
		document.addEventListener('click', function() { window.setTimeout(poo_party, 5000);}, true);
		
		if (is_forum_page())
			poo_party();
		else
			{
			if (document.location.href.indexOf("facebook.com/mousehunt")==-1)
				{
				add_mh_friends();	
				poo_fb_mhz();
				} //will be called later if on MH page
			}
		}


	if (document.location.href.indexOf("facebook.com/mousehunt")!=-1)
		{
		get_mh_hash(document.body.innerHTML);
		
		if (!mh_hash)
			return;
		
		ur_name = $('fb_menu_account').childNodes[0].innerHTML;
		ur_fb_id = gup($('app10337532241_gamelogo').childNodes[0].href,'snuid');
		//alert(ur_name+'*'+ur_fb_id);
		
		if ($('app10337532241_contentcontainer') && $('app10337532241_contentcontainer').innerHTML.indexOf("You sounded the Hunter's Horn!")!=-1)
			{
			var todai = new Date();
			GM_setValue('usr_chk_tm_last',String(todai));
			}
		
		if (usr_mh_mn && $('app10337532241_mainnav'))
			{
			var mmenubar = $('app10337532241_mainnav'); 
			var menubar = mmenubar.childNodes[1].childNodes[1];
			
			//fbjs_dom.eventHandler.call([fbjs_dom.get_instance(this,10337532241),function(a10337532241_event) {a10337532241_javascript:a10337532241_toggleNavCategory('nav.travel', 'visible');},10337532241],new fbjs_event(event));
			menubar.addEventListener("mouseover", function() {
			$('app10337532241_nav.travel').style.visibility='visible';
			},
			false);
			
			//fbjs_dom.eventHandler.call([fbjs_dom.get_instance(this,10337532241),function(a10337532241_event) {a10337532241_javascript:a10337532241_toggleNavCategory('nav.travel', 'visible');},10337532241],new fbjs_event(event));
			menubar.addEventListener("mouseout", function() {
			$('app10337532241_nav.travel').style.visibility='hidden';
			},
			false);
			var obj = document.createElement('span');
			obj.innerHTML = '<ul id="app10337532241_nav.travel" style="left: 140px; width: 120px;" >'+
			'<li><a href="http://apps.facebook.com/mousehunt/travel.php">Travel Now</a></li>'+
			'<li><a href="http://furoma.com/mousehunt_travel_planner.html?utm_campaign=mhizer_menu">PF Travel Planner</a></li>'+
			'<li><a href="http://furoma.com/best_location.html?utm_campaign=mhizer_menu">PF Best Location</a></li>'+
			'<li><a href="http://furoma.com/forbidden_grove_timer.html?utm_campaign=mhizer_menu">PF FG Timer</a></li>'+
			'</ul>';
			menubar.appendChild(obj);
			
			
			
			menubar = $('app10337532241_nav.inventory');
			menubar.style.width='100px';
			obj = document.createElement('li');
			obj.innerHTML = 
			'<a href="http://furoma.com/catch_rates_estimates.html?utm_campaign=mhizer_menu">PF Catch Rates</a>';
			menubar.appendChild(obj);
			obj = document.createElement('li');
			obj.innerHTML = 
			'<a href="http://furoma.com/best_setup.html?utm_campaign=mhizer_menu">PF Best Setup</a>';
			menubar.appendChild(obj);

			menubar = $('app10337532241_nav.shops');
			obj = document.createElement('li');
			obj.innerHTML = 
			'<a href="http://furoma.com/mousehuntizer/?utm_campaign=mhizer_menu">PF Config MHizer</a>';
			menubar.appendChild(obj);
			obj = document.createElement('li');
			obj.innerHTML = 
			'<a href="http://furoma.com/game_zone.html?utm_campaign=mhizer_menu">PF Game Zone</a>';
			menubar.appendChild(obj);
			
			menubar = $('app10337532241_nav.mice');
			obj = document.createElement('li');
			obj.innerHTML = 
			'<a href="http://furoma.com/mousehuntizer/template.html?page=mouse_tally&utm_campaign=mhizer_menu">PF Mouse Tally</a>';
			menubar.appendChild(obj);

			menubar = $('app10337532241_nav.friends');
			obj = document.createElement('li');
			obj.innerHTML = 
			'<a href="http://furoma.com/mousehunt_tariff_calculator.html?utm_campaign=mhizer_menu">PF Tariff Calculator</a>';
			menubar.appendChild(obj);
			
			menubar = $('app10337532241_nav.lore');
			obj = document.createElement('li');
			obj.innerHTML = 
			'<a href="http://furoma.com/mhwiki/?utm_campaign=mhizer_menu">PF MH Uncyclopedia</a>';
			menubar.appendChild(obj);
			
			

			menubar = mmenubar.childNodes[1].childNodes[13];
			menubar.addEventListener("mouseover", function() {
			$('app10337532241_nav.news').style.visibility='visible';
			},
			false);
			menubar.addEventListener("mouseout", function() {
			$('app10337532241_nav.news').style.visibility='hidden';
			},
			false);
			var obj = document.createElement('span');
			obj.innerHTML = '<ul id="app10337532241_nav.news" style="left: 606px; width: 100px;" >'+
			'<li><a href="http://apps.facebook.com/mousehunt/news.php">Official News</a></li>'+	
			'<li><a href="http://www.ustream.tv/channel/mousehunt-live!">Feedback Friday</a></li>'+
			'<li><a href="http://www.facebook.com/pooflinger">PF Facebook Page</a></li>'+
			'<li><a href="http://furoma.com/guide/?utm_campaign=mhizer_menu">PF Sean\'s Guide</a></li>'+
			'<li><a href="http://furoma.com/analytics/?utm_campaign=mhizer_menu">PF MH Analytics</a></li>'+
			'<li><a href="http://furoma.com/mhsearch/?utm_campaign=mhizer_menu">PF MH Search</a></li>'+
			'</ul>';
			menubar.appendChild(obj);
			
			menubar = xpathFirst("//div[@class='journalcontent']");
			if (menubar && menubar.childNodes.length>0)
				{
				var obj = document.createElement('span');
				obj.innerHTML='<SPAN style=position:relative;left:80px;>Analyze with: '+
				'<A href=http://furoma.com/mousehunt_log_summarizer.php?utm_campaign=mhizer_journal>PF Log Summarizer</A> | '+
				'<A href=http://furoma.com/log_parser.html?utm_campaign=mhizer_journal>PF Log Parser</A></SPAN>';
				menubar.insertBefore(obj, menubar.childNodes[0]);
				}
			}
			
		
		if(usr_mh_ss && $('app10337532241_hud'))
			{
						
			/*var ifr = document.createElement('iframe');
			ifr.style.display = 'none';
			ifr.style.zIndex = '100';
			ifr.id = 'ifr';
			ifr.setAttribute ('name', 'ifr');
			document.body.appendChild(ifr);*/
			
			mtitlep = $('app10337532241_titlebar').getAttribute('title').replace(' complete','');
			
			var newcol = document.createElement('div');
			newcol.setAttribute('class','hudstatlist');
			//newcol.style.position = 'relative';
			//newcol.style.left = '7px';
			//newcol.style.left = '7px';
			newcol.innerHTML = 
				'<span class=hudstatlabel>Potions</span> | '
				+'<span class=hudstatlabel>Crafting</span> | '
				+'<span class=hudstatlabel>Misc</span> | '
				+'<span class=hudstatlabel>Friends</span> | '
				+'<span class=hudstatlabel>Pooflinger</span> | '
				+'<span class=hudstatlabel>Special</span>';

			$('app10337532241_hud').insertBefore(newcol, $('app10337532241_hud').childNodes[$('app10337532241_hud').childNodes.length-2]);
			
			var allS = $('app10337532241_hud').getElementsByTagName('span');
			for (var i=0; i<allS.length; i++)
				{
				if(allS[i].getAttribute('class')=='hudstatlabel')
					{
					
					var dd = document.createElement('div');
					
					var aurl;
					var Txt=allS[i].innerHTML.replace(':',''), Txt2=Txt;
						
					if (Txt=='Location')
						{
						aurl='http://apps.facebook.com/mousehunt/travel.php';
						dd.style.width='200px';
						mloc = allS[i].parentNode.innerHTML.match(/&nbsp;&nbsp;(.+)/)[1];
						dd.innerHTML=
						'<A mhizer=1 href=http://furoma.com/mousehunt_travel_planner.html?utm_campaign=mhizer_status>PF Travel Planner</A>'
						+' | <A mhizer=1 href=http://furoma.com/forbidden_grove_timer.html?utm_campaign=mhizer_status>PF FG Timer</A>'
						+' <a href=\'javascript:alert("'
						+'This list shows only locations that have been associated with a favorite setup.'
						+'\\nTo travel to other locations, please visit PF Travel Planner.'
						+'\\n\\nIf auto-posting to Travel Planner is turned on, and you do not want to stop over anywhere, then you can also call the Chauffeur from here.'
						+'");\'>[?]</a><hr>'
						+'<span id=loc_list></span>';
						Txt2=Txt+':';
						}
					else if (Txt=='Title')
						{
						aurl='http://apps.facebook.com/mousehunt/scoreboard.php';
						dd.style.width='250px';
						mtitle = allS[i].parentNode.innerHTML.match(/&nbsp;&nbsp;(.+) \(/)[1];
						dd.innerHTML = //mtitle + ' ('+mtitlep+')'
							'<b>All Stats</b>: '
							+'<a mhizer="1" href="http://apps.facebook.com/mousehunt/scoreboard.php?seek='+ur_fb_id+'&amp;sort=points">point rank</a> | '
							+'<a mhizer="1" href="http://apps.facebook.com/mousehunt/scoreboard.php?seek='+ur_fb_id+'&amp;sort=gold">gold rank</a> | '
							+'<a mhizer="1" href="http://apps.facebook.com/mousehunt/scoreboard.php?seek='+ur_fb_id+'&amp;sort=mice">mice rank</a>'
							+'<br><b>Friend Stats</b>: '
							+'<a mhizer="1" href="http://apps.facebook.com/mousehunt/scoreboard.php?view=frnds&seek='+ur_fb_id+'&amp;sort=points">point rank</a> | '
							+'<a mhizer="1" href="http://apps.facebook.com/mousehunt/scoreboard.php?view=frnds&seek='+ur_fb_id+'&amp;sort=gold">gold rank</a> | '
							+'<a mhizer="1" href="http://apps.facebook.com/mousehunt/scoreboard.php?view=frnds&seek='+ur_fb_id+'&amp;sort=mice">mice rank</a>'
							;
						
						

						allS[i].parentNode.innerHTML = '<nobr><span class="hudstatlabel">Title:</span>&nbsp;&nbsp;'
						+ mtitle + ' ('+mtitlep+')';
						Txt2=Txt+':';
						}
					else if (Txt=='Base')
						{
						aurl='http://apps.facebook.com/mousehunt/inventory.php?tab=invTraps';
						dd.style.width='200px';
						mbase = allS[i].parentNode.innerHTML.match(/&nbsp;&nbsp;(.+)/)[1];
						dd.innerHTML='';
						Txt2=Txt+':';
						}
					else if (Txt=='Weapon')
						{
						aurl='http://apps.facebook.com/mousehunt/inventory.php?tab=invTraps';
						dd.style.width='250px';
						mweapon = allS[i].parentNode.innerHTML.match(/&nbsp;&nbsp;(.+)/)[1];
						dd.innerHTML='';
						Txt2=Txt+':';
						}
					else if (Txt=='Cheese')
						{
						aurl='http://apps.facebook.com/mousehunt/inventory.php?tab=invCheese';
						dd.style.width='200px';
						if (allS[i].parentNode.innerHTML.match(/&nbsp;&nbsp;(.+) \(/))
							{
							mcheese = allS[i].parentNode.innerHTML.match(/&nbsp;&nbsp;(.+) \(/)[1];
							mcheese_cnt = allS[i].parentNode.innerHTML.match(/&nbsp;&nbsp;(.+) \((.+)\)/)[2].replace(/,/g,'');;
							}
						else
							{mcheese = 'none';
							mcheese_cnt = '0';
							}
						dd.innerHTML='';
						Txt2=Txt+':';
						}
					else if (Txt=='Trap Power')
						{
						aurl='javascript:;';
						dd.style.width='600px';
						dd.innerHTML=
						'<A mhizer=1 id=save_setup href=javascript:;>Save this setup</A>'
						+'<span id=equip_fav_setup_area> | <A mhizer=1 id=equip_fav_setup href=javascript:;>Equip with favorite setup for '+mloc+'</A></span>'
						+' | <A mhizer=1 id=save_setup_loc href=javascript:;>Save as favorite setup for '+mloc+'</A>'
						+' <a href=\'javascript:alert("'
						+'Do you want to save as favorite for other locations?'
						+'\\nWait until you travel there, or use the Best Location Tool!'
						+'");\'>[?]</a>'
						+'<br> <A mhizer=1 href=http://furoma.com/best_location.html?utm_campaign=mhizer_status>PF Best Location</A>'
						+' | <A mhizer=1 href=http://furoma.com/best_setup.html?utm_campaign=mhizer_status>PF Best Setup</A>'
						+' | <A mhizer=1 href=http://furoma.com/catch_rates_estimates.html?utm_campaign=mhizer_status>PF Catch Rates</A>'
						+'<hr><span id=setup_list>No setups saved</span>';
						Txt2=Txt+':';
						}
					else if (Txt=='Potions')
						{
						aurl='http://apps.facebook.com/mousehunt/inventory.php?tab=invPotions';
						dd.style.width='300px';
						dd.innerHTML='';
						}
					else if (Txt=='Crafting')
						{
						aurl='http://apps.facebook.com/mousehunt/inventory.php?tab=invCrafting';
						dd.style.width='400px';
						dd.innerHTML='';
						}
					else if (Txt=='Misc')
						{
						aurl='http://apps.facebook.com/mousehunt/inventory.php?tab=invMisc';
						dd.style.width='200px';
						dd.innerHTML='';
						}
					else if (Txt=='Friends')
						{
						aurl='http://furoma.com/mousehuntizer/template.html?page=mh_friends';
						dd.style.width='200px';
						dd.innerHTML='';
						}
					else if (Txt=='Gold')
						{
						aurl='http://apps.facebook.com/mousehunt/scoreboard.php?seek='+ur_fb_id+'&sort=gold';
						dd.style.width='150px';
						dd.innerHTML=
						'<A href=http://apps.facebook.com/mousehunt/scoreboard.php?seek='+ur_fb_id+'&sort=gold>Global rank</A>'+
						' | <A href=http://apps.facebook.com/mousehunt/scoreboard.php?view=frnds&seek='+ur_fb_id+'&sort=gold>Friend rank</A>';
						Txt2=Txt+':';
						}
					else if (Txt=='Points')
						{
						aurl='http://apps.facebook.com/mousehunt/scoreboard.php?view=frnds&seek='+ur_fb_id+'&sort=gold';
						dd.style.width='150px';
						dd.innerHTML=
						'<A href=http://apps.facebook.com/mousehunt/scoreboard.php?seek='+ur_fb_id+'&sort=points>Global rank</A>'+
						' | <A href=http://apps.facebook.com/mousehunt/scoreboard.php?view=frnds&seek='+ur_fb_id+'&sort=points>Friend rank</A>';
						Txt2=Txt+':';
						}
					else if (Txt=='Pooflinger')
						{
						aurl='http://www.facebook.com/pooflinger';
						dd.style.width='150px';
						dd.innerHTML=
						'<A mhizer=1 href=http://www.facebook.com/pooflinger>PF on Facebook</A>'+
						'<BR><A mhizer=1 href=http://furoma.com/?utm_campaign=mhizer_status>PF Tools Homepage</A>'+
						'<BR><A mhizer=1 href=http://furoma.com/mousehuntizer?utm_campaign=mhizer_status>PF Config MHizer</A>';
						
						}
					else if (Txt=='Special')
						{
						aurl='javascript:;';
						dd.style.width='150px';
						dd.innerHTML=
						'<A mhizer=1 href=http://furoma.com/mousehuntizer/template.html?page=mh_friends&utm_campaign=mhizer_status>PF MH Friends</A>'+
						'<BR><A mhizer=1 href=http://furoma.com/mousehuntizer/template.html?page=mouse_tally&utm_campaign=mhizer_status>PF Mouse Tally</A>';
						
						}
					else
						continue;
					
					allS[i].innerHTML = '<A mhizer=1 style=color:inherit href='+aurl+' rel="mhizer_menu'+Txt+'">'+Txt2+'</A>';
					
					
					dd.id='mhizer_menu'+Txt;
					dd.setAttribute('class','balloonstyle');
					//$('app_content_10337532241').appendChild(dd);
					document.body.appendChild(dd);
					}
				}
			
			
			// INIT JS FILE
			init_js_balloon();
				
					
			// INIT DISPLAY INVENTORY
			
			if (document.location.href.indexOf("facebook.com/mousehunt/inventory.php")==-1)
				{
				
				mh_inventory = GM_getValue('mh_inventory', '').split(',');
				
				/*var i=-1;
				do
					{
					mh_inventory.push(GM_getValue('mh_inventory'+(++i), 'none'));
					}
				while (mh_inventory[i]!='none' && i<100)
				mh_inventory.splice(i, 1); */
				
				//if (i==0)
					//ifr.setAttribute ('src','http://apps.facebook.com/mousehunt/inventory.php');
				}
			
			// DISPLAY SAVED SETUPS
			
			display_setup();
			
			
			// SAVE SETUP
			
			$('save_setup').addEventListener("click", save_setup, false);
				
			$('save_setup_loc').addEventListener("click", save_setup_loc, false);
	
			}
		
		// START INVENTORY 
		if (document.location.href.indexOf("facebook.com/mousehunt/inventory.php")!=-1
			&& $('app10337532241_invCheese') && $('app10337532241_invTraps'))
			{
			
			get_list();
			
			if(gup(window.location.href, 'Mhizer')!='')
				{
				check_and_go(); 
				}
			
			}
			// END INVENTORY PAGE
			
			// START DISPLAY
			display_list();
			// END DISPLAY
		
		
		google_analytics();
		
		if (document.location.href.indexOf("facebook.com/mousehunt/supplies.php")!=-1)
			{
			var allDivs = xpathFirst("//select[@name='trade_recipient']");
			allDivs.value=gup(document.location.href,'trade_recipient');
			}
		else if (document.location.href.indexOf("facebook.com/mousehunt/travel.php")!=-1)
			{
			var route = gup(document.location.href,'route');
			var cost = parseInt(gup(document.location.href,'cost'));
			if (route==null || route=='' || ((cost==null || cost=='') && cost!=0))
				return;
			
			var aspan = $('app10337532241_hud').getElementsByTagName('li');
			for (var i=0; i<aspan.length; i++)
				if (aspan[i].innerHTML.indexOf('Gold:')!=-1)
					{
					aspan = aspan[i].innerHTML.replace('<span class="hudstatlabel">Gold:</span>&nbsp;&nbsp;','').replace(/,/g,'');
					aspan = parseInt(aspan);
					break;
					}
			if (aspan < cost && !confirm('You cannot afford the whole trip. Do you want to continue?'+
				'\n\nYou have '+aspan+ ' gold, but you need '+cost+' gold.'))
				return;

			
			route = route.split(',');
			
			var stop = (route[0].indexOf('MHizer')==0)? 1:0;
			var new_route = new Array();
			
			for (var i=stop+1; i<route.length;i++)
				new_route[i-stop-1]=route[i].replace(/%20/g,' ').replace(/%27/g,"'");
			stop = route[stop].replace(/%20/g,' ').replace(/%27/g,"'");
			
			var objw = document.createElement('div');
			//objw.style.position='absolute';
			//objw.style.left='0px';
			//objw.style.top='80px';
			objw.style.width='100%';
			//objw.style.height='220px';
			objw.style.background='lightyellow';
			//objw.style.zIndex='100';
			objw.style.verticalAlign='center';
			objw.style.textAlign='center';
			objw.id = 'objw';
			

			var atag = document.getElementsByTagName('a');
			var afound = false;
			
			if (stop!='Break')
				for (var i=0; i<atag.length;i++)
					if (atag[i].innerHTML==stop)
						{
						afound=true;
						go_url = atag[i].href + '&hash=' +mh_hash+ '&route='+
							((new_route.length==0)? 'done':new_route)
							+'&prev='+stop;
						break;
						}
			
			if (0)//$('app10337532241_contentcontainer').innerHTML.indexOf('Unable to change hunting location.')!=-1)
				{
				objw.innerHTML='<span style=color:brown><span style=font-size:10pt;>'+
				'<B>Sorry. Something is wrong - the Chauffeur is sick.".</B>'+
				'<br><BR>Perhaps the MHizer has a bug, or you do not have access the area ('+
				'you need a map or a higher rank), or you are already at the area.'+
				'<br>If you believe it is a bug, please report the following message to peter[at]furoma.com Thank you.'+
				'<blockquote style="border:1px solid;">URL='+window.location.href+'<br>Error=cannot drive</blockquote><br>'+
				'<a href=javascript:history.back();>Try again</a> | '+
				'<a href=http://furoma.com/mousehunt_travel_planner.html>Back to Travel Planner</a> | '+
				'<a href=javascript:; onclick=document.getElementById("objw").style.display="none";>Close this message</a>'+
				'</span></span>';
				document.body.insertBefore(objw,document.body.childNodes[0]);
				}
			else if (stop=='Break')
				{
				go_url = 'http://apps.facebook.com/mousehunt/travel.php?route='+new_route;
				
				objw.innerHTML='<span style=color:brown><span style=font-size:20pt;><BR>At your request, the Chauffeur is taking a break.<BR></SPAN>'
				+'<span style=font-size:14pt>After the break: '+ ((new_route.length==0)? 'done!':new_route)
				+'<br><br>'
				+'Shop<span style=font-size:10pt> (links open in new window)</span>: '
				+'<A target=_blank href=http://apps.facebook.com/mousehunt/cheeseshoppe.php>Cheese Shoppe</A> | '
				+'<A target=_blank href=http://apps.facebook.com/mousehunt/generalstore.php>General store</A> | '
				+'<A target=_blank href=http://apps.facebook.com/mousehunt/trapsmith.php>Trapsmith</A> | '
				+'<A target=_blank href=http://apps.facebook.com/mousehunt/cartographer.php>Cartographer</A>'
				+'<br><br><A href="'+go_url+'" style=font-size:12pt;font-weight:bold;>Click here to RESUME</A> | '
				+'<A href=javascript:; id=MHizerStop style=font-size:12pt;font-weight:bold;>Click here to STOP</A><span>';
				document.body.insertBefore(objw,document.body.childNodes[0]);
				
				$('MHizerStop').addEventListener("click", function () {document.body.removeChild($('objw'));MHizerSec=-1;}, true );
				}
			else if (!afound && route!='done')	// cannot find the travel link
				{
				objw.innerHTML='<span style=color:brown><span style=font-size:10pt;>'+
				'<B>Sorry the Chauffer does not know this location - "' +stop+ '".</B>'+
				'<br><BR>Perhaps the MHizer has a bug, or you do not have access the area ('+
				'you need a map or a higher rank), or you are already at the area.'+
				'<br>If you believe it is a bug, please report the following message to peter[at]furoma.com Thank you.'+
				'<blockquote style="border:1px solid;">URL='+window.location.href+'<br>Error=not found</blockquote><br>'+
				'<a href=http://furoma.com/mousehunt_travel_planner.html>Back to Travel Planner</a> | '+
				'<a href=javascript:; onclick=document.getElementById("objw").style.display="none";>Close this message</a>'+
				'</span></span>';
				document.body.insertBefore(objw,document.body.childNodes[0]);
				}
			else if (route=='done' && usr_mh_sm && //smart maid
					$('equip_fav_setup_area') && $('equip_fav_setup_area').style.display == 'inline')
				{
				//equip_setup($('equip_fav_setup'));
				
				go_url=$('equip_fav_setup').href;
				if (go_url.indexOf('alert')!=-1)
					return;
				
				objw.innerHTML='<span style=font-size:14pt;><BR>'
				+'Preparing your favorite setup for '+mloc+' in <SPAN id=MHizerSec>'+usr_delay+'</SPAN> seconds.<BR></SPAN>'
				+'<span style=font-size:14pt>'
				+'<br><br>'
				+'<A href="'+go_url+'" style=font-size:12pt;font-weight:bold;>Equip now</A> | '
				+'<A href=javascript:; id=MHizerStop style=font-size:12pt;font-weight:bold;>Stop the Maid</A>'
				+'</span>';
				document.body.insertBefore(objw,document.body.childNodes[0]);
				
				$('MHizerStop').addEventListener("click", function () {objw.style.display='none';MHizerSec=-1;}, true );
				
				
				MHizer_travel_GO();
				
				}
			else if (route!='done')
				{
				objw.innerHTML='<span style=font-size:14pt;><BR>Driving to '+stop+' in <SPAN id=MHizerSec>'+usr_delay+'</SPAN> seconds.<BR></SPAN>'
				+'<span style=font-size:14pt>And then: '+ ((new_route.length==0)? 'done!':new_route)
				+'<br><br>'
				+'<A href="'+go_url+'" style=font-size:12pt;font-weight:bold;>Travel now</A> | '
				+'<A href=javascript:; id=MHizerStop style=font-size:12pt;font-weight:bold;>Stop the Chauffeur</A>'
				+'</span>'
				document.body.insertBefore(objw,document.body.childNodes[0]);
				
				$('MHizerStop').addEventListener("click", function () {objw.style.display='none';MHizerSec=-1;}, true );
				
				MHizer_travel_GO();
				
				/*
				http://apps.facebook.com/mousehunt/travel.php?route=MHizer-Town%20of%20Gnawnia,Town%20of%20Digby,Meadow,Mountain,Meadow,Town%20of%20Gnawnia,Meadow,Town%20of%20Gnawnia
				*/
				}
				
			}
		
		
		add_mh_friends();
		poo_fb_mhz();
		
		}
	else if (document.location.href.indexOf('furoma.com/mousehunt_log_summarizer')!=-1)
		{

		var newbutt=$('cheese_cost');
		var obj = document.createElement('span');
		obj.innerHTML='<input style=background:brown type=button class=button value="Post log entries from MH" id="MHizerButt" />';
		newbutt.parentNode.insertBefore(obj, newbutt.parentNode.childNodes[10]);
		//alert(newbutt.parentNode.innerHTML);
		$('MHizerButt').addEventListener("click", function () {to_summarizer();}, true );

		var obj2 = document.createElement('span');
		newbutt=$('data_form');
		obj2.innerHTML='<input style=background:brown type=button class=button value="Prefill form with MHizer" id="MHizerButt2" />';
		newbutt.insertBefore(obj2, newbutt.childNodes[0]);
		$('MHizerButt2').addEventListener("click", function () {to_catch_rates();}, true );
		
		if ($('shit') && $('shit').value.length<10  && usr_chk_ls)
			to_summarizer();
		}
	else if (document.location.href.indexOf('furoma.com/log_parser')!=-1)
		{
		var newbutt=xpathFirst("//input[@value='Reset']");
		var obj = document.createElement('span');
		obj.innerHTML='<input style=background:brown type=button class=button value="Post log entries from MH" id="MHizerButt" /><BR />';
		newbutt.parentNode.insertBefore(obj, newbutt.parentNode.childNodes[6]);
		
		$('MHizerButt').addEventListener("click", function () {to_summarizer();}, true );
		if (usr_chk_lp)
			to_summarizer();
		}
	else if (document.location.href.indexOf('furoma.com/best_setup')!=-1)
		{
		var newbutt=xpathFirst("//a[@href='javascript:addAllTraps()']");
		var obj = document.createElement('span');
		obj.innerHTML=' <a id=MHizerButt href=javascript:; class="a-button" style="background:brown">Post inventory from MH</a>';
		newbutt.parentNode.insertBefore(obj, newbutt.parentNode.childNodes[1]);
		$('MHizerButt').addEventListener("click", function () {to_best_setup();}, true );
		if (usr_chk_bs)
			to_best_setup();
		}
	else if (document.location.href.indexOf('furoma.com/best_location')!=-1)
		{
		init_js_balloon();
		
		var newbutt=$('input_body');
		var obj = document.createElement('span');
		obj.innerHTML=' <a id=MHizerButt href=javascript:; class="a-button" style="background:brown">Post inventory from MH</a>';
		newbutt.parentNode.insertBefore(obj, newbutt.parentNode.childNodes[0]);
		$('MHizerButt').addEventListener("click", function () {to_best_setup();}, true );
		if (usr_chk_bs)
			to_best_setup();

		//var st=document.createElement("style");
		//st.innerHTML= 
		//".mhzl {display:none;} .mhzl a{color:blue;} .mhzl a:hover{color:red;}";
		//document.body.appendChild(st);
		/*
		document.body.innerHTML+="<a href=dsd class=mhzl>dsds</a>";*/
				
		$('generate').addEventListener("click", function () {
			
			//	[table_id, location_index, weapon_index, base_index, cheese_index, number of rows to show balloon]

			var i, allTR, thisTR, thisTRloc_cell, table_id, ddiv;
			var table_id_array = [['best_setup', 1,2,3,4,6], ['mouse_setup',0,1,2,3,5]];
			for (table_id=0; table_id<table_id_array.length; table_id++)
				{
			
				//allTR = xpath("//tr[@class='ui-widget-content jqgrow']", $(table_id_array[table_id][0]));
				allTR = $(table_id_array[table_id][0]).getElementsByTagName('tr');
				
				for (i=0; i<allTR.length && i<table_id_array[table_id][5]; i++)
					
					{
					thisTR = allTR[i];
					thisTRloc_cell = thisTR.childNodes[table_id_array[table_id][1]];
					mloc = thisTR.childNodes[table_id_array[table_id][1]].innerHTML;
					mweapon = thisTR.childNodes[table_id_array[table_id][2]].innerHTML;
					mbase = thisTR.childNodes[table_id_array[table_id][3]].innerHTML;
					mcheese = thisTR.childNodes[table_id_array[table_id][4]].innerHTML;
					

					mcheese = xfm_cheese(mcheese);
						
					
					thisTRloc_cell.innerHTML = "<a href=javascript:; mhizer=1 id=A"+table_id+"_"+i+
						" rel=mhizer_thisTR"+table_id+"_"+i+
						">"+thisTRloc_cell.innerHTML+"</a>";
					//($('mhizer_thisTR"+table_id+"_"+i+"')
					//ddiv.style.top = $(table_id_array[table_id][0]).style.top;
					
					
					ddiv = document.createElement("div");
					ddiv.id="mhizer_thisTR"+table_id+"_"+i;
					ddiv.style.width = '150px';
					ddiv.setAttribute('class','balloonstyle');
					ddiv.innerHTML=
						"[ <a title='Travel Planner' href='http://furoma.com/mousehunt_travel_planner.html?whereto="+mloc+"'>TP</a>"+
						" | <a title='Equip this setup now' href='http://apps.facebook.com/mousehunt/inventory.php?Mhizer=Setup&"+
							"Weapon="+mweapon+"&Base="+mbase+"&Cheese="+mcheese+"'>Equip</a>"+
						((usr_mh_ss)? // smart stats only - allowing saving and favoriting
						" | <a title='Save this setup' href=javascript:; id=thisTRSave"+table_id+"_"+i+
							" mweapon='"+mweapon+"' mbase='"+mbase+"' mcheese='"+mcheese+"'>Save</a>"+
						" | <a title='Save as my favorite setup for "+mloc+"' href=javascript:; "+
							"id=thisTRFav"+table_id+"_"+i+
							" mloc='"+mloc+"' mweapon='"+mweapon+"' mbase='"+mbase+"' mcheese='"+mcheese+"'>Fav</a>"+
						" ]" : "]");
					
					
					document.body.appendChild(ddiv);
					
					// correct top position for scrolling
					$("A"+table_id+"_"+i).addEventListener("mouseover", function () {
						var ao=$(this.id.replace('A','mhizer_thisTR'));
						ao.style.top=(ao.style.top.replace('px','')+5)+'px';
						//this.parentNode.parentNode.parentNode.parentNode.parentNode.scrollTop)
						}, true);
						
					if (usr_mh_ss)
						{
						$("thisTRSave"+table_id+"_"+i).addEventListener("click", function () {
							mweapon = shortenme(this.getAttribute('mweapon'));
							mbase = shortenme(this.getAttribute('mbase'));
							mcheese = shortenme(this.getAttribute('mcheese'));
							init_setup();
							save_setup();
							}, true);
						
						$("thisTRFav"+table_id+"_"+i).addEventListener("click", function () {
							mloc = shortenme(this.getAttribute('mloc'));
							mweapon = shortenme(this.getAttribute('mweapon'));
							mbase = shortenme(this.getAttribute('mbase'));
							mcheese = shortenme(this.getAttribute('mcheese'));
							init_setup();
							save_setup_loc();
							}, true);
						}
					
					}
				}
			
			js_balloon();
			
			}, true );
			
		
		}
	else if (document.location.href.indexOf('furoma.com/catch_rates')!=-1)
		{
		var newbutt=xpathFirst("//button[@onclick='switch_display()']");
		var obj = document.createElement('span');
		obj.innerHTML=' <button id=MHizerButt style="background:brown;border:black 1pt grove;color:white;">Post settings from MH</button> ';
		newbutt.parentNode.insertBefore(obj, newbutt);
		$('MHizerButt').addEventListener("click", function () {to_catch_rates();}, true );
		if (usr_chk_cr)
			to_catch_rates();
		}

	else if (document.location.href.indexOf('furoma.com/mousehunt_travel_planner')!=-1)
		{
		
		if(gup(window.location.href,'whereto')!='')
			{
			
			var k = gup(window.location.href,'whereto')
				.replace(/%20/g,' ').replace(/%27/g,"'").toLowerCase();
			var q = document.getElementsByTagName('label');
			for (var i=0, j=0; i<q.length; i++)
				if (q[i].getAttribute('for').indexOf('form_destination')==0)
					{
					
					cid=q[i].getAttribute('for');
					if (q[i].innerHTML.toLowerCase().indexOf(k)!=-1)
						{
						if (!$(cid).disabled)
							$(cid).click();
						//$(cid).checked=true;
						//unsafeWindow.source=j;
						
						//unsafeWindow.source=q[i].getAttribute('for').replace('form_source','');

						break;
						}
					j++;
					}//*/
									
			}
		
		var newbutt=xpathFirst("//th[@colspan='2']");
		var obj = document.createElement('span');
		obj.innerHTML=' <button id=MHizerButt style="background:brown;border:black 1pt grove;color:white;">Prefill form with MHizer</button> ';
		newbutt.appendChild(obj, newbutt);
		$('MHizerButt').addEventListener("click", function () {to_travel_planner();}, true );
		
		newbutt=xpathFirst("//input[@onclick='swaploc();calculate();']");
		var obj2 = document.createElement('span');
		obj2.innerHTML=' <button id=MHizerButt2 style="background:brown;border:black 1pt grove;color:white;">MHizer Chauffeur</button> (one-click traveling to your destination)';
		newbutt.parentNode.appendChild(obj2, newbutt);
		$('MHizerButt2').addEventListener("click", to_chauffeur, true );
		
		if (usr_chk_tp)
			to_travel_planner();
		}
	else if (document.location.href.indexOf('mousehuntizer/template.html?page=mouse_tally')!=-1)
		{
		$('title').innerHTML = 'MouseHuntizer - Mouse Tally';
		document.title = 'Mouse Tally Page';
		$('content').innerHTML = 'Loading mouse data from MH Wiki...';
		

		xmlhttp('http://mhwiki.hitgrab.com/wiki/index.php/Cheat_Sheet?rand='+Date(),
			function (res) {
			
			
			var tm = document.createElement('div');
			tm.innerHTML = res;
			$('content').appendChild(tm);
			
			var t = tm.getElementsByTagName('table');
			for (var i=0; i<t.length; i++)
				{
				if (t[i].innerHTML.indexOf('Assassin')!=-1)
					{
					tm.innerHTML = '<table id=wiki style=display:none;>'+t[i].innerHTML+'</table>';
					break;
					}
				}
			

			
			var t = $('wiki').getElementsByTagName('tr');
			var region = new Array();
			var area = new Array();
			var mouse = new Array();
			var wiki_url = 'http://mhwiki.hitgrab.com';
			var mouse_unknown_pix = 'http://furoma.com/mousehuntizer/mouse_unknown.gif';
			
			// INIT REGION
			for (var i=1, region_name, region_size, region_elem; i<t[0].getElementsByTagName('th').length; i++)
				{
				region_name = t[0].getElementsByTagName('th')[i].innerHTML.replace('\n','');
				region_size = t[0].getElementsByTagName('th')[i].getAttribute('colspan');
				
				region_size = (region_size)? parseInt(region_size):1;
				
				region_elem = new Array();
				
				region_elem.push(region_name);
				region_elem.push(region_size);
				region_elem.push([]); // area list
				
				//[region_name, region_size, blank_array]
				region.push(region_elem);

				}
			
			
			// INIT AREA
			for (var i=0, area_name, blank_array; i<t[1].getElementsByTagName('a').length; i++)
				{
				area_name = t[1].getElementsByTagName('a')[i].getAttribute('title');
				
				blank_array = new Array();
				blank_array.push(area_name);
				blank_array.push([]);
				blank_array.push(i);	// AREA ID
				
				area.push (blank_array);
				
				}
			
			// INIT MOUSE
			for (var i=0, mouse_name, mouse_full_name, mouse_link, mouse_elem, mouse_special; i<t.length; i++)
				{
				if (t[i].getAttribute('bgcolor') == '#dddddd' ||
					t[i].getAttribute('bgcolor') == '#bbbbbb')
					continue;

				mouse_full_name = t[i].getElementsByTagName('a')[0].getAttribute('title').replace(' Mouse','');
				mouse_name = t[i].getElementsByTagName('a')[0].innerHTML;
				mouse_link = t[i].getElementsByTagName('a')[0].getAttribute('href');
				
				if (t[i].getElementsByTagName('td')[0].innerHTML.indexOf('**')!=-1)
					mouse_special = 2;
				else if (t[i].getElementsByTagName('td')[0].innerHTML.indexOf('*')!=-1)
					mouse_special = 1;
				else
					mouse_special = 0;
				
				// MOUSE ARRAY DEFINITION ===
				// 0 mouse_name, 1 mouse_full_name, 2 mouse_link (wiki), 3 mouse photo url, 
				// 4 catch total, 5 map status, 6 special codes (0=not, 1=seasonal, 2=event/prize)
				//
				mouse.push ([mouse_name, mouse_full_name, mouse_link,
					mouse_unknown_pix, 0, true, mouse_special]);
				
				for (var j=1, bg, mouse_elem; j<t[i].getElementsByTagName('td').length; j++)
					{
					if (t[i].getElementsByTagName('td')[j].innerHTML.indexOf('X')!=-1)
						area[j-1][1].push(mouse_full_name);
					}
					
				}
			

			
			for (var i=0, region_index=0, area_count=1; i<area.length; i++, area_count++)
				{
				if(area_count>region[region_index][1])
						{
						region_index++;
						area_count = 1;
						}
				region[region_index][2].push(area[i][2]);
				}
			
			var ori_height = 0;
			
			//======================= FETCH PROFILE DATA ===========================
			var fetch_profile_data = function () {
			
			var snuid = '';
			if ($('show_snuid'))
				snuid = gup($('show_snuid').value,'snuid');
				
			$('content').innerHTML = 'Loading MouseHunt profile...';
			
			
			//http://apps.facebook.com/mousehunt/hunterprofile.php?snuid=666561064 jennifer
			xmlhttp('http://apps.facebook.com/mousehunt/hunterprofile.php?snuid='+snuid+'&rand='+Date(),
				function (res) {
				
				//$('content').innerHTML = '';		
				
				var region_link = function (x) {
						return '<A href=javascript:; id=region_'+x+' size='+region[x][1]
							+' area='+region[x][2]
							+'><NOBR>'+region[x][0]+'</NOBR></A>';
					};
				
				var area_link = function (x) {
						return '<A href=javascript:; id=area_'+area[x][2]+' area='+x
							+'><NOBR>'+area[x][0]+'</NOBR></A>';
					};

				
				var str = '<DIV style=width:100%;background:lightgreen;><B>Profile</B></DIV>'
				str += '<BR /><B style=color:brown;font-size:12pt;>';
				str += '<A href=http://apps.facebook.com/mousehunt/hunterprofile.php?snuid='+snuid;
				str += ' style=text-decoration:none;>';
				str += res.match(/<div class=\"sectionname\"([^<]+)<\/div>/)[0];
				str += '</A></B>';
				
				str += '<BR /><A id=show_yours href=javascript:;>Your mouse tally</A>'
					+ ' | Someone else\'s mouse tally: '
					+ '<INPUT type=text id=show_snuid style=width:200px; value="MH profile or Trade link URL" '
					+ 'onfocus=\'if (this.value=="MH profile or Trade link URL") this.value="";\''
					+ 'onblur=\'if (this.value=="") this.value="MH profile or Trade link URL";\' />'
					+ '<INPUT type=button id=show_someone class=button value=Submit />'
					+ ' | <A target=_blank href=http://mhwiki.hitgrab.com/wiki/index.php/Cheat_Sheet#Mice>Mouse & location reference</A>';
				
				region.sort();
				
				str += '<BR /><BR /><DIV style=width:100%;background:lightgreen;><B>Settings</B></DIV>';
				
				str += '<BR /><TABLE border=0 cellpadding=0; cellspacing=5>';
				str += '<COL width=120>';
				
				str += '<TR valign=top><TD><B>Filter by region:</B> ';
				str += '<TD><A href=javascript:; id=show_all_1 filter=show_all>ALL</A>';
				for (var i=0; i<region.length; i++)
					str += ' | ' + region_link(i);
					
				area.sort();
				
				str += '<TR valign=top><TD><B>Filter by area:</B> ';
				str += '<TD><A href=javascript:; id=show_all_2 filter=show_all>ALL</A>';
				for (var i=0; i<area.length; i++)
					str += ' | ' + area_link(i);
				
				str += '<TR valign=top><TD><B>Filter by access:</B> ';
				str += '<TD><A href=javascript:; id=map_yes filter=show_all>On your map</A>';
				str += ' | <A href=javascript:; id=map_no filter=show_all>Outside your map</A>';
				str += ' | <A href=javascript:; id=wiki_no filter=show_all>Unknown locations</A>';
				
				str += '<TR valign=top><TD><B>Display option:</B> ';
				str += '<TD><input type=checkbox name=caught id=caught checked><label for=caught>Caught mice</label></input>';
				str += '<input type=checkbox name=uncaught id=uncaught checked><label for=uncaught>Uncaught mice</label></input>';
				str += ' | <input type=checkbox name=common id=common checked><label for=common>Common mice</label></input>';
				str += '<input type=checkbox name=seasonal id=seasonal checked><label for=seasonal>Seasonal mice</label></input>';
				str += '<input type=checkbox name=event id=event checked><label for=event>Event/prize mice</label></input>';
				
				
				str += '<TR valign=top><TD><B>Sort option:</B> ';
				str += '<TD><a id=sort_alpha href=javascript:;>By name</a>';
				str += ' | <a id=sort_catch_a href=javascript:;>By catches</a>';
				str += ' | <a id=sort_catch_d href=javascript:;>By catches (desc)</a>';
				
				str += '</TABLE>';
				
				var mouse_copy = new Array();
				for (var i=0; i<mouse.length; i++)
					{
					mouse_copy.push(mouse[i][1].toLowerCase().replace(/ /g,'_').replace(/\'/g,''));
					
					mouse[i][4] = 0; // SET mouse catch to ZERO
					mouse[i][5] = 0; // SET map status to NOT found
					}

				
				var mouse_data = res.match(/\.app_content_10337532241 \.([^ ]+) { background-image: url\(\"([^"]+)\"/g);
				for (var i=0, is_found, mouse_data_elem, mouse_name; i<mouse_data.length; i++)
					{
					mouse_data_elem = mouse_data[i].match(/\.app_content_10337532241 \.([^ ]+) { background-image: url\(\"([^"]+)\"/);
					
					is_found=false;
					
					for (var j=0; j<mouse_copy.length; j++)
						{
						if (mouse_data_elem[1] == mouse_copy[j])
							{
							is_found = true;
							mouse[j][3] = mouse_data_elem[2];
							mouse[j][5] = 1;	// map status = found
							break;
							}
						}
						
					if (!is_found)
						{
						mouse_name = new Array();
						mouse_name = mouse_data_elem[1].split('');
						mouse_name[0] = mouse_name[0].toUpperCase();
						for (var j=2; j<mouse_name.length; j++)
							{
							if (mouse_name[j-1]=='_')
								{
								mouse_name[j-1]=' ';
								mouse_name[j]=mouse_name[j].toUpperCase();
								}
							}
						mouse_name = mouse_name.toString().replace(/,/g,'');
						
						mouse.push([mouse_name,
							mouse_name,
							'',	// LINK not found
							mouse_data_elem[2],
							0,	// COUNT = 0
							-1,	// MAP STATUS = unknown locations
							0]	// COMMON mice
							);
						mouse_copy.push(mouse_data_elem[1]);
						}
					}
					
				
				ul = res.replace(/\n/g,'').match(/<div class=\"tallyheading(.+)<\/ul>/)[1];
				ul = ul.split('</ul>');
				

				for (var i=0; i<ul.length; i++)
					{
					if(ul[i].indexOf('<li class="numcatches">')==-1)
						continue;
					for (var j=0; j<mouse.length; j++)
						{
						if (mouse_copy[j] == ul[i].match(/<div class=\"mousepic ([^"]+)\"/)[1])
							mouse[j][4] = parseInt(ul[i].match(/<li class=\"numcatches\">x(.+)<\/li>/)[1].replace(/,/g,''));
							
						}
					}

								
				// BEGIN FUNCTIONS =======================================
				var mouse_link = function (x) {
	
					return '<DIV id="mouse_'+mouse[x][1]+'"'+
						' map='+mouse[x][5]+
						((mouse[x][4])? ' count='+mouse[x][4]:'')+
						((mouse[x][6])? ' special='+mouse[x][6]:'')+
						' style=font-size:8pt;height:75px;float:left;>'+
						((mouse[x][5]!=-1)? '<A target=_blank href='+wiki_url+mouse[x][2]+' style=text-decoration:none;>':'')+
						'<DIV style=width:55px;float:left><IMG border=0 src="'+
						((mouse[x][4])? mouse[x][3]:mouse_unknown_pix)+
						'"></IMG></DIV>'+
						'<DIV style=width:100px;float:left>'+mouse[x][1]+
						'<BR />x'+mouse[x][4]+
						'</DIV></A></DIV>';
					};
				var filter_area = function () {
					
					var f_area = new Array();
					var val, this_id;	
					

					if (reload)	// checkbox
						{
						val = last_val;
						}
					else	
						{						
						if (this.getAttribute('filter')=='show_all')
							{
							if (this.id.indexOf('show_all')==0)
								last_fn = 'show_all';
							else 
								last_fn = 'show_'+this.id; // can be map_yes, map_no or wiki_no
							
							reload = false;	// It's a link, not a checkbox (map stts or ALL)
							}
						else
							{
							val = this.getAttribute('area');
							last_val = val;
							
							last_fn = (this.getAttribute('size'))? 'filter_region':'filter_area';
							// region or area
							}
						}
					
					if (last_fn.indexOf('show_')==0)
						{
						if (last_fn=='show_all')
							this_id = false;
						else
							this_id = last_fn.replace('show_','');
							
						for (var i=0; i<mouse.length; i++)
							$('mouse_'+mouse[i][1]).style.display=filter_check(mouse[i][1], this_id)?'block':'none';
						
						if (!reload)
							$('tally_area').innerHTML = this.innerHTML;
						}
					else
						{
						if (last_fn=='filter_region')	//region
							{
							f_area=val.split(',');
							for (var i=0; i<f_area.length; i++)
								{
								f_area[i] = parseInt($('area_'+f_area[i]).getAttribute('area'));
								}
							}
						else	//last_fn == 'filter_area' //area
							f_area.push (parseInt(val));
						
						
						for (var i=0; i<mouse.length; i++)
							$('mouse_'+mouse[i][1]).style.display='none';
							
						if (!reload)
							{		
							$('tally_area').innerHTML = area[f_area[0]][0];

							for (var i=1; i<f_area.length; i++)
								$('tally_area').innerHTML += ' <FONT color=brown>+</FONT> '+area[f_area[i]][0];
							}
							
						for (var i=0; i<f_area.length; i++)
							for (var j=0; j<area[f_area[i]][1].length; j++)
								{
								if (filter_check(area[f_area[i]][1][j]))
									$('mouse_'+area[f_area[i]][1][j]).style.display = 'block';
								}
						}

					wrap_up();
					};	
				
				var wrap_up = function () {
						var mouse_count=0;
						for (var i=0; i<mouse.length; i++)
							{
							if ($('mouse_'+mouse[i][1]).style.display != 'none')
								mouse_count++;
							}
						if (mouse_count==0)
							$('no_mouse').style.display = 'inline';
						else
							$('no_mouse').style.display = 'none';
						
						$('tally_count').innerHTML = mouse_count;
						
						$('content').style.height = (75*Math.max(1,Math.ceil(mouse_count/5))+ori_height) + 'px';
						
					};
				
				var filter_check = function (i, this_id) {
						var o = $('mouse_'+i);
						
						if (o.getAttribute('count') && !$('caught').checked)
							return false
						if (!o.getAttribute('count') && !$('uncaught').checked)
							return false;
						if (!o.getAttribute('special') && !$('common').checked)
							return false;
						if (o.getAttribute('special')==1 && !$('seasonal').checked)
							return false;
						if (o.getAttribute('special')==2 && !$('event').checked)
							return false;
						if (o.getAttribute('map')!=1 && this_id && this_id=='map_yes')
							return false;
						if (o.getAttribute('map')!=0 && this_id && this_id=='map_no')
							return false;
						if (o.getAttribute('map')!=-1 && this_id && this_id=='wiki_no')
							return false;
							
						return true;
					};
				
				var reload = false, last_fn='show_all', last_val='show_all';
				
				var filter_reload = function () {
						reload = true;

						filter_area();
						reload = false;
					};
				
				var sort_reload = function () {
						var str = '';
						if (!this.id || this.id=='sort_alpha')
							{
							str += mouse_link(0);
							for (var i=1; i<mouse.length; i++)
								str += mouse_link(i);
							}
						else
							{
							var mouse_sort = new Array();
							
							for (var i=0; i<mouse.length; i++)
								mouse_sort.push([mouse[i][4],i]);
							
							if (this.id=='sort_catch_a')
								mouse_sort.sort(sort_a);
							else
								mouse_sort.sort(sort_d);
							
							str += mouse_link(mouse_sort[0][1]);
							for (var i=1; i<mouse.length; i++)
								str += mouse_link(mouse_sort[i][1]);
							}
						$('mouse_tally').innerHTML = str;
						
						if (this.id)			// not start up
							filter_reload();
					};
				
				var sort_a = function (a, b) {
						return a[0] - b[0];
					};
				var sort_d = function (a, b) {
						return b[0] - a[0];
					};
				
				// END FUNCTIONS
				
				mouse.sort();
				
				
				str += '<BR /><BR />';

				str += '<DIV style=width:100%;background:lightgreen;><B>Mouse Tally (<SPAN id=tally_count'
				str += '></SPAN>)</B> - <I id=tally_area>ALL</I>:</DIV><BR />';
				str += '<SPAN id=no_mouse>No mice to display</SPAN>';
				str += '<DIV id=mouse_tally>';
				
				str += '</DIV><BR />';
			
				$('content').innerHTML = str;// + $('content').innerHTML;					
				//$('content').style.height = '100%';
				$('content').style.width = '800px';
				
				if (ori_height==0)
					ori_height = parseInt($('content').offsetHeight.toString().replace('px',''));
				
				sort_reload();
				wrap_up();
				poo_fb_mhz();
				
				$('show_yours').addEventListener("click", fetch_profile_data, false);
				$('show_someone').addEventListener("click", fetch_profile_data, false);
				
				$('caught').addEventListener("click", filter_reload, false);
				$('uncaught').addEventListener("click", filter_reload, false);
				$('common').addEventListener("click", filter_reload, false);
				$('seasonal').addEventListener("click", filter_reload, false);
				$('event').addEventListener("click", filter_reload, false);
				
				$('sort_alpha').addEventListener("click", sort_reload, false);
				$('sort_catch_a').addEventListener("click", sort_reload, false);
				$('sort_catch_d').addEventListener("click", sort_reload, false);
				
				$('show_all_1').addEventListener("click", filter_area, false);
				$('show_all_2').addEventListener("click", filter_area, false);
				$('map_yes').addEventListener("click", filter_area, false);
				$('map_no').addEventListener("click", filter_area, false);
				$('wiki_no').addEventListener("click", filter_area, false);
				
				for (var i=0; i<area.length; i++)
					$('area_'+i).addEventListener("click", filter_area, false);
				for (var i=0; i<region.length; i++)
					$('region_'+i).addEventListener("click", filter_area, false);
	
				});
				};
			// ============ END FETCH PROFILE DATA
			
			fetch_profile_data();
			});
		
		
		}
	else if (document.location.href.indexOf('mousehuntizer/template.html?page=mh_friends')!=-1)
		{
		$('content').innerHTML = 
		( (GM_getValue('mh_friends','')=='')? 'There is nobody in your PF MH Friend List.<br>':
			'<div id=fb_menu_friends_dropdown></div>')+
		'<br>'+
		'[ <a href=http://apps.facebook.com/mousehunt/scoreboard.php?view=frnds&sort=points>Scoreboard</a>'+
		' | <a href=http://apps.facebook.com/mousehunt/huntersgroup.php>Hunting Group</a>'+
		' | <a href=http://apps.facebook.com/mousehunt/organizeparty.php>Hunting Party</a> ]';
		$('content').style.width = '300px';
		
		$('title').innerHTML = 'MouseHuntizer - PF MH Friends Page';
		document.title = 'PF MH Friends Page';

		//$('content').id =  'fb_menu_friends_dropdown';
		//var obj = document.createElement('div');
		//obj.id = 'fb_menu_friends_dropdown';
		//$('content').appendChild(obj);

		
		// add friends first mhz later
		add_mh_friends();
		//poo_fb_mhz();
		
		
		}
	else if (is_config_page)
		{
		if (gup(window.location.href,'whereto')=='pf')
			$('rm_pf').style.display='';
			
		$('chk_install').innerHTML = 'OK';
		$('chk_version').innerHTML = your_version;
		$('chk_latest_version').innerHTML = '(checking)';
		$('update_link').style.display='none';
		$('outputtext').style.display='';

		if (latest_version == " ")
			CheckVersion();

		chk_valid();
		chk_reset();
		

		$('usr_chk_tm_alarm_vol').selectedIndex = (usr_chk_tm_alarm_wmp)? 5:usr_chk_tm_alarm_vol/20-1;
		
		for (var i=0; i<$("usr_chk_tm_pos").options.length; i++)
			if ($("usr_chk_tm_pos").options[i].value==usr_chk_tm_pos)
				{
				$("usr_chk_tm_pos").selectedIndex=i;
				break;
				}
				
		for (var i=0; i<$("usr_chk_tm_alarm_file").options.length; i++)
			if ($("usr_chk_tm_alarm_file").options[i].value==usr_chk_tm_alarm_file)
				{
				$("usr_chk_tm_alarm_file").selectedIndex=i;
				break;
				}
		for (var i=0; i<$("usr_chk_tm_update").options.length; i++)
			if ($("usr_chk_tm_update").options[i].value==usr_chk_tm_update)
				{
				$("usr_chk_tm_update").selectedIndex=i;
				break;
				}
		for (var i=0; i<$("usr_delay").options.length; i++)
			if ($("usr_delay").options[i].value==usr_delay)
				{
				$("usr_delay").selectedIndex=i;
				break;
				}

		$('usr_debug_yes').addEventListener('click', function () {usr_debug=true;chk_valid();}, true);
		$('usr_debug_no').addEventListener('click', function () {usr_debug=false;chk_valid();}, true);
		
		//$('usr_chk_k_yes').addEventListener('click', function () {usr_chk_k=true;chk_valid();}, true);
		//$('usr_chk_k_no').addEventListener('click', function () {usr_chk_k=false;chk_valid();}, true);
		$('usr_chk_fr_yes').addEventListener('click', function () {usr_chk_fr=true;chk_valid();}, true);
		$('usr_chk_fr_no').addEventListener('click', function () {usr_chk_fr=false;chk_valid();}, true);
		$('usr_chk_pt_yes').addEventListener('click', function () {usr_chk_pt=true;chk_valid();}, true);
		$('usr_chk_pt_no').addEventListener('click', function () {usr_chk_pt=false;chk_valid();}, true);
		$('usr_chk_rk_yes').addEventListener('click', function () {usr_chk_rk=true;chk_valid();}, true);
		$('usr_chk_rk_no').addEventListener('click', function () {usr_chk_rk=false;chk_valid();}, true);
		$('usr_chk_ls_yes').addEventListener('click', function () {usr_chk_ls=true;chk_valid();}, true);
		$('usr_chk_ls_no').addEventListener('click', function () {usr_chk_ls=false;chk_valid();}, true);
		$('usr_chk_lp_yes').addEventListener('click', function () {usr_chk_lp=true;chk_valid();}, true);
		$('usr_chk_lp_no').addEventListener('click', function () {usr_chk_lp=false;chk_valid();}, true);
		$('usr_chk_cr_yes').addEventListener('click', function () {usr_chk_cr=true;chk_valid();}, true);
		$('usr_chk_cr_no').addEventListener('click', function () {usr_chk_cr=false;chk_valid();}, true);
		$('usr_chk_bs_yes').addEventListener('click', function () {usr_chk_bs=true;chk_valid();}, true);
		$('usr_chk_bs_no').addEventListener('click', function () {usr_chk_bs=false;chk_valid();}, true);
		$('usr_chk_bl_yes').addEventListener('click', function () {usr_chk_bl=true;chk_valid();}, true);
		$('usr_chk_bl_no').addEventListener('click', function () {usr_chk_bl=false;chk_valid();}, true);
		$('usr_chk_tp_yes').addEventListener('click', function () {usr_chk_tp=true;chk_valid();}, true);
		$('usr_chk_tp_no').addEventListener('click', function () {usr_chk_tp=false;chk_valid();}, true);
		
		
		$('usr_chk_tm_mh_yes').addEventListener('click', function () {usr_chk_tm_mh=true;chk_valid();}, true);
		$('usr_chk_tm_mh_no').addEventListener('click', function () {usr_chk_tm_mh=false;chk_valid();}, true);
		$('usr_chk_tm_fb_yes').addEventListener('click', function () {usr_chk_tm_fb=true;chk_valid();}, true);
		$('usr_chk_tm_fb_no').addEventListener('click', function () {usr_chk_tm_fb=false;chk_valid();}, true);

		$('usr_ld_msg_yes').addEventListener('click', function () {usr_ld_msg=true;chk_valid();}, true);
		$('usr_ld_msg_no').addEventListener('click', function () {usr_ld_msg=false;chk_valid();}, true);

		$('usr_rm_fb_yes').addEventListener('click', function () {usr_rm_fb=true;chk_valid();}, true);
		$('usr_rm_fb_no').addEventListener('click', function () {usr_rm_fb=false;chk_valid();}, true);
		$('usr_rm_pf_yes').addEventListener('click', function () {usr_rm_pf=true;chk_valid();}, true);
		$('usr_rm_pf_no').addEventListener('click', function () {usr_rm_pf=false;chk_valid();}, true);
		
		$('usr_mh_mn_yes').addEventListener('click', function () {usr_mh_mn=true;chk_valid();}, true);
		$('usr_mh_mn_no').addEventListener('click', function () {usr_mh_mn=false;chk_valid();}, true);
		$('usr_fb_mhz_yes').addEventListener('click', function () {usr_fb_mhz=true;chk_valid();}, true);
		$('usr_fb_mhz_no').addEventListener('click', function () {usr_fb_mhz=false;chk_valid();}, true);
		$('usr_mh_sc_yes').addEventListener('click', function () {usr_mh_sc=true;chk_valid();}, true);
		$('usr_mh_sc_no').addEventListener('click', function () {usr_mh_sc=false;chk_valid();}, true);
		$('usr_mh_ss_yes').addEventListener('click', function () {usr_mh_ss=true;chk_valid();}, true);
		$('usr_mh_ss_no').addEventListener('click', function () {usr_mh_ss=false;chk_valid();}, true);
		$('usr_mh_sm_yes').addEventListener('click', function () {usr_mh_sm=true;chk_valid();}, true);
		$('usr_mh_sm_no').addEventListener('click', function () {usr_mh_sm=false;chk_valid();}, true);
		
		
		$('usr_chk_tm_alarm_yes').addEventListener('click', function () {usr_chk_tm_alarm=true;chk_valid();}, true);
		$('usr_chk_tm_alarm_no').addEventListener('click', function () {usr_chk_tm_alarm=false;chk_valid();}, true);
		$('usr_chk_tm_alarm_vol').addEventListener('change', function () {
			var arr=$('usr_chk_tm_alarm_vol').value.split(',');
			if (arr[0]=="false")
				{
				if (usr_chk_tm_alarm_wmp)
					{
					if (confirm("Usually a default player is Quicktime, which may cause a temporary freeze when the alarm sounds.\nDo you want to proceed?"))
						{
						usr_chk_tm_alarm_wmp=false;
						}
					else 
						{
						$('usr_chk_tm_alarm_vol').selectedIndex=5;
						return;
						}
					}
				}
			else
				usr_chk_tm_alarm_wmp=true;
			usr_chk_tm_alarm_vol=arr[1];
			soundAlarm();
			chk_valid();}, true);
		
		$('usr_chk_tm_alarm_cnfm_yes').addEventListener('click', function () {usr_chk_tm_alarm_cnfm=true;chk_valid();}, true);
		$('usr_chk_tm_alarm_cnfm_no').addEventListener('click', function () {usr_chk_tm_alarm_cnfm=false;chk_valid();}, true);
		$('usr_chk_tm_title_yes').addEventListener('click', function () {usr_chk_tm_title=true;chk_valid();}, true);
		$('usr_chk_tm_title_no').addEventListener('click', function () {usr_chk_tm_title=false;chk_valid();}, true);

		
		$('usr_chk_tm_pos').addEventListener('change', function () {usr_chk_tm_pos=$('usr_chk_tm_pos').value;chk_valid();}, true);
		$('usr_chk_tm_alarm_file').addEventListener('change', function () {usr_chk_tm_alarm_file=$('usr_chk_tm_alarm_file').value;soundAlarm();chk_valid();}, true);
		$('usr_chk_tm_update').addEventListener('change', function () {usr_chk_tm_update=parseInt($('usr_chk_tm_update').value);chk_valid();}, true);
		$('usr_delay').addEventListener('change', function () {usr_delay=parseInt($('usr_delay').value);chk_valid();}, true);
		

		$('reset_on').addEventListener('click', function () {usr_chk_fr=usr_chk_pt=usr_chk_rk=usr_chk_ls=usr_chk_lp=usr_chk_cr=usr_chk_bs=usr_chk_bl=usr_chk_tp=usr_ld_msg=usr_chk_tm_mh=usr_chk_tm_fb=usr_rm_fb=usr_mh_mn=usr_fb_mhz=usr_mh_sc=usr_mh_ss=usr_mh_sm=usr_chk_tm_alarm=usr_chk_tm_alarm_cnfm=usr_chk_tm_title=true;chk_valid();chk_reset();GM_setValue("MSG_POSITION", "35px_750px");}, true);
		$('reset_off').addEventListener('click', function () {usr_chk_fr=usr_chk_pt=usr_chk_rk=usr_chk_ls=usr_chk_lp=usr_chk_cr=usr_chk_bs=usr_chk_bl=usr_chk_tp=usr_ld_msg=usr_chk_tm_mh=usr_chk_tm_fb=usr_rm_fb=usr_mh_mn=usr_fb_mhz=usr_mh_sc=usr_mh_ss=usr_mh_sm=usr_chk_tm_alarm=usr_chk_tm_alarm_cnfm=usr_chk_tm_title=false;chk_valid();chk_reset();GM_setValue("MSG_POSITION", "35px_750px");}, true);
		$('reset_perf').addEventListener('click', function () {usr_chk_fr=usr_chk_pt=usr_chk_rk=usr_chk_ls=usr_chk_lp=usr_chk_cr=usr_chk_bs=usr_chk_bl=usr_chk_tp=usr_chk_tm_fb=usr_chk_tm_alarm=false;usr_chk_tm_mh=usr_rm_fb=usr_ld_msg=usr_chk_tm_alarm_cnfm=usr_chk_tm_title=usr_mh_mn=usr_fb_mhz=usr_mh_sc=usr_mh_ss=usr_mh_sm=true;chk_valid();chk_reset();}, true);

		}

}

MAIN_PROGRAM();
GM_registerMenuCommand("MH - Pooflinger Options", function () {window.location.href=CONFIG_URL;});

function google_analytics()
{
		// Google Analytics Stuff
		if (usr_mh_mn || usr_mh_ss)
			{
			var allLinks = document.body.getElementsByTagName('a');
			for (var i=0; i<allLinks.length; i++)
				//if (allLinks[i].href.indexOf('furoma.com')!=-1)
				if (allLinks[i].innerHTML.indexOf('PF ')==0)
					{
					allLinks[i].target='_blank';
					allLinks[i].style.color='#995522';
					if (allLinks[i].href.indexOf('http://furoma.com')==0)
						allLinks[i].href+='&utm_source=mhizer&utm_medium=gm&utm_content=mhizer_'+your_version;
					}
			}
}

function chk_reset()
{
	$('usr_debug_yes').checked=usr_debug;
	$('usr_debug_no').checked=!usr_debug;

	//$('usr_chk_k_yes').checked=usr_chk_k;
	//$('usr_chk_k_no').checked=!usr_chk_k;
	
	$('usr_chk_fr_yes').checked=usr_chk_fr;
	$('usr_chk_fr_no').checked=!usr_chk_fr;
	$('usr_chk_pt_yes').checked=usr_chk_pt;
	$('usr_chk_pt_no').checked=!usr_chk_pt;
	$('usr_chk_rk_yes').checked=usr_chk_rk;
	$('usr_chk_rk_no').checked=!usr_chk_rk;
	$('usr_ld_msg_yes').checked=usr_ld_msg;
	$('usr_ld_msg_no').checked=!usr_ld_msg;

	$('usr_chk_ls_yes').checked=usr_chk_ls;
	$('usr_chk_ls_no').checked=!usr_chk_ls;
	$('usr_chk_lp_yes').checked=usr_chk_lp;
	$('usr_chk_lp_no').checked=!usr_chk_lp;
	$('usr_chk_cr_yes').checked=usr_chk_cr;
	$('usr_chk_cr_no').checked=!usr_chk_cr;
	$('usr_chk_bs_yes').checked=usr_chk_bs;
	$('usr_chk_bs_no').checked=!usr_chk_bs;
	$('usr_chk_bl_yes').checked=usr_chk_bl;
	$('usr_chk_bl_no').checked=!usr_chk_bl;
	$('usr_chk_tp_yes').checked=usr_chk_tp;
	$('usr_chk_tp_no').checked=!usr_chk_tp;
	
	$('usr_chk_tm_mh_yes').checked=usr_chk_tm_mh;
	$('usr_chk_tm_mh_no').checked=!usr_chk_tm_mh;
	$('usr_chk_tm_fb_yes').checked=usr_chk_tm_fb;
	$('usr_chk_tm_fb_no').checked=!usr_chk_tm_fb;
	
	$('usr_chk_tm_alarm_yes').checked=usr_chk_tm_alarm;
	$('usr_chk_tm_alarm_no').checked=!usr_chk_tm_alarm;
	$('usr_chk_tm_alarm_cnfm_yes').checked=usr_chk_tm_alarm_cnfm;
	$('usr_chk_tm_alarm_cnfm_no').checked=!usr_chk_tm_alarm_cnfm;	
	$('usr_chk_tm_title_yes').checked=usr_chk_tm_title;
	$('usr_chk_tm_title_no').checked=!usr_chk_tm_title;

	$('usr_rm_fb_yes').checked=usr_rm_fb;
	$('usr_rm_fb_no').checked=!usr_rm_fb;
	$('usr_rm_pf_yes').checked=usr_rm_pf;
	$('usr_rm_pf_no').checked=!usr_rm_pf;
	
	$('usr_mh_mn_yes').checked=usr_mh_mn;
	$('usr_mh_mn_no').checked=!usr_mh_mn;
	$('usr_fb_mhz_yes').checked=usr_fb_mhz;
	$('usr_fb_mhz_no').checked=!usr_fb_mhz;
	$('usr_mh_sc_yes').checked=usr_mh_sc;
	$('usr_mh_sc_no').checked=!usr_mh_sc;

		
	$('usr_mh_ss_yes').checked=usr_mh_ss;
	$('usr_mh_ss_no').checked=!usr_mh_ss;
	$('usr_mh_sm_yes').checked=usr_mh_sm;
	$('usr_mh_sm_no').checked=!usr_mh_sm;
	

}
function chk_valid()
{

	/*
	if(!usr_chk_k && (usr_chk_pt || usr_chk_rk || usr_chk_tm_fb))
		{
		alert('King\'s reward is turned on for you.\nBecause you need it in order to display points, rank, or timer on FB webboards!');
		$('usr_chk_k_yes').checked = usr_chk_k =  true;
		
		}
	*/
	
	if(!usr_mh_ss)
		{
		$('usr_mh_sm_yes').disabled = true;
		$('usr_mh_sm_no').disabled = true;
		usr_mh_sm = false;
		$('usr_mh_sm_yes').checked=usr_mh_sm;
		$('usr_mh_sm_no').checked=!usr_mh_sm;
		}
	else
		{
		$('usr_mh_sm_yes').disabled = false;
		$('usr_mh_sm_no').disabled = false;
		}
		
	GM_setValue('usr_debug',usr_debug);
	
	//GM_setValue('usr_chk_k',usr_chk_k);
	GM_setValue('usr_chk_pt',usr_chk_pt);
	GM_setValue('usr_chk_rk',usr_chk_rk);
	GM_setValue('usr_chk_fr',usr_chk_fr);
	GM_setValue('usr_chk_ls',usr_chk_ls);
	GM_setValue('usr_chk_lp',usr_chk_lp);
	GM_setValue('usr_chk_cr',usr_chk_cr);
	GM_setValue('usr_chk_bs',usr_chk_bs);
	GM_setValue('usr_chk_bl',usr_chk_bl);
	GM_setValue('usr_chk_tp',usr_chk_tp);

	GM_setValue('usr_chk_tm_mh',usr_chk_tm_mh);
	GM_setValue('usr_chk_tm_fb',usr_chk_tm_fb);
	GM_setValue('usr_chk_tm_pos',usr_chk_tm_pos);
	
	GM_setValue('usr_ld_msg',usr_ld_msg);
	GM_setValue('usr_rm_fb',usr_rm_fb);
	GM_setValue('usr_rm_pf',usr_rm_pf);
	
	GM_setValue('usr_mh_mn',usr_mh_mn);
	GM_setValue('usr_fb_mhz',usr_fb_mhz);
	GM_setValue('usr_mh_sc',usr_mh_sc);
	GM_setValue('usr_mh_ss',usr_mh_ss);
	GM_setValue('usr_mh_sm',usr_mh_sm);
	GM_setValue('usr_delay',usr_delay);
	
	GM_setValue('usr_chk_tm_alarm',usr_chk_tm_alarm);
	GM_setValue('usr_chk_tm_alarm_wmp',usr_chk_tm_alarm_wmp);
	GM_setValue('usr_chk_tm_alarm_vol',usr_chk_tm_alarm_vol);
	GM_setValue('usr_chk_tm_alarm_cnfm',usr_chk_tm_alarm_cnfm);		
	GM_setValue('usr_chk_tm_title',usr_chk_tm_title);
	GM_setValue('usr_chk_tm_alarm_file',usr_chk_tm_alarm_file);
	GM_setValue('usr_chk_tm_update',usr_chk_tm_update);
}