/**** script/controls.js ****/
var commonControls = {
	/**
	 * Switcher control (i.e. currency switcher)
	 * @param string|array Switchers
	 * @param string Active element class name
	 * @param string Inactive element class name
	 * @param function Callback function
	 */
	switcher: function (control, activeClass, inactiveClass, callback, hiddenInput) {
		$(control).each(function() {
			if ((this.tagName).toLowerCase() == "ul") {
				// hidden switcher value
				if (hiddenInput) {
					var hidden = hiddenInput;
				} else {
					var hidden = $(this).next("input");
				}
				// current option
				var current = null;
				$("li", this).each(function() {
					// hidden option value
					var hiddenValue = $("input:first", this).val();
					// set current option
					if (!current && $(this).children("a:first").hasClass(activeClass)) current  = this;
					//disabling a element click handler
					$("a", this).click(function(e){
						return false;
					})
					// option click handler					
					$(this).mousedown(function(e) {
						// if can activate
						if (!$(this).hasClass(activeClass) && (e.button == 0 || e.button == 1)) {
							// previous switcher value
							var prevValue = hidden.val();
							// deselect siblings
							$(this).siblings().children("a").removeClass(activeClass).addClass(inactiveClass);
							// select this option
							$("a", this).removeClass(inactiveClass).addClass(activeClass);
							// set hidden field
							if (hidden) {
								hidden.val(hiddenValue);
							}
							// call function
							var justClickedItem = this;
							if ($.isFunction(callback)) callback.call(this, current, justClickedItem);
							// change current item link
							current = this;
						}
						return false;
					});
				});
			}
		});
		if (hiddenInput) {
			hiddenInput.val($(control).children('li:first').children('input:first').val());
		}	
	}, 
	
	customSwitcher: function(control, activeClass, hiddenInput, callback) {
		this.switcher(control, activeClass, null, callback, hiddenInput);
	}
}
;

/**** script/jquery.bgiframe.pack.js ****/
/* Copyright (c) 2006 Brandon Aaron (http://brandonaaron.net)
 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) 
 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
 *
 * $LastChangedDate: 2007-06-19 20:23:36 -0500 (Tue, 19 Jun 2007) $
 * $Rev: 2110 $
 *
 * Version 2.1
 */
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}('(f($){$.r.H=$.r.l=f(s){j($.b.17&&k($.b.g)<=6){s=$.G({c:\'3\',7:\'3\',e:\'3\',5:\'3\',q:U,i:\'N:o;\'},s||{});J a=f(n){h n&&n.C==B?n+\'4\':n},p=\'<t 15="l"12="0"X="-1"i="\'+s.i+\'"\'+\'V="T:Q;P:O;z-M:-1;\'+(s.q!==o?\'L:K(I=\\\'0\\\');\':\'\')+\'c:\'+(s.c==\'3\'?\'9(((k(2.8.m.F)||0)*-1)+\\\'4\\\')\':a(s.c))+\';\'+\'7:\'+(s.7==\'3\'?\'9(((k(2.8.m.E)||0)*-1)+\\\'4\\\')\':a(s.7))+\';\'+\'e:\'+(s.e==\'3\'?\'9(2.8.D+\\\'4\\\')\':a(s.e))+\';\'+\'5:\'+(s.5==\'3\'?\'9(2.8.R+\\\'4\\\')\':a(s.5))+\';\'+\'"/>\';h 2.S(f(){j($(\'> t.l\',2).A==0)2.y(x.W(p),2.w)})}h 2};j(!$.b.g)$.b.g=v.u.Z().14(/.+(?:13|11|10|Y)[\\/: ]([\\d.]+)/)[1]})(16);',62,70,'||this|auto|px|height||left|parentNode|expression||browser|top||width|function|version|return|src|if|parseInt|bgiframe|currentStyle||false|html|opacity|fn||iframe|userAgent|navigator|firstChild|document|insertBefore||length|Number|constructor|offsetWidth|borderLeftWidth|borderTopWidth|extend|bgIframe|Opacity|var|Alpha|filter|index|javascript|absolute|position|block|offsetHeight|each|display|true|style|createElement|tabindex|ie|toLowerCase|ra|it|frameborder|rv|match|class|jQuery|msie'.split('|'),0,{}))
;

/**** script/drag.js ****/
var Drag = {
    observe: function(element, onmove, onup, ondown) {
        var drag = null;
        var prev = null;
        var doc = element.ownerDocument;
        
        element.ondragmove = onmove;
        element.ondragup = onup;
        element.ondragdown = ondown;

        $(element).mousedown(function(e) {
            var pos = $(element).offset();
            drag = jQuery.extend({}, e);
            // offsetX and offsetY are in pixels relative to the top left element corner.
            drag.offsetX = drag.pageX - pos.left;
            drag.offsetY = drag.pageY - pos.top;
            prev = [e.pageX, e.pageY];
            if (element.ondragdown) {
                if (element.ondragdown(drag) === false) {
                    drag = null;
                    return;
                }
            }
            return false;
        });

        $(doc).mouseup(function(e) {
            if (!drag) return;
            if (element.ondragup) {
                element.ondragup(e, drag);
            }
            drag = null;
            return false;
        });

        $(doc).mousemove(function(e) {
            if (!drag) return;
            e.dx = e.pageX - prev[0];
            e.dy = e.pageY - prev[1];
            prev = [e.pageX, e.pageY]; // update if BEFORE ondragmove call! important!
            if (element.ondragmove) {
                element.ondragmove(e, drag);
            }
            return false;
        });
        
        $(element).bind('selectstart', function(e) {
            return false;
        });
    }
}
;

