
(function($){$.toJSON=function(o)
{if(typeof(JSON)=='object'&&JSON.stringify)
return JSON.stringify(o);var type=typeof(o);if(o===null)
return"null";if(type=="undefined")
return undefined;if(type=="number"||type=="boolean")
return o+"";if(type=="string")
return $.quoteString(o);if(type=='object')
{if(typeof o.toJSON=="function")
return $.toJSON(o.toJSON());if(o.constructor===Date)
{var month=o.getUTCMonth()+1;if(month<10)month='0'+month;var day=o.getUTCDate();if(day<10)day='0'+day;var year=o.getUTCFullYear();var hours=o.getUTCHours();if(hours<10)hours='0'+hours;var minutes=o.getUTCMinutes();if(minutes<10)minutes='0'+minutes;var seconds=o.getUTCSeconds();if(seconds<10)seconds='0'+seconds;var milli=o.getUTCMilliseconds();if(milli<100)milli='0'+milli;if(milli<10)milli='0'+milli;return'"'+year+'-'+month+'-'+day+'T'+
hours+':'+minutes+':'+seconds+'.'+milli+'Z"';}
if(o.constructor===Array)
{var ret=[];for(var i=0;i<o.length;i++)
ret.push($.toJSON(o[i])||"null");return"["+ret.join(",")+"]";}
var pairs=[];for(var k in o){var name;var type=typeof k;if(type=="number")
name='"'+k+'"';else if(type=="string")
name=$.quoteString(k);else
continue;if(typeof o[k]=="function")
continue;var val=$.toJSON(o[k]);pairs.push(name+":"+val);}
return"{"+pairs.join(", ")+"}";}};$.evalJSON=function(src)
{if(typeof(JSON)=='object'&&JSON.parse)
return JSON.parse(src);return eval("("+src+")");};$.secureEvalJSON=function(src)
{if(typeof(JSON)=='object'&&JSON.parse)
return JSON.parse(src);var filtered=src;filtered=filtered.replace(/\\["\\\/bfnrtu]/g,'@');filtered=filtered.replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,']');filtered=filtered.replace(/(?:^|:|,)(?:\s*\[)+/g,'');if(/^[\],:{}\s]*$/.test(filtered))
return eval("("+src+")");else
throw new SyntaxError("Error parsing JSON, source is not valid.");};$.quoteString=function(string)
{if(string.match(_escapeable))
{return'"'+string.replace(_escapeable,function(a)
{var c=_meta[a];if(typeof c==='string')return c;c=a.charCodeAt();return'\\u00'+Math.floor(c/16).toString(16)+(c%16).toString(16);})+'"';}
return'"'+string+'"';};var _escapeable=/["\\\x00-\x1f\x7f-\x9f]/g;var _meta={'\b':'\\b','\t':'\\t','\n':'\\n','\f':'\\f','\r':'\\r','"':'\\"','\\':'\\\\'};})(jQuery);;$j=jQuery;
jQuery.fn.outerHTML = function() {
	return $('<div>').append( this.eq(0).clone() ).html();
};
function date_m2h(d,type){
	if(d=='' || d=='0000-00-00')return '-';
	if(!type)type='date';
	date=d.replace(/([0-9]+)-([0-9]+)-([0-9]+).*/,'$3-$2-$1',d).replace(/-0/g,'-');
	var m=months[date.replace(/.*-([0-9]+)-.*/,'$1')];
	date=date.replace(/-[0-9]+-/,'-'+m+'-');
	if(type=='date')return date;
	var time=d.replace(/.* /,'');
	if(type=='time')return time;
	return time+', '+date;
}
function htmlspecialchars(str) {
	if (!str) {
		return '';
	}
	return $('<i>').text(str).html();
}
// { kaejax
function kaejax_create_functions(url,f){
	kaejax_is_loaded=1;
	for(var i=0;i<f.length;++i){
		eval('window.x_'+f[i]+'=function(){kaejax_do_call("'+f[i]+'",arguments)}');
		function_urls[f[i]]=url;
	}
}
function kaejax_do_call(func_name,args){
	var uri=function_urls[func_name];
	if(!window.kaejax_timeouts[uri]){
		window.kaejax_timeouts[uri]={t:setTimeout('kaejax_sendRequests("'+uri+'")',1),c:[],callbacks:[]};
	}
	var l=window.kaejax_timeouts[uri].c.length,v2=[];
	for(var i=0;i<args.length-1;++i){
		v2[v2.length]=args[i];
	}
	window.kaejax_timeouts[uri].c[l]={f:func_name,v:v2};
	window.kaejax_timeouts[uri].callbacks[l]=args[args.length-1];
}
function kaejax_sendRequests(uri){
	var t=window.kaejax_timeouts[uri],callbacks=window.kaejax_timeouts[uri].callbacks;
	t.callbacks=null;
	window.kaejax_timeouts[uri]=null;
	var x=new XMLHttpRequest(),post_data="kaejax="+escape(Json.toString(t)).replace(/%([89A-F][A-Z0-9])/g,'%u00$1').replace('+','%2B');
	x.open('POST',uri,true);
	x.setRequestHeader("Method","POST "+uri+" HTTP/1.1");
	x.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	x.onreadystatechange=function(){
		if(x.readyState!=4)return;
		var v=eval('('+unescape(x.responseText.replace(/%/g,'%25'))+')');
		var f,p;
		for(var i=0;i<t.c.length;++i){
			var f=callbacks[i],p=[];
			p=[];
			if($.isArray(f)){
				p=f;
				f=f[0];
			}
			if(f)f(v[i],p);
		}
	}
	x.send(post_data);
}
// }
function loadScript(url){
	if($.inArray(url,loadedScripts)>-1)return 0;
	loadedScripts.push(url);
	if(kaejax_is_loaded&&/\.php/.test(url))url+=(/\?/.test(url)?'&':'?')+'kaejax_is_loaded';
	$.getScript(url);
	return 1;
}
window.ww={
	CKEDITOR:'ckeditor'
};
// { variables
var function_urls=[],loadedScripts=[],kaejax_is_loaded=0,months=['--','Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];
var kaejax_timeouts=[];
// }
var Json = {
	toString: function(arr) {
		return $.toJSON(arr);
	}
};
$(function(){
	var el=$('.ajaxmenu')[0];
	if(!el)return;
	var id=el.id.replace(/ajaxmenu/,'');
	if(id && id=='am_top')return;
	loadScript('/j/menu.php?pageid='+pagedata.id);
});
;/**
 * Copyright (c) 2009 Anders Ekdahl (http://coffeescripter.com/)
 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
 *
 * Version: 1.2.2
 *
 * Demo and documentation: http://coffeescripter.com/code/ad-gallery/
 */
eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('(8($){$.3g.3h=8(b){4 c={2m:\'X.3i\',1S:0,Y:0.7,2n:o,1t:3j,u:o,w:o,2o:z,2p:z,1T:0,s:{18:z,1U:o,19:3k,2q:\'3l\',2r:\'3m\',1V:z,2s:\'(\',2t:\')\',2u:o,2v:o},2w:\'1W-2x\',2y:z,1u:z,1v:{1a:o,2z:o,2A:o}};4 d=$.2B(o,c,b);5(b&&b.s){d.s=$.2B(o,c.s,b.s)};5(!d.s.18){d.s.1U=o};4 e=[];$(3).2C(8(){4 a=1w 1X(3,d);e[e.H]=a});v e};8 2D(a,b,c){4 d=13(a.t(\'P\'),10);5(b==\'B\'){4 e=\'-\'+3.C+\'A\';a.t(\'P\',3.C+\'A\')}x{4 e=3.C+\'A\';a.t(\'P\',\'-\'+3.C+\'A\')};5(c){c.t(\'1x\',\'-\'+c[0].2E+\'A\');c.1b({1x:0},3.q.1t*2)};v{1c:{P:e},1d:{P:d}}};8 2F(a,b,c){4 d=13(a.t(\'B\'),10);5(b==\'B\'){4 e=\'-\'+3.G+\'A\';a.t(\'B\',3.G+\'A\')}x{4 e=3.G+\'A\';a.t(\'B\',\'-\'+3.G+\'A\')};5(c){c.t(\'1x\',\'-\'+c[0].2E+\'A\');c.1b({1x:0},3.q.1t*2)};v{1c:{B:e},1d:{B:d}}};8 2G(a,b,c){4 d=a.u();4 e=a.w();4 f=13(a.t(\'B\'),10);4 g=13(a.t(\'P\'),10);a.t({u:0,w:0,P:3.C/2,B:3.G/2});v{1c:{u:0,w:0,P:3.C/2,B:3.G/2},1d:{u:d,w:e,P:g,B:f}}};8 2H(a,b,c){a.t(\'Q\',0);v{1c:{Q:0},1d:{Q:1}}};8 2I(a,b,c){a.t(\'Q\',0);v{1c:{Q:0},1d:{Q:1},19:0}};8 1X(a,b){3.1a(a,b)};1X.2J={14:o,R:o,1y:o,T:o,X:o,1m:o,L:o,1z:o,1A:o,1e:o,1f:o,s:o,G:0,C:0,M:0,15:o,1B:0,q:o,E:o,1g:o,1C:o,1a:8(b,c){4 d=3;3.14=$(b);3.q=c;3.2K();3.2L();5(3.q.u){3.G=3.q.u;3.R.u(3.q.u);3.14.u(3.q.u)}x{3.G=3.R.u()};5(3.q.w){3.C=3.q.w;3.R.w(3.q.w)}x{3.C=3.R.w()};3.1B=3.T.u();3.M=0;3.15=o;3.1g=o;3.2M();5(3.q.2o){3.2N()};4 e=8(a){v d.1D(a)};3.s=1w 1Y(e,3.q.s);3.I.J(3.s.2O());5(3.q.s.18){3.s.18()}x{3.s.1Z()};5(3.q.2p){3.2P()};5(3.q.2y){3.2Q()};4 f=3.q.1S;5(20.21.22&&20.21.22.3n(\'#r-U\')===0){f=20.21.22.2R(/[^0-9]+/g,\'\');5((f*1)!=f){f=3.q.1S}};3.1E(z);3.1n(f,8(){5(d.q.s.1U){d.Z(f+1);d.s.1o()}});3.N(3.q.1v.1a)},2L:8(){3.1C={\'1W-3o\':2D,\'1W-2x\':2F,\'3p\':2G,\'3q\':2H,\'3r\':2I}},2K:8(){3.I=3.14.D(\'.r-I\');3.1y=$(\'<p F="r-3s"></p>\');3.I.J(3.1y);3.R=3.14.D(\'.r-U-14\');3.R.3t();3.T=3.14.D(\'.r-T\');3.L=3.T.D(\'.r-3u\');3.1m=$(\'<y F="r-1m"></y>\');3.X=$(\'<16 F="r-X" 1F="\'+3.q.2m+\'">\');3.R.J(3.X);3.X.11();$(1G.3v).J(3.1m)},1E:8(a){5(a){3.X.1h()}x{3.X.11()}},3w:8(a,b){5($.23(b)){3.1C[a]=b}},2M:8(){4 f=3;3.E=[];4 g=0;4 h=0;4 j=3.L.D(\'a\');4 k=j.H;5(3.q.Y<1){j.D(\'16\').t(\'Q\',3.q.Y)};j.2C(8(i){4 a=$(3);4 b=a.O(\'3x\');4 c=a.D(\'16\');5(!f.24(c[0])){c.2S(8(){g+=3.1p.1p.25;h++})}x{g+=c[0].1p.1p.25;h++};a.1H(\'r-1I\'+i);a.1q(8(){f.1n(i);f.s.K();v o}).2T(8(){5(!$(3).1r(\'.r-1i\')&&f.q.Y<1){$(3).D(\'16\').1J(1K,1)};f.Z(i)},8(){5(!$(3).1r(\'.r-1i\')&&f.q.Y<1){$(3).D(\'16\').1J(1K,f.q.Y)}});4 d=o;5(c.1L(\'r-1j\')){d=c.1L(\'r-1j\')}x 5(c.O(\'26\')&&c.O(\'26\').H){d=c.O(\'26\')};4 e=o;5(c.1L(\'r-S\')){e=c.1L(\'r-S\')}x 5(c.O(\'S\')&&c.O(\'S\').H){e=c.O(\'S\')};f.E[i]={1I:c.O(\'1F\'),U:b,27:o,1k:o,1j:d,S:e,1l:o}});4 l=28(8(){5(k==h){f.T.D(\'.r-1I-3y\').t(\'u\',g+\'A\');1M(l)}},3z)},2Q:8(){4 a=3;$(1G).2U(8(e){5(e.29==39){a.1D();a.s.K()}x 5(e.29==37){a.2a();a.s.K()}})},2N:8(){3.1e=$(\'<y F="r-2b"><y F="r-2b-U"></y></y>\');3.1f=$(\'<y F="r-2V"><y F="r-2V-U"></y></y>\');3.R.J(3.1e);3.R.J(3.1f);4 a=3;3.1f.2W(3.1e).3A(8(e){$(3).t(\'w\',a.C);$(3).D(\'y\').1h()}).3B(8(e){$(3).D(\'y\').11()}).1q(8(){5($(3).1r(\'.r-2b\')){a.1D();a.s.K()}x{a.2a();a.s.K()}}).D(\'y\').t(\'Q\',0.7)},2P:8(){4 c=3;3.1A=$(\'<y F="r-2c"></y>\');3.1z=$(\'<y F="r-3C"></y>\');3.T.J(3.1A);3.T.2X(3.1z);4 d=0;4 e=o;$(3.1z).2W(3.1A).1q(8(){4 a=c.1B-3D;5(c.q.1T>0){4 a=c.q.1T};5($(3).1r(\'.r-2c\')){4 b=c.L.17()+a}x{4 b=c.L.17()-a};5(c.q.s.1V){c.s.K()};c.L.1b({17:b+\'A\'});v o}).t(\'Q\',0.6).2T(8(){4 b=\'B\';5($(3).1r(\'.r-2c\')){b=\'2d\'};e=28(8(){d++;5(d>30&&c.q.s.1V){c.s.K()};4 a=c.L.17()+1;5(b==\'B\'){a=c.L.17()-1};c.L.17(a)},10);$(3).t(\'Q\',1)},8(){d=0;1M(e);$(3).t(\'Q\',0.6)})},2e:8(){3.1y.2f((3.M+1)+\' / \'+3.E.H);5(!3.q.1u){3.1f.1h().t(\'w\',3.C);3.1e.1h().t(\'w\',3.C);5(3.M==(3.E.H-1)){3.1e.11()};5(3.M==0){3.1f.11()}};3.N(3.q.1v.2z)},2Y:8(a,b){5(b>3.C){4 c=a/b;b=3.C;a=3.C*c};5(a>3.G){4 c=b/a;a=3.G;b=3.G*c};v{u:a,w:b}},2Z:8(a,b,c){a.t(\'P\',\'31\');5(c<3.C){4 d=3.C-c;a.t(\'P\',(d/2)+\'A\')};a.t(\'B\',\'31\');5(b<3.G){4 d=3.G-b;a.t(\'B\',(d/2)+\'A\')}},32:8(a){4 b=o;5(a.1j.H||a.S.H){4 c=\'\';5(a.S.H){c=\'<33 F="r-34-S">\'+a.S+\'</33>\'};4 b=\'\';5(a.1j.H){b=\'<12>\'+a.1j+\'</12>\'};b=$(\'<p F="r-U-34">\'+c+b+\'</p>\')};v b},1n:8(a,b){5(3.E[a]&&!3.1g){4 c=3;4 d=3.E[a];3.1g=z;5(!d.1k){3.1E(z);3.Z(a,8(){c.1E(o);c.2g(a,b)})}x{3.2g(a,b)}}},2g:8(a,b){5(3.E[a]){4 c=3;4 d=3.E[a];4 e=$(1G.3E(\'y\')).1H(\'r-U\');4 f=$(1w 35()).O(\'1F\',d.U);e.J(f);3.R.2X(e);4 g=3.2Y(d.1l.u,d.1l.w);f.O(\'u\',g.u);f.O(\'w\',g.w);e.t({u:g.u+\'A\',w:g.w+\'A\'});3.2Z(e,g.u,g.w);4 h=3.32(d,e);5(h){e.J(h);4 i=g.u-13(h.t(\'36-B\'),10)-13(h.t(\'36-2d\'),10);h.t(\'u\',i+\'A\')};3.38(3.T.D(\'.r-1I\'+a));4 j=\'2d\';5(3.M<a){j=\'B\'};3.N(3.q.1v.2A);5(3.15||3.q.2n){4 k=3.q.1t;4 l=\'3F\';4 m=3.1C[3.q.2w].2h(3,e,j,h);5(1N m.19!=\'1O\'){k=m.19};5(1N m.3a!=\'1O\'){l=m.3a};5(3.15){4 n=3.15;n.1b(m.1c,k,l,8(){n.3G()})};e.1b(m.1d,k,l,8(){c.M=a;c.15=e;c.1g=o;c.2e();c.N(b)})}x{3.M=a;3.15=e;3.1g=o;c.2e();3.N(b)}}},3b:8(){5(3.M==(3.E.H-1)){5(!3.q.1u){v o};4 a=0}x{4 a=3.M+1};v a},1D:8(a){4 b=3.3b();5(b===o)v o;3.Z(b+1);3.1n(b,a);v z},3c:8(){5(3.M==0){5(!3.q.1u){v o};4 a=3.E.H-1}x{4 a=3.M-1};v a},2a:8(a){4 b=3.3c();5(b===o)v o;3.Z(b-1);3.1n(b,a);v z},3H:8(){4 a=3;4 i=0;8 2i(){5(i<a.E.H){i++;a.Z(i,2i)}};a.Z(i,2i)},Z:8(a,b){5(3.E[a]){4 c=3.E[a];5(!3.E[a].1k){4 d=$(1w 35());d.O(\'1F\',c.U);5(!3.24(d[0])){3.1m.J(d);4 e=3;d.2S(8(){c.1k=z;c.1l={u:3.u,w:3.w};e.N(b)}).27(8(){c.27=z;c.1k=o;c.1l=o})}x{c.1k=z;c.1l={u:d[0].u,w:d[0].w};3.N(b)}}x{3.N(b)}}},24:8(a){5(1N a.3d!=\'1O\'&&!a.3d){v o};5(1N a.3e!=\'1O\'&&a.3e==0){v o};v z},38:8(a){3.L.D(\'.r-1i\').3f(\'r-1i\');a.1H(\'r-1i\');5(3.q.Y<1){3.L.D(\'a:3I(.r-1i) 16\').1J(1K,3.q.Y);a.D(\'16\').1J(1K,1)};4 b=a[0].1p.3J;b-=(3.1B/2)-(a[0].25/2);3.L.1b({17:b+\'A\'})},N:8(a){5($.23(a)){a.2h(3)}}};8 1Y(a,b){3.1a(a,b)};1Y.2J={1P:o,1Q:o,V:o,I:o,q:o,2j:o,1s:o,W:o,1R:o,1a:8(a,b){4 c=3;3.2j=a;3.q=b},2O:8(){3.1P=$(\'<12 F="r-s-1o">\'+3.q.2q+\'</12>\');3.1Q=$(\'<12 F="r-s-K">\'+3.q.2r+\'</12>\');3.V=$(\'<12 F="r-s-V"></12>\');3.I=$(\'<y F="r-s-I"></y>\');3.I.J(3.1P).J(3.1Q).J(3.V);3.V.11();4 a=3;3.1P.1q(8(){a.1o()});3.1Q.1q(8(){a.K()});$(1G).2U(8(e){5(e.29==3K){5(a.W){a.K()}x{a.1o()}}});v 3.I},1Z:8(){3.1s=o;3.K();3.I.11()},18:8(){3.1s=z;3.I.1h()},3L:8(){5(3.1s){3.1Z()}x{3.18()}},1o:8(){5(3.W||!3.1s)v o;4 a=3;3.W=z;3.I.1H(\'r-s-W\');3.2k();3.N(3.q.2u);v z},K:8(){5(!3.W)v o;3.W=o;3.V.11();3.I.3f(\'r-s-W\');1M(3.1R);3.N(3.q.2v);v z},2k:8(){4 c=3;4 d=3.q.2s;4 e=3.q.2t;1M(c.1R);3.V.1h().2f(d+(3.q.19/2l)+e);4 f=0;3.1R=28(8(){f+=2l;5(f>=c.q.19){4 a=8(){5(c.W){c.2k()};f=0};5(!c.2j(a)){c.K()};f=0};4 b=13(c.V.3M().2R(/[^0-9]/g,\'\'),10);b--;5(b>0){c.V.2f(d+b+e)}},2l)},N:8(a){5($.23(a)){a.2h(3)}}}})(3N);',62,236,'|||this|var|if|||function||||||||||||||||false||settings|ad|slideshow|css|width|return|height|else|div|true|px|left|image_wrapper_height|find|images|class|image_wrapper_width|length|controls|append|stop|thumbs_wrapper|current_index|fireCallback|attr|top|opacity|image_wrapper|title|nav|image|countdown|running|loader|thumb_opacity|preloadImage||hide|span|parseInt|wrapper|current_image|img|scrollLeft|enable|speed|init|animate|old_image|new_image|next_link|prev_link|in_transition|show|active|desc|preloaded|size|preloads|showImage|start|parentNode|click|is|enabled|animation_speed|cycle|callbacks|new|bottom|gallery_info|scroll_back|scroll_forward|nav_display_width|animations|nextImage|loading|src|document|addClass|thumb|fadeTo|300|data|clearInterval|typeof|undefined|start_link|stop_link|countdown_interval|start_at_index|scroll_jump|autostart|stop_on_scroll|slide|AdGallery|AdGallerySlideshow|disable|window|location|hash|isFunction|isImageLoaded|offsetWidth|longdesc|error|setInterval|keyCode|prevImage|next|forward|right|_afterShow|html|_showWhenLoaded|call|preloadNext|nextimage_callback|_next|1000|loader_image|animate_first_image|display_next_and_prev|display_back_and_forward|start_label|stop_label|countdown_prefix|countdown_sufix|onStart|onStop|effect|hori|enable_keyboard_move|afterImageVisible|beforeImageVisible|extend|each|VerticalSlideAnimation|offsetHeight|HorizontalSlideAnimation|ResizeAnimation|FadeAnimation|NoneAnimation|prototype|setupElements|setupAnimations|findImages|initNextAndPrev|create|initBackAndForward|initKeyEvents|replace|load|hover|keydown|prev|add|prepend|_getContainedImageSize|_centerImage||0px|_getDescription|strong|description|Image|padding||highLightThumb||easing|nextIndex|prevIndex|complete|naturalWidth|removeClass|fn|adGallery|gif|400|5000|Start|Stop|indexOf|vert|resize|fade|none|info|empty|thumbs|body|addAnimation|href|list|100|mouseover|mouseout|back|50|createElement|swing|remove|preloadAll|not|offsetLeft|83|toggle|text|jQuery'.split('|'),0,{}));jQuery.fn.outer = function() {
  return $( $('<div></div>').html(this.clone()) ).html();
}
/*-------------------------------------------------------------------- 
Scripts for creating and manipulating custom menus based on standard <ul> markup
Version: 3.0, 03.31.2009

By: Maggie Costello Wachs (maggie@filamentgroup.com) and Scott Jehl (scott@filamentgroup.com)
	http://www.filamentgroup.com
	* reference articles: http://www.filamentgroup.com/lab/jquery_ipod_style_drilldown_menu/
		
Copyright (c) 2009 Filament Group
Dual licensed under the MIT (filamentgroup.com/examples/mit-license.txt) and GPL (filamentgroup.com/examples/gpl-license.txt) licenses.
--------------------------------------------------------------------*/


var allUIMenus = [];

$.fn.fgmenu = function(options){
	var caller = this;
	var options = options;
	var m = new Menu(caller, options);	
	allUIMenus.push(m);
	
	$(this)
	.mousedown(function(){
		if (!m.menuOpen) { m.showLoading(); };
	})	
	.mouseover(function(){
		if (m.menuOpen == false) { m.showMenu(); }
	});
};

function Menu(caller, options){
	var menu = this;
	var caller = $(caller);
	var container = $('<div class="fg-menu-container ui-widget ui-widget-content ui-corner-all">'+options.content+'</div>');
	
	this.menuOpen = false;
	this.menuExists = false;
	
	var options = jQuery.extend({
		content: null,
		width: 180, // width of menu container, must be set or passed in to calculate widths of child menus
		maxHeight: 180, // max height of menu (if a drilldown: height does not include breadcrumb)
		positionOpts: {
			posX: 'left', 
			posY: 'bottom',
			offsetX: 0,
			offsetY: 0,
			directionH: 'right',
			directionV: 'down', 
			detectH: true, // do horizontal collision detection  
			detectV: true, // do vertical collision detection
			linkToFront: false
		},
		showSpeed: 200, // show/hide speed in milliseconds
//		callerOnState: 'ui-state-active', // class to change the appearance of the link/button when the menu is showing
//		loadingState: 'ui-state-loading', // class added to the link/button while the menu is created
//		linkHover: 'ui-state-hover', // class for menu option hover state
		linkHoverSecondary: 'li-hover', // alternate class, may be used for multi-level menus		
	// ----- multi-level menu defaults -----
		crossSpeed: 200, // cross-fade speed for multi-level menus
		crumbDefaultText: 'Choose an option:',
		backLink: true, // in the ipod-style menu: instead of breadcrumbs, show only a 'back' link
		backLinkText: 'Back',
		flyOut: true, // multi-level menus are ipod-style by default; this parameter overrides to make a flyout instead
		nextMenuLink: 'ui-icon-triangle-1-e', // class to style the link (specifically, a span within the link) used in the multi-level menu to show the next level
		topLinkText: 'All',
		nextCrumbLink: 'ui-icon-carat-1-e'	
	}, options);
	
	var killAllMenus = function(){
		$.each(allUIMenus, function(i){
			if (allUIMenus[i].menuOpen) { allUIMenus[i].kill(); };	
		});
	};
	
	this.kill = function(){
		caller
			.removeClass(options.loadingState)
			.removeClass('fg-menu-open')
			.removeClass(options.callerOnState);	
		container.find('li').removeClass(options.linkHoverSecondary).find('a').removeClass(options.linkHover);		
		if (options.flyOutOnState) { container.find('li a').removeClass(options.flyOutOnState); };	
		if (options.callerOnState) { 	caller.removeClass(options.callerOnState); };			
		if (container.is('.fg-menu-ipod')) { menu.resetDrilldownMenu(); };
		if (container.is('.fg-menu-flyout')) { menu.resetFlyoutMenu(); };	
		container.parent().hide();	
		menu.menuOpen = false;
		$(document).unbind('click', killAllMenus);
		$(document).unbind('keydown');
	};
	
	this.showLoading = function(){
		caller.addClass(options.loadingState);
	};

	this.showMenu = function(){
		killAllMenus();
		if (!menu.menuExists) { menu.create() };
		caller
			.addClass('fg-menu-open')
			.addClass(options.callerOnState);
		container.parent().show().click(function(){ menu.kill(); return false; });
		container.hide().slideDown(options.showSpeed).find('.fg-menu:eq(0)');
		menu.menuOpen = true;
		caller.removeClass(options.loadingState);
	};
	
	this.create = function(){	
		container.css({ width: options.width }).appendTo('body').find('ul:first,table:first>tbody>tr>td>ul').not('.fg-menu-breadcrumb').addClass('fg-menu');
		container.find('ul, li a').addClass('ui-corner-all');
		
		// aria roles & attributes
		container.find('ul').attr('role', 'menu').eq(0).attr('aria-activedescendant','active-menuitem').attr('aria-labelledby', caller.attr('id'));
		container.find('li').attr('role', 'menuitem');
		container.find('li:has(ul)').attr('aria-haspopup', 'true').find('ul').attr('aria-expanded', 'false');
		container.find('a').attr('tabindex', '-1');
		
		// when there are multiple levels of hierarchy, create flyout or drilldown menu
		if (container.find('ul').size() > 1) {
			if (1 || options.flyOut) { menu.flyout(container, options); }
			else { menu.drilldown(container, options); }	
		}
		else {
			container.find('a').click(function(){
				menu.chooseItem(this);
				return false;
			});
		};	
		if (container.find('ul').length==0) {
			container.css('visibility','hidden');
		}
		
		if (options.linkHover) {
			var allLinks = container.find('.fg-menu li a');
			allLinks.hover(
				function(){
					var menuitem = $(this);
					$('.'+options.linkHover).removeClass(options.linkHover).blur().parent().removeAttr('id');
					$(this).addClass(options.linkHover).focus().parent().attr('id','active-menuitem');
				},
				function(){
					$(this).removeClass(options.linkHover).blur().parent().removeAttr('id');
				}
			);
		};
		
		if (options.linkHoverSecondary) {
			container.find('.fg-menu li').hover(
				function(){
					$(this).siblings('li').removeClass(options.linkHoverSecondary);
					if (options.flyOutOnState) { $(this).siblings('li').find('a').removeClass(options.flyOutOnState); }
					$(this).addClass(options.linkHoverSecondary);
				},
				function(){ $(this).removeClass(options.linkHoverSecondary); }
			);
		};	
		
		menu.setPosition(container, caller, options);
		menu.menuExists = true;
	};
	
	this.chooseItem = function(item){
		location.href = $(item).attr('href');return;
		menu.kill();
		// edit this for your own custom function/callback:
		$('#menuSelection').text($(item).text());	
	};
};

Menu.prototype.flyout = function(container, options) {
	var menu = this;
	
	this.resetFlyoutMenu = function(){
		var allLists = container.find('ul ul');
		allLists.removeClass('ui-widget-content').hide();	
	};
	
	container.addClass('fg-menu-flyout').find('li:has(ul)').each(function(){
		var linkWidth = container.width();
		var showTimer, hideTimer;
		var allSubLists = $(this).find('ul');	
		
		allSubLists
			.css({
				"position":"absolute",
				left: linkWidth,
				width: linkWidth,
				top: this.offsetTop
			})
			.hide();
			
		$(this).find('a:eq(0)').addClass('fg-menu-indicator').html('<span>' + $(this).find('a:eq(0)').text() + '</span><span class="ui-icon '+options.nextMenuLink+'"></span>').hover(
			function(){
				clearTimeout(hideTimer);
				var subList = $(this).next();
				if (!fitVertical(subList, $(this).offset().top)) { subList.css({ top: 'auto', bottom: 0 }); };
				if (!fitHorizontal(subList, $(this).offset().left + 100)) { subList.css({ left: 'auto', right: linkWidth, 'z-index': 999 }); };
				showTimer = setTimeout(function(){
					subList.addClass('ui-widget-content').show(options.showSpeed).attr('aria-expanded', 'true');	
				}, 300);	
			},
			function(){
				clearTimeout(showTimer);
				var subList = $(this).next();
				hideTimer = setTimeout(function(){
					subList.removeClass('ui-widget-content').hide(options.showSpeed).attr('aria-expanded', 'false');
				}, 400);	
			}
		);

		$(this).find('ul a').hover(
			function(){
				clearTimeout(hideTimer);
				if ($(this).parents('ul').prev().is('a.fg-menu-indicator')) {
					$(this).parents('ul').prev().addClass(options.flyOutOnState);
				}
			},
			function(){
				hideTimer = setTimeout(function(){
					allSubLists.hide(options.showSpeed);
					container.find(options.flyOutOnState).removeClass(options.flyOutOnState);
				}, 500);	
			}
		);	
	});
	
	container.find('a').click(function(){
		menu.chooseItem(this);
		return false;
	});
};


Menu.prototype.drilldown = function(container, options) {
	var menu = this;	
	var topList = container.find('.fg-menu');	
	var breadcrumb = $('<ul class="fg-menu-breadcrumb ui-widget-header ui-corner-all ui-helper-clearfix"></ul>');
	var crumbDefaultHeader = $('<li class="fg-menu-breadcrumb-text">'+options.crumbDefaultText+'</li>');
	var firstCrumbText = (options.backLink) ? options.backLinkText : options.topLinkText;
	var firstCrumbClass = (options.backLink) ? 'fg-menu-prev-list' : 'fg-menu-all-lists';
	var firstCrumbLinkClass = (options.backLink) ? 'ui-corner-all' : '';
	var firstCrumbIcon = (options.backLink) ? '<span class="ui-icon ui-icon-triangle-1-w"></span>' : '';
	var firstCrumb = $('<li class="'+firstCrumbClass+'"><a href="#" class="'+firstCrumbLinkClass+'">'+firstCrumbIcon+firstCrumbText+'</a></li>');
	
	container.addClass('fg-menu-ipod');
	
	if (options.backLink) { breadcrumb.addClass('fg-menu-footer').appendTo(container).hide(); }
	else { breadcrumb.addClass('fg-menu-header').prependTo(container); };
	breadcrumb.append(crumbDefaultHeader);
	
	var checkMenuHeight = function(el){
		if (el.height() > options.maxHeight) { el.addClass('fg-menu-scroll') };	
		el.css({ height: options.maxHeight });
	};
	
	var resetChildMenu = function(el){ el.removeClass('fg-menu-scroll').removeClass('fg-menu-current').height('auto'); };
	
	this.resetDrilldownMenu = function(){
		$('.fg-menu-current').removeClass('fg-menu-current');
		topList.animate({ left: 0 }, options.crossSpeed, function(){
			$(this).find('ul').each(function(){
				$(this).hide();
				resetChildMenu($(this));				
			});
			topList.addClass('fg-menu-current');			
		});		
		$('.fg-menu-all-lists').find('span').remove();	
		breadcrumb.empty().append(crumbDefaultHeader);		
		$('.fg-menu-footer').empty().hide();	
		checkMenuHeight(topList);		
	};
	
	topList
		.addClass('fg-menu-content fg-menu-current ui-widget-content ui-helper-clearfix')
		.css({ width: container.width() })
		.find('ul')
			.css({ width: container.width(), left: container.width() })
			.addClass('ui-widget-content')
			.hide();		
	checkMenuHeight(topList);	
	
	topList.find('a').each(function(){
		// if the link opens a child menu:
		if ($(this).next().is('ul')) {
			$(this)
				.addClass('fg-menu-indicator')
				.each(function(){ $(this).html('<span>' + $(this).text() + '</span><span class="ui-icon '+options.nextMenuLink+'"></span>'); })
				.mouseover(function(){ // ----- show the next menu			
					var nextList = $(this).next();
		    		var parentUl = $(this).parents('ul:eq(0)');   		
		    		var parentLeft = (parentUl.is('.fg-menu-content')) ? 0 : parseFloat(topList.css('left'));    		
		    		var nextLeftVal = Math.round(parentLeft - parseFloat(container.width()));
		    		var footer = $('.fg-menu-footer');
		    		
		    		// show next menu   		
		    		resetChildMenu(parentUl);
		    		checkMenuHeight(nextList);
					topList.animate({ left: nextLeftVal }, options.crossSpeed);						
		    		nextList.show().addClass('fg-menu-current').attr('aria-expanded', 'true');    
		    		
		    		var setPrevMenu = function(backlink){
		    			var b = backlink;
		    			var c = $('.fg-menu-current');
			    		var prevList = c.parents('ul:eq(0)');
			    		c.hide().attr('aria-expanded', 'false');
		    			resetChildMenu(c);
		    			checkMenuHeight(prevList);
			    		prevList.addClass('fg-menu-current').attr('aria-expanded', 'true');
			    		if (prevList.hasClass('fg-menu-content')) { b.remove(); footer.hide(); };
		    		};		
		
					// initialize "back" link
					if (options.backLink) {
						if (footer.find('a').size() == 0) {
							footer.show();
							$('<a href="#"><span class="ui-icon ui-icon-triangle-1-w"></span> <span>Back</span></a>')
								.appendTo(footer)
								.click(function(){ // ----- show the previous menu
									var b = $(this);
						    		var prevLeftVal = parseFloat(topList.css('left')) + container.width();		    						    		
						    		topList.animate({ left: prevLeftVal },  options.crossSpeed, function(){
						    			setPrevMenu(b);
						    		});			
									return false;
								});
						}
					}
					// or initialize top breadcrumb
		    		else { 
		    			if (breadcrumb.find('li').size() == 1){				
							breadcrumb.empty().append(firstCrumb);
							firstCrumb.find('a').click(function(){
								menu.resetDrilldownMenu();
								return false;
							});
						}
						$('.fg-menu-current-crumb').removeClass('fg-menu-current-crumb');
						var crumbText = $(this).find('span:eq(0)').text();
						var newCrumb = $('<li class="fg-menu-current-crumb"><a href="javascript://" class="fg-menu-crumb">'+crumbText+'</a></li>');	
						newCrumb
							.appendTo(breadcrumb)
							.find('a').click(function(){
								if ($(this).parent().is('.fg-menu-current-crumb')){
									menu.chooseItem(this);
								}
								else {
									var newLeftVal = - ($('.fg-menu-current').parents('ul').size() - 1) * 180;
									topList.animate({ left: newLeftVal }, options.crossSpeed, function(){
										setPrevMenu();
									});
								
									// make this the current crumb, delete all breadcrumbs after this one, and navigate to the relevant menu
									$(this).parent().addClass('fg-menu-current-crumb').find('span').remove();
									$(this).parent().nextAll().remove();									
								};
								return false;
							});
						newCrumb.prev().append(' <span class="ui-icon '+options.nextCrumbLink+'"></span>');
		    		};			
		    		return false;    		
    			});
		}
		// if the link is a leaf node (doesn't open a child menu)
		else {
			$(this).click(function(){
				menu.chooseItem(this);
				return false;
			});
		};
	});
};


/* Menu.prototype.setPosition parameters (defaults noted with *):
	referrer = the link (or other element) used to show the overlaid object 
	settings = can override the defaults:
		- posX/Y: where the top left corner of the object should be positioned in relation to its referrer.
				X: left*, center, right
				Y: top, center, bottom*
		- offsetX/Y: the number of pixels to be offset from the x or y position.  Can be a positive or negative number.
		- directionH/V: where the entire menu should appear in relation to its referrer.
				Horizontal: left*, right
				Vertical: up, down*
		- detectH/V: detect the viewport horizontally / vertically
		- linkToFront: copy the menu link and place it on top of the menu (visual effect to make it look like it overlaps the object) */

Menu.prototype.setPosition = function(widget, caller, options) { 
	var el = widget;
	var referrer = caller;
	var dims = {
		refX: referrer.offset().left,
		refY: referrer.offset().top,
		refW: referrer.outerWidth(),
		refH: referrer.outerHeight()
	};	
	var options = options;
	var xVal, yVal;
	
	var helper = $('<div class="positionHelper"></div>');
	helper.css({ position: 'absolute', left: dims.refX, top: dims.refY, width: dims.refW, height: 1 });
	el.wrap(helper);
	
	// get X pos
	switch(options.positionOpts.posX) {
		case 'left': 	xVal = 0; 
			break;				
		case 'center': xVal = dims.refW / 2;
			break;				
		case 'right': xVal = dims.refW;
			break;
	};
	
	// get Y pos
	switch(options.positionOpts.posY) {
		case 'top': 	yVal = 0;
			break;				
		case 'center': yVal = dims.refH / 2;
			break;				
		case 'bottom': yVal = dims.refH;
			break;
	};
	
	// add the offsets (zero by default)
	xVal += options.positionOpts.offsetX;
	yVal += options.positionOpts.offsetY;
	
	// position the object vertically
	if (options.positionOpts.directionV == 'up') {
		el.css({ top: 'auto', bottom: yVal });
		if (options.positionOpts.detectV && !fitVertical(el)) {
			el.css({ bottom: 'auto', top: yVal });
		}
	} 
	else {
		el.css({ bottom: 'auto', top: yVal });
		if (options.positionOpts.detectV && !fitVertical(el)) {
			el.css({ top: 'auto', bottom: yVal });
		}
	};
	
	// and horizontally
	if (options.positionOpts.directionH == 'left') {
		el.css({ left: 'auto', right: xVal });
		if (options.positionOpts.detectH && !fitHorizontal(el)) {
			el.css({ right: 'auto', left: xVal });
		}
	} 
	else {
		el.css({ right: 'auto', left: xVal });
		if (options.positionOpts.detectH && !fitHorizontal(el)) {
			el.css({ left: 'auto', right: xVal });
		}
	};
	
	// if specified, clone the referring element and position it so that it appears on top of the menu
	if (options.positionOpts.linkToFront) {
		referrer.clone().addClass('linkClone').css({
			position: 'absolute', 
			top: 0, 
			right: 'auto', 
			bottom: 'auto', 
			left: 0, 
			width: referrer.width(), 
			height: referrer.height()
		}).insertAfter(el);
	};
};


/* Utilities to sort and find viewport dimensions */

function sortBigToSmall(a, b) { return b - a; };

function getScrollTop(){
	return self.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop;
};

function getScrollLeft(){
	return self.pageXOffset || document.documentElement.scrollLeft || document.body.scrollLeft;
};

function getWindowHeight(){
	var de = document.documentElement;
	return self.innerHeight || (de && de.clientHeight) || document.body.clientHeight;
};

function getWindowWidth(){
	var de = document.documentElement;
	return self.innerWidth || (de && de.clientWidth) || document.body.clientWidth;
};

/* Utilities to test whether an element will fit in the viewport
	Parameters:
	el = element to position, required
	leftOffset / topOffset = optional parameter if the offset cannot be calculated (i.e., if the object is in the DOM but is set to display: 'none') */
	
function fitHorizontal(el, leftOffset){
	var leftVal = parseInt(leftOffset) || $(el).offset().left;
	return (leftVal + $(el).width() <= getWindowWidth() + getScrollLeft() && leftVal - getScrollLeft() >= 0);
};

function fitVertical(el, topOffset){
return true;
	var topVal = parseInt(topOffset) || $(el).offset().top;
	return (topVal + $(el).height() <= getWindowHeight() + getScrollTop() && topVal - getScrollTop() >= 0);
};

/*-------------------------------------------------------------------- 
 * javascript method: "pxToEm"
 * by:
   Scott Jehl (scott@filamentgroup.com) 
   Maggie Wachs (maggie@filamentgroup.com)
   http://www.filamentgroup.com
 *
 * Copyright (c) 2008 Filament Group
 * Dual licensed under the MIT (filamentgroup.com/examples/mit-license.txt) and GPL (filamentgroup.com/examples/gpl-license.txt) licenses.
 *
 * Description: Extends the native Number and String objects with pxToEm method. pxToEm converts a pixel value to ems depending on inherited font size.  
 * Article: http://www.filamentgroup.com/lab/retaining_scalable_interfaces_with_pixel_to_em_conversion/
 * Demo: http://www.filamentgroup.com/examples/pxToEm/	 	
 *							
 * Options:  	 								
 		scope: string or jQuery selector for font-size scoping
 		reverse: Boolean, true reverses the conversion to em-px
 * Dependencies: jQuery library						  
 * Usage Example: myPixelValue.pxToEm(); or myPixelValue.pxToEm({'scope':'#navigation', reverse: true});
 *
 * Version: 2.0, 08.01.2008 
 * Changelog:
 *		08.02.2007 initial Version 1.0
 *		08.01.2008 - fixed font-size calculation for IE
--------------------------------------------------------------------*/

Number.prototype.pxToEm = String.prototype.pxToEm = function(settings){
	//set defaults
	settings = jQuery.extend({
		scope: 'body',
		reverse: false
	}, settings);
	
	var pxVal = (this == '') ? 0 : parseFloat(this);
	var scopeVal;
	var getWindowWidth = function(){
		var de = document.documentElement;
		return self.innerWidth || (de && de.clientWidth) || document.body.clientWidth;
	};	
	
	/* When a percentage-based font-size is set on the body, IE returns that percent of the window width as the font-size. 
		For example, if the body font-size is 62.5% and the window width is 1000px, IE will return 625px as the font-size. 	
		When this happens, we calculate the correct body font-size (%) and multiply it by 16 (the standard browser font size) 
		to get an accurate em value. */
				
	if (settings.scope == 'body' && $.browser.msie && (parseFloat($('body').css('font-size')) / getWindowWidth()).toFixed(1) > 0.0) {
		var calcFontSize = function(){		
			return (parseFloat($('body').css('font-size'))/getWindowWidth()).toFixed(3) * 16;
		};
		scopeVal = calcFontSize();
	}
	else { scopeVal = parseFloat(jQuery(settings.scope).css("font-size")); };
			
	var result = (settings.reverse == true) ? (pxVal * scopeVal).toFixed(2) + 'px' : (pxVal / scopeVal).toFixed(2) + 'em';
	return result;
};

$('#menu-top>ul>li>a').addClass('fg-menu-top-level');

$('.fg-menu,.fg-menu-top-level')
	.live('mouseover',function(){
		this.mouse_is_over=true;
		clearTimeout(window.fgmenu_mouseout_timer);
	})
	.live('mouseout',function(){
		this.mouse_is_over=false;
		window.fgmenu_mouseout_timer=setTimeout(function(){
			var o=0;
			$('.fg-menu,.fg-menu-top-level').each(function(){
				if (this.mouse_is_over) o++;
			});
			if(!o){
				$.each(allUIMenus, function(i){
					if (allUIMenus[i].menuOpen) { allUIMenus[i].kill(); };	
				});
			}
		},500);
	});
;