/**** script/raphael.js ****/
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}('9 1L=(I(q){9 r=I(){J r.3k.2v(r,N)};r.4F="0.5.4G";r.19=q;9 C={};I 2g(a,b,c,d,e,f){7.m=[[a||1,b||0,0],[c||0,d||1,0],[e||0,f||0,1],]}C.1e=C.1g=C.1w=C.1y=I(x){J x};K(q=="2K"){2g.1p.2w=I(){J"4H:4I.4J.2g(4K="+7.m[0][0]+", 4L="+7.m[1][0]+", 4M="+7.m[0][1]+", 4N="+7.m[1][1]+", 4O="+7.m[2][0]+", 4P="+7.m[2][1]+", 4Q=\'4R 4S\', 4T=\'4U\')"};9 t=I(j,l,m){9 g=17.1u("1m:1N"),2x=g.1h;2x.2h="2i";2x.1H=0;2x.1z=0;2x.11=m.11+"1A";2x.14=m.14+"1A";9 n=17.1u("1m:2j"),2y=n.1h;2y.11=m.11+"1A";2y.14=m.14+"1A";n.1a="";K(j["3F"]){n.4V=j["3F"]}n.2L=7.2L;n.2M=7.2M;g.1b(n);m.18.1b(g);9 p=1n z(n,g,m);u(p,j);K(j.1I){v(p,j.1I)}p.Q=20;p.19="1a";p.1a=[];p.O={x:0,y:0,2o:0,2p:0,Q:20};p.2k="";p.2z=I(){7.Q=20;J 7};p.36=I(){7.Q=2N;J 7};p.3G=I(){7.2k="";9 a=7.1a;7.1a=[];1l(9 i=0,1i=a.1c;i<1i;i++){K(a[i].19!="3l"){7[a[i].19+"3H"].2v(7,a[i].1O)}1j{7.2q()}}J 7};p.2b=I(x,y){9 d=7.Q?"m":"t";9 a=7.Q?m.1e:m.1w;9 b=7.Q?m.1g:m.1y;d+=T.15(a(13(x,10)))+" "+T.15(b(13(y,10)));7[0].1a=7.2k+=d;7.O.x=(7.Q?0:7.O.x)+a(13(x,10));7.O.y=(7.Q?0:7.O.y)+b(13(y,10));7.O.Q=7.Q;7.1a.1M({19:"3I",1O:[].2O.2A(N,0),21:7.Q});J 7};p.1o=I(x,y){9 d=7.Q?"l":"r";9 a=7.Q?m.1e:m.1w;9 b=7.Q?m.1g:m.1y;d+=T.15(a(13(x,10)))+" "+T.15(b(13(y,10)));7[0].1a=7.2k+=d;7.O.x=(7.Q?0:7.O.x)+a(13(x,10));7.O.y=(7.Q?0:7.O.y)+b(13(y,10));7.O.Q=7.Q;7.1a.1M({19:"3J",1O:[].2O.2A(N,0),21:7.Q});J 7};p.37=I(a,b,c,e,f,g){f=(7.Q?0:7.O.x)+f;g=(7.Q?0:7.O.y)+g;9 h=7.O.x,2P=7.O.y,x=(h-f)/2,y=(2P-g)/2,k=(c==e?-1:1)*T.4W((a*a*b*b-a*a*y*y-b*b*x*x)/(a*a*y*y+b*b*x*x)),1E=k*a*y/b+(h+f)/2,1J=k*-b*x/a+(2P+g)/2,d=e?(7.Q?"4X":"4Y"):(7.Q?"4Z":"50"),1e=7.Q?m.1e:m.1w,1g=7.Q?m.1g:m.1y,1H=T.15(1E-a),1z=T.15(1J-b);d+=[1H,1z,T.15(1H+a*2),T.15(1z+b*2),T.15(h),T.15(2P),T.15(1e(13(f,10))),T.15(1e(13(g,10)))].22(", ");7[0].1a=7.2k+=d;7.O.x=(7.Q?0:7.O.x)+1e(13(f,10));7.O.y=(7.Q?0:7.O.y)+1g(13(g,10));7.O.Q=7.Q;7.1a.1M({19:"3K",1O:[].2O.2A(N,0),21:7.Q});J 7};p.3L=I(a,b,c){K(!c){J 7.1o(a,b)}1j{9 p={};p.1e=7.Q?m.1e:m.1w;p.1g=7.Q?m.1g:m.1y;9 x=T.15(p.1e(T.15(13(a,10)*1f)/1f));9 y=T.15(p.1g(T.15(13(b,10)*1f)/1f));9 w=T.15(m.1w(T.15(13(c,10)*1f)/1f));9 d=7.Q?"c":"v";9 e=[T.15(7.O.x)+w,T.15(7.O.y),x-w,y,x,y];d+=e.22(" ")+" ";7.O.x=(7.Q?0:7.O.x)+e[4];7.O.y=(7.Q?0:7.O.y)+e[5];7.O.2o=e[2];7.O.2p=e[3];7[0].1a=7.2k+=d;7.1a.1M({19:"3M",1O:[].2O.2A(N,0),21:7.Q});J 7}};p.1q=I(){9 d=7.Q?"c":"v";9 a=7.Q?m.1e:m.1w;9 b=7.Q?m.1g:m.1y;K(N.1c==6){7.O.x=(7.Q?0:7.O.x)+a(13(N[4],10));7.O.y=(7.Q?0:7.O.y)+b(13(N[5],10));7.O.2o=T.15(a(13(N[2],10)));7.O.2p=T.15(b(13(N[3],10)));d+=T.15(a(13(N[0],10)))+" "+T.15(b(13(N[1],10)))+" "+T.15(a(13(N[2],10)))+" "+T.15(b(13(N[3],10)))+" "+T.15(a(13(N[4],10)))+" "+T.15(b(13(N[5],10)))+" ";7.O.Q=7.Q}7[0].1a=7.2k+=d;7.1a.1M({19:"3N",1O:[].2O.2A(N,0),21:7.Q});J 7};p.2B=I(r,a){9 R=.3O*r,23=7.Q,o=7;K(23){7.36();23=I(){o.2z()}}1j{23=I(){}}9 b={l:I(){J{u:I(){o.1q(-R,0,-r,-(r-R),-r,-r)},d:I(){o.1q(-R,0,-r,r-R,-r,r)}}},r:I(){J{u:I(){o.1q(R,0,r,-(r-R),r,-r)},d:I(){o.1q(R,0,r,r-R,r,r)}}},u:I(){J{r:I(){o.1q(0,-R,-(R-r),-r,r,-r)},l:I(){o.1q(0,-R,R-r,-r,-r,-r)}}},d:I(){J{r:I(){o.1q(0,R,-(R-r),r,r,r)},l:I(){o.1q(0,R,R-r,r,-r,r)}}}};b[a.38(0)]()[a.38(1)]();23();J o};p.2q=I(){7[0].1a=(7.2k+="x e");J 7};K(1k l=="2c"){l=l.2d(/([3P])/39,",$1,").2d(/(\\d+\\.?\\d*)(\\s)(\\d)/39,"$1,$3");1a=l.3m(",");9 i=0,1i=1a.1c;p.2z();3n(i<1i){K(C.2Q[1a[i]]){i=C.2Q[1a[i]](p,1a,i)}i++}}J p};9 u=I(o,a){9 s=o[0].1h;o.P=o.P||{};1l(9 b 1r a){o.P[b]=a[b]}a["2e-3Q"]&&(s.51=a["2e-3Q"]);a["2e-3R"]&&(s.52=a["2e-3R"]);a["2e"]&&(s.2e=a["2e"]);a["2e-3a"]&&(s.53=a["2e-3a"]);K(1k a.1B!="1s"||1k a["1d-11"]!="1s"||1k a.1x!="1s"||1k a.1d!="1s"){o=o.2j||o[0];9 c=(o.2R("1x")&&o.2R("1x")[0])||17.1u("1m:1x");K("1x-1B"1r a||"1B"1r a){c.1B=((a["1x-1B"]+1||2)-1)*((a.1B+1||2)-1)}K(a.1x){c.24=20}K(c.24==1s||a.1x=="1P"){c.24=2N}K(c.24&&a.1x){c.25=a.1x}o.1b(c);9 d=(o.2R("1d")&&o.2R("1d")[0])||17.1u("1m:1d");K((a.1d&&a.1d!="1P")||a["1d-11"]||a["1d-1B"]||a["1d-2S"]){d.24=20}K(a.1d=="1P"||1k d.24=="1s"){d.24=2N}K(d.24&&a.1d){d.25=a.1d}d.1B=((a["1d-1B"]+1||2)-1)*((a.1B+1||2)-1);a["1d-3S"]&&(d.54=a["1d-3S"]||"3T");d.3U=a["1d-3U"]||8;a["1d-3V"]&&(d.55={56:"58",3W:"3W",15:"15"}[a["1d-3V"]]||"3T");a["1d-11"]&&(d.3a=(13(a["1d-11"],10)||1)*12/16);K(a["1d-2S"]){9 e=a["1d-2S"].2d(" ",",").3m(","),3o=[],3X=d.3a;1l(9 i=0,1i=e.1c;i<1i;i++){9 f=e[i]/3X;K(!59(f)){3o.1M(f)}};d.5a=3o.22(" ")}o.1b(d)}};9 v=I(o,a){o.P=o.P||{};o.P.1I=a;o=o.2j||o[0];9 b=o.2R("1x");K(b.1c){b=b[0]}1j{b=17.1u("1m:1x")}K(a.1t.1c){b.24=20;b.19=(a.19.3p()=="5b")?"1I":"5c";K(1k a.1t[0].25!="1s"){b.25=a.1t[0].25||"#1C"}K(1k a.1t[0].1B!="1s"){b.1B=a.1t[0].1B}K(1k a.1t[a.1t.1c-1].1B!="1s"){b.5d=a.1t[a.1t.1c-1].1B}K(1k a.1t[a.1t.1c-1].25!="1s"){b.5e=a.1t[a.1t.1c-1].25||"#1C"}9 c="";1l(9 i=1,1i=a.1t.1c-1;i<1i;i++){c+=a.1t[i].3b+" "+a.1t[i].25;K(i!=1i-1){c+=","}};K(c){b.5f=c}K(a.1U){9 d=T.15(T.3Y((1G(a.1U[3],10)-1G(a.1U[1],10))/(1G(a.1U[2],10)-1G(a.1U[0],10)))*57.29)+5g;b.5h=d+5i}K(a.19.3p()=="5j"){b.5k="0.5, 0.5";b.5l="0, 0";b.5m="1P"}}};9 z=I(b,c,d){9 e=0,5n=0,5o=0,5p=1;7[0]=b;7.X=0;7.Y=0;7.P={};7.1v=c;7.26=d;7.3q=I(a){K(a==1s){J e}e+=a;7.1v.1h.5q=e;J 7}};z.1p.2C=I(a){9 b=7.1v.1h,2D=7[0].1h;1l(9 i 1r a){7.P[i]=a[i]}9 c=7.P,x,y,w,h;3Z(7.19){1F"2T":x=c.1E-c.r;y=c.1J-c.r;w=h=c.r*2;1V;1F"2U":x=c.1E-c.2l;y=c.1J-c.2m;w=c.2l*2;h=c.2m*2;1V;1F"2f":1F"2E":x=c.x;y=c.y;w=c.w;h=c.h;1V;1F"1K":7.3r.v=["m",T.15(c.x),", ",T.15(c.y-2),"l",T.15(c.x)+1,", ",T.15(c.y-2)].22("");J;3s:J}9 d=7.26.11/2-w/2,1z=7.26.14/2-h/2;b.2h="2i";b.1H=x-d+"1A";b.1z=y-1z+"1A";7.X=x-d;7.Y=y-1z;7.W=w;7.H=h;b.11=7.26.11+"1A";b.14=7.26.14+"1A";2D.2h="2i";2D.1z=1z+"1A";2D.1H=d+"1A";2D.11=w+"1A";2D.14=h+"1A"};z.1p.40=I(){7.1v.1h.3c="1P";J 7};z.1p.41=I(){7.1v.1h.3c="42";J 7};z.1p.3t=I(x,y){K(x==1s&&y==1s){J{x:7.X,y:7.Y}}7.X+=x;7.Y+=y;7.1v.1h.1H=7.X+"1A";7.1v.1h.1z=7.Y+"1A";J 7};z.1p.3u=I(a,b,c,d,e,f){3v=1n 2g(a,b,c,d,e,f);7.1v.1h.43=3v;J 7};z.1p.44=I(x,y){K(x==1s&&y==1s){J}y=y||x;K(x!=0&&!(x==1&&y==1)){9 a=T.15(x/T.45(x)),3d=T.15(y/T.45(y)),s=7[0].1h;K(a!=1||3d!=1){s.43=1n 2g(a,0,0,3d,0,0)}9 b=1G(s.11,10)*x*a;9 c=1G(s.14,10)*y*3d;9 d=1G(s.1H,10);9 e=1G(s.1z,10);s.1H=7.X=d+7.W/2-b/2;s.1z=7.Y=e+7.H/2-c/2;s.11=7.W=b;s.14=7.H=c}J 7};z.1p.2V=I(){J{x:7.1v.5r,y:7.1v.5s,11:7.1v.5t,14:7.1v.5u}};z.1p.2W=I(){7[0].1D.27(7[0]);7.1v.1D.27(7.1v);7.2j&&7.2j.1D.27(7.2j)};z.1p.2F=I(){K(N.1c==1&&1k N[0]=="2c"){J 7.P[N[0]]}K(7.P&&N.1c==1&&N[0]46 47){9 a={};1l(9 i=0,1i=N[0].1c;i<1i;i++){a[N[0][i]]=7.P[N[0][i]]};J a}K(7[0].5v.3p()=="1N"){9 b=7[0].2X;7.P=7.P||{};K(N.1c==2){7.P[N[0]]=N[1]}1j K(N.1c==1||1k N[0]=="2r"){1l(9 j 1r N[0]){7.P[j]=N[0][j]}}1l(9 i=0,1i=b.1c;i<1i;i++){7.2F.2v(1n 5w(b[i],7[0],7.26),N)}}1j{9 c;K(N.1c==2){c={};c[N[0]]=N[1]}K(N.1c==1&&1k N[0]=="2r"){c=N[0]}K(c){u(7,c);7.2C(c);K(c.1I){v(7,c.1I)}K(c.1K&&7.19=="1K"){7[0].2c=c.1K}K(c.2Y){7[0].2Y=c.2Y}}}J 7};z.1p.48=I(){7.1v.1D.1b(7.1v);J 7};z.1p.49=I(){K(7.1v.1D.1Q!=7.1v){7.1v.1D.3e(7.1v,7.1v.1D.1Q)}J 7};9 A=I(a,x,y,r){9 g=17.1u("1m:1N");9 o=17.1u("1m:4a");g.1b(o);a.18.1b(g);9 b=1n z(o,g,a);u(b,{1d:"#1C",1x:"1P"});b.2C({x:x-r,y:y-r,w:r*2,h:r*2});b.P.1E=x;b.P.1J=y;b.P.r=r;b.19="2T";J b};9 B=I(a,x,y,w,h,r){9 g=17.1u("1m:1N");9 o=17.1u(r?"1m:5x":"1m:2f");K(r){o.5y=r/(T.2Z(w,h))}g.1b(o);a.18.1b(g);9 b=1n z(o,g,a);u(b,{1d:"#1C"});b.2C({x:x,y:y,w:w,h:h});b.P.x=x;b.P.y=y;b.P.w=w;b.P.h=h;b.P.r=r;b.19="2f";J b};9 D=I(a,x,y,b,c){9 g=17.1u("1m:1N");9 o=17.1u("1m:4a");g.1b(o);a.18.1b(g);9 d=1n z(o,g,a);u(d,{1d:"#1C"});d.2C({x:x-b,y:y-c,w:b*2,h:c*2});d.P.1E=x;d.P.1J=y;d.P.2l=b;d.P.2m=c;d.19="2U";J d};9 E=I(a,b,x,y,w,h){9 g=17.1u("1m:1N");9 o=17.1u("1m:2E");o.5z=b;g.1b(o);a.18.1b(g);9 c=1n z(o,g,a);c.19="2E";c.2C({x:x,y:y,w:w,h:h});c.P.x=x;c.P.y=y;c.P.w=w;c.P.h=h;J c};9 F=I(a,x,y,b){9 g=17.1u("1m:1N"),2G=g.1h;9 c=17.1u("1m:2j"),2y=c.1h;9 d=17.1u("1m:1a"),5A=d.1h;d.v=["m",T.15(x),", ",T.15(y-2),"l",T.15(x)+1,", ",T.15(y-2)].22("");d.5B=20;2y.11=a.11;2y.14=a.14;2G.2h="2i";2G.1H=0;2G.1z=0;2G.11=a.11;2G.14=a.14;9 o=17.1u("1m:3r");o.2c=b;o.24=20;o.2L=a.2L;o.2M=a.2M;c.1b(o);c.1b(d);g.1b(c);a.18.1b(g);9 e=1n z(o,g,a);e.2j=c;e.3r=d;e.19="1K";e.P.x=x;e.P.y=y;e.P.w=1;e.P.h=1;J e};9 G=I(a){9 b=17.1u("1m:1N"),2H=b.1h;2H.2h="2i";2H.1H=0;2H.1z=0;2H.11=a.11;2H.14=a.14;K(a.18){a.18.1b(b)}9 c=1n z(b,b,a);1l(9 f 1r a){K(f.38(0)!="4b"&&1k a[f]=="I"){c[f]=(I(f){J I(){9 e=a[f].2v(a,N);b.1b(e[0].1D);J e}})(f)}}c.19="1N";J c};r.3k=I(){9 d,11,14;K(1k N[0]=="2c"){d=17.4c(N[0]);11=N[1];14=N[2]}K(1k N[0]=="2r"){d=N[0];11=N[1];14=N[2]}K(1k N[0]=="4d"){d=1;x=N[0];y=N[1];11=N[2];14=N[3]}K(!d){4e 1n 4f("2K 4g 4h 4i.");}K(!17.4j["1m"]){17.4j.5C("1m","5D:5E-5F-5G:26");17.5H().5I("1m\\\\:*","5J:4k(#3s#2K)")}9 c=17.1u("5K"),r=C.18=17.1u("1m:1N"),28=c.1h,30=r.1h;C.11=11;C.14=14;11=11||"5L";14=14||"5M";28.5N="2f(0 "+11+" "+14+" 0)";28.2h="2i";30.11=11;30.14=14;r.2L=(11=="1f%"?11:13(11))+" "+(14=="1f%"?14:13(14));r.2M="0 0";9 b=17.1u("1m:2f"),31=b.1h;31.1H=31.1z=0;31.11=30.11;31.14=30.14;b.5O=b.5P="f";r.1b(b);c.1b(r);K(d==1){17.4l.1b(c);28.2h="2i";28.1H=x+"1A";28.1z=y+"1A";28.11=11;28.14=14;d={1h:{11:11,14:14}}}1j{28.11=d.1h.11=11;28.14=d.1h.14=14;K(d.1Q){d.3e(c,d.1Q)}1j{d.1b(c)}}1l(9 e 1r C){d[e]=C[e]}d.3w=I(){9 a=[];1l(9 i=0,1i=r.2X.1c;i<1i;i++){K(r.2X[i]!=b){a.1M(r.2X[i])}}1l(i=0,1i=a.1c;i<1i;i++){r.27(a[i])}};J d};C.2W=I(){C.18.1D.1D.27(C.18.1D)}}K(q=="2I"){2g.1p.2w=I(){J"3u("+7.m[0][0]+", "+7.m[1][0]+", "+7.m[0][1]+", "+7.m[1][1]+", "+7.m[2][0]+", "+7.m[2][1]+")"};9 t=I(j,k,l){9 m=17.1W(l.1R,"1a");m.U("1x","1P");K(j){1l(9 n 1r j){K(j.1I){v(m,j.1I,l)}1j{m.U(n,j[n])}}}K(l.18){l.18.1b(m)}9 p=1n z(m,l);1l(9 n 1r j){p.P[n]=j[n]}p.Q=20;p.1a=[];p.O={x:0,y:0,2o:0,2p:0};p.2z=I(){7.Q=20;J 7};p.36=I(){7.Q=2N;J 7};p.3G=I(){7[0].U("d","5Q 0");9 a=7.1a;7.1a=[];1l(9 i=0,1i=a.1c;i<1i;i++){K(a[i].19!="3l"){7[a[i].19+"3H"].2v(7,a[i].1O)}1j{7.2q()}}J 7};p.2b=I(x,y){9 d=7.Q?"M":"m";9 a=7.Q?l.1e:l.1w;9 b=7.Q?l.1g:l.1y;d+=a(13(x,10))+" "+b(13(y,10))+" ";9 c=7[0].2s("d")||"";7[0].U("d",c+d);7.O.x=(7.Q?0:7.O.x)+l.1e(13(x,10));7.O.y=(7.Q?0:7.O.y)+l.1g(13(y,10));7.1a.1M({19:"3I",1O:N,21:7.Q});J 7};p.1o=I(x,y){7.O.x=(7.Q?0:7.O.x)+l.1e(13(x,10));7.O.y=(7.Q?0:7.O.y)+l.1g(13(y,10));9 d=7.Q?"L":"l";9 a=7.Q?l.1e:l.1w;9 b=7.Q?l.1g:l.1y;d+=a(13(x,10))+" "+b(13(y,10))+" ";9 c=7[0].2s("d")||"";7[0].U("d",c+d);7.1a.1M({19:"3J",1O:N,21:7.Q});J 7};p.37=I(a,b,c,e,x,y){9 d=7.Q?"A":"a";9 f=7.Q?l.1e:l.1w;9 g=7.Q?l.1g:l.1y;d+=[l.1w(13(a,10)),l.1y(13(b,10)),0,c,e,f(13(x,10)),g(13(y,10))].22(" ");9 h=7[0].2s("d")||"";7[0].U("d",h+d);7.O.x=l.1e(13(x,10));7.O.y=l.1g(13(y,10));7.1a.1M({19:"3K",1O:N,21:7.Q});J 7};p.3L=I(a,b,c){K(!c){J 7.1o(a,b)}1j{9 p={};p.1e=7.Q?l.1e:l.1w;p.1g=7.Q?l.1g:l.1y;9 x=p.1e(T.15(13(a,10)*1f)/1f);9 y=p.1g(T.15(13(b,10)*1f)/1f);9 w=l.1w(T.15(13(c,10)*1f)/1f);9 d=7.Q?"C":"c";9 e=[7.O.x+w,7.O.y,x-w,y,x,y];1l(9 i=0,1i=e.1c;i<1i;i++){d+=e[i]+" "}7.O.x=(7.Q?0:7.O.x)+e[4];7.O.y=(7.Q?0:7.O.y)+e[5];7.O.2o=e[2];7.O.2p=e[3];9 f=7[0].2s("d")||"";7[0].U("d",f+d);7.1a.1M({19:"3M",1O:N,21:7.Q});J 7}};p.1q=I(){9 p={};p.1e=7.Q?l.1e:l.1w;p.1g=7.Q?l.1g:l.1y;K(N.1c==6){9 d=7.Q?"C":"c";1l(9 i=0,1i=N.1c;i<1i;i++){d+=p[(i%2==0)?"1e":"1g"](T.15(13(N[i],10)*1f)/1f)+" "}7.O.x=(7.Q?0:7.O.x)+p.1e((13(N[4],10)*1f)/1f);7.O.y=(7.Q?0:7.O.y)+p.1g((13(N[5],10)*1f)/1f);7.O.2o=p.1e((13(N[2],10)*1f)/1f);7.O.2p=p.1g((13(N[3],10)*1f)/1f)}1j{K(N.1c==4){9 d=7.Q?"S":"s";1l(9 i=0,1i=N.1c;i<1i;i++){d+=p[i%2==0?"1e":"1g"]((13(N[i],10)*1f)/1f)+" "}}7.O.x=(7.Q?0:7.O.x)+p.1e((13(N[2],10)*1f)/1f);7.O.y=(7.Q?0:7.O.y)+p.1g((13(N[3],10)*1f)/1f);7.O.2o=p.1e((13(N[0],10)*1f)/1f);7.O.2p=p.1g((13(N[1],10)*1f)/1f)}9 a=7[0].2s("d")||"";7[0].U("d",a+d);7.1a.1M({19:"3N",1O:N,21:7.Q});J 7};p.2B=I(r,a){9 R=.3O*r,23=7.Q,o=7;K(23){7.36();23=I(){o.2z()}}1j{23=I(){}}9 b={l:I(){J{u:I(){o.1q(-R,0,-r,-(r-R),-r,-r)},d:I(){o.1q(-R,0,-r,r-R,-r,r)}}},r:I(){J{u:I(){o.1q(R,0,r,-(r-R),r,-r)},d:I(){o.1q(R,0,r,r-R,r,r)}}},u:I(){J{r:I(){o.1q(0,-R,-(R-r),-r,r,-r)},l:I(){o.1q(0,-R,R-r,-r,-r,-r)}}},d:I(){J{r:I(){o.1q(0,R,-(R-r),r,r,r)},l:I(){o.1q(0,R,R-r,r,-r,r)}}}};b[a[0]]()[a[1]]();23();J o};p.2q=I(){9 a=7[0].2s("d")||"";7[0].U("d",a+"Z ");7.1a.1M({19:"3l"});J 7};K(1k k=="2c"){k=k.2d(/([3P])/39,",$1,").2d(/(\\d+\\.?\\d*)(\\s)(\\d)/39,"$1,$3");1a=k.3m(",");9 i=0,1i=1a.1c;p.2z();3n(i<1i){K(C.2Q[1a[i]]){i=C.2Q[1a[i]](p,1a,i)}i++}}J p};9 v=I(o,a,b){9 c=17.1W(b.1R,a.19+"5R");c.2Y="5S-1I-"+b.4m++;K(a.1U&&a.1U.1c){c.U("5T",a.1U[0]);c.U("2P",a.1U[1]);c.U("5U",a.1U[2]);c.U("5V",a.1U[3])}b.3f.1b(c);1l(9 i=0,1i=a.1t.1c;i<1i;i++){9 d=17.1W(b.1R,"3x");d.U("3b",a.1t[i].3b?a.1t[i].3b:(i==0)?"0%":"1f%");d.U("3x-25",a.1t[i].25||"#5W");K(1k a.1t[i].1B!="1s"){d.U("3x-1B",a.1t[i].1B)}c.1b(d)};o.U("1x","4k(#"+c.2Y+")")};9 z=I(c,d){9 X=0,Y=0,32={33:0,x:0,y:0},2t=1,2u=1,3v=5X;7[0]=c;7.1X=d;7.P=7.P||{};7.1S=[];7.3q=I(a){K(a==1s){J 32.33}9 b=7.2V();32.33+=a;K(32.33){7.1S[0]=("3q("+32.33+" "+(b.x+b.11/2)+" "+(b.y+b.14/2)+")")}1j{7.1S[0]=""}7[0].U("3g",7.1S.22(" "));J 7};7.3t=I(x,y){K(x==1s&&y==1s){J{x:X,y:Y}}X+=x;Y+=y;K(X&&Y){7.1S[1]="3t("+X+","+Y+")"}1j{7.1S[1]=""}7[0].U("3g",7.1S.22(" "));J 7};7.44=I(x,y){K(x==1s&&y==1s){J{x:2t,y:2u}}y=y||x;K(x!=0&&!(x==1&&y==1)){2t*=x;2u*=y;K(!(2t==1&&2u==1)){9 a=7.2V(),34=a.x*(1-2t)+(a.11/2-a.11*2t/2),4n=a.y*(1-2u)+(a.14/2-a.14*2u/2);7.1S[2]=1n 2g(2t,0,0,2u,34,4n)}1j{7.1S[2]=""}7[0].U("3g",7.1S.22(" "))}J 7}};z.1p.40=I(){7[0].1h.3c="1P";J 7};z.1p.41=I(){7[0].1h.3c="42";J 7};z.1p.3u=I(a,b,c,d,e,f){7.1S[3]=1n 2g(a,b,c,d,e,f);7[0].U("3g",7.1S.22(" "));J 7};z.1p.2W=I(){7[0].1D.27(7[0])};z.1p.2V=I(){J 7[0].2V()};z.1p.2F=I(){K(N.1c==1&&1k N[0]=="2c"){J 7[0].2s(N[0])}K(N.1c==1&&N[0]46 47){9 a={};1l(9 j 1r N[0]){a[N[0][j]]=7.P[N[0][j]]}J a}K(N.1c==2){9 b=N[0],1T=N[1];7[b]=1T;7.P[b]=1T;3Z(b){1F"2l":1F"1E":1F"x":7[0].U(b,7.1X.1e(1T));1V;1F"2m":1F"1J":1F"y":7[0].U(b,7.1X.1g(1T));1V;1F"11":7[0].U(b,7.1X.1w(1T));1V;1F"14":7[0].U(b,7.1X.1y(1T));1V;1F"1I":v(7[0],1T,7.1X);1V;1F"1d-2S":7[0].U(b,1T.2d(" ",","));1V;1F"1K":K(7.19=="1K"){7[0].27(7[0].1Q);7[0].1b(17.3y(1T))}1V;3s:9 c=b.2d(/(\\-.)/g,I(w){J w.2n(1).4o()});7[0].1h[c]=1T;7[0].U(b,1T);1V}}1j K(N.1c==1&&1k N[0]=="2r"){9 d=N[0];1l(9 e 1r d){7.P[e]=d[e];K(e=="1d-2S"){7[0].U(e,d[e].2d(" ",","))}1j K(e=="1K"&&7.19=="1K"){7[0].2X.1c&&7[0].27(7[0].1Q);7[0].1b(17.3y(d.1K))}1j{9 c=e.2d(/(\\-.)/g,I(w){J w.2n(1).4o()});7[0].1h[c]=d[e];7[0].U(e,d[e])}}K(d.1I){7.P.1I=d.1I;v(7[0],d.1I,7.1X)}}J 7};z.1p.48=I(){7[0].1D.1b(7[0]);J 7};z.1p.49=I(){K(7[0].1D.1Q!=7[0]){7[0].1D.3e(7[0],7[0].1D.1Q)}J 7};9 A=I(a,x,y,r){9 b=17.1W(a.1R,"2T");b.U("1E",a.1e(x));b.U("1J",a.1g(y));b.U("r",r);b.U("1x","1P");b.U("1d","#1C");K(a.18){a.18.1b(b)}9 c=1n z(b,a);c.P=c.P||{};c.P.1E=x;c.P.1J=y;c.P.r=r;c.P.1d="#1C";c.19="2T";J c};9 B=I(a,x,y,w,h,r){9 b=17.1W(a.1R,"2f");b.U("x",a.1e(x));b.U("y",a.1g(y));b.U("11",a.1w(w));b.U("14",a.1y(h));K(r){b.U("2l",r);b.U("2m",r)}b.U("1x","1P");b.U("1d","#1C");K(a.18){a.18.1b(b)}9 c=1n z(b,a);c.P=c.P||{};c.P.x=x;c.P.y=y;c.P.11=w;c.P.14=h;c.P.1d="#1C";K(r){c.P.2l=c.P.2m=r}c.19="2f";J c};9 D=I(a,x,y,b,c){9 d=17.1W(a.1R,"2U");d.U("1E",a.1e(x));d.U("1J",a.1g(y));d.U("2l",a.1w(b));d.U("2m",a.1y(c));d.U("1x","1P");d.U("1d","#1C");K(a.18){a.18.1b(d)}9 e=1n z(d,a);e.P=e.P||{};e.P.1E=x;e.P.1J=y;e.P.2l=b;e.P.2m=c;e.P.1d="#1C";e.19="2U";J e};9 E=I(a,b,x,y,w,h){9 c=17.1W(a.1R,"2E");c.U("x",a.1e(x));c.U("y",a.1g(y));c.U("11",a.1w(w));c.U("14",a.1y(h));c.5Y(a.3z,"5Z",b);K(a.18){a.18.1b(c)}9 d=1n z(c,a);d.P=d.P||{};d.P.x=x;d.P.y=y;d.P.11=w;d.P.14=h;d.19="2E";J d};9 F=I(a,x,y,b){9 c=17.1W(a.1R,"1K");c.U("x",x);c.U("y",y);c.U("1K-60","61");c.U("1x","#1C");K(b){c.1b(17.3y(b))}K(a.18){a.18.1b(c)}9 d=1n z(c,a);d.P=d.P||{};d.P.x=x;d.P.y=y;d.P.1x="#1C";d.19="1K";J d};9 G=I(a){9 b=17.1W(a.1R,"g");K(a.18){a.18.1b(b)}9 i=1n z(b,a);1l(9 f 1r a){K(f[0]!="4b"&&1k a[f]=="I"){i[f]=(I(f){J I(){9 e=a[f].2v(a,N);b.1b(e[0]);J e}})(f)}}i.19="1N";J i};r.3k=I(){K(1k N[0]=="2c"){9 a=17.4c(N[0]);9 b=N[1];9 c=N[2]}K(1k N[0]=="2r"){9 a=N[0];9 b=N[1];9 c=N[2]}K(1k N[0]=="4d"){9 a=1,x=N[0],y=N[1],b=N[2],c=N[3]}K(!a){4e 1n 4f("2I 4g 4h 4i.");}C.18=17.1W(C.1R,"1X");C.18.U("11",b||4p);C.11=b||4p;C.18.U("14",c||4q);C.14=c||4q;K(a==1){17.4l.1b(C.18);C.18.1h.2h="2i";C.18.1h.1H=x+"1A";C.18.1h.1z=y+"1A"}1j{K(a.1Q){a.3e(C.18,a.1Q)}1j{a.1b(C.18)}}a={18:C.18,3w:I(){3n(7.18.1Q){7.18.27(7.18.1Q)}7.3f=17.1W(C.1R,"3f");7.4m=0;7.18.1b(7.3f)}};1l(9 d 1r C){K(d!="62"){a[d]=C[d]}}a.3w();J a};C.2W=I(){C.18.1D.27(C.18)};C.1R="4r://4s.4t.4u/63/1X";C.3z="4r://4s.4t.4u/64/3z"}K(q=="2K"||q=="2I"){C.2T=I(x,y,r){J A(7,x,y,r)};C.2f=I(x,y,w,h,r){J B(7,x,y,w,h,r)};C.2U=I(x,y,a,b){J D(7,x,y,a,b)};C.1a=I(a,b){J t(a,b,7)};C.2E=I(a,x,y,w,h){J E(7,a,x,y,w,h)};C.1K=I(x,y,a){J F(7,x,y,a)};C.1N=I(){J G(7)};C.65=I(x,y,w,h,r){K(r&&1G(r,10)){J 7.1a({1d:"#1C"}).2b(x+r,y).1o(x+w-r,y).2B(r,"66").1o(x+w,y+h-r).2B(r,"67").1o(x+r,y+h).2B(r,"68").1o(x,y+r).2B(r,"69").2q()}J 7.1a({1d:"#1C"}).2b(x,y).1o(x+w,y).1o(x+w,y+h).1o(x,y+h).2q()};C.6a=I(x,y,w,h,a,b,c){c=c||"#1C";9 p=7.1a({1d:c,"1d-11":1}).2b(x,y).1o(x+w,y).1o(x+w,y+h).1o(x,y+h).1o(x,y);1l(9 i=1;i<b;i++){p.2b(x,y+i*T.15(h/b)).1o(x+w,y+i*T.15(h/b))}1l(9 i=1;i<a;i++){p.2b(x+i*T.15(w/a),y).1o(x+i*T.15(w/a),y+h)}J p};C.6b=I(a,b,c,d,w,h){9 e=(c-a)/w;9 f=(d-b)/h;7.1e=I(x){J a+x*e};7.1g=I(y){J b+y*f};7.1w=I(w){J w*e};7.1y=I(h){J h*f}};C.6c=I(){7.1e=7.1g=7.1w=7.1y=I(x){J x}};C.3A=I(){K(r.19=="2I"){9 a=C.2f(-C.11,-C.14,C.11*3,C.14*3).2F({1d:"1P"});4v(I(){a.2W()},0)}};z.1p.6d=I(x,y,d,e){6e(7.4w);K("1E"1r 7.P||"x"1r 7.P){9 f=("1E"1r 7.P),X=7.P.1E||7.P.x,Y=7.P.1J||7.P.y;K(x==X&&y==Y){J 7}9 g=y-Y,34=x-X,3h=g/34,4x=Y-3h*X,4y=T.3Y(7.3h);7.3B=7.6f*T.6g(4y);K(x<X){7.3B=-7.3B}9 h=1n 4z(),35=7;(I(){9 a=(1n 4z()).4A()-h.4A();K(a<d){9 b=X+a*34/d;9 c=b*3h+4x;35.2F(f?{1E:b,1J:c}:{x:b,y:c});35.4w=4v(N.3i,1);C.3A()}1j{35.2F(f?{1E:x,1J:y}:{x:x,y:y});C.3A();e&&e.2A(35)}})()}J 7};C.2Q={M:I(p,a,i){p.2b(a[++i]*1,a[++i]*1);J i},m:I(p,a,i){p.2b(p.O.x+a[++i]*1,p.O.y+a[++i]*1);J i},C:I(p,a,i){p.1q(a[++i]*1,a[++i]*1,a[++i]*1,a[++i]*1,a[++i]*1,a[++i]*1);J i},c:I(p,a,i){p.1q(p.O.x+a[++i]*1,p.O.y+a[++i]*1,p.O.x+a[++i]*1,p.O.y+a[++i]*1,p.O.x+a[++i]*1,p.O.y+a[++i]*1);J i},S:I(p,a,i){p.1q(a[++i]*1,a[++i]*1,a[++i]*1,a[++i]*1);J i},s:I(p,a,i){p.1q(p.O.x+a[++i]*1,p.O.y+a[++i]*1,p.O.x+a[++i]*1,p.O.y+a[++i]*1);J i},L:I(p,a,i){p.1o(a[++i]*1,a[++i]*1);J i},l:I(p,a,i){p.1o(p.O.x+a[++i]*1,p.O.y+a[++i]*1);J i},H:I(p,a,i){p.1o(a[++i]*1,p.O.y);J i},h:I(p,a,i){p.1o(p.O.x+a[++i]*1,p.O.y);J i},V:I(p,a,i){p.1o(p.O.x,a[++i]*1);J i},v:I(p,a,i){p.1o(p.O.x,p.O.y+a[++i]*1);J i},A:I(p,a,i){p.37(a[++i]*1,a[++i]*1,a[i+=2],a[++i]*1,a[++i]*1,a[++i]*1,a[++i]*1);J i},a:I(p,a,i){p.37(p.O.x+a[++i]*1,p.O.y+a[++i]*1,a[i+=2]*1,a[++i]*1,a[++i]*1,p.O.x+a[++i]*1,p.O.y+a[++i]*1);J i},z:I(p,a,i){p.2q();J i}};J r}1j{J I(){}}})((!(3C.4B&&3C.4B.6h==2))?"2K":"2I");1L.26=!(1L.1X=(1L.19=="2I"));K(1L.26&&3C.6i){1L.19="6j 6k";1L.26=1L.1X=2N}1L.2w=I(){J"6l 6m 6n "+7.19};1L.4C=I(a,c,d){K(1k a=="2r"&&"h"1r a&&"s"1r a&&"b"1r a){d=a.b;c=a.s;a=a.h}9 e,1Y,1Z;K(d==0){J{r:0,g:0,b:0,3D:"#1C"}}1j{9 i=T.6o(a*6),f=(a*6)-i,p=d*(1-c),q=d*(1-(c*f)),t=d*(1-(c*(1-f)));[I(){e=d;1Y=t;1Z=p},I(){e=q;1Y=d;1Z=p},I(){e=p;1Y=d;1Z=t},I(){e=p;1Y=q;1Z=d},I(){e=t;1Y=p;1Z=d},I(){e=d;1Y=p;1Z=q},I(){e=d;1Y=t;1Z=p},][i]()}9 h={r:e,g:1Y,b:1Z};e*=2J;1Y*=2J;1Z*=2J;9 r=T.15(e).2w(16);K(r.1c==1){r="0"+r}9 g=T.15(1Y).2w(16);K(g.1c==1){g="0"+g}9 b=T.15(1Z).2w(16);K(b.1c==1){b="0"+b}h.3D="#"+r+g+b;J h};1L.6p=I(a,b,c){K(1k a=="2r"&&"r"1r a&&"g"1r a&&"b"1r a){c=a.b;b=a.g;a=a.r}K(1k a=="2c"&&a.38(0)=="#"){K(a.1c==4){c=1G(a.2n(3),16);b=1G(a.2n(2,3),16);a=1G(a.2n(1,2),16)}1j{c=1G(a.2n(5),16);b=1G(a.2n(3,5),16);a=1G(a.2n(1,3),16)}}K(a>1||b>1||c>1){a/=2J;b/=2J;c/=2J}9 d=T.6q(a,b,c),2Z=T.2Z(a,b,c),2a,3E,4D=d;K(2Z==d){J{h:0,s:0,b:d}}1j{9 e=(d-2Z);3E=e/d;K(a==d){2a=(b-c)/e}1j K(b==d){2a=2+((c-a)/e)}1j{2a=4+((a-b)/e)}2a/=6;K(2a<0){2a+=1}K(2a>1){2a-=1}}J{h:2a,s:3E,b:4D}};1L.4E=I(a){9 b=N.3i.3j=N.3i.3j||{h:0,s:1,b:a||.6r};9 c=7.4C(b.h,b.s,b.b);b.h+=.6s;K(b.h>1){b.h=0;b.s-=.2;K(b.s<=0){N.3i.3j={h:0,s:1,b:b.b}}}J c.3D};1L.4E.6t=I(){7.3j=1s};',62,402,'|||||||this||var|||||||||||||||||||||||||||||||||||function|return|if|||arguments|last|attrs|isAbsolute|||Math|setAttribute|||||||width||parseFloat|height|round||document|canvas|type|path|appendChild|length|stroke|_getX|100|_getY|style|ii|else|typeof|for|rvml|new|lineTo|prototype|curveTo|in|undefined|dots|createElement|Group|_getW|fill|_getH|top|px|opacity|000|parentNode|cx|case|parseInt|left|gradient|cy|text|Raphael|push|group|arg|none|firstChild|svgns|transformations|value|vector|break|createElementNS|svg|green|blue|true|pos|join|rollback|on|color|vml|removeChild|cs||hue|moveTo|string|replace|font|rect|Matrix|position|absolute|shape|Path|rx|ry|substring|bx|by|andClose|object|getAttribute|ScaleX|ScaleY|apply|toString|gl|ol|absolutely|call|addRoundedCorner|setBox|os|image|attr|gs|els|SVG|255|VML|coordsize|coordorigin|false|slice|y1|pathfinder|getElementsByTagName|dasharray|circle|ellipse|getBBox|remove|childNodes|id|min|rs|bs|Rotation|deg|dx|that|relatively|arcTo|charAt|ig|weight|offset|display|diry|insertBefore|defs|transform|coeff|callee|start|_create|end|split|while|dashesn|toLowerCase|rotate|textpath|default|translate|matrix|tMatrix|clear|stop|createTextNode|xlink|safari|xs|window|hex|saturation|class|redraw|To|move|line|arc|cplineTo|cpline|curve|5522|mzlhvcsqta|family|size|linejoin|miter|miterlimit|linecap|square|str|atan|switch|hide|show|block|filter|scale|abs|instanceof|Array|toFront|toBack|oval|_|getElementById|number|throw|Error|container|not|found|namespaces|url|body|gradients|dy|toUpperCase|320|200|http|www|w3|org|setTimeout|animation_in_progress|plus|alpha|Date|getTime|SVGPreserveAspectRatio|hsb2rgb|brightness|getColor|version|9b|progid|DXImageTransform|Microsoft|M11|M12|M21|M22|Dx|Dy|sizingmethod|auto|expand|filtertype|bilinear|className|sqrt|wa|wr|at|ar|fontFamily|fontSize|fontWeight|joinstyle|endcap|butt||flat|isNaN|dashstyle|linear|gradientradial|opacity2|color2|colors|180|angle|90|radial|focusposition|focussize|method|RotX|RotY|Scale|rotation|offsetLeft|offsetTop|offsetWidth|offsetHeight|tagName|item|roundrect|arcsize|src|ps|textpathok|add|urn|schemas|microsoft|com|createStyleSheet|addRule|behavior|div|320px|200px|clip|filled|stroked|M0|Gradient|raphael|x1|x2|y2|fff|null|setAttributeNS|href|anchor|middle|create|2000|1999|linerect|rd|dl|lu|ur|drawGrid|setGrid|clearGrid|animateTo|clearTimeout|step|cos|SVG_PRESERVEASPECTRATIO_XMINYMIN|CanvasRenderingContext2D|Canvas|only|Your|browser|supports|floor|rgb2hsb|max|75|075|reset'.split('|'),0,{}))
;

/**** script/popup.js ****/
/**
 * Popup window control constructor.
 * 
 * This object is singletone but it can be used for several forms. To specify
 * form as backend to save data pass form as first parameter to show method.
 * 
 * @return {popupControl}
 * @requires raphael.js
 */
function popupControl() {
	if (!this.constructor.prototype.instance) {
		// wrapper for popup window
		this.popupWrapper = $("#overall_modal_wrapper")
		// popup window element, one for all popup calls
		this.popup = $("#overall_modal");
		// popup background element, one for all popup calls
		this.background = $("#overall_screen");
		// indicate display state
		this.visible = false;
		// init popup
		this.initPopup();
		this.isIE = jQuery.browser.msie;
		//svg settings
		this.svgSettings = {
			fill: "#bae0ed",
			height: {
				highways: 400,
				regions: 550,
				districts: 550
			},
			width: {				
				highways: 400,
				regions: 550,
				districts: 550
			}
		}
		// store instance in prototype
		this.constructor.prototype.instance = this;
	}
	// return instance
	return this.constructor.prototype.instance;
}

/**
 * Districts Map area select interaction
 * 
 * @param {jQuery} tabContainer for tab
 */
popupControl.prototype.initDistrictsAreaSelect = function(tabContainer) {
	// get districts tab if it is not one specified
	if (!tabContainer) {
		tabContainer = this.popup.find("#popup_okrug");
	}
	// multiple select box
	var list = tabContainer.children(".modal_container:first").children(".modal_param:first").find("select.modal_list:first");
	//form containing select box to be hidden right after info window is shown
	var selectBoxForm = tabContainer.children(".modal_container:first").children(".modal_param:first");
	
	// link to this object
	var control = this;
	
	// use class name as inited flag
	var flagInited = "area_inited";
	// init handlers
	if (!tabContainer.hasClass(flagInited)) {
		var title, modalMarker, mapContainer, isDraggable;
		// get needle elemets
		tabContainer.children().each(function() {
			// title to display selected items
			if ($(this).hasClass("modal_title")) title = $(this);
			// modal marker to stop overflowing
			else if ($(this).hasClass("modal_marker")) modalMarker = $(this);
			// image and map areas container
			else if ($(this).hasClass("modal_container")) {
				mapContainer = $(this).children(".modal_map:first");
				isDraggable = mapContainer.hasClass("draggable");
			}
		});
		// span with text "nothing selected"	
		var nothingSpan = title.children(".nothing:first");
		// "cursor" span used to detect title overflow 
		var cursorSpan = title.children(".cursor:first");
		
		// hash represents options liks with areas and images, keys are ids
		var entities = {}
		// select box options
		var options = list.find("option").each(function() {
			this.group = {option: this};
			entities[$(this).val()] = this.group;
		});

		//container dynamically created popups will be added to
		var infoWindowContainer = $('#infoWindowContainer');
		
		// get map area elements
		var moscowMapAreas = mapContainer.children("map:first").children().each(function(){
			var className = String($(this).attr("class"));
			var keyRegExp = new RegExp(/key_(\S+)(?:\s|$)/);
			var districtIDRegExp = new RegExp(/obj_(\S+)(?:\s|$)/);
			this.key = className.match(keyRegExp) ? className.match(keyRegExp)[1] : null;
			this.districtID = className.match(districtIDRegExp) ? className.match(districtIDRegExp)[1] : null;
			this.options = $('',list).children();
		})
		
		//click handler for moscow map area (district)
		function moscowMapAreaClickHandler(event) {
			var currentArea = this;
			if (currentArea.districtID && currentArea.key) {
				if (isWindowAlreadyCreated(currentArea.districtID)) {
					//hide select box form
					selectBoxForm.addClass("hidden");
					//synchronize selected options and info window and show the latter
					synchronizeInfoWindow(getInfoWindowByDistrictID(currentArea.districtID).show(), currentArea.districtID)
				} else {
					//getting the copy of already created template 
					//new info window will be based on
					var newInfoWindow = getInfoWindowTemplate($(currentArea));
					//display loading indicator while waiting for ajax response data
					//loadingIndicator.show();
					infoWindowContainer.append(newInfoWindow);
					initInfoWindowClickHandlers(newInfoWindow);
					$.ajax({
						url: '/popup/get-districts?okrug_id=' + currentArea.districtID,
						type: 'GET',
						dataType: 'json',
						error: function(XMLHttpRequest, textStatus, errorThrown) {
							newInfoWindow.remove();
						},
						success: function(objects) {
							//assigning unique key to new info window
							newInfoWindow.addClass("district_"+currentArea.districtID);
							//creatig map element
							var mapElement = $(document.createElement("map"));
							mapElement.attr("id", "map_districts_"+currentArea.districtID);
							mapElement.attr("name", "map_districts_"+currentArea.districtID);
							$.each(objects, function(index){
								//creating area element
								var areaElement = createAreaElement(this);
								mapElement.append(areaElement);
								//creating img element
								var imgElement = createImgElement(currentArea, this);
								newInfoWindow.children(".infoWindowWrapper").append(imgElement);
							})
							//creating district map image
							var districtMapImage = createDistrictMapImage(currentArea);
							//removing ajax loader picture
							newInfoWindow.removeClass('loading');
							//populating info window with content
							newInfoWindow.children(".infoWindowWrapper").prepend(districtMapImage).append(mapElement);
							//hide select box form
							selectBoxForm.addClass("hidden");
							//show info window
							newInfoWindow.show();
							//init additional event handlers responsible for selecting certain subdistrict
							initInfoWindowInteraction(newInfoWindow, currentArea.districtID);
							//synchronize selected options and info window 
							synchronizeInfoWindow(newInfoWindow, currentArea.districtID);

						}
					});
				}
			}
		}
		
		//binding click handler to moscowMapAreas
		moscowMapAreas.each(function(){
			$(this).click(moscowMapAreaClickHandler);
		})
		

		function isWindowAlreadyCreated(districtID) {
			return infoWindowContainer.children('.district_'+districtID).length;
		}
		
		function getInfoWindowByDistrictID(districtID) {
			return infoWindowContainer.children('.district_'+districtID);
		}

		function getInfoWindowTemplate(area) {
			var infoWindowTemplate = infoWindowContainer.children(".infoWindowTemplate").clone().removeClass('infoWindowTemplate');
			//setting the value of district name caption
			infoWindowTemplate.addClass("window_" + area[0].key);
			infoWindowTemplate.find('.currentSubdistrict').text(area.attr("alt"));
			return infoWindowTemplate;
		}
		
		function createAreaElement(object) {
			if (object) {
				var areaElement = $(document.createElement("area"));
				areaElement.attr("coords", object.coords);
				areaElement.attr("shape", "poly");
				areaElement.attr("alt", object.name);
				areaElement.attr("title", object.name);
				areaElement.attr("class", "obj_"+object.id);
				return areaElement;
			}
		}
		
		function createImgElement(area, object) {
			if (object) {
				var imgElement = $(document.createElement("img"));
				imgElement.attr("src","/img/maps/districts/" + area.key + "/" + object.key + ".png");
				imgElement.attr("class", "transparent subdistrict obj_" + object.id + " " + object.key);
				imgElement.attr("style", "display:none;");
				return imgElement;
			}
		}
		
		function createDistrictMapImage(district) {
			if (district.districtID && district.key) {
				var districtMapImage = $(document.createElement("img"));
				districtMapImage.attr("src", "/img/maps/districts/" + district.key + "/main.png");
				districtMapImage.attr("usemap", "#map_districts_"+district.districtID);
				districtMapImage.addClass("districtMap").addClass('transparent');
				return districtMapImage;
			}
		}
		
		function initInfoWindowClickHandlers(infoWindow) {
			
			//event handler for 'select all district' button
			$('.selectDistrict', infoWindow).toggle(
				function(){
					$('.subdistrict', infoWindow).show();
				},
				function() {
					$('.subdistrict', infoWindow).show();
				}
			)
			
			//event handler for close button or any other control intended for submitting selected subdistricts
			$('.ok', infoWindow).click(function(){
				var selectedSubdistricts = new Array();
				$('.subdistrict', infoWindow).each(function(){
					if ($(this).css('display') == 'block') {
						this.group.option.selected = true;
					} else {
						this.group.option.selected = false;
					}
				})
				infoWindow.hide();
				selectBoxForm.removeClass("hidden");
				list.change();
			})
			
			//event handler for cancel button
			$('.cancel', infoWindow).click(function(){
				infoWindow.hide();
				selectBoxForm.removeClass("hidden");
				//selectBoxForm.show();
			})
		}
		
		function synchronizeInfoWindow (infoWindow, districtID) {
			$('.subdistrict', infoWindow).hide();
			list.children('optgroup.obj_' + districtID).children().each(function(){
				$(this.group.img)[this.selected ? "show" : "hide"]();
			})		
		}
		
		function initInfoWindowInteraction(infoWindow, districtID) {
			var infoWindowOptions = list.children('optgroup.obj_' + districtID).children().each(function(){
				this.group = {
					option: this,
					infoWindow: infoWindow[0]
				}
				entities[$(this).val()] = this.group;
				
			});
			var infoWindowImages = infoWindow.find("img.subdistrict").each(function(){
				var id = $(this).attr("class").match(/obj_(\d+)/);
				if (id && entities[id[1]]) {
					entities[id[1]].img = this;
					this.group = entities[id[1]]; 
				}
			}).click(infoWindowAreaClickHandler)
			  .bind("mouseover", infoWindowAreaMouseEnterHandler)
			  .bind("mouseout", infoWindowAreaMouseLeaveHandler)
			var infoWindowAreas = infoWindow.find("map:first").children().each(function(){
				var id = $(this).attr("class").match(/obj_(\d+)/);
				if (id && entities[id[1]]) {
					entities[id[1]].area = this;
					this.group = entities[id[1]];
				}
			}).click(infoWindowAreaClickHandler)
			  .bind("mouseover", infoWindowAreaMouseEnterHandler)
			  .bind("mouseout", infoWindowAreaMouseLeaveHandler)
		}
		
		//click handler for info window areas (subdistricts)
		function infoWindowAreaClickHandler(event) {
			var infoWindow = $(this.group.infoWindow);
			//if the user clicked on selected subdistrict in order to unselect it
			//we should apply special algorithm for defining which are user cursor belongs to
			//since image has shape of rectangle but no polygon
			if (this.tagName.toLowerCase() == 'img') {
				var districtMapImageCoords = infoWindow.find('img.districtMap').offset();		
				//calculating mouse coords relative to district map
				var mouseX = event.pageX - districtMapImageCoords.left;
				var mouseY = event.pageY - districtMapImageCoords.top;
				//toggling the image of subdistrict the mouse coords are located inside of
				infoWindow.find('area').each(function(){
					var infoWindowAreaCoords = this.group.area.coords.split(",");
					if (control.isInsideOfPolygon(infoWindowAreaCoords, mouseX, mouseY)) {
						$(this.group.img).toggle();
					}
				})
			} else {
				$(this.group.img).toggle();
			}
		}
		
		//mouseocer handler for info window areas as well as for info window images
		function infoWindowAreaMouseEnterHandler (event) {
			var infoWindow = $(this.group.infoWindow);
			var areaNameField = infoWindow.find(".controlBlock .name");
			var subdistrictName = $(this.group.area).attr("alt");
			areaNameField.children("span:first").text(subdistrictName);
			areaNameField.show();
		}
		
		function infoWindowAreaMouseLeaveHandler (event) {
			var infoWindow = $(this.group.infoWindow);
			var areaNameField = infoWindow.find(".controlBlock .name");
			//var subdistrictName = $(this.group.area).attr("alt");
			//areaNameField.children("span:first").text(subdistrictName);
			areaNameField.hide();
		}
		
		// refresh title list on select list change
		list.bind("change", {
			options: options,
			title: title,
			nothingSpan : nothingSpan,
			cursorSpan: cursorSpan,
			tabContainer: tabContainer,
			list: list,
			control: control,
			modalMarker: modalMarker
		}, control.listChangeHandler)

		
}
	// set inited flag
	tabContainer.addClass(flagInited);
}

/**
 * Map area select interaction
 * 
 * @param {jQuery} tabContainer for tab
 */
popupControl.prototype.initAreaSelect = function(tabContainer) {
	// get current tab if no one specified
	if (!tabContainer) {
		tabContainer = this.popup.children(".modal_struct:visible:first");
	}
	// multiple select box
	var list = tabContainer.children(".modal_container:first").children(".modal_param:first").find("select.modal_list:first");
	
	// link to this object
	var control = this;
	
	// use class name as inited flag
	var flagInited = "area_inited";
	// init handlers
	if (!tabContainer.hasClass(flagInited)) {
		var title, modalMarker, mapContainer, isDraggable;
		// get needle elemets
		tabContainer.children().each(function() {
			// title to display selected items
			if ($(this).hasClass("modal_title")) title = $(this);
			// modal marker to stop overflowing
			else if ($(this).hasClass("modal_marker")) modalMarker = $(this);
			// image and map areas container
			else if ($(this).hasClass("modal_container")) {
				mapContainer = $(this).children(".modal_map:first");
				isDraggable = mapContainer.hasClass("draggable");
			}
		});
		// span with text "nothing selected"	
		var nothingSpan = title.children(".nothing:first");
		// "cursor" span used to detect title overflow 
		var cursorSpan = title.children(".cursor:first");
		
		// hash represents options liks with areas and images, keys are ids
		var entities = {}
		// select box options
		var options = list.find("option").each(function() {
			this.group = {option: this};
			entities[$(this).val()] = this.group;
		});
		// image elemets to show on select
		var mapImages = mapContainer.children("img").not(":first").each(function() {
			var id = String($(this).attr("class")).match(/obj_(\d+)/);
			if (id && entities[id[1]]) {
				entities[id[1]].img = this;
				this.group = entities[id[1]]; 
			}
		});
		// get map area elements
		var mapAreas = mapContainer.children("map:first").children().each(function() {
			var id = $(this).attr("class").match(/obj_(\d+)/);
			if (id && entities[id[1]]) {
				entities[id[1]].area = this;
				this.group = entities[id[1]];
			}
		});
		
		
		// area click event handler
		var areaClickHandler = function(event) {
			// change selected state
			var typeOfShape = mapAreas[1].group.area.shape;
			//  to avoid overlapping effect during map images click handlers
			//  we divide handlers for map images and for polyline map areas
			if ((this.tagName).toLowerCase() == "img" && typeOfShape == 'poly') { //for map images
				var mapImageCoords = mapContainer.children("img:first").offset();
				//calculating mouse coords relative to map
				var mouseX = event.pageX - mapImageCoords.left;
				var mouseY = event.pageY - mapImageCoords.top;
				//defining what area user clicked on and
				//and changing the state of corresponding option in listbox
				$(mapAreas).each(function(){ //for circle map images and map areas
					var mapAreaCoords = this.group.area.coords.split(",");
					if (control.isInsideOfPolygon(mapAreaCoords, mouseX, mouseY)) {
						this.group.option.selected = !this.group.option.selected;
					}					
				})				
			} else {
				this.group.option.selected = !this.group.option.selected;
			}
			// toggle area image state
			$(this).trigger("#toggle");
			// trigger list change
			list.change();
		}
		// area toggle event handler
		var areaToggleHandler = function() {
			// show or hide image
				$(this.group.img)[this.group.option.selected ? "show" : "hide"]();
		}
		// area mouse over event handler
		var areaMouseoverHandler = function() {
			mapContainer.css("cursor", "default");
		}
		// area mouse out event handler
		var areaMouseoutHandler = function() {
			mapContainer.css("cursor", "pointer");
			mapContainer.css("cursor", "hand");
		}
		
		// map areas and set handlers
		$(mapAreas).add(mapImages).each(function() {
			// select or deselect list option on map area click
			$(this).click(areaClickHandler).bind("#toggle", areaToggleHandler);
			// change cursor for draggable map
			if (isDraggable) {
				$(this).mouseover(areaMouseoverHandler).mouseout(areaMouseoutHandler);
			}
		});
		
		// refresh title list on select list change
		list.bind("change", {
			options: options,
			title: title,
			nothingSpan : nothingSpan,
			cursorSpan: cursorSpan,
			tabContainer: tabContainer,
			list: list,
			control: control,
			modalMarker: modalMarker
		}, control.listChangeHandler)
		
	}
	// set inited flag
	tabContainer.addClass(flagInited);
}

popupControl.prototype.initSVGPathSelect = function(tabContainer) {

	var control = this;
	var list = tabContainer.children(".modal_container:first").children(".modal_param:first").find("select.modal_list:first");
	
	// use class name as inited flag
	var flagInited = "area_inited";
	// init handlers
	if (!tabContainer.hasClass(flagInited)) {
		var title, modalMarker, mapContainer, isDraggable;
		// get needle elemets
		tabContainer.children().each(function() {
			// title to display selected items
			if ($(this).hasClass("modal_title")) title = $(this);
			// modal marker to stop overflowing
			else if ($(this).hasClass("modal_marker")) modalMarker = $(this);
			// image and map areas container
			else if ($(this).hasClass("modal_container")) {
				mapContainer = $(this).children(".modal_map:first");
				isDraggable = mapContainer.hasClass("draggable");
			}
		});
		// span with text "nothing selected"	
		var nothingSpan = title.children(".nothing:first");
		// "cursor" span used to detect title overflow 
		var cursorSpan = title.children(".cursor:first");
		
		// hash represents options liks with areas and images, keys are ids
		var entities = {}
		// select box options
		var options = list.find("option").each(function() {
			this.group = {option: this};
			entities[$(this).val()] = this.group;
		});
		
		
		// image elemets to show on select
		$.each(control.currentTabContent.svgPathes, function() {
			var id = this[0].id;
			var raphaelPath = this;
			if (entities[id] && id!="moscow") {
				entities[id].path = this[0];
				this[0].group = entities[id];
				this[0].selected = false;
				control.createTooltip(this[0]);
				this[0].style.cursor = control.isIE ? "hand" : "pointer";
				var defaultColor = raphaelPath.fillColor || "#bae0ed" ;
				$(this[0]).mouseover(function() {
					if (!this.selected) {
						raphaelPath.attr({fill: raphaelPath.hoverColor})
						control.currentTabContent.svgPaper.safari();
					}
				})
				.mouseout(function() {
					if (!this.selected) {
						raphaelPath.attr({fill: defaultColor})
					}
				})
				.click(function(){
					this.group.option.selected = !this.group.option.selected;
					this.selected = !this.selected;
					raphaelPath.attr({fill: raphaelPath.hoverColor})
					list.change();
				})
				.dblclick(function(){
					var newOptionGroupState = !(this.group.option.parentNode.selectedAll || false);
					$(this.group.option.parentNode).children().each(function(){
						this.selected = newOptionGroupState;
					})
					list.change();
					this.group.option.parentNode.selectedAll = newOptionGroupState;
					return false;
				})
				.bind('#toggle', function(){
					if (this.group.option.selected && !this.selected) {
						this.selected = true;
						raphaelPath.attr({fill: raphaelPath.hoverColor})
					} else if (!this.group.option.selected && this.selected) {
						$(this).trigger('#reset');
					}
				})
				.bind('#reset',function(){
					raphaelPath.attr({fill: defaultColor});
					this.selected = false;
				})
			}
		});
		
		list.bind("change", {
			options: options,
			title: title,
			nothingSpan : nothingSpan,
			cursorSpan: cursorSpan,
			tabContainer: tabContainer,
			list: list,
			control: control,
			modalMarker: modalMarker
		}, control.svgListChangeHandler)
		
	}
	// set inited flag
	tabContainer.addClass(flagInited);
}

/**
 * Create list item.
 * 
 * @param {String} text
 * @param {String} className
 * @param {Boolean} leadingComma
 * @return {Object}
 */
popupControl.prototype.createItemSpan = function(text, className, leadingComma, cursorSpan) {
	// create item span element
	var item = $("<span>" + text + " <a class='del'><img src='/img/popup/del.gif' width='12' height='12' /></a></span>");
	// add class name
	if (className) {
		item.addClass(className);
	}
	// insert item before cursor
	cursorSpan.before(item);
	// insert leading comma
	if (leadingComma) {
		item.comma = $("<span class='comma'>, </span>");
		item.before(item.comma);
	}
	return item;
}

popupControl.prototype.svgListChangeHandler = function(event) {

	
	//retreiveing variables from event object
	var title = event.data.title;
	var nothingSpan = event.data.nothingSpan;
	var cursorSpan = event.data.cursorSpan;
	var options = event.data.options;
	var tabContainer = event.data.tabContainer;
	var list = event.data.list;
	var control = event.data.control;
	var modalMarker = event.data.modalMarker;
	
	// get selected items
	var selected = options.each(function() {
		$(this.group.path).trigger("#toggle");
	}).filter(":selected");
	
	// get existing items
	var items = title.children("span[class*='option']");
	// get selected ids
	var selectedIds = [];
	selected.each(function() { selectedIds.push($(this).val()); });
	// remove dots
	title.children(".dots").each(function() {
		$(this).prev(".comma:first").remove();
		$(this).remove();
	});
	// remove unselected items
	var existingIds = [];
	items.each(function() {
		var id = String($(this).attr("class"));
		if (id) {
			// if item not in selected ids array, remove it
			if ($.inArray(id, selectedIds) < 0) {
				var comma = $(this).next(".comma:first");
				if (comma.length) {
					// remove trailing comma
					comma.remove();
				} else {
					// remove leading comma
					$(this).prev(".comma:first").remove();
				}
				$(this).remove();
			} else {
				existingIds.push(id);
			}
		}
	});
	// count selected items
	var count = selectedIds.length;
	if (count) {
		nothingSpan.hide();
		// items to hide behind "..."
		var overflowIds = [];
		// do insert leading comma
		var insertComma = !!existingIds.length
		// add new selected items
		selected.each(function(){
			// get item id
			var id =$(this).val();
			// skip existing items
			if ($.inArray(id, existingIds) > -1) {
				return;
			}
			
			// create item span element
			
			var item = control.createItemSpan($(this).text(), null, insertComma, cursorSpan);
			// get offsets
			var cursorOffset = cursorSpan.offset();
			var markerOffset = modalMarker.offset();
			// check cursor position
			if (cursorOffset && markerOffset &&
				// overflow on second line
				((cursorOffset.top > markerOffset.top && cursorOffset.left > markerOffset.left)
				// or jump to third line
				|| cursorOffset.top > markerOffset.top + modalMarker.height())
			) {
				if (item.comma) {
					item.comma.remove();
				}
				item.remove();
				overflowIds.push(id);
			} else {
				insertComma = true;
				// add class name to set id
				item.addClass("option_" + id);
				// set delete button click handler
				item.find("a:first").click(function(){
					var option = selected.filter("[value = " + id + "]:first");
					if (option) {
						option[0].selected = false;
						list.change();
					}
				});
			}
		});
		// create "..." item for overflow items
		if (overflowIds.length) {
			var item = control.createItemSpan("...", "dots", true, cursorSpan);
			item.find("a:first").click(function(){
				selected.each(function() {
					if ($.inArray(parseInt($(this).val()), overflowIds) > -1) {
						this.selected = false;
					}
				});
				list.change()
			});
		}
	} else {
		nothingSpan.show();
	}
	
	// set tab item caption
	$("#for_" + tabContainer.attr("id")).each(function() {
		$(this).text($(this).text().replace(
			/(\s*\(\d+\))?$/, 
			(count ? " (" + count + ")" : "")
		));
	});
}

popupControl.prototype.listChangeHandler = function(event) {
	
	//retreiveing variables from event object
	var title = event.data.title;
	var nothingSpan = event.data.nothingSpan;
	var cursorSpan = event.data.cursorSpan;
	var options = event.data.options;
	var tabContainer = event.data.tabContainer;
	var list = event.data.list;
	var control = event.data.control;
	var modalMarker = event.data.modalMarker;
	
	// get selected items
	var selected = options.each(function() {
		$(this.group.area).trigger("#toggle");
	}).filter(":selected");
	// get existing items
	var items = title.children("span[class*='option']");
	// get selected ids
	var selectedIds = [];
	selected.each(function() { selectedIds.push(parseInt($(this).val())); });
	// remove dots
	title.children(".dots").each(function() {
		$(this).prev(".comma:first").remove();
		$(this).remove();
	});
	// remove unselected items
	var existingIds = [];
	items.each(function() {
		var id = String($(this).attr("class")).match(/option_([1-9]\d*)/);
		if (id) {
			id = parseInt(id[1]);
			// if item not in selected ids array, remove it
			if ($.inArray(id, selectedIds) < 0) {
				var comma = $(this).next(".comma:first");
				if (comma.length) {
					// remove trailing comma
					comma.remove();
				} else {
					// remove leading comma
					$(this).prev(".comma:first").remove();
				}
				$(this).remove();
			} else {
				existingIds.push(id);
			}
		}
	});
	// count selected items
	var count = selectedIds.length;
	if (count) {
		nothingSpan.hide();
		// items to hide behind "..."
		var overflowIds = [];
		// do insert leading comma
		var insertComma = !!existingIds.length
		// add new selected items
		selected.each(function(){
			// get item id
			var id = parseInt($(this).val());
			// skip existing items
			if ($.inArray(id, existingIds) > -1) {
				return;
			}
			
			// create item span element
			
			var item = control.createItemSpan($(this).text(), null, insertComma, cursorSpan);
			// get offsets
			var cursorOffset = cursorSpan.offset();
			var markerOffset = modalMarker.offset();
			// check cursor position
			if (cursorOffset && markerOffset &&
				// overflow on second line
				((cursorOffset.top > markerOffset.top && cursorOffset.left > markerOffset.left)
				// or jump to third line
				|| cursorOffset.top > markerOffset.top + modalMarker.height())
			) {
				if (item.comma) {
					item.comma.remove();
				}
				item.remove();
				overflowIds.push(id);
			} else {
				insertComma = true;
				// add class name to set id
				item.addClass("option_" + id);
				// set delete button click handler
				item.find("a:first").click(function(){
					var option = selected.filter("[value = " + id + "]:first");
					if (option) {
						option[0].selected = false;
						list.change();
					}
				});
			}
		});
		// create "..." item for overflow items
		if (overflowIds.length) {
			var item = control.createItemSpan("...", "dots", true, cursorSpan);
			item.find("a:first").click(function(){
				selected.each(function() {
					if ($.inArray(parseInt($(this).val()), overflowIds) > -1) {
						this.selected = false;
					}
				});
				list.change()
			});
		}
	} else {
		nothingSpan.show();
	}
	
	// set tab item caption
	$("#for_" + tabContainer.attr("id")).each(function() {
		$(this).text($(this).text().replace(
			/(\s*\(\d+\))?$/, 
			(count ? " (" + count + ")" : "")
		));
	});

}

/**
 * Init draggable map.
 * Call this funciton only after tab content show.
 * 
 * @param {jQuery} mapContainer
 */
popupControl.prototype.initDraggable = function(tabContentContainer) {
	if (this.popup && tabContentContainer) {
		// map container
		var mapContainer = tabContentContainer.find(".modal_map:first");
		// use class name as inited flag
		var flagInited = "draggable_inited";
		// check for draggable and init handlers
		if (tabContentContainer.hasClass("draggable") && !mapContainer.hasClass(flagInited)) {
			// map image
			var map = mapContainer.children("img:first");
			// set map center
			mapContainer[0].scrollLeft = Math.abs(parseInt(mapContainer.width() / 2 - map.width() / 2));
			mapContainer[0].scrollTop = Math.abs(parseInt(mapContainer.height() / 2 - map.height() / 2));
			// observe drag event
			Drag.observe(mapContainer, function(e) {
				mapContainer[0].scrollLeft -= e.dx;
				mapContainer[0].scrollTop -= e.dy;
			});
			// set inited flag
			mapContainer.addClass(flagInited).addClass("draggable");
		}

	}
}

/**
 * Init tab content
 * 
 * @param {jQuery} tabContainer for tab
 */
popupControl.prototype.initTabOnShow = function(tabContentContainer) {
	if (this.popup && tabContentContainer) {
		var modalContainer = tabContentContainer.children(".modal_container:first");
		// init draggable
		this.initDraggable(tabContentContainer);
		// trigger list change event to reload selected items
		setTimeout(function(){ //timeout for decreasing delay of displaying popup window 
			modalContainer.children(".modal_param:first").find("select.modal_list:first").change();
		},100)		
	}
}

/**
 * Init popup tabs
 */
popupControl.prototype.initTabs = function() {
	if (this.popup) {
		var control = this;
		var tabPrefix = new RegExp("^for_");
		var tabPrefixForID = new RegExp("^for_popup_");
		// get all tab items
		this.tabs = this.popup.children("ul.modal_tabs:first").children();
		this.tabs.each(function(i){
			// tab item element
			var tabLink = $(this).children("a:first");
			// tab id
			this.tabID = String($(this).children('a:first').attr("id")).replace(tabPrefixForID, "");
			// tab content container
			var tabContent = $("#" + (String(tabLink.attr("id")).replace(tabPrefix, "")));
			// tab content wrapper
			var tabContentWrapper = tabContent.children('.modal_struct_wrapper');
			// adding additional DOM property for tab which will store corresponding tab content
			this.contentContainer = tabContent;
			this.contentWrapper = tabContentWrapper;
			// adding additional DOM properties for stoting info about width and height of tab content area
			var className = this.contentContainer[0].className;
			this.contentHeight = className.match(/height_(\d+px)/)[1];
			this.contentWidth = className.match(/width_(\d+px)/)[1];
			
			// map container
			var mapContainer = tabContent.children(".modal_container:first").children(".modal_map:first");
			
			// activate first tab
			if (i == 0) {
				tabContent.show();
				control.currentTabContent = tabContentWrapper;
				control.currentTab = $(this);
			} else {
				tabLink.addClass("inactive");
				tabContent.hide();
			}
			
			// tab item click handler
			$(this).click(function(){
				// if can activate and left button pressed
				if ($("a:first", this).hasClass("inactive")) {
					
					// deactivate siblings
					$(this).siblings().children("a").each(function(){
						// deactivate tab item
						$(this).addClass("inactive");
						// hide tab content
						$(this).parent()[0].contentContainer.hide();
					});
					
					// activate this tab
					tabLink.removeClass("inactive");
					
					control.currentTabContent = tabContentWrapper;
					control.currentTab = $(this);
					
					tabContent.show();
					control.popup.animate({width: this.contentWidth}, 500);
					tabContent.animate({height: this.contentHeight}, 500, function() {
						//load tab content if it hasnt been created before
						if (!control.isTabContentLoaded(tabContent)) {
							control.loadTabContent(control.currentTab, tabContentWrapper);
						} else {
							control.tabs.each(function(){
								if (this.tabID != control.currentTab[0].tabID) {
									this.contentContainer.css({
										height: control.currentTab[0].contentHeight
									})
								}
							})
						}

					})
					
					// resize popup window and background
					//control.resize();
				}
			});
		});
	}
}

popupControl.prototype.isTabContentLoaded = function(tabContentContainer) {
	return tabContentContainer.hasClass("loaded");
}

popupControl.prototype.loadMoscowOkrugs = function(tabContentContainer, tabID, tab) {
	var control = this;
	$.ajax({
		url: '/xml/moscow_okrugs_svg_10.xml',
		dataType: 'xml',
		success: function(data) {
			tabContentContainer.svgPaperWidth = control.svgSettings.width[tabID];
			tabContentContainer.svgPaperHeight = control.svgSettings.height[tabID];
			tabContentContainer.append(control.createSVGModalContainer(data, tabID));
			control.initSVGPathSelect(tabContentContainer);
			//init draggable
			control.initTabOnShow(tabContentContainer);
			//loading data
			control.loadData(control.currentTabContent);
			// submit form handling
			tabContentContainer.find("form.modal_form:first").submit(function(){
				control.saveData();
				return false;
			}).children("div").children("input").click(function(){
				control.hide();
			});
			tabContentContainer.parent().removeClass("popupLoading").addClass("loaded");
			tabContentContainer.addClass("loaded");
			control.tabs.each(function(){
				if (this.tabID != tabID) {
					this.contentContainer.css({
						height: tab[0].contentHeight
					})
				}
			})
		},
		error: function(XMLHttpRequest, textStatus, errorThrown) {
			debugger;
		}
	})
}



/**
 * dynamic loading of tab content via AJAX
 * @param {jQuery} tab
 */
popupControl.prototype.loadTabContent = function(tab, tabContentContainer) {
	var control = this;
	if (tab.length && !tabContentContainer.hasClass("loaded")) {
		var tabID = tab[0].tabID;
		control.popup.animate({width: tab[0].contentWidth}, 500);
		control.currentTab[0].contentContainer.animate({height: tab[0].contentHeight}, 500, function() {
			var url = '/popup/get-' + tabID;
			$.ajax({
				url: url,
				dataType: 'json',
				success: function(objects){
					if (tabContentContainer.hasClass('svg')) {
						tabContentContainer.svgPaperWidth = control.svgSettings.width[tabID];
						tabContentContainer.svgPaperHeight = control.svgSettings.height[tabID];
						tabContentContainer.append(control.createSVGModalContainer(objects, tabID));
						control.initSVGPathSelect(tabContentContainer);
					} else {
						tabContentContainer.append(control.createModalContainer(objects, tabID));
						// init area select routines
						if (tabContentContainer.parent()[0].id == 'popup_okrugs') {
							control.initDistrictsAreaSelect(tabContentContainer);
						} else {
							control.initAreaSelect(tabContentContainer);
						}
					}
					//init draggable
					control.initTabOnShow(tabContentContainer);
					//loading data
					control.loadData(control.currentTabContent);
					// submit form handling
					tabContentContainer.find("form.modal_form:first").submit(function(){
						control.saveData();
						return false;
					}).children("div").children("input").click(function(){
						control.hide();
						if ($.isFunction(control.onCancel)) {
							control.onCancel();
						}
					});
					tabContentContainer.parent().removeClass("popupLoading").addClass("loaded");
					tabContentContainer.addClass("loaded");
					control.tabs.each(function(){
						if (this.tabID != tabID) {
							this.contentContainer.css({
								height: tab[0].contentHeight
							})
						}
					})			
				}
			})
		})
	}
}


popupControl.prototype.createSVGModalContainer = function(data, tabID) {
	var SVGModalContainer = $('<div class="modal_container"></div>');
	if (tabID =='districts') {
		SVGModalContainer.append(this.createSVGPaperForDistricts(data))
	} else {
		SVGModalContainer.append(this.createSVGPaper(data))
	}
	SVGModalContainer.append(this.createModalParam(data, tabID));
	return SVGModalContainer;
}

popupControl.prototype.createSVGPaperForDistricts = function(data) {
	var control = this;
	var modalMap = $('<div class="modal_map"></div>');
	this.currentTabContent.svgPaper = new Raphael(modalMap[0], this.currentTabContent.svgPaperWidth, this.currentTabContent.svgPaperHeight);
	this.currentTabContent.svgPathes = {};
	
	$.each(data, function(i){
		var okrugID = i;
		var fillColor = "#"+this.okrug.color;
		var hoverColor = "#"+this.okrug.hover_color;
		$.each(this.districts, function(){
			control.currentTabContent.svgPathes[this.id] = control.currentTabContent.svgPaper.path({fill: fillColor}, this.coords);
			control.currentTabContent.svgPathes[this.id][0].tooltipText = this.name;
			control.currentTabContent.svgPathes[this.id][0].id = this.id;
			control.currentTabContent.svgPathes[this.id].hoverColor = hoverColor;
			control.currentTabContent.svgPathes[this.id].fillColor = fillColor;
		})
	})
	return modalMap;
}


popupControl.prototype.createSVGPaper = function(pathes) {
	var control = this;
	var modalMap = $('<div class="modal_map"></div>');
	this.currentTabContent.svgPaper = new Raphael(modalMap[0], this.currentTabContent.svgPaperWidth, this.currentTabContent.svgPaperHeight);
	this.currentTabContent.svgPathes = {};
	$.each(pathes, function() {
		if (this.id) {
			control.currentTabContent.svgPathes[this.id] = control.currentTabContent.svgPaper.path(control.svgSettings, this.coords);
			control.currentTabContent.svgPathes[this.id].hoverColor = this.label ? "#"+this.label : "#ACACAC";
			control.currentTabContent.svgPathes[this.id][0].id = this.id;
			control.currentTabContent.svgPathes[this.id][0].tooltipText = this.name;
		} else {
			control.currentTabContent.svgPaper.path(control.svgSettings, this.coords);
		}
	})
	
	return modalMap;
}



/**
 * dynamic creating of modal container content
 * 
 * @param  {JSON} hash containing objects required for creating modal container elements
 * @param  {String} tab ID
 * @return {jQuery} modal container containing map (image + areas) with select box
 * 
 */
popupControl.prototype.createModalContainer = function(objects, tabID) {
	
	var modalContainer = $('<div class="modal_container"></div>');
	modalContainer.append(this.createModalMap(objects, tabID))
				  .append(this.createModalParam(objects, tabID));
				  
	return modalContainer;
}

/**
 * dynamic creating of modal container map
 * 
 * @param  {JSON} hash containing objects required for creating modal container elements
 * @param  {String} tab ID
 * @return {jQuery} modal map (image + areas)
 * 
 */
popupControl.prototype.createModalMap = function(objects, tabID) {
	var control = this;
	
	//crrate modal map element
	var modalMap = $('<div class="modal_map"></div>');
	//create modal map image
	var modalMapImg = $(document.createElement("img"));
	modalMapImg.attr("src","/img/popup/maps/" + tabID + ".gif");
	modalMapImg.attr("useMap", "#map_"+tabID);
	//crete modal map areas
	var modalMapAreasContainer = $(document.createElement("map"));
	modalMapAreasContainer.attr("id","map_" + tabID);
	modalMapAreasContainer.attr("name","map_" + tabID);
	$.each(objects, function(){
		var areaElement = $(document.createElement("area"));
		areaElement.addClass("obj_" + this.id);
		if (this.key) areaElement.addClass("key_" + this.key);
		areaElement.attr("alt", this.name);
		areaElement.attr("title", this.name);
		areaElement.attr("shape", this.shapeType);
		areaElement.attr("nohref", "nohref");
		areaElement.attr("coords", this.coords);
		modalMapAreasContainer.append(areaElement);
	})
	//append modal map + modal map areas
	modalMap.append(modalMapImg).append(modalMapAreasContainer);
	
	if (tabID != 'okrugs') {
		$.each(objects, function(){
			var activeImg = $(document.createElement("img"));
			if (tabID == 'regions') {
				activeImg.attr("src","/img/popup/" + tabID + "/" + this.key + ".gif");
			} else if (tabID == 'metro') {
				activeImg.attr("src","/img/popup/metro/marker.gif");
			}
			activeImg.addClass("obj_" + this.id).addClass("pointer");
			activeImg.css({
				display: 'none',
				marginTop: -6,
				marginLeft: -6,
				top: this.y,
				left: this.x
			})
			modalMap.append(activeImg);
		})
	}
	
	return modalMap;
}

/**
 * dynamic creating of modal param container
 * 
 * @param  {JSON} hash containing objects required for creating modal container elements
 * @param  {String} tab ID
 * @return {jQuery} modal param container
 * 
 */
popupControl.prototype.createModalParam = function(objects, tabID){
	var control = this;
	
	//create select box container
	var modalParamContainer = $("<div class='modal_param'><div class='paramWrapper'><form class='modal_form'><div></div></form></div></div>");
	var selectBoxContainer = modalParamContainer.find('form > div');
	if (tabID == 'districts') {
		selectBoxContainer.append(control.createSelectBoxForDistricts(objects));
	} else {
		selectBoxContainer.append(control.createSelectBox(objects));
	}
	var cancelButton = $(document.createElement("input"))
						.addClass("button back")
						.attr("type", "button")
						.val(L('popup_back'));
	var submitButton = $(document.createElement("input"))
						.addClass("button done")
						.attr("type", "submit")
						.val(L('popup_done'));
						
	selectBoxContainer.append(submitButton).append(cancelButton);
	
	return modalParamContainer;
}


popupControl.prototype.createSelectBoxForHighways = function(pathes) {
	//create select box
	var selectBox = $(document.createElement("select"));
	selectBox.addClass("modal_list");
	selectBox.attr("multiple", "multiple");
	//populating select box with options
	pathes.each(function(){
		var newOption = $(document.createElement("option"));
		newOption.val($(this).attr('id'));
		newOption.text($(this).attr('name'));
		selectBox.append(newOption);
	})

	return selectBox;
}


/**
 * dynamic creating of select box for okrugs tab
 * 
 * @param  {JSON} hash containing objects required for creating modal container elements
 * @return {jQuery} select box
 * 
 */
popupControl.prototype.createSelectBoxForDistricts = function(objects){
	
	var selectBox = document.createElement("select");
	selectBox.className = "modal_list";
	selectBox.setAttribute("multiple", "multiple");
	
	$.each(objects, function(i){
		var okrugID = i;
		
		var optgroup = document.createElement("optgroup");
		optgroup.className = "obj_" + okrugID;
		optgroup.setAttribute("label", this.okrug.name);
		
		$.each(this.districts, function(){
			var newOption = document.createElement("option");
			newOption.value = this.id;
			$(newOption).text(this.name);
			optgroup.appendChild(newOption);
		})
		
		selectBox.appendChild(optgroup);
		
	})
	
	return $(selectBox);
}

/**
 * dynamic creating of select box for non-okrugs tab
 * 
 * @param  {JSON} hash containing objects required for creating modal container elements
 * @return {jQuery} select box
 * 
 */
popupControl.prototype.createSelectBox = function(objects){
	//create select box
	var selectBox = $(document.createElement("select"));
	selectBox.addClass("modal_list");
	selectBox.attr("multiple", "multiple");
	//populating select box with options
	$.each(objects, function(){
		var newOption = $(document.createElement("option"));
		newOption.val(this.id);
		newOption.text(this.name);
		selectBox.append(newOption);
	})
	
	return selectBox;
}

/**
 * Init popup
 */
popupControl.prototype.initPopup = function() {
	if (this.background && this.popup) {
		var control = this;
		// change popup state on browser window resize
		$(window).resize(function() {
			if (control.visible) control.resize();
		});
		this.initTabs();
	}
}

popupControl.prototype.dataContainerClassName = "data_container";

/**
 * Return data container for current backend form. If id specified return
 * data sub container.
 * 
 * @param {String} id
 * @return {jQuery}
 */
popupControl.prototype.getDataContainer = function(id) {
	// set parent to main container if id specified or to backend form otherwise
	var parent = id ? this.getDataContainer() : this.backend;
	if (parent) {
		// container class
		var cls = this.dataContainerClassName + (id ? "_" + id : "");
		// get data container
		var container = parent.children("." + cls + ":first");
		// create data container if no one exists
		if (!container.length) {
			container = $("<div class='" + cls + "'></div>");
			parent.append(container);
		}
		return container;
	} else {
		return null;
	}
}

/**
 * Load data from "backend" form hidden fields and select according options
 */
popupControl.prototype.loadData = function(currentTabContent) {
	if (this.popup && this.backend) {
		var control = this,
			tabContents;
		if (currentTabContent) {
			tabContents = currentTabContent;
		} else {
			tabContents = this.popup.children(".modal_struct").filter(function(){
				return $(this).hasClass("loaded")
			})
		}
		tabContents.each(function(){
			var tabContentID = currentTabContent ? this.parentNode.id : this.id;
			var id = tabContentID.replace(/^popup_/, "");
			var container = control.getDataContainer(id);
			var count = 0;
			// load data
			if (container) {
				// get stored data
				var data = new Array();
				container.children().each(function() { data.push($(this).val()); });
				count = data.length;
				// set options
				var modalParams = $(this).find(".modal_container:first").children(".modal_param:first");
				modalParams.find("option").each(function(){
					this.selected = $.inArray($(this).val(), data) >= 0;
				});
				modalParams.find('.modal_list').change();
			}
			// set tab item caption
			if (count) {
				$("#for_" + tabContentID).each(function(){
					$(this).text($(this).text().replace(
						/(\s*\(\d+\))?$/, 
						(count ? " (" + count + ")" : "")
					));
				});
			}
		})
	}
}

/**
 * Save data to "backend" form hidden fields from selected options
 */
popupControl.prototype.saveData = function() {
	if (this.popup && this.backend) {
		var control = this;
		var result = [];
		var structure = {};
		
		// save data for all tabs
		this.popup.children(".modal_struct").each(function() {
			// get data container
			var id = (this.id).match(/popup_(\S+)/, "")[1];
			var container = control.getDataContainer(id);
			if (container) {
				container.children().remove();
			}
			structure[id] = {};
			// save selected options
			$(this).find(".modal_container:first").find(".modal_param:first").find("option:selected").each(function(){
				if (container) {
					container.append("<input type='hidden' name='" + id + "[]' value='" + $(this).val() + "' />");
				}
				result.push($(this).text());
				structure[id][$(this).val()] = $(this).text();
			});
		});
		if ($.isFunction(this.onResult)) {
			this.onResult(result.join(', '), structure);
		}
	}
}

/**
 * Init backend form to save data
 * 
 * @param {jQuery} form
 */
popupControl.prototype.initBackend = function(form) {
	this.backend = form;
}

/**
 * Init on result event function
 * 
 * @param {Funciton} onResult
 */
popupControl.prototype.initOnResultCallback = function(onResult) {
	this.onResult = onResult;
}

/**
 * Init on cancel event function
 * 
 * @param {Funciton} onCancel
 */
popupControl.prototype.initOnCancelCallback = function(onCancel) {
	this.onCancel = onCancel;
}

/**
 * Resize and move popup window
 */
popupControl.prototype.resize = function() {
	
	// visible document width and height
	var docWidth  = $(window).width();
	var docHeight = $(window).height();
	// popup window width and height
	var winWidth  = $(this.popup).width();
	var winHeight = $(this.popup).height();
	// min offset
	var min = 10;
	// new left and top offsets
	var winOffsetLeft = docWidth  <= winWidth  + 2 * min ? min : Math.floor((docWidth  - winWidth)  / 2);
	var winOffsetTop  = docHeight <= winHeight + 2 * min ? min : Math.floor((docHeight - winHeight) / 2);
	if (winOffsetTop > 100) winOffsetTop = 100;
	// set new offsets for popup window
	//$(this.popup).css({left: winOffsetLeft + "px", top: winOffsetTop + "px"});
	// background height
	var clientHeight = $(document).height();
	$(this.background).height(winHeight + winOffsetTop < clientHeight ? clientHeight + "px" : "100%");
}

/**
 * Scroll page to the top
 */
popupControl.prototype.scrollTop = function() {
	window.scrollTo(0, 0);
}

/**
 * Show popup window.
 * 
 * @param {jQuery} form
 * @param {Function} onResult
 */
popupControl.prototype.show = function(form, onResult, onCancel) {
	if (this.background && this.popup && form) {
		var control = this;
		// show and resize popup window, scroll to top
		this.resize();
		this.background.show();
		this.popupWrapper.show();
		this.tabs.each(function(){
			this.contentContainer.css({
				height: control.currentTab[0].contentHeight
			})
			control.popup.css({
				width: control.currentTab[0].contentWidth
			})
		})
		this.popup.show();
		this.scrollTop();
		// set visible flags
		this.visible = true;
		// set backend form and load data
		this.initBackend(form);
		this.initOnResultCallback(onResult);
		this.initOnCancelCallback(onCancel);
		this.loadTabContent(this.currentTab, this.currentTabContent);
		this.loadData();
		// set escape close handler
		$(document).bind("keydown", {control: this}, function(e) {
			if (e.keyCode == 27) e.data.control.hide();
		});
	}
}

/**
 * Hide popup window
 */
popupControl.prototype.hide = function() {
	if (this.background && this.popup) {
		this.popup.hide();
		this.popupWrapper.hide();
		this.background.hide();
		this.visible = false;
		// remove key down handler
		$(document).unbind("keydown");
	}
}

popupControl.prototype.createTooltip = function(objects) {
	var control = this;
	var tooltipClassName = 'popupTooltip';
	$(objects).each(function(){
		var i = Math.floor(Math.random()*1000000);
		$("body").append("<div class='"+tooltipClassName+"' id='"+tooltipClassName+i+"'><p>"+this.tooltipText+"</p></div>");
		var tooltip = $("#"+tooltipClassName+i);
		$(this).mouseover(function(){
			tooltip.show();
		}).mousemove(function(e){
			tooltip.css({left:e.pageX + 15, top:e.pageY-15});
		}).mouseout(function(){
			tooltip.fadeOut(150);
			tooltip.hide();
		});
		//if (jQuery.browser.msie) {
		if (false) {
			$(this).mousemove(function(e){
				tooltip.css({left:e.pageX - 125, top:e.pageY-15})
			});
		} else {
			$(this).mousemove(function(e){
				tooltip.css({left:e.pageX + 15, top:e.pageY-15})
			});
		}	
	})
}


/**
 * returns true if the point is inside of polygon.
 * 
 * @param {Array} poly - array representing the coords of map area (x1,y1,x2,y2...)
 * @param {Number} px  - mouse X coordinate
 * @param {Number} py  - mouse Y coordinate
 * @return {Boolean}   - boolean flag indicating if the point which coords were passed belongs to polygon or not	
 */
popupControl.prototype.isInsideOfPolygon = function(poly,px,py) {
	 var numberOfPoints = poly.length; // number of points in polygon
     var xnew,ynew,xold,yold,x1,y1,x2,y2,i;
     var isInside=false;

     if (numberOfPoints/2 < 3) { // points don't describe a polygon
          return false;
     }
     xold=poly[numberOfPoints-2];
     yold=poly[numberOfPoints-1];
     
     for (i=0 ; i < numberOfPoints ; i=i+2) {
          xnew=poly[i];
          ynew=poly[i+1];
          if (xnew > xold) {
               x1=xold;
               x2=xnew;
               y1=yold;
               y2=ynew;
          }
          else {
               x1=xnew;
               x2=xold;
               y1=ynew;
               y2=yold;
          }
          if ((xnew < px) == (px <= xold) && ((py-y1)*(x2-x1) < (y2-y1)*(px-x1))) {
               isInside=!isInside;
          }
          xold=xnew;
          yold=ynew;
     }
     return isInside;
}

;

/**** script/jquery.ui.min.js ****/
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}(';(u($){$.z={19:{1r:u(a,b,c){A d=$.z[a].2V;2J(A i 56 c){d.2K[i]=d.2K[i]||[];d.2K[i].4d([b,c[i]])}},15:u(a,b,c){A d=a.2K[b];6(!d){H}2J(A i=0;i<d.1i;i++){6(a.B[d[i][0]]){d[i][1].1z(a.D,c)}}}},3G:{},C:u(a){6($.z.3G[a]){H $.z.3G[a]}A b=$(\'<1S 4e="z-7m">\').1e(a).C({J:\'16\',q:\'-6j\',8:\'-6j\',3j:\'4f\'}).2g(\'1A\');$.z.3G[a]=!!((!(/2r|6k/).Q(b.C(\'17\'))||(/^[1-9]/).Q(b.C(\'G\'))||(/^[1-9]/).Q(b.C(\'F\'))||!(/2W/).Q(b.C(\'7n\'))||!(/4g|7o\\(0, 0, 0, 0\\)/).Q(b.C(\'7p\'))));7q{$(\'1A\').24(0).57(b.24(0))}7r(e){}H $.z.3G[a]},3k:u(a){$(a).3l(\'3H\',\'6l\').C(\'6m\',\'2W\')},7s:u(a){$(a).3l(\'3H\',\'7t\').C(\'6m\',\'\')},3I:u(e,a){A b=/q/.Q(a||"q")?\'1s\':\'1t\',58=N;6(e[b]>0)H T;e[b]=1;58=e[b]>0?T:N;e[b]=0;H 58}};A j=$.3J.1T;$.3J.1T=u(){$("*",4).1r(4).2h("1T");H j.1z(4,2X)};u 4h(a,b,c){A d=$[a][b].4h||[];d=(2L d=="4i"?d.4j(/,?\\s+/):d);H($.7u(c,d)!=-1)}$.2s=u(g,h){A i=g.4j(".")[0];g=g.4j(".")[1];$.3J[g]=u(b){A c=(2L b==\'4i\'),59=7v.2V.7w.15(2X,1);6(c&&4h(i,g,b)){A d=$.V(4[0],g);H(d?d[b].1z(d,59):1u)}H 4.1b(u(){A a=$.V(4,g);6(c&&a&&$.6n(a[b])){a[b].1z(a,59)}1d 6(!c){$.V(4,g,6o $[i][g](4,b))}})};$[i][g]=u(c,d){A f=4;4.2M=g;4.6p=i+\'-\'+g;4.B=$.1f({},$.2s.2N,$[i][g].2N,d);4.D=$(c).2i(\'2Y.\'+g,u(e,a,b){H f.2Y(a,b)}).2i(\'5a.\'+g,u(e,a){H f.5a(a)}).2i(\'1T\',u(){H f.3m()});4.3n()};$[i][g].2V=$.1f({},$.2s.2V,h)};$.2s.2V={3n:u(){},3m:u(){4.D.3o(4.2M)},5a:u(a){H 4.B[a]},2Y:u(a,b){4.B[a]=b;6(a==\'1n\'){4.D[b?\'1e\':\'26\'](4.6p+\'-1n\')}},7x:u(){4.2Y(\'1n\',N)},7y:u(){4.2Y(\'1n\',T)}};$.2s.2N={1n:N};$.z.27={4k:u(){A a=4;4.D.2i(\'5b.\'+4.2M,u(e){H a.5c(e)});6($.1J.2Z){4.6q=4.D.3l(\'3H\');4.D.3l(\'3H\',\'6l\')}4.7z=N},4l:u(){4.D.30(\'.\'+4.2M);($.1J.2Z&&4.D.3l(\'3H\',4.6q))},5c:u(e){(4.2B&&4.3K(e));4.4m=e;A a=4,6r=(e.7A==1),6s=(2L 4.B.3L=="4i"?$(e.31).4n().1r(e.31).7B(4.B.3L).1i:N);6(!6r||6s||!4.4o(e)){H T}4.4p=!4.B.3M;6(!4.4p){4.7C=7D(u(){a.4p=T},4.B.3M)}6(4.5d(e)&&4.5e(e)){4.2B=(4.32(e)!==N);6(!4.2B){e.5f();H T}}4.5g=u(e){H a.6t(e)};4.5h=u(e){H a.3K(e)};$(P).2i(\'6u.\'+4.2M,4.5g).2i(\'6v.\'+4.2M,4.5h);H N},6t:u(e){6($.1J.2Z&&!e.5i){H 4.3K(e)}6(4.2B){4.2O(e);H N}6(4.5d(e)&&4.5e(e)){4.2B=(4.32(4.4m,e)!==N);(4.2B?4.2O(e):4.3K(e))}H!4.2B},3K:u(e){$(P).30(\'6u.\'+4.2M,4.5g).30(\'6v.\'+4.2M,4.5h);6(4.2B){4.2B=N;4.33(e)}H N},5d:u(e){H(11.1B(11.28(4.4m.1K-e.1K),11.28(4.4m.1L-e.1L))>=4.B.3p)},5e:u(e){H 4.4p},32:u(e){},2O:u(e){},33:u(e){},4o:u(e){H T}};$.z.27.2N={3L:X,3p:1,3M:0}})(3N);(u($){$.2s("z.12",$.1f({},$.z.27,{3n:u(){A o=4.B;6(o.K==\'5j\'&&!(/(Y|16|2t)/).Q(4.D.C(\'J\')))4.D.C(\'J\',\'Y\');4.D.1e(\'z-12\');(o.1n&&4.D.1e(\'z-12-1n\'));4.4k()},32:u(e){A o=4.B;6(4.K||o.1n||$(e.31).3O(\'.z-L-O\'))H N;A a=!4.B.O||!$(4.B.O,4.D).1i?T:N;$(4.B.O,4.D).5k("*").7E().1b(u(){6(4==e.31)a=T});6(!a)H N;6($.z.1j)$.z.1j.34=4;4.K=$.6n(o.K)?$(o.K.1z(4.D[0],[e])):(o.K==\'3P\'?4.D.3P():4.D);6(!4.K.4n(\'1A\').1i)4.K.2g((o.2g==\'Z\'?4.D[0].35:o.2g));6(4.K[0]!=4.D[0]&&!(/(2t|16)/).Q(4.K.C("J")))4.K.C("J","16");4.1U={8:(M(4.D.C("4q"),10)||0),q:(M(4.D.C("4r"),10)||0)};4.1M=4.K.C("J");4.I=4.D.I();4.I={q:4.I.q-4.1U.q,8:4.I.8-4.1U.8};4.I.1g={8:e.1K-4.I.8,q:e.1L-4.I.q};4.1C=4.K.1C();A b=4.1C.I();6(4.1C[0]==P.1A&&$.1J.7F)b={q:0,8:0};4.I.Z={q:b.q+(M(4.1C.C("4s"),10)||0),8:b.8+(M(4.1C.C("4t"),10)||0)};A p=4.D.J();4.I.Y=4.1M=="Y"?{q:p.q-(M(4.K.C("q"),10)||0)+4.1C[0].1s,8:p.8-(M(4.K.C("8"),10)||0)+4.1C[0].1t}:{q:0,8:0};4.1o=4.5l(e);4.1k={F:4.K.1V(),G:4.K.1W()};6(o.2C){6(o.2C.8!=1u)4.I.1g.8=o.2C.8+4.1U.8;6(o.2C.2u!=1u)4.I.1g.8=4.1k.F-o.2C.2u+4.1U.8;6(o.2C.q!=1u)4.I.1g.q=o.2C.q+4.1U.q;6(o.2C.2v!=1u)4.I.1g.q=4.1k.G-o.2C.2v+4.1U.q}6(o.W){6(o.W==\'Z\')o.W=4.K[0].35;6(o.W==\'P\'||o.W==\'3q\')4.W=[0-4.I.Y.8-4.I.Z.8,0-4.I.Y.q-4.I.Z.q,$(o.W==\'P\'?P:3q).F()-4.I.Y.8-4.I.Z.8-4.1k.F-4.1U.8-(M(4.D.C("3Q"),10)||0),($(o.W==\'P\'?P:3q).G()||P.1A.35.4u)-4.I.Y.q-4.I.Z.q-4.1k.G-4.1U.q-(M(4.D.C("3R"),10)||0)];6(!(/^(P|3q|Z)$/).Q(o.W)){A c=$(o.W)[0];A d=$(o.W).I();4.W=[d.8+(M($(c).C("4t"),10)||0)-4.I.Y.8-4.I.Z.8,d.q+(M($(c).C("4s"),10)||0)-4.I.Y.q-4.I.Z.q,d.8+11.1B(c.6w,c.36)-(M($(c).C("4t"),10)||0)-4.I.Y.8-4.I.Z.8-4.1k.F-4.1U.8-(M(4.D.C("3Q"),10)||0),d.q+11.1B(c.4u,c.3a)-(M($(c).C("4s"),10)||0)-4.I.Y.q-4.I.Z.q-4.1k.G-4.1U.q-(M(4.D.C("3R"),10)||0)]}}4.1c("1p",e);4.1k={F:4.K.1V(),G:4.K.1W()};6($.z.1j&&!o.6x)$.z.1j.5m(4,e);4.K.1e("z-12-5n");4.2O(e);H T},2j:u(d,a){6(!a)a=4.J;A b=d=="16"?1:-1;H{q:(a.q+4.I.Y.q*b+4.I.Z.q*b-(4.1M=="2t"||(4.1M=="16"&&4.1C[0]==P.1A)?0:4.1C[0].1s)*b+(4.1M=="2t"?$(P).1s():0)*b+4.1U.q*b),8:(a.8+4.I.Y.8*b+4.I.Z.8*b-(4.1M=="2t"||(4.1M=="16"&&4.1C[0]==P.1A)?0:4.1C[0].1t)*b+(4.1M=="2t"?$(P).1t():0)*b+4.1U.8*b)}},5l:u(e){A o=4.B;A a={q:(e.1L-4.I.1g.q-4.I.Y.q-4.I.Z.q+(4.1M=="2t"||(4.1M=="16"&&4.1C[0]==P.1A)?0:4.1C[0].1s)-(4.1M=="2t"?$(P).1s():0)),8:(e.1K-4.I.1g.8-4.I.Y.8-4.I.Z.8+(4.1M=="2t"||(4.1M=="16"&&4.1C[0]==P.1A)?0:4.1C[0].1t)-(4.1M=="2t"?$(P).1t():0))};6(!4.1o)H a;6(4.W){6(a.8<4.W[0])a.8=4.W[0];6(a.q<4.W[1])a.q=4.W[1];6(a.8>4.W[2])a.8=4.W[2];6(a.q>4.W[3])a.q=4.W[3]}6(o.1q){A b=4.1o.q+11.1G((a.q-4.1o.q)/o.1q[1])*o.1q[1];a.q=4.W?(!(b<4.W[1]||b>4.W[3])?b:(!(b<4.W[1])?b-o.1q[1]:b+o.1q[1])):b;A c=4.1o.8+11.1G((a.8-4.1o.8)/o.1q[0])*o.1q[0];a.8=4.W?(!(c<4.W[0]||c>4.W[2])?c:(!(c<4.W[0])?c-o.1q[0]:c+o.1q[0])):c}H a},2O:u(e){4.J=4.5l(e);4.1N=4.2j("16");4.J=4.1c("29",e)||4.J;6(!4.B.13||4.B.13!="y")4.K[0].2a.8=4.J.8+\'2b\';6(!4.B.13||4.B.13!="x")4.K[0].2a.q=4.J.q+\'2b\';6($.z.1j)$.z.1j.29(4,e);H N},33:u(e){A a=N;6($.z.1j&&!4.B.6x)A a=$.z.1j.2D(4,e);6((4.B.3b=="7G"&&!a)||(4.B.3b=="7H"&&a)||4.B.3b===T){A b=4;$(4.K).1v(4.1o,M(4.B.3b,10)||7I,u(){b.1c("1w",e);b.5o()})}1d{4.1c("1w",e);4.5o()}H N},5o:u(){4.K.26("z-12-5n");6(4.B.K!=\'5j\'&&!4.3S)4.K.1T();4.K=X;4.3S=N},2K:{},5p:u(e){H{K:4.K,J:4.J,4v:4.1N,B:4.B}},1c:u(n,e){$.z.19.15(4,n,[e,4.5p()]);6(n=="29")4.1N=4.2j("16");H 4.D.2h(n=="29"?n:"29"+n,[e,4.5p()],4.B[n])},3m:u(){6(!4.D.V(\'12\'))H;4.D.3o("12").30(".12").26(\'z-12\');4.4l()}}));$.1f($.z.12,{2N:{2g:"Z",13:N,3L:":4w",3M:0,3p:1,K:"5j"}});$.z.19.1r("12","17",{1p:u(e,a){A t=$(\'1A\');6(t.C("17"))a.B.5q=t.C("17");t.C("17",a.B.17)},1w:u(e,a){6(a.B.5q)$(\'1A\').C("17",a.B.5q)}});$.z.19.1r("12","1y",{1p:u(e,a){A t=$(a.K);6(t.C("1y"))a.B.5r=t.C("1y");t.C(\'1y\',a.B.1y)},1w:u(e,a){6(a.B.5r)$(a.K).C(\'1y\',a.B.5r)}});$.z.19.1r("12","2E",{1p:u(e,a){A t=$(a.K);6(t.C("2E"))a.B.5s=t.C("2E");t.C(\'2E\',a.B.2E)},1w:u(e,a){6(a.B.5s)$(a.K).C(\'2E\',a.B.5s)}});$.z.19.1r("12","4x",{1p:u(e,a){$(a.B.4x===T?"7J":a.B.4x).1b(u(){$(\'<1S 4e="z-12-4x" 2a="5t: #7K;"></1S>\').C({F:4.36+"2b",G:4.3a+"2b",J:"16",2E:"0.7L",1y:6y}).C($(4).I()).2g("1A")})},1w:u(e,a){$("1S.7M").1b(u(){4.35.57(4)})}});$.z.19.1r("12","3T",{1p:u(e,b){A o=b.B;A i=$(4).V("12");o.2w=o.2w||20;o.2x=o.2x||20;i.2k=u(a){6z{6(/2r|3T/.Q(a.C(\'3c\'))||(/2r|3T/).Q(a.C(\'3c-y\')))H a;a=a.Z()}6A(a[0].35);H $(P)}(4);i.2l=u(a){6z{6(/2r|3T/.Q(a.C(\'3c\'))||(/2r|3T/).Q(a.C(\'3c-x\')))H a;a=a.Z()}6A(a[0].35);H $(P)}(4);6(i.2k[0]!=P&&i.2k[0].4y!=\'4z\')i.5u=i.2k.I();6(i.2l[0]!=P&&i.2l[0].4y!=\'4z\')i.5v=i.2l.I()},29:u(e,a){A o=a.B;A i=$(4).V("12");6(i.2k[0]!=P&&i.2k[0].4y!=\'4z\'){6((i.5u.q+i.2k[0].3a)-e.1L<o.2w)i.2k[0].1s=i.2k[0].1s+o.2x;6(e.1L-i.5u.q<o.2w)i.2k[0].1s=i.2k[0].1s-o.2x}1d{6(e.1L-$(P).1s()<o.2w)$(P).1s($(P).1s()-o.2x);6($(3q).G()-(e.1L-$(P).1s())<o.2w)$(P).1s($(P).1s()+o.2x)}6(i.2l[0]!=P&&i.2l[0].4y!=\'4z\'){6((i.5v.8+i.2l[0].36)-e.1K<o.2w)i.2l[0].1t=i.2l[0].1t+o.2x;6(e.1K-i.5v.8<o.2w)i.2l[0].1t=i.2l[0].1t-o.2x}1d{6(e.1K-$(P).1t()<o.2w)$(P).1t($(P).1t()-o.2x);6($(3q).F()-(e.1K-$(P).1t())<o.2w)$(P).1t($(P).1t()+o.2x)}}});$.z.19.1r("12","5w",{1p:u(e,c){A d=$(4).V("12");d.3d=[];$(c.B.5w===T?\'.z-12\':c.B.5w).1b(u(){A a=$(4);A b=a.I();6(4!=d.D[0])d.3d.4d({6B:4,F:a.1V(),G:a.1W(),q:b.q,8:b.8})})},29:u(e,a){A c=$(4).V("12");A d=a.B.7N||20;A f=a.4v.8,1X=f+c.1k.F,1H=a.4v.q,1Y=1H+c.1k.G;2J(A i=c.3d.1i-1;i>=0;i--){A l=c.3d[i].8,r=l+c.3d[i].F,t=c.3d[i].q,b=t+c.3d[i].G;6(!((l-d<f&&f<r+d&&t-d<1H&&1H<b+d)||(l-d<f&&f<r+d&&t-d<1Y&&1Y<b+d)||(l-d<1X&&1X<r+d&&t-d<1H&&1H<b+d)||(l-d<1X&&1X<r+d&&t-d<1Y&&1Y<b+d)))4A;6(a.B.6C!=\'7O\'){A g=11.28(t-1Y)<=20;A h=11.28(b-1H)<=20;A j=11.28(l-1X)<=20;A k=11.28(r-f)<=20;6(g)a.J.q=c.2j("Y",{q:t-c.1k.G,8:0}).q;6(h)a.J.q=c.2j("Y",{q:b,8:0}).q;6(j)a.J.8=c.2j("Y",{q:0,8:l-c.1k.F}).8;6(k)a.J.8=c.2j("Y",{q:0,8:r}).8}6(a.B.6C!=\'7P\'){A g=11.28(t-1H)<=20;A h=11.28(b-1Y)<=20;A j=11.28(l-f)<=20;A k=11.28(r-1X)<=20;6(g)a.J.q=c.2j("Y",{q:t,8:0}).q;6(h)a.J.q=c.2j("Y",{q:b-c.1k.G,8:0}).q;6(j)a.J.8=c.2j("Y",{q:0,8:l}).8;6(k)a.J.8=c.2j("Y",{q:0,8:r-c.1k.F}).8}}}});$.z.19.1r("12","6D",{1p:u(e,b){A c=$(4).V("12");c.4B=[];$(b.B.6D).1b(u(){6($.V(4,\'5x\')){A a=$.V(4,\'5x\');c.4B.4d({S:a,6E:a.B.3b});a.7Q();a.1c("3r",e,c)}})},1w:u(e,a){A b=$(4).V("12");$.1b(b.4B,u(){6(4.S.3s){4.S.3s=0;b.3S=T;4.S.3S=N;6(4.6E)4.S.B.3b=T;4.S.33(e);4.S.D.2h("7R",[e,$.1f(4.S.z(),{7S:b.D})],4.S.B["7T"]);4.S.B.K=4.S.B.5y}1d{4.S.1c("3t",e,b)}})},29:u(e,a){A c=$(4).V("12"),E=4;A d=u(o){A l=o.8,r=l+o.F,t=o.q,b=t+o.G;H(l<(4.1N.8+4.I.1g.8)&&(4.1N.8+4.I.1g.8)<r&&t<(4.1N.q+4.I.1g.q)&&(4.1N.q+4.I.1g.q)<b)};$.1b(c.4B,u(i){6(d.15(c,4.S.7U)){6(!4.S.3s){4.S.3s=1;4.S.1Z=$(E).3P().2g(4.S.D).V("5x-6B",T);4.S.B.5y=4.S.B.K;4.S.B.K=u(){H a.K[0]};e.31=4.S.1Z[0];4.S.4o(e,T);4.S.32(e,T,T);4.S.I.1g.q=c.I.1g.q;4.S.I.1g.8=c.I.1g.8;4.S.I.Z.8-=c.I.Z.8-4.S.I.Z.8;4.S.I.Z.q-=c.I.Z.q-4.S.I.Z.q;c.1c("7V",e)}6(4.S.1Z)4.S.2O(e)}1d{6(4.S.3s){4.S.3s=0;4.S.3S=T;4.S.B.3b=N;4.S.33(e,T);4.S.B.K=4.S.B.5y;4.S.1Z.1T();6(4.S.6F)4.S.6F.1T();c.1c("7W",e)}}})}});$.z.19.1r("12","3u",{1p:u(e,c){A d=$.7X($(c.B.3u.7Y)).7Z(u(a,b){H(M($(a).C("1y"),10)||c.B.3u.1l)-(M($(b).C("1y"),10)||c.B.3u.1l)});$(d).1b(u(i){4.2a.1y=c.B.3u.1l+i});4[0].2a.1y=c.B.3u.1l+d.1i}})})(3N);(u($){$.2s("z.21",{3n:u(){4.D.1e("z-21");4.2m=0;4.2P=1;A o=4.B,2c=o.2c;o=$.1f(o,{2c:o.2c&&o.2c.3U==80?o.2c:u(d){H $(d).3O(2c)}});4.4C={F:4.D[0].36,G:4.D[0].3a};$.z.1j.3v.4d(4)},2K:{},z:u(c){H{12:(c.1Z||c.D),K:c.K,J:c.J,4v:c.1N,B:4.B,D:4.D}},3m:u(){A a=$.z.1j.3v;2J(A i=0;i<a.1i;i++)6(a[i]==4)a.81(i,1);4.D.26("z-21 z-21-1n").3o("21").30(".21")},3w:u(e){A a=$.z.1j.34;6(!a||(a.1Z||a.D)[0]==4.D[0])H;6(4.B.2c.15(4.D,(a.1Z||a.D))){$.z.19.15(4,\'3w\',[e,4.z(a)]);4.D.2h("82",[e,4.z(a)],4.B.3w)}},3x:u(e){A a=$.z.1j.34;6(!a||(a.1Z||a.D)[0]==4.D[0])H;6(4.B.2c.15(4.D,(a.1Z||a.D))){$.z.19.15(4,\'3x\',[e,4.z(a)]);4.D.2h("83",[e,4.z(a)],4.B.3x)}},2D:u(e,b){A c=b||$.z.1j.34;6(!c||(c.1Z||c.D)[0]==4.D[0])H N;A d=N;4.D.5k(".z-21").84(".z-12-5n").1b(u(){A a=$.V(4,\'21\');6(a.B.6G&&$.z.3y(c,$.1f(a,{I:a.D.I()}),a.B.4D)){d=T;H N}});6(d)H N;6(4.B.2c.15(4.D,(c.1Z||c.D))){$.z.19.15(4,\'2D\',[e,4.z(c)]);4.D.2h("2D",[e,4.z(c)],4.B.2D);H T}H N},3r:u(e){A a=$.z.1j.34;$.z.19.15(4,\'3r\',[e,4.z(a)]);6(a)4.D.2h("85",[e,4.z(a)],4.B.3r)},3t:u(e){A a=$.z.1j.34;$.z.19.15(4,\'3t\',[e,4.z(a)]);6(a)4.D.2h("86",[e,4.z(a)],4.B.3t)}});$.1f($.z.21,{2N:{1n:N,4D:\'3y\'}});$.z.3y=u(a,c,d){6(!c.I)H N;A e=(a.1N||a.J.16).8,1X=e+a.1k.F,1H=(a.1N||a.J.16).q,1Y=1H+a.1k.G;A l=c.I.8,r=l+c.4C.F,t=c.I.q,b=t+c.4C.G;87(d){4E\'88\':H(l<e&&1X<r&&t<1H&&1Y<b);3V;4E\'3y\':H(l<e+(a.1k.F/2)&&1X-(a.1k.F/2)<r&&t<1H+(a.1k.G/2)&&1Y-(a.1k.G/2)<b);3V;4E\'89\':H(l<((a.1N||a.J.16).8+(a.3e||a.I.1g).8)&&((a.1N||a.J.16).8+(a.3e||a.I.1g).8)<r&&t<((a.1N||a.J.16).q+(a.3e||a.I.1g).q)&&((a.1N||a.J.16).q+(a.3e||a.I.1g).q)<b);3V;4E\'8a\':H((1H>=t&&1H<=b)||(1Y>=t&&1Y<=b)||(1H<t&&1Y>b))&&((e>=l&&e<=r)||(1X>=l&&1X<=r)||(e<l&&1X>r));3V;6k:H N;3V}};$.z.1j={34:X,3v:[],5m:u(t,e){A m=$.z.1j.3v;A a=e?e.8b:X;2J(A i=0;i<m.1i;i++){6(m[i].B.1n||(t&&!m[i].B.2c.15(m[i].D,(t.1Z||t.D))))4A;m[i].3W=m[i].D.C("3j")!="2W";6(!m[i].3W)4A;m[i].I=m[i].D.I();m[i].4C={F:m[i].D[0].36,G:m[i].D[0].3a};6(a=="8c"||a=="8d")m[i].3r.15(m[i],e)}},2D:u(a,e){A b=N;$.1b($.z.1j.3v,u(){6(!4.B)H;6(!4.B.1n&&4.3W&&$.z.3y(a,4,4.B.4D))b=4.2D.15(4,e);6(!4.B.1n&&4.3W&&4.B.2c.15(4.D,(a.1Z||a.D))){4.2P=1;4.2m=0;4.3t.15(4,e)}});H b},29:u(f,e){6(f.B.8e)$.z.1j.5m(f,e);$.1b($.z.1j.3v,u(){6(4.B.1n||4.6H||!4.3W)H;A a=$.z.3y(f,4,4.B.4D);A c=!a&&4.2m==1?\'2P\':(a&&4.2m==0?\'2m\':X);6(!c)H;A b;6(4.B.6G){A d=4.D.4n(\'.z-21:6I(0)\');6(d.1i){b=$.V(d[0],\'21\');b.6H=(c==\'2m\'?1:0)}}6(b&&c==\'2m\'){b[\'2m\']=0;b[\'2P\']=1;b.3x.15(b,e)}4[c]=1;4[c==\'2P\'?\'2m\':\'2P\']=0;4[c=="2m"?"3w":"3x"].15(4,e);6(b&&c==\'2P\'){b[\'2P\']=0;b[\'2m\']=1;b.3w.15(b,e)}})}};$.z.19.1r("21","4F",{3r:u(e,a){$(4).1e(a.B.4F)},3t:u(e,a){$(4).26(a.B.4F)},2D:u(e,a){$(4).26(a.B.4F)}});$.z.19.1r("21","4G",{3w:u(e,a){$(4).1e(a.B.4G)},3x:u(e,a){$(4).26(a.B.4G)},2D:u(e,a){$(4).26(a.B.4G)}})})(3N);(u($){$.2s("z.L",$.1f({},$.z.27,{3n:u(){A d=4,o=4.B;A f=4.D.C(\'J\');4.5z=4.D;4.D.1e("z-L").C({J:/4H/.Q(f)?\'Y\':f});$.1f(o,{3X:!!(o.2n),K:o.K||o.22||o.1v?o.K||\'8f\':X,2F:o.2F===T?\'z-L-3Y-O\':o.2F});A g=\'5A 6J #8g\';o.6K={\'z-L\':{3j:\'4f\'},\'z-L-O\':{J:\'16\',5t:\'#6L\',8h:\'0.5A\'},\'z-L-n\':{17:\'n-14\',G:\'2d\',8:\'1a\',2u:\'1a\',5B:g},\'z-L-s\':{17:\'s-14\',G:\'2d\',8:\'1a\',2u:\'1a\',5C:g},\'z-L-e\':{17:\'e-14\',F:\'2d\',q:\'1a\',2v:\'1a\',5D:g},\'z-L-w\':{17:\'w-14\',F:\'2d\',q:\'1a\',2v:\'1a\',5E:g},\'z-L-1D\':{17:\'1D-14\',F:\'2d\',G:\'2d\',5D:g,5C:g},\'z-L-1E\':{17:\'1E-14\',F:\'2d\',G:\'2d\',5C:g,5E:g},\'z-L-1I\':{17:\'1I-14\',F:\'2d\',G:\'2d\',5D:g,5B:g},\'z-L-1F\':{17:\'1F-14\',F:\'2d\',G:\'2d\',5E:g,5B:g}};o.5F={\'z-L-O\':{5t:\'#6L\',6M:\'5A 6J #8i\',G:\'6N\',F:\'6N\'},\'z-L-n\':{17:\'n-14\',q:\'1a\',8:\'45%\'},\'z-L-s\':{17:\'s-14\',2v:\'1a\',8:\'45%\'},\'z-L-e\':{17:\'e-14\',2u:\'1a\',q:\'45%\'},\'z-L-w\':{17:\'w-14\',8:\'1a\',q:\'45%\'},\'z-L-1D\':{17:\'1D-14\',2u:\'1a\',2v:\'1a\'},\'z-L-1E\':{17:\'1E-14\',8:\'1a\',2v:\'1a\'},\'z-L-1F\':{17:\'1F-14\',8:\'1a\',q:\'1a\'},\'z-L-1I\':{17:\'1I-14\',2u:\'1a\',q:\'1a\'}};o.5G=4.D[0].5H;6(o.5G.5I(/8j|4I|4w|6O|5i|8k/i)){A h=4.D;6(/Y/.Q(h.C(\'J\'))&&$.1J.6P)h.C({J:\'Y\',q:\'2r\',8:\'2r\'});h.6Q($(\'<1S 4e="z-5J"	2a="3c: 5K;"></1S>\').C({J:h.C(\'J\'),F:h.1V(),G:h.1W(),q:h.C(\'q\'),8:h.C(\'8\')}));A j=4.D;4.D=4.D.Z();4.D.V(\'L\',4);4.D.C({4q:j.C("4q"),4r:j.C("4r"),3Q:j.C("3Q"),3R:j.C("3R")});j.C({4q:0,4r:0,3Q:0,3R:0});6($.1J.8l&&o.5f)j.C(\'14\',\'2W\');o.2G=j.C({J:\'4H\',8m:1,3j:\'4f\'});4.D.C({5L:j.C(\'5L\')});4.3Z()}6(!o.1h)o.1h=!$(\'.z-L-O\',4.D).1i?"e,s,1D":{n:\'.z-L-n\',e:\'.z-L-e\',s:\'.z-L-s\',w:\'.z-L-w\',1D:\'.z-L-1D\',1E:\'.z-L-1E\',1I:\'.z-L-1I\',1F:\'.z-L-1F\'};6(o.1h.3U==6R){o.1y=o.1y||6y;6(o.1h==\'8n\')o.1h=\'n,e,s,w,1D,1E,1I,1F\';A n=o.1h.4j(",");o.1h={};A k={O:\'J: 16; 3j: 2W; 3c:5K;\',n:\'q: 2Q; F:3z%;\',e:\'2u: 2Q; G:3z%;\',s:\'2v: 2Q; F:3z%;\',w:\'8: 2Q; G:3z%;\',1D:\'2v: 2Q; 2u: 1a;\',1E:\'2v: 2Q; 8: 1a;\',1I:\'q: 2Q; 2u: 1a;\',1F:\'q: 2Q; 8: 1a;\'};2J(A i=0;i<n.1i;i++){A l=$.8o(n[i]),5M=o.6K,41=\'z-L-\'+l,5N=!$.z.C(41)&&!o.2F,6S=$.z.C(\'z-L-3Y-O\'),6T=$.1f(5M[41],5M[\'z-L-O\']),6U=$.1f(o.5F[41],!6S?o.5F[\'z-L-O\']:{});A m=/1E|1D|1I|1F/.Q(l)?{1y:++o.1y}:{};A p=(5N?k[l]:\'\'),13=$([\'<1S 4e="z-L-O \',41,\'" 2a="\',p,k.O,\'"></1S>\'].5O(\'\')).C(m);o.1h[l]=\'.z-L-\'+l;4.D.6V(13.C(5N?6T:{}).C(o.2F?6U:{}).1e(o.2F?\'z-L-3Y-O\':\'\').1e(o.2F))}6(o.2F)4.D.1e(\'z-L-3Y\').C(!$.z.C(\'z-L-3Y\')?{}:{})}4.6W=u(a){a=a||4.D;2J(A i 56 o.1h){6(o.1h[i].3U==6R)o.1h[i]=$(o.1h[i],4.D).6X();6(o.4g)o.1h[i].C({2E:0});6(4.D.3O(\'.z-5J\')&&o.5G.5I(/4I|4w|6O|5i/i)){A b=$(o.1h[i],4.D),5P=0;5P=/1E|1I|1F|1D|n|s/.Q(i)?b.1W():b.1V();A c=[\'5Q\',/1I|1F|n/.Q(i)?\'8p\':/1D|1E|s/.Q(i)?\'8q\':/^e$/.Q(i)?\'8r\':\'8s\'].5O("");6(!o.4g)a.C(c,5P);4.3Z()}6(!$(o.1h[i]).1i)4A}};4.6W(4.D);o.3A=$(\'.z-L-O\',d.D);6(o.3k)o.3A.1b(u(i,e){$.z.3k(e)});o.3A.8t(u(){6(!o.4J){6(4.6Y)A a=4.6Y.5I(/z-L-(1D|1E|1I|1F|n|e|s|w)/i);d.13=o.13=a&&a[1]?a[1]:\'1D\'}});6(o.6Z){o.3A.70();$(d.D).1e("z-L-5R").8u(u(){$(4).26("z-L-5R");o.3A.6X()},u(){6(!o.4J){$(4).1e("z-L-5R");o.3A.70()}})}4.4k()},2K:{},z:u(){H{5z:4.5z,D:4.D,K:4.K,J:4.J,R:4.R,B:4.B,2e:4.2e,1o:4.1o}},1c:u(n,e){$.z.19.15(4,n,[e,4.z()]);6(n!="14")4.D.2h(["14",n].5O(""),[e,4.z()],4.B[n])},3m:u(){A b=4.D,4K=b.8v(".z-L").24(0);4.4l();A c=u(a){$(a).26("z-L z-L-1n").3o("L").30(".L").5k(\'.z-L-O\').1T()};c(b);6(b.3O(\'.z-5J\')&&4K){b.Z().6V($(4K).C({J:b.C(\'J\'),F:b.1V(),G:b.1W(),q:b.C(\'q\'),8:b.C(\'8\')})).8w().1T();c(4K)}},32:u(e){6(4.B.1n)H N;A a=N;2J(A i 56 4.B.1h){6($(4.B.1h[i])[0]==e.31)a=T}6(!a)H N;A o=4.B,5S=4.D.J(),18=4.D,4L=u(v){H M(v,10)||0},4M=$.1J.2Z&&$.1J.5T<7;o.4J=T;o.5U={q:$(P).1s(),8:$(P).1t()};6(18.3O(\'.z-12\')||(/16/).Q(18.C(\'J\'))){A b=$.1J.2Z&&!o.W&&(/16/).Q(18.C(\'J\'))&&!(/Y/).Q(18.Z().C(\'J\'));A c=b?o.5U.q:0,71=b?o.5U.8:0;18.C({J:\'16\',q:(5S.q+c),8:(5S.8+71)})}6($.1J.6P&&/Y/.Q(18.C(\'J\')))18.C({J:\'Y\',q:\'2r\',8:\'2r\'});4.72();A d=4L(4.K.C(\'8\')),4N=4L(4.K.C(\'q\'));6(o.W){d+=$(o.W).1t()||0;4N+=$(o.W).1s()||0}4.I=4.K.I();4.J={8:d,q:4N};4.R=o.K||4M?{F:18.1V(),G:18.1W()}:{F:18.F(),G:18.G()};4.2e=o.K||4M?{F:18.1V(),G:18.1W()}:{F:18.F(),G:18.G()};4.1o={8:d,q:4N};4.2R={F:18.1V()-18.F(),G:18.1W()-18.G()};4.73={8:e.1K,q:e.1L};o.2n=(2L o.2n==\'74\')?o.2n:((4.2e.G/4.2e.F)||1);6(o.5V)$(\'1A\').C(\'17\',4.13+\'-14\');4.1c("1p",e);H T},2O:u(e){A b=4.K,o=4.B,8x={},E=4,5W=4.73,a=4.13;A c=(e.1K-5W.8)||0,75=(e.1L-5W.q)||0;A d=4.2y[a];6(!d)H N;A f=d.1z(4,[e,c,75]),4M=$.1J.2Z&&$.1J.5T<7,8y=4.2R;6(o.3X||e.4O)f=4.76(f,e);f=4.77(f,e);4.1c("14",e);b.C({q:4.J.q+"2b",8:4.J.8+"2b",F:4.R.F+"2b",G:4.R.G+"2b"});6(!o.K&&o.2G)4.3Z();4.5X(f);4.D.2h("14",[e,4.z()],4.B["14"]);H N},33:u(e){4.B.4J=N;A o=4.B,4L=u(v){H M(v,10)||0},E=4;6(o.K){A a=o.2G,3B=a&&(/4I/i).Q(a.24(0).5H),4P=3B&&$.z.3I(a.24(0),\'8\')?0:E.2R.G,4Q=3B?0:E.2R.F;A s={F:(E.R.F-4Q),G:(E.R.G-4P)},8=(M(E.D.C(\'8\'),10)+(E.J.8-E.1o.8))||X,q=(M(E.D.C(\'q\'),10)+(E.J.q-E.1o.q))||X;6(!o.1v)4.D.C($.1f(s,{q:q,8:8}));6(o.K&&!o.1v)4.3Z()}6(o.5V)$(\'1A\').C(\'17\',\'2r\');4.1c("1w",e);6(o.K)4.K.1T();H N},5X:u(a){A o=4.B;4.I=4.K.I();6(a.8)4.J.8=a.8;6(a.q)4.J.q=a.q;6(a.G)4.R.G=a.G;6(a.F)4.R.F=a.F},76:u(b,e){A o=4.B,4R=4.J,3C=4.R,a=4.13;6(b.G)b.F=(3C.G/o.2n);1d 6(b.F)b.G=(3C.F*o.2n);6(a==\'1E\'){b.8=4R.8+(3C.F-b.F);b.q=X}6(a==\'1F\'){b.q=4R.q+(3C.G-b.G);b.8=4R.8+(3C.F-b.F)}H b},77:u(b,e){A c=4.K,o=4.B,3D=o.3X||e.4O,a=4.13,5Y=b.F&&o.4S&&o.4S<b.F,5Z=b.G&&o.4T&&o.4T<b.G,60=b.F&&o.42&&o.42>b.F,61=b.G&&o.43&&o.43>b.G;6(60)b.F=o.42;6(61)b.G=o.43;6(5Y)b.F=o.4S;6(5Z)b.G=o.4T;A d=4.1o.8+4.2e.F,62=4.J.q+4.R.G;A f=/1E|1F|w/.Q(a),44=/1F|1I|n/.Q(a);6(60&&f)b.8=d-o.42;6(5Y&&f)b.8=d-o.4S;6(61&&44)b.q=62-o.43;6(5Z&&44)b.q=62-o.4T;A g=!b.F&&!b.G;6(g&&!b.8&&b.q)b.q=X;1d 6(g&&!b.q&&b.8)b.8=X;H b},3Z:u(){A o=4.B;6(!o.2G)H;A c=o.2G,18=4.K||4.D;6(!o.3E){A b=[c.C(\'4s\'),c.C(\'8z\'),c.C(\'8A\'),c.C(\'4t\')],p=[c.C(\'8B\'),c.C(\'8C\'),c.C(\'8D\'),c.C(\'8E\')];o.3E=$.78(b,u(v,i){A a=M(v,10)||0,5Q=M(p[i],10)||0;H a+5Q})}c.C({G:(18.G()-o.3E[0]-o.3E[2])+"2b",F:(18.F()-o.3E[1]-o.3E[3])+"2b"})},72:u(){A a=4.D,o=4.B;4.63=a.I();6(o.K){4.K=4.K||$(\'<1S 2a="3c:5K;"></1S>\');A b=$.1J.2Z&&$.1J.5T<7,64=(b?1:0),65=(b?2:-1);4.K.1e(o.K).C({F:a.1V()+65,G:a.1W()+65,J:\'16\',8:4.63.8-64+\'2b\',q:4.63.q-64+\'2b\',1y:++o.1y});4.K.2g("1A");6(o.3k)$.z.3k(4.K.24(0))}1d{4.K=a}},2y:{e:u(e,a,b){H{F:4.2e.F+a}},w:u(e,a,b){A o=4.B,2o=4.2e,4U=4.1o;H{8:4U.8+a,F:2o.F-a}},n:u(e,a,b){A o=4.B,2o=4.2e,4U=4.1o;H{q:4U.q+b,G:2o.G-b}},s:u(e,a,b){H{G:4.2e.G+b}},1D:u(e,a,b){H $.1f(4.2y.s.1z(4,2X),4.2y.e.1z(4,[e,a,b]))},1E:u(e,a,b){H $.1f(4.2y.s.1z(4,2X),4.2y.w.1z(4,[e,a,b]))},1I:u(e,a,b){H $.1f(4.2y.n.1z(4,2X),4.2y.e.1z(4,[e,a,b]))},1F:u(e,a,b){H $.1f(4.2y.n.1z(4,2X),4.2y.w.1z(4,[e,a,b]))}}}));$.1f($.z.L,{2N:{3L:":4w",3p:1,3M:0,5f:T,4g:N,42:10,43:10,2n:N,3k:T,5V:T,6Z:N,2F:N}});$.z.19.1r("L","W",{1p:u(e,a){A o=a.B,E=$(4).V("L"),18=E.D;A b=o.W,1x=(b 8F $)?b.24(0):(/Z/.Q(b))?18.Z().24(0):b;6(!1x)H;E.66=$(1x);6(/P/.Q(b)||b==P){E.46={8:0,q:0};E.4V={8:0,q:0};E.3F={D:$(P),8:0,q:0,F:$(P).F(),G:$(P).G()||P.1A.35.4u}}1d{E.46=$(1x).I();E.4V=$(1x).J();E.4W={G:$(1x).79(),F:$(1x).7a()};A c=E.46,44=E.4W.G,7b=E.4W.F,F=($.z.3I(1x,"8")?1x.6w:7b),G=($.z.3I(1x)?1x.4u:44);E.3F={D:1x,8:c.8,q:c.q,F:F,G:G}}},14:u(e,a){A o=a.B,E=$(4).V("L"),8G=E.4W,1O=E.46,2o=E.R,4X=E.J,3D=o.3X||e.4O,2H={q:0,8:0},1x=E.66;6(1x[0]!=P&&/4H/.Q(1x.C(\'J\')))2H=E.4V;6(4X.8<(o.K?1O.8:2H.8)){E.R.F=E.R.F+(o.K?(E.J.8-1O.8):(E.J.8-2H.8));6(3D)E.R.G=E.R.F*o.2n;E.J.8=o.K?1O.8:2H.8}6(4X.q<(o.K?1O.q:0)){E.R.G=E.R.G+(o.K?(E.J.q-1O.q):E.J.q);6(3D)E.R.F=E.R.G/o.2n;E.J.q=o.K?1O.q:0}A b=(o.K?E.I.8-1O.8:(E.J.8-2H.8))+E.2R.F,67=(o.K?E.I.q-1O.q:E.J.q)+E.2R.G;6(b+E.R.F>=E.3F.F){E.R.F=E.3F.F-b;6(3D)E.R.G=E.R.F*o.2n}6(67+E.R.G>=E.3F.G){E.R.G=E.3F.G-67;6(3D)E.R.F=E.R.G/o.2n}},1w:u(e,a){A o=a.B,E=$(4).V("L"),4X=E.J,1O=E.46,2H=E.4V,1x=E.66;A b=$(E.K),47=b.I(),w=b.7a(),h=b.79();6(o.K&&!o.1v&&/Y/.Q(1x.C(\'J\')))$(4).C({8:(47.8-1O.8),q:(47.q-1O.q),F:w,G:h});6(o.K&&!o.1v&&/4H/.Q(1x.C(\'J\')))$(4).C({8:2H.8+(47.8-1O.8),q:2H.q+(47.q-1O.q),F:w,G:h})}});$.z.19.1r("L","1q",{14:u(e,b){A o=b.B,E=$(4).V("L"),2o=E.R,1P=E.2e,2S=E.1o,a=E.13,8H=o.3X||e.4O;o.1q=2L o.1q=="74"?[o.1q,o.1q]:o.1q;A c=11.1G((2o.F-1P.F)/(o.1q[0]||1))*(o.1q[0]||1),3f=11.1G((2o.G-1P.G)/(o.1q[1]||1))*(o.1q[1]||1);6(/^(1D|s|e)$/.Q(a)){E.R.F=1P.F+c;E.R.G=1P.G+3f}1d 6(/^(1I)$/.Q(a)){E.R.F=1P.F+c;E.R.G=1P.G+3f;E.J.q=2S.q-3f}1d 6(/^(1E)$/.Q(a)){E.R.F=1P.F+c;E.R.G=1P.G+3f;E.J.8=2S.8-c}1d{E.R.F=1P.F+c;E.R.G=1P.G+3f;E.J.q=2S.q-3f;E.J.8=2S.8-c}}});$.z.19.1r("L","1v",{1w:u(e,b){A o=b.B,E=$(4).V("L");A c=o.2G,3B=c&&(/4I/i).Q(c.24(0).5H),4P=3B&&$.z.3I(c.24(0),\'8\')?0:E.2R.G,4Q=3B?0:E.2R.F;A d={F:(E.R.F-4Q),G:(E.R.G-4P)},8=(M(E.D.C(\'8\'),10)+(E.J.8-E.1o.8))||X,q=(M(E.D.C(\'q\'),10)+(E.J.q-E.1o.q))||X;E.D.1v($.1f(d,q&&8?{q:q,8:8}:{}),{8I:o.8J||"8K",8L:o.8M||"8N",8O:u(){A a={F:M(E.D.C(\'F\'),10),G:M(E.D.C(\'G\'),10),q:M(E.D.C(\'q\'),10),8:M(E.D.C(\'8\'),10)};6(c)c.C({F:a.F,G:a.G});E.5X(a);E.1c("1v",e)}})}});$.z.19.1r("L","22",{1p:u(e,a){A o=a.B,E=$(4).V("L"),48=o.2G,2o=E.R;6(!48)E.22=E.D.3P();1d E.22=48.3P();E.22.C({2E:.25,3j:\'4f\',J:\'Y\',G:2o.G,F:2o.F,5L:0,8:0,q:0}).1e(\'z-L-22\').1e(2L o.22==\'4i\'?o.22:\'\');E.22.2g(E.K)},14:u(e,a){A o=a.B,E=$(4).V("L"),48=o.2G;6(E.22)E.22.C({J:\'Y\',G:E.R.G,F:E.R.F})},1w:u(e,a){A o=a.B,E=$(4).V("L"),48=o.2G;6(E.22&&E.K)E.K.24(0).57(E.22.24(0))}});$.z.19.1r("L","2p",{1p:u(e,b){A o=b.B,E=$(4).V("L"),4Y=u(a){$(a).1b(u(){$(4).V("L-68",{F:M($(4).F(),10),G:M($(4).G(),10),8:M($(4).C(\'8\'),10),q:M($(4).C(\'q\'),10)})})};6(2L(o.2p)==\'7c\'){6(o.2p.1i){o.2p=o.2p[0];4Y(o.2p)}1d{$.1b(o.2p,u(a,c){4Y(a)})}}1d{4Y(o.2p)}},14:u(e,f){A o=f.B,E=$(4).V("L"),1P=E.2e,2S=E.1o;A g={G:(E.R.G-1P.G)||0,F:(E.R.F-1P.F)||0,q:(E.J.q-2S.q)||0,8:(E.J.8-2S.8)||0},69=u(e,c){$(e).1b(u(){A d=$(4).V("L-68"),2a={},C=c&&c.1i?c:[\'F\',\'G\',\'q\',\'8\'];$.1b(C||[\'F\',\'G\',\'q\',\'8\'],u(i,a){A b=(d[a]||0)+(g[a]||0);6(b&&b>=0)2a[a]=b||X});$(4).C(2a)})};6(2L(o.2p)==\'7c\'){$.1b(o.2p,u(a,c){69(a,c)})}1d{69(o.2p)}},1w:u(e,a){$(4).3o("L-68-1p")}})})(3N);(u($){$.3J.6a=$.3J.6a||u(a){H 4.1b(u(){$(4).4n(a).6I(0).8P(4).1T()})};$.2s("z.1Q",{2K:{},z:u(e){H{B:4.B,O:4.U,1R:4.B.13!="8Q"||!4.B.13?11.1G(4.1R(X,4.B.13=="2z"?"y":"x")):{x:11.1G(4.1R(X,"x")),y:11.1G(4.1R(X,"y"))},4Z:4.7d()}},1c:u(n,e){$.z.19.15(4,n,[e,4.z()]);4.D.2h(n=="50"?n:"50"+n,[e,4.z()],4.B[n])},3m:u(){4.D.26("z-1Q z-1Q-1n").3o("1Q").30(".1Q");6(4.O&&4.O.1i){4.O.6a("a");4.O.1b(u(){$(4).V("27").4l()})}4.6b&&4.6b.1T()},2Y:u(a,b){$.2s.2V.2Y.1z(4,2X);6(/1l|1B|3g/.Q(a)){4.6c()}6(a=="4Z"){b?4.O.1i==2&&4.6d():4.7e()}},3n:u(){A c=4;4.D.1e("z-1Q");4.6c();4.O=$(4.B.O,4.D);6(!4.O.1i){c.O=c.6b=$(c.B.1h||[0]).78(u(){A a=$("<1S/>").1e("z-1Q-O").2g(c.D);6(4.6e)a.3l("6e",4.6e);H a[0]})}A d=u(a){4.D=$(a);4.D.V("27",4);4.B=c.B;4.D.2i("5b",u(){6(c.U)4.51(c.U);c.2I(4,1)});4.4k()};$.1f(d.2V,$.z.27,{32:u(e){H c.1p.15(c,e,4.D[0])},33:u(e){H c.1w.15(c,e,4.D[0])},2O:u(e){H c.29.15(c,e,4.D[0])},4o:u(){H T},7f:u(e){4.5c(e)}});$(4.O).1b(u(){6o d(4)}).6Q(\'<a 8R="8S:8T(0)" 2a="8U:2W;6M:2W;"></a>\').Z().2i(\'2I\',u(e){c.2I(4.6f)}).2i(\'51\',u(e){c.51(4.6f)}).2i(\'6g\',u(e){6(!c.B.8V)c.6g(e.8W,4.6f)});4.D.2i(\'5b.1Q\',u(e){c.1g.1z(c,[e]);c.U.V("27").7f(e);c.52=c.52+1});$.1b(4.B.1h||[],u(a,b){c.49(b.1p,a,T)});6(!3h(4.B.7g))4.49(4.B.7g,0,T);4.2T=$(4.O[0]);6(4.O.1i==2&&4.B.4Z)4.6d()},6c:u(){A a=4.D[0],o=4.B;4.2f={F:4.D.1V(),G:4.D.1W()};$.1f(o,{13:o.13||(a.36<a.3a?\'2z\':\'6h\'),1B:!3h(M(o.1B,10))?{x:M(o.1B,10),y:M(o.1B,10)}:({x:o.1B&&o.1B.x||3z,y:o.1B&&o.1B.y||3z}),1l:!3h(M(o.1l,10))?{x:M(o.1l,10),y:M(o.1l,10)}:({x:o.1l&&o.1l.x||0,y:o.1l&&o.1l.y||0})});o.2U={x:o.1B.x-o.1l.x,y:o.1B.y-o.1l.y};o.1m={x:o.1m&&o.1m.x||M(o.1m,10)||(o.3g?o.2U.x/(o.3g.x||M(o.3g,10)||o.2U.x):0),y:o.1m&&o.1m.y||M(o.1m,10)||(o.3g?o.2U.y/(o.3g.y||M(o.3g,10)||o.2U.y):0)}},6g:u(a,b){6(/(37|38|39|40)/.Q(a)){4.49({x:/(37|39)/.Q(a)?(a==37?\'-\':\'+\')+\'=\'+4.4a("x"):0,y:/(38|40)/.Q(a)?(a==38?\'-\':\'+\')+\'=\'+4.4a("y"):0},b)}},2I:u(a,b){4.U=$(a).1e(\'z-1Q-O-7h\');6(b)4.U.Z()[0].2I()},51:u(a){$(a).26(\'z-1Q-O-7h\');6(4.U&&4.U[0]==a){4.2T=4.U;4.U=X}},1g:u(e){A a=[e.1K,e.1L];A b=N;4.O.1b(u(){6(4==e.31)b=T});6(b||4.B.1n||!(4.U||4.2T))H;6(!4.U&&4.2T)4.2I(4.2T,T);4.I=4.D.I();4.49({y:4.2A(e.1L-4.I.q-4.U[0].3a/2,"y"),x:4.2A(e.1K-4.I.8-4.U[0].36/2,"x")},X,!4.B.3p)},6d:u(){6(4.2q)H;4.2q=$(\'<1S></1S>\').1e(\'z-1Q-4Z\').C({J:\'16\'}).2g(4.D);4.53()},7e:u(){4.2q.1T();4.2q=X},53:u(){A a=4.B.13=="2z"?"q":"8";A b=4.B.13=="2z"?"G":"F";4.2q.C(a,(M($(4.O[0]).C(a),10)||0)+4.3i(0,4.B.13=="2z"?"y":"x")/2);4.2q.C(b,(M($(4.O[1]).C(a),10)||0)-(M($(4.O[0]).C(a),10)||0))},7d:u(){H 4.2q?4.2A(M(4.2q.C(4.B.13=="2z"?"G":"F"),10),4.B.13=="2z"?"y":"x"):X},7i:u(){H 4.O.8X(4.U[0])},1R:u(a,b){6(4.O.1i==1)4.U=4.O;6(!b)b=4.B.13=="2z"?"y":"x";A c=$(a!=1u&&a!==X?4.O[a]||a:4.U);6(c.V("27").54){H M(c.V("27").54[b],10)}1d{H M(((M(c.C(b=="x"?"8":"q"),10)/(4.2f[b=="x"?"F":"G"]-4.3i(a,b)))*4.B.2U[b])+4.B.1l[b],10)}},2A:u(a,b){H 4.B.1l[b]+(a/(4.2f[b=="x"?"F":"G"]-4.3i(X,b)))*4.B.2U[b]},23:u(a,b){6(4.2f.F==0&&4.2f.G==0){4.2f.F=4.B.F;4.2f.G=4.B.G}H((a-4.B.1l[b])/4.B.2U[b])*(4.2f[b=="x"?"F":"G"]-4.3i(X,b))},4b:u(a,b){6(4.2q){6(4.U[0]==4.O[0]&&a>=4.23(4.1R(1),b))a=4.23(4.1R(1,b)-4.4a(b),b);6(4.U[0]==4.O[1]&&a<=4.23(4.1R(0),b))a=4.23(4.1R(0,b)+4.4a(b),b)}6(4.B.1h){A c=4.B.1h[4.7i()];6(a<4.23(c.1l,b)){a=4.23(c.1l,b)}1d 6(a>4.23(c.1B,b)){a=4.23(c.1B,b)}}H a},4c:u(a,b){6(a>=4.2f[b=="x"?"F":"G"]-4.3i(X,b))a=4.2f[b=="x"?"F":"G"]-4.3i(X,b);6(a<=0)a=0;H a},3i:u(a,b){H $(a!=1u&&a!==X?4.O[a]:4.U)[0]["I"+(b=="x"?"8Y":"8Z")]},4a:u(a){H 4.B.1m[a]||1},1p:u(e,a){A o=4.B;6(o.1n)H N;4.2f={F:4.D.1V(),G:4.D.1W()};6(!4.U)4.2I(4.2T,T);4.I=4.D.I();4.6i=4.U.I();4.3e={q:e.1L-4.6i.q,8:e.1K-4.6i.8};4.52=4.1R();4.1c(\'1p\',e);4.29(e,a);H T},1w:u(e){4.1c(\'1w\',e);6(4.52!=4.1R())4.1c(\'7j\',e);4.2I(4.U,T);H N},29:u(e,a){A o=4.B;A b={q:e.1L-4.I.q-4.3e.q,8:e.1K-4.I.8-4.3e.8};6(!4.U)4.2I(4.2T,T);b.8=4.4c(b.8,"x");b.q=4.4c(b.q,"y");6(o.1m.x){A c=4.2A(b.8,"x");c=11.1G(c/o.1m.x)*o.1m.x;b.8=4.23(c,"x")}6(o.1m.y){A c=4.2A(b.q,"y");c=11.1G(c/o.1m.y)*o.1m.y;b.q=4.23(c,"y")}b.8=4.4b(b.8,"x");b.q=4.4b(b.q,"y");6(o.13!="2z")4.U.C({8:b.8});6(o.13!="6h")4.U.C({q:b.q});4.U.V("27").54={x:11.1G(4.2A(b.8,"x"))||0,y:11.1G(4.2A(b.q,"y"))||0};6(4.2q)4.53();4.1c(\'50\',e);H N},49:u(a,b,c){A o=4.B;4.2f={F:4.D.1V(),G:4.D.1W()};6(b==1u&&!4.U&&4.O.1i!=1)H N;6(b==1u&&!4.U)b=0;6(b!=1u)4.U=4.2T=$(4.O[b]||b);6(a.x!==1u&&a.y!==1u){A x=a.x,y=a.y}1d{A x=a,y=a}6(x!==1u&&x.3U!=7k){A d=/^\\-\\=/.Q(x),55=/^\\+\\=/.Q(x);6(d||55){x=4.1R(X,"x")+M(x.7l(d?\'=\':\'+=\',\'\'),10)}1d{x=3h(M(x,10))?1u:M(x,10)}}6(y!==1u&&y.3U!=7k){A d=/^\\-\\=/.Q(y),55=/^\\+\\=/.Q(y);6(d||55){y=4.1R(X,"y")+M(y.7l(d?\'=\':\'+=\',\'\'),10)}1d{y=3h(M(y,10))?1u:M(y,10)}}6(o.13!="2z"&&x!==1u){6(o.1m.x)x=11.1G(x/o.1m.x)*o.1m.x;x=4.23(x,"x");x=4.4c(x,"x");x=4.4b(x,"x");o.1v?4.U.1w().1v({8:x},(11.28(M(4.U.C("8"))-x))*(!3h(M(o.1v))?o.1v:5)):4.U.C({8:x})}6(o.13!="6h"&&y!==1u){6(o.1m.y)y=11.1G(y/o.1m.y)*o.1m.y;y=4.23(y,"y");y=4.4c(y,"y");y=4.4b(y,"y");o.1v?4.U.1w().1v({q:y},(11.28(M(4.U.C("q"))-y))*(!3h(M(o.1v))?o.1v:5)):4.U.C({q:y})}6(4.2q)4.53();4.U.V("27").54={x:11.1G(4.2A(x,"x"))||0,y:11.1G(4.2A(y,"y"))||0};6(!c){4.1c(\'1p\',X);4.1c(\'1w\',X);4.1c(\'7j\',X);4.1c("50",X)}}});$.z.1Q.4h="1R";$.z.1Q.2N={O:".z-1Q-O",3p:1,1v:N}})(3N);',62,558,'||||this||if||left||||||||||||||||||top||||function|||||ui|var|options|css|element|self|width|height|return|offset|position|helper|resizable|parseInt|false|handle|document|test|size|instance|true|currentHandle|data|containment|null|relative|parent||Math|draggable|axis|resize|call|absolute|cursor|el|plugin|0px|each|propagate|else|addClass|extend|click|handles|length|ddmanager|helperProportions|min|stepping|disabled|originalPosition|start|grid|add|scrollTop|scrollLeft|undefined|animate|stop|ce|zIndex|apply|body|max|offsetParent|se|sw|nw|round|y1|ne|browser|pageX|pageY|cssPosition|positionAbs|co|os|slider|value|div|remove|margins|outerWidth|outerHeight|x2|y2|currentItem||droppable|ghost|translateValue|get||removeClass|mouse|abs|drag|style|px|accept|4px|originalSize|actualSize|appendTo|triggerHandler|bind|convertPositionTo|overflowY|overflowX|isover|aspectRatio|cs|alsoResize|rangeElement|auto|widget|fixed|right|bottom|scrollSensitivity|scrollSpeed|_change|vertical|convertValue|_mouseStarted|cursorAt|drop|opacity|knobHandles|proportionallyResize|cop|focus|for|plugins|typeof|widgetName|defaults|mouseDrag|isout|0pt|sizeDiff|op|previousHandle|realMax|prototype|none|arguments|setData|msie|unbind|target|mouseStart|mouseStop|current|parentNode|offsetWidth||||offsetHeight|revert|overflow|snapElements|clickOffset|oy|steps|isNaN|handleSize|display|disableSelection|attr|destroy|init|removeData|distance|window|activate|isOver|deactivate|stack|droppables|over|out|intersect|100|_handles|ista|csize|pRatio|borderDif|parentData|cssCache|unselectable|hasScroll|fn|mouseUp|cancel|delay|jQuery|is|clone|marginRight|marginBottom|cancelHelperRemoval|scroll|constructor|break|visible|_aspectRatio|knob|_proportionallyResize||hname|minWidth|minHeight|ch||containerOffset|ho|pr|moveTo|oneStep|translateRange|translateLimits|push|class|block|transparent|getter|string|split|mouseInit|mouseDestroy|_mouseDownEvent|parents|mouseCapture|_mouseDelayMet|marginLeft|marginTop|borderTopWidth|borderLeftWidth|scrollHeight|absolutePosition|input|iframeFix|tagName|HTML|continue|sortables|proportions|tolerance|case|activeClass|hoverClass|static|textarea|resizing|wrapped|num|ie6|curtop|shiftKey|soffseth|soffsetw|cpos|maxWidth|maxHeight|sp|containerPosition|containerSize|cp|_store|range|slide|blur|firstValue|updateRange|sliderValue|pe|in|removeChild|has|args|getData|mousedown|mouseDown|mouseDistanceMet|mouseDelayMet|preventDefault|_mouseMoveDelegate|_mouseUpDelegate|button|original|find|generatePosition|prepareOffsets|dragging|clear|uiHash|_cursor|_zIndex|_opacity|background|overflowYOffset|overflowXOffset|snap|sortable|_helper|originalElement|1px|borderTop|borderBottom|borderRight|borderLeft|knobTheme|_nodeName|nodeName|match|wrapper|hidden|margin|dt|loadDefault|join|padWrapper|padding|autohide|iniPos|version|documentScroll|preserveCursor|smp|_updateCache|ismaxw|ismaxh|isminw|isminh|dh|elementOffset|ie6offset|pxyoffset|containerElement|hoset|alsoresize|_alsoResize|unwrap|generated|initBoundaries|createRange|id|firstChild|keydown|horizontal|handleOffset|5000px|default|on|MozUserSelect|isFunction|new|widgetBaseClass|_mouseUnselectable|btnIsLeft|elIsCancel|mouseMove|mousemove|mouseup|scrollWidth|dropBehaviour|1000|do|while|item|snapMode|connectToSortable|shouldRevert|placeholder|greedy|greedyChild|eq|solid|defaultTheme|F2F2F2|border|8px|select|opera|wrap|String|userKnobClass|allDefTheme|allKnobTheme|append|_renderAxis|show|className|autoHide|hide|dscrolll|_renderProxy|originalMousePosition|number|dy|_updateRatio|_respectSize|map|innerHeight|innerWidth|cw|object|getRange|removeRange|trigger|startValue|active|handleIndex|change|Number|replace|gen|backgroundImage|rgba|backgroundColor|try|catch|enableSelection|off|inArray|Array|slice|enable|disable|started|which|filter|_mouseDelayTimer|setTimeout|andSelf|mozilla|invalid|valid|500|iframe|fff|001|DragDropIframeFix|snapTolerance|inner|outer|refreshItems|sortreceive|sender|receive|containerCache|toSortable|fromSortable|makeArray|group|sort|Function|splice|dropover|dropout|not|dropactivate|dropdeactivate|switch|fit|pointer|touch|type|dragstart|sortactivate|refreshPositions|proxy|DEDEDE|fontSize|808080|canvas|img|safari|zoom|all|trim|Top|Bottom|Right|Left|mouseover|hover|children|end|props|csdif|borderRightWidth|borderBottomWidth|paddingTop|paddingRight|paddingBottom|paddingLeft|instanceof|ps|ratio|duration|animateDuration|slow|easing|animateEasing|swing|step|after|both|href|javascript|void|outline|noKeyboard|keyCode|index|Width|Height'.split('|'),0,{}))
;

/**** script/custom-scroll.js ****/
function CustomScroll(container, options) {
	this.container = container;
	this.containerHeight = this.container.height();
	this.list = this.container.children(":first");
	this.listHeight = this.list.height();
	this.defaults = {
		//the number of pixels list will be scrolled up or down in the case of mousewheel using
		scrollStep:		12,
		//boolean flag indicating if the value of scroll step will be calculated automatically or not
		autoScrollStep:	false
	}
	this.options = $.extend(this.defaults, options);
	this.initCustomScroll();
}
CustomScroll.prototype.initCustomScroll = function() {
	if (this.listHeight > this.containerHeight) {
		this.setScrollStep();
		this.createCustomScroll();
		this.setScrollParams();
		this.enableScrollPaneDrag();
		this.enableMouseWheelSupport();
		this.enableScrollPaneTrackClickHandler();		
	}
}

CustomScroll.prototype.setScrollStep = function() {
	if (this.options.autoScrollStep) {
		this.options.scrollStep = (4*this.listHeight)/this.list.children().length
	}
}

CustomScroll.prototype.createCustomScroll = function() {
	//cration of DOM Elements representing scroll pane track and scroll pane itself
	this.scrollPaneTrack = $("<div class='scrollPaneTrack'></div>");
	this.scrollPane = $("<div class='scrollPane'></div>");
	this.container.append(this.scrollPaneTrack.append(this.scrollPane));
}

CustomScroll.prototype.setScrollParams = function() {
	this.scrollPaneTrackHeight = this.scrollPaneTrack.height();
	this.scrollPaneHeight = this.scrollPane.height();
	this.maxOffset = this.containerHeight - this.listHeight;
}

CustomScroll.prototype.enableScrollPaneDrag = function() {
	var _this = this;
	this.scrollPane.draggable({
		axis: 'y',
		containment: this.scrollPaneTrack,
		drag: function(event, ui) {
			_this.updateList(ui.helper[0].offsetTop);
		}
	});
	// stop event propogation in order 
	// to prevent unexpected offset of scroll pane in the end of draggin the latter
	this.scrollPane.click(function(){
		return false;
	})	
}

CustomScroll.prototype.enableMouseWheelSupport = function() {
	var _this = this;
	this.container.bind(
		'mousewheel',
		// mousewheel handler should return boolean value indicating if user have an opportunity
		// to keep on scrolling up or down. in the case user has scroll down the list till the end
		// mousewheel event should propogate to window - that's why we return FALSE in such cases and
		// TRUE value in opposite ones.
		// @param event - jQuery Event object
		// @param delta - -1 | +1. -1 value stands for scrolling down. +1 - for scrolling up 
		
		function(event, delta) {
			var currentOffset = _this.list[0].offsetTop;
			var isScrollable = (delta > 0 && currentOffset < 0) || (delta < 0 && currentOffset > _this.maxOffset);
			if (isScrollable) {
				_this.updateListAndScrollPane(currentOffset + delta * _this.options.scrollStep)
			}
			return !isScrollable;
		}
	)
}

CustomScroll.prototype.enableScrollPaneTrackClickHandler = function() {
	var _this = this;
	this.scrollPaneTrack.click(function(event){
		var offset = event.pageY - _this.scrollPaneTrack.offset().top;
		offset = offset > (_this.scrollPaneTrackHeight - _this.scrollPaneHeight) ? (_this.scrollPaneTrackHeight - _this.scrollPaneHeight) : offset; 
		_this.scrollPane.css({
			"top": offset + "px"
		})
		_this.updateList(offset);
		return false;
	})
}

CustomScroll.prototype.updateListAndScrollPane = function(offset) {
	if (offset > 0) {
		var actualOffset = 0;
	} else {
		var actualOffset = offset < this.maxOffset ? this.maxOffset : offset;
	}
	this.list.css({
		"top" : actualOffset + "px"
	})
	this.scrollPane.css({
		"top": Math.floor(Math.abs(actualOffset/this.maxOffset)*(this.scrollPaneTrackHeight - this.scrollPaneHeight)) + "px"
	})
}

CustomScroll.prototype.updateList = function(offset) {
	var actualOffset = (offset/(this.scrollPaneTrackHeight-this.scrollPaneHeight))*this.maxOffset;		
	this.list.css({
		"top" : actualOffset + "px"
	})				
}
;

/**** script/search-form.js ****/
String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ''); };

/**
 * @requires CustomScroll
 * @requires popupControl
 */
function SearchForm(options) {
	//form container
	this.form = $("#searchForm");
	//block for selecting city
	this.selectCityList = $("#selectCityList");
	//block responsible for switching between search form modes 
	this.formModesSwitcher = {
		container: $("#formModesSwitcher"),
		currentMode: $("#currentMode"),
		switcher: $("#formModesSwitcher > h3 > a")
	}	
	// link for hiding or displaying popup maps
	this.pickOnMapLink = $("#pickOnMap", this.form);
	//link for displaying All Regions Link
	this.allRegionsLink = $("#allRegions");
	// link for hiding or displaying Select City block
	this.selectCityLink = $("#selectRegion").add(this.allRegionsLink);
	// link to area info page
	this.areaInfoLink = $("#areaInfo");
	// separate reference for DOM node storing current city name
	this.currentCityBlock = $("#selectRegion");	
	//list representing realty types
	this.realtyTypes = $("#realtyTypes", this.form);
	//list representing realty types
	this.sourceTypes = $("#sourceTypes", this.form);
	//list of currencies user would like to set price in
	this.listOfCurrencies = $("#priceRange", this.form);
	// price range block containing fields fot max and min prices
	this.priceRange = {
		inputs: {
			max: $("#price_max", this.form),
			min: $("#price_min", this.form)
		},
		noPrice:  $(".not-matter > a", $("#priceRangeInputs", this.form))
	}
	// list representing available action types (buy, rent and etc)
	this.actionTypesList = this.form.find("ul.actionTypes:first");	
	// main input string
	this.inputField = this.form.find("#inputString");	
	// set of list with search examples
	this.searchExamples = this.form.find("#searchExamples").children();
	// object which will contain all cities
	this.cities = {};
	// object storing selected city
	this.currentCity = {};
	// if IE
	this.isIE = jQuery.browser.msie
	this.defaults = {
		//the number of pixels list will be scrolled up or down in the case of mousewheel using
		agencyID: ""
	}
	this.options = $.extend(this.defaults, options);
	
	this.initSearchForm(); 
}

SearchForm.prototype.initSearchForm = function() {
	this.initFormModesSwitcher();
	this.initCitiesList();
	this.initCitySelection();
	this.initActionTypesList();
	this.initSearchExamples();
	this.initInputField();
	this.initFormSubmitHandler();
	this.initSwitchers();
	this.initPopup();
}

SearchForm.prototype.initFormModesSwitcher = function() {
	
	var that = this;
	
	this.formModesSwitcher.container
	.add(this.formModesSwitcher.currentMode)
	.click(function(){
		var isInputMode = that.form.hasClass("inputMode");

		if (isInputMode) {
			that.formModesSwitcher.container.attr("class", "block formMode");
			that.form.attr("class", "formMode");
		} else {
			that.formModesSwitcher.container.attr("class", "block inputMode");
			that.form.attr("class", "inputMode");
		}
		
		var currentModeName = isInputMode ? L('search_form_current_form') : L('search_form_current_input');
		var switcherText = isInputMode ? L('search_form_input_mode_header') : L('search_form_form_mode_header');
		that.formModesSwitcher.currentMode.text(currentModeName);
		that.formModesSwitcher.switcher.text(switcherText);
		
		return false;
	})
	.focus(function(){
		$(this).blur();
	})
	
}


SearchForm.prototype.initCitySelection = function() {
	var that = this;
	var isCustomScrollEnabled = false;
	
	// preloading images in order to level down the delay
	// which will occur during loading this images 
	var preloadedImage = new Image();
	preloadedImage.src = "/img/_temp/select_city_close.gif";
	preloadedImage = new Image(); 
	preloadedImage.src = "/img/_temp/scroll_track_bg.gif";
	preloadedImage = new Image(); 
	preloadedImage.src = "/img/_temp/scroll_pane_bg.gif";
	preloadedImage = new Image(); 
	preloadedImage.src = "/img/_temp/select_city_bg.gif";
 
	
	// custom scroll should be created only after
	// Select City Block became visible
	if (this.citiesListLength > 1) {
		this.selectCityLink.click(function(){
			that.selectCityList.toggle();
			if (!isCustomScrollEnabled) {
				//enabling custom vertical scrolling
				that.selectCityList.find(".block .cityListContainer").each(function(){
					new CustomScroll($(this));
				})
				isCustomScrollEnabled = !isCustomScrollEnabled;
			}
			return false;
		})
	} else {
		this.selectCityLink.click(function(){
			return false;
		})
	}
	
	// close button handler	
	this.selectCityList.children(".close").click(function(){
		that.selectCityList.hide();
		return false;
	})
}

SearchForm.prototype.initCitiesList = function() {
	var that = this;
	
	// private variabe storing all links representing cities use can choose from
	var cities = this.selectCityList.find(".block .cityListContainer > ul  a");
	this.citiesListLength = 0;
		
	// binding click handler to each city link
	cities.each(function(){
		$(this).click(function(){
			var cityKey = this.className;
			that.cities[that.currentCity.key].selected = false
			that.cities[cityKey].selected = true;
			that.currentCity.node.parent().attr("class", "")
			that.prevCity = that.currentCity;
			that.currentCity = that.cities[cityKey];
			that.currentCity.node.parent().attr("class", "selected")
			that.selectCityList.hide();
			that.currentCityBlock.text(that.currentCity.name);
			that.areaInfoLink.attr('href', that.currentCity.href);
			that.updateForm();
			that.updatePopup();
			return false;
		})
		that.citiesListLength ++;
	})
	
	// populating cities object
	cities.each(function(){
		var t = $(this);
		var popupTabs = this.getAttribute("rel").trim();
		that.cities[this.className] = {
			key: this.className,
			name: t.text(),
			href: this.getAttribute('href'),
			tip: this.getAttribute("name"),
			selected: t.parent().hasClass("selected"),
			node: t,
			tabs: popupTabs.length ? popupTabs.split(" ") : new Array()
		}
	})
	
	// setting currentCity
	$.each(this.cities, function(){
		if (this.selected) {
			that.currentCity = this;
			that.prevCity = that.currentCity;
		}
	})
}

SearchForm.prototype.initActionTypesList = function() {
	var that = this;
	
	var actionTypes = $("a", this.actionTypesList); 
	
	//setting current action type
	actionTypes.each(function(){
		if (this.className == "selected") {
			that.currentActionType = this.parentNode.className;
		}
	})
	
	actionTypes.each(function(){
		var t = $(this);
		t.click(function(){
			actionTypes.each(function(){
				this.className = "";
			})
			this.className = "selected";
			that.currentActionType = this.parentNode.className;
			that.updateForm();			
			return false;
		})
		t.focus(function(){ t.blur(); })
		
	})
}

SearchForm.prototype.initSearchExamples = function() {
	var that = this;
	
	this.searchExamples.find("li > a").each(function(){
		var t = $(this);
		t.click(function(){
			that.updateInputFieldValue(t.text());
			return false;
		})
		t.focus(function(){ t.blur(); })		
	})
}

SearchForm.prototype.getInputFieldVaue = function() {
	if (this.inputField.val() == this.currentCity.tip) {
		return "";
	} else {
		return this.inputField.val();
	}
}

SearchForm.prototype.seriaizeInputField = function() {
	var inputFieldValue = this.getInputFieldVaue();
	var inputFieldName = this.inputField.attr("name");
	return inputFieldName + "=" + inputFieldValue;
}

SearchForm.prototype.initFormSubmitHandler = function() {
	var that = this;
	this.form.submit(function(){
		var inputValue = that.inputField.val();
		var trimmedInputValue = inputValue.trim();
		if (trimmedInputValue.match(/^\d+$/)) {
			window.location.pathname = "/object/" + trimmedInputValue.match(/^\d+$/)[0];
			return false;
		} else if (trimmedInputValue == "") {
			that.inputField[0].disabled = true;
		} else if (trimmedInputValue.substring(trimmedInputValue.length-1)==','){
			that.inputField.val(trimmedInputValue.substring(0,trimmedInputValue.length-1))
		} else if (inputValue == that.currentCity.tip) {
			that.inputField.hide().show();
			that.inputField[0].disabled = true;
		}
	})
}

SearchForm.prototype.initPopup = function() {
	if (window.popupControl) {
		var that = this;
		this.popup = new popupControl();
		
		this.updatePopup();
		this.pickOnMapLink.click(function(){
			that.popup.show(
				that.form,
				function() {
					that.form.submit();
			})
			return false;
		})
	}
}



SearchForm.prototype.updatePopup = function() {
	if (this.currentCity.tabs.length) {
		var that = this;
		var isCurrentTabSet = false;
		this.pickOnMapLink.show();
		this.popup.tabs.each(function(){
			var tabPrefix = new RegExp("^for_popup_");
			var tabID = $('a', this).attr('id').replace(tabPrefix, "");
			if ($.inArray(tabID, that.currentCity.tabs) > -1) {
				$(this).show();
				if (!isCurrentTabSet) {
					$(this.contentContainer).show();
					$('a', this).removeClass('inactive');
					that.popup.currentTab = $(this);
					that.popup.currentTabContent = $(this.contentWrapper);
					isCurrentTabSet = true;
				} else {
					$(this.contentContainer).hide();
					$('a', this).addClass('inactive');
				}
			} else {
				$(this).hide();
				$('a', this).addClass('inactive');
				this.contentContainer.hide();
			}
		})
	} else {
		this.pickOnMapLink.hide();
	}
}


SearchForm.prototype.initSwitchers = function() {
	var that = this;
	
	//switcher for realty types, source types and currencies
	commonControls.switcher(this.realtyTypes.add(this.sourceTypes).add(this.listOfCurrencies), "selected", "");
	
	this.priceRange.inputs.max.add(this.priceRange.inputs.min).change(function(){
		if (that.priceRange.inputs.max.val() == "" && that.priceRange.inputs.min.val() == "") {
			that.priceRange.noPrice.attr("class", "selected")
		} else {
			that.priceRange.noPrice.attr("class", "")
		}
	})
	
	this.priceRange.noPrice
	.click(function(){
		$.each(that.priceRange.inputs, function(){
			this.val("");
		});
		that.priceRange.noPrice.attr("class", "selected");
		return false;
	})
	.focus(function(){ $(this).blur(); })

}

SearchForm.prototype.initInputField = function() {
	var that = this;
	
	this.inputField.blur(function(e){
		if (this.value == '') {
			that.updateInputFieldValue(that.currentCity.tip);
		}
	});
	
	this.inputField.focus(function(e){
		if (this.value == that.currentCity.tip){
			this.value = '';
		} 
	});
		
	this.initAutoSuggest();
}

SearchForm.prototype.fixIEBehaviour = function() {
	if (this.isIE) {
		this.inputField.hide().show().focus();
	} 
}

SearchForm.prototype.initAutoSuggest = function() {
	if (jQuery.isFunction(jQuery.fn.autocomplete)) {
		
		var that = this;
		
		this.inputField.autocomplete({
			ajax_get: function(key, cont) {
				return $.getJSON('/suggest',
				 		  {'q': key},
				 		  function(responseData) {
				 		  	var suggestions = [];
				 		  	var maxNumberOfSuggestions = $.browser.opera ? 10 : 20
				 		  	for (var i=0; i<maxNumberOfSuggestions; i++) {
				 		  		suggestions.push({
				 		  			id: i,
				 		  			value: responseData.suggest[i],
				 		  			info: "    "
				 		  		});
				 		  	}
				 		  	cont(suggestions);
				 		  }
				)
			},
			minchars: 1,
			height: 184,
			multi: true,
			callback: function(suggestObject) {
				var updatedSearchInput = that.inputField.val();
				that.updateInputFieldValue(updatedSearchInput+", ", true);
			},
			pre_callback: function() {
				that.fixIEBehaviour();
			}
		})
	}
}

SearchForm.prototype.updateInputFieldValue = function(value, focus) {
	this.inputField.val(value);
	// absolutely insane behaviour in the case of IE after input value is updated via JavaScript
	// so we should redraw input field once again to fix it
	if (this.isIE) {
		this.inputField.hide().show();
		if (focus) {
			this.inputField.focus()
		}
	} 	
}

SearchForm.prototype.updateForm = function() {
	var that = this;
	
	//update action attribute
	var prefix = this.form.attr("action").match(/^\/commercial/) ? "/commercial/" : "/";
	if (this.options.agencyID.length) {
		this.form.attr("action", prefix + this.currentCity.key + "/" + this.currentActionType + "/agency/" + this.options.agencyID);
	} else {
		this.form.attr("action", prefix + this.currentCity.key + "/" + this.currentActionType);
	}

	//update search examples
	this.searchExamples.hide();
	this.searchExamples.filter(function(){
		var t = $(this);
		return (t.hasClass(that.currentCity.key) && t.hasClass(that.currentActionType))
	}).show();
	// update input field value in the case the latter still stores 
	// - the tip value
	// - blank string
	// - or one of search examples of the previous city
	// otherwise we leave it unchanged
	if (this.prevCity) {
		if (this.inputField.val() == this.prevCity.tip || this.inputField.val() == "") {
			this.updateInputFieldValue(this.currentCity.tip);
		}
	}
	//saving current city and action type in cookie
	$.cookie('actionType', this.currentActionType, {path: '/', expire: 0});
	$.cookie('city', this.currentCity.key, {path: '/', expire: 0});
}

;

/**** script/index.js ****/
$(document).ready(function() {
	new SearchForm();
	
	if (typeof OffersStream == "function") {
		var stream = new OffersStream();
		$("#offersStreamButton").click(function() {
			var button = $(this)
			if (button.hasClass("pause")) {
				stream.stop();
				button.removeClass("pause").addClass("play");
			} else {
				stream.start();
				button.removeClass("play").addClass("pause");
			}
		});
	}
	$('.column').each(function() {
		if ($(this).html().length < 40) {
			$(this).hide();
		}
	});
	$('#newsTab').show();

	
})
;

/**** script/jquery-autocomplete.js ****/
/**
 * Extending jQuery with autocomplete
 * Version: 1.4.2
 * Author: Yanik Gleyzer (clonyara)
 */
(function($) {

// some key codes
 var RETURN = 13;
 var TAB = 9;
 var ESC = 27;
 var ARRLEFT = 37;
 var ARRUP = 38;
 var ARRRIGHT = 39;
 var ARRDOWN = 40;
 var BACKSPACE = 8;
 var DELETE = 46;
 
function debug(s){
  $('#info').append(htmlspecialchars(s)+'<br>');
}

// getting caret position obj: {start,end}
function getCaretPosition(obj){
  var start = -1;
  var end = -1;
  if(typeof obj.selectionStart != "undefined"){
	start = obj.selectionStart;
    end = obj.selectionEnd;
  }
  else if(document.selection&&document.selection.createRange){
	var M=document.selection.createRange();
    var Lp;
    try{
      Lp = M.duplicate();
      Lp.moveToElementText(obj);
    }catch(e){
      Lp=obj.createTextRange();
    }
    Lp.setEndPoint("EndToStart",M);
    start=Lp.text.length;
    if(start>obj.value.length)
      start = -1;
    
    Lp.setEndPoint("EndToStart",M);
    end=Lp.text.length;
    if(end>obj.value.length)
      end = -1;
  }
  return {'start':start,'end':end};
}

// set caret to
function setCaret(obj,l){
  obj.focus();
  if (obj.setSelectionRange){
    obj.setSelectionRange(l,l);
  }
  else if(obj.createTextRange){
    m = obj.createTextRange();      
    m.moveStart('character',l);
    m.collapse();
    m.select();
  }
}
// prepare array with velued objects
// required properties are id and value
// rest of properties remaines
function prepareArray(jsondata){
  var new_arr = [];
  for(var i=0;i<jsondata.length;i++){
    if(jsondata[i].id != undefined && jsondata[i].value != undefined){
      jsondata[i].id = jsondata[i].id+"";
      jsondata[i].value = jsondata[i].value+"";
      if(jsondata[i].info != undefined)
        jsondata[i].info = jsondata[i].info+"";
      new_arr.push(jsondata[i]);
    }
  }
  return new_arr;
}
// php analogs
function escapearg(s){
  if(s == undefined || !s) return '';
  return s.replace('\\','\\\\').
           replace('*','\\*').
           replace('.','\\.').
           replace('/','\\/');
}
function htmlspecialchars(s){
  if(s == undefined || !s) return '';
  return s.replace('&','&amp;').
           replace('<','&lt;').
           replace('>','&gt;');
}
function ltrim(s){
  if(s == undefined || !s) return '';
  return s.replace(/^\s+/g,'');
}

// extending jQuery
$.fn.autocomplete = function(options){ return this.each(function(){
  // take me
  var me = $(this);
  var me_this = $(this).get(0);
  var inputFieldValue = new String();

  // test for supported text elements
  if(!me.is('input:text,input:password,textarea'))
  return;

  // get or ajax_get required!
  if(!options && (!$.isFunction(options.get) || !options.ajax_get)){
  return;
  }  
  // check plugin enabled
  if(me.attr('jqac') == 'on') return;

  // plugin on!
  me.attr('jqac','on');

  // no browser's autocomplete!
  me.attr('autocomplete','off');

  // default options
  options = $.extend({ 
                      delay     : 100 ,
                      timeout   : 5000 ,
                      minchars  : 3 ,
                      multi     : false ,
                      cache     : true , 
                      height    : 150 ,
                      autowidth : false ,
                      noresults : 'No results'
                      },
                      options);

  // bind key events
  // handle special keys here
  me.keydown(function(ev){
    switch(ev.which){
      // return choose highlighted item or default propogate
      case RETURN:
        if(!suggestions_menu || !current_highlight) return true;
        else setHighlightedValue();
        return false;
      // escape clears menu
      case ESC:
        clearSuggestions();
        return false;
    }
    return true;
  });
  me.keydown(function(ev){
    // ev.which doesn't work here - it always returns 0
    switch(ev.keyCode){
      case ESC:
        return false;
      // up changes highlight
      case ARRUP:
        changeHighlight(ev.keyCode);
        return false;
      // down changes highlight or open new menu
      case ARRDOWN:
        if(!suggestions_menu) getSuggestions(getUserInput());
        else changeHighlight(ev.keyCode);
        return false;
     }
     return true;
  });
  // handle normal characters here
  me.keyup(function(ev) {
      switch(ev.which) {
        case ESC: case ARRLEFT: case ARRRIGHT: case ARRUP: case ARRDOWN:
          return false;
        default:
          getSuggestions(getUserInput());
      }
      return true;
  });
  
  $('body').click(function(){
		clearSuggestions();
  })

  // init variables
  var user_input = "";
  var input_chars_size  = 0;
  var suggestions = [];
  var current_highlight = 0;
  var suggestions_menu = false;
  var suggestions_list = false;
  var loading_indicator = false;
  var clearSuggestionsTimer = false;
  var getSuggestionsTimer = null;
  var getSuggestionsLoader = null;
  var showLoadingTimer = false;
  var zIndex = '100';

  // get user input
  function getUserInput(){
    var val = me.val();
    if(options.multi){
      var pos = getCaretPosition(me_this);
      var start = pos.start;
      for(;start>0 && val.charAt(start-1) != ',';start--){}
      var end = pos.start;
      for(;end<val.length && val.charAt(end) != ',';end++){}
      var val = val.substr(start,end-start);
    }
    return ltrim(val);
  }
  // set suggestion
  function setSuggestion(val){
    user_input = val;
    if(options.multi){
      var orig = me.val();
      
	  var pos = getCaretPosition(me_this);
	  var start = pos.start;
	  for(;start>0 && orig.charAt(start-1) != ',';start--){}
	  
	  var prevValue = orig.replace(/[^,]*$/, "");
      me.val(prevValue + (prevValue.length > 0 ? ' ' : '') + val);
	  
      setCaret(me_this,start + val.length + (start>0?1:0));
    }
    else{
      me_this.focus();
      me.val(val);
    }
  }
  // get suggestions
  function getSuggestions(val){
    // input length is less than the min required to trigger a request
    // reset input string
    // do nothing
    if (val.length < options.minchars){
      clearSuggestions();
      return false;
    }
    
    user_input = val;
    input_chars_size = val.length;
    killTimeout();
    getSuggestionsTimer = setTimeout( 
      function(){ 
        suggestions = [];
        // call pre callback, if exists
        if($.isFunction(options.pre_callback))
          options.pre_callback();
        // call get
        if($.isFunction(options.get)){
          suggestions = prepareArray(options.get(val));
          createList(suggestions);
        }
        // call AJAX get
        else if($.isFunction(options.ajax_get)){
          clearSuggestions();
          getSuggestionsLoader = options.ajax_get(val,ajax_continuation);
        }
      },
      options.delay 
    );

    return false;
  };
  // AJAX continuation
  function ajax_continuation(jsondata){
    getSuggestionsLoader = null;
    suggestions = prepareArray(jsondata);
    createList(suggestions);
  }
  // create suggestions list
  function createList(arr){
    if(suggestions_menu)
      $(suggestions_menu).remove();
    killTimeout();

    // create holding div
    suggestions_menu = $('<div class="jqac-menu"></div>').get(0);

    // ovveride some necessary CSS properties 
    $(suggestions_menu).css({'position':'absolute',
                             'z-index':zIndex,
                             'max-height':options.height+'px',
                             'overflow-y':'auto'});

    // create and populate ul
    suggestions_list = $('<ul></ul>').get(0);
    // set some CSS's
    $(suggestions_list).
      css('list-style','none').
      css('margin','0px').
      css('padding','2px').
      css('overflow','hidden');
    // regexp for replace 
    var re = new RegExp("("+escapearg(htmlspecialchars(user_input))+")",'ig');
    // loop throught arr of suggestions creating an LI element for each suggestion
    for (var i=0;i<arr.length;i++){
      var val = new String(arr[i].value);
      // using RE
      var output = htmlspecialchars(val).replace(re,'<em>$1</em>');
      // using substr
      //var st = val.toLowerCase().indexOf( user_input.toLowerCase() );
      //var len = user_input.length;
      //var output = val.substring(0,st)+"<em>"+val.substring(st,st+len)+"</em>"+val.substring(st+len);

      var span = $('<span class="jqac-link">'+output+'</span>').get(0);
      if (arr[i].info != undefined && arr[i].info != ""){
        var infoSpan = $('<span class="jqac-info">'+arr[i].info+'</span>');
      }

      $(span).attr('name',i+1);
      $(infoSpan).attr('name',i+1);

      var li = $('<li></li>').get(0);
      $(li).append(infoSpan)
      $(li).append(span);
      $(suggestions_list).append(li);
    }
	
	$(suggestions_list).children().each(function() {
		$(this).mouseover(function(){
					var listItemNumber = $(".jqac-info", this).attr("name");
					setHighlight(listItemNumber, true)
				})
				.click(function(){
					setHighlightedValue();
					return false;
				})
	})

    // no results
    if (arr.length > 0){

	    $(suggestions_menu).append(suggestions_list);
		$(suggestions_list)
		
	
	    // get position of target textfield
	    // position holding div below it
	    // set width of holding div to width of field
	    var pos = me.offset();
	
	    $(suggestions_menu).css('left', pos.left + "px");
	    $(suggestions_menu).css('top', ( pos.top + me.height() + 1 ) + "px");
	    if(!options.autowidth)
	      $(suggestions_menu).width(me.width());
	
	    // set mouseover functions for div
	    // when mouse pointer leaves div, set a timeout to remove the list after an interval
	    // when mouse enters div, kill the timeout so the list won't be removed
	    $(suggestions_menu).mouseover(function(){ killTimeout() });
	    $(suggestions_menu).mouseout(function(){ resetTimeout() });
	
	    // add DIV to document
		//in the case of IE6 we should hide select
		if (jQuery.browser.version == '6.0' && jQuery.browser.msie) {
			$('#sort-select').hide();
		}
				
	    $('body').append(suggestions_menu);
	
	    // bgIFRAME support
	    if($.fn.bgiframe)
	      $(suggestions_menu).bgiframe({height: suggestions_menu.scrollHeight});
	
	
	    // adjust height: add +20 for scrollbar
	    
	    if(suggestions_menu.scrollHeight > options.height){
	      $(suggestions_menu).height(options.height);
	    }
	    
		
	    // currently no item is highlighted
	    current_highlight = 0;
	
	    // remove list after an interval
	    clearSuggestionsTimer = setTimeout(function () { clearSuggestions() }, options.timeout);
	  }
  };
  // set highlighted value
  function setHighlightedValue(){
    if(current_highlight && suggestions[current_highlight-1]){
      var sugg = suggestions[ current_highlight-1 ];
      if(sugg.affected_value != undefined && sugg.affected_value != '')
        setSuggestion(sugg.affected_value);
      else
        setSuggestion(sugg.value);

      // pass selected object to callback function, if exists
      if ($.isFunction(options.callback))
        options.callback( suggestions[current_highlight-1] );

      clearSuggestions();
    }
  };
  // change highlight according to key
  function changeHighlight(key){	
    if(!suggestions_list || suggestions.length == 0) return false;
    var n;
    if (key == ARRDOWN)
      n = current_highlight + 1;
    else if (key == ARRUP)
      n = current_highlight - 1;

    if (n > $(suggestions_list).children().size())
      n = 1;
    if (n < 1)
      n = $(suggestions_list).children().size();
    setHighlight(n);
  };
  // change highlight
  function setHighlight(n,mouse_mode){
    if (!suggestions_list) return false;
    if (current_highlight > 0) clearHighlight();
    current_highlight = Number(n);
    var li = $(suggestions_list).children().get(current_highlight-1);
    li.className = 'jqac-highlight';
    // for mouse mode don't adjust scroll! prevent scrolling jumps
    if(!mouse_mode) adjustScroll(li);
    killTimeout();
  };
  // clear highlight
  function clearHighlight(){
    if (!suggestions_list)return false;
    if (current_highlight > 0){
      $(suggestions_list).children().get(current_highlight-1).className = '';
      current_highlight = 0;
    }
  };
  // clear suggestions list
  function clearSuggestions(){
    killTimeout();
    if(suggestions_menu){
      $(suggestions_menu).remove();
	  $('#sort-select').show();
      suggestions_menu = false;
      suggestions_list = false;
      current_highlight = 0;
    }
  };
  // set scroll
  function adjustScroll(el){
    if(!suggestions_menu) return false;
    var viewportHeight = suggestions_menu.clientHeight;        
    var wholeHeight = suggestions_menu.scrollHeight;
    var scrolled = suggestions_menu.scrollTop;
    var elTop = el.offsetTop;
    var elBottom = elTop + el.offsetHeight;
    if(elBottom > scrolled + viewportHeight){
      suggestions_menu.scrollTop = elBottom - viewportHeight;
    }
    else if(elTop < scrolled){
      suggestions_menu.scrollTop = elTop;
    }
    return true; 
  }
  // timeout funcs
  function killTimeout(){
    if (clearSuggestionsTimer) {
    	clearTimeout(clearSuggestionsTimer);
    }
    if (getSuggestionsLoader) {
    	getSuggestionsLoader.abort();
    }
  };
  function resetTimeout(){
    clearTimeout(clearSuggestionsTimer);
    clearSuggestionsTimer = setTimeout(function () { clearSuggestions() }, 1000);
  };

})};

})($);

;

/**** script/jquery.mousewheel.js ****/
/* Copyright (c) 2006 Brandon Aaron (brandon.aaron@gmail.com || http://brandonaaron.net)
 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
 * Thanks to: http://adomas.org/javascript-mouse-wheel/ for some pointers.
 * Thanks to: Mathias Bank(http://www.mathias-bank.de) for a scope bug fix.
 *
 * $LastChangedDate: 2007-12-20 09:02:08 -0600 (Thu, 20 Dec 2007) $
 * $Rev: 4265 $
 *
 * Version: 3.0
 * 
 * Requires: $ 1.2.2+
 */

(function($) {

$.event.special.mousewheel = {
	setup: function() {
		var handler = $.event.special.mousewheel.handler;
		
		// Fix pageX, pageY, clientX and clientY for mozilla
		if ( $.browser.mozilla )
			$(this).bind('mousemove.mousewheel', function(event) {
				$.data(this, 'mwcursorposdata', {
					pageX: event.pageX,
					pageY: event.pageY,
					clientX: event.clientX,
					clientY: event.clientY
				});
			});
	
		if ( this.addEventListener )
			this.addEventListener( ($.browser.mozilla ? 'DOMMouseScroll' : 'mousewheel'), handler, false);
		else
			this.onmousewheel = handler;
	},
	
	teardown: function() {
		var handler = $.event.special.mousewheel.handler;
		
		$(this).unbind('mousemove.mousewheel');
		
		if ( this.removeEventListener )
			this.removeEventListener( ($.browser.mozilla ? 'DOMMouseScroll' : 'mousewheel'), handler, false);
		else
			this.onmousewheel = function(){};
		
		$.removeData(this, 'mwcursorposdata');
	},
	
	handler: function(event) {
		var args = Array.prototype.slice.call( arguments, 1 );
		
		event = $.event.fix(event || window.event);
		// Get correct pageX, pageY, clientX and clientY for mozilla
		$.extend( event, $.data(this, 'mwcursorposdata') || {} );
		var delta = 0, returnValue = true;
		
		if ( event.wheelDelta ) delta = event.wheelDelta/120;
		if ( event.detail     ) delta = -event.detail/3;
//		if ( $.browser.opera  ) delta = -event.wheelDelta;
		
		event.data  = event.data || {};
		event.type  = "mousewheel";
		
		// Add delta to the front of the arguments
		args.unshift(delta);
		// Add event to the front of the arguments
		args.unshift(event);

		return $.event.handle.apply(this, args);
	}
};

$.fn.extend({
	mousewheel: function(fn) {
		return fn ? this.bind("mousewheel", fn) : this.trigger("mousewheel");
	},
	
	unmousewheel: function(fn) {
		return this.unbind("mousewheel", fn);
	}
});

})(jQuery);
;
