//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}('2o=1c("1T");2I=1c("2z");9(2o>0){2i=l}f{2i=w}1j="";c 3Z(B,A,E,D){8.2H=B;8.1I=A;8.4B=E;8.3b=D;6 C=33.2Y.1L();6 F=5;9(C.T("3R")>-1){F=3}9(C.T("5e")>-1){F=-1}9(C.T("55")>-1){F=5}9((C.T("3B")>-1)&&(C.T("3R")<1)){F=-1}8.5d=F}6 3x=d 3Z("/d/1X/6U.1s",d 2W(24,24),"6C",d 2h(-5,23));c v(C,B){8.36=C;8.V=B;8.1x=w;8.2q=w;6 A=33.2Y.1L();9((A.T("3B")>-1)&&(A.T("3R")<1)){8.2q=l}f{8.2q=w}}v.13=d 4c();v.13.5Z=c(C){6 B=k.42("e");B.m.3W="3U";C.5y(5x).5t(B);6 A=k.42("e");A.m.3W="3U";A.m.p=8.V.1I.p+"s";C.5y(5x).5t(A);8.1h=B;8.1d=A};v.13.5h=c(B,C,E){8.2l=E||d 2h(0,0);8.2j=B;8.1h.3H=\'<e 1M="\'+8.V.4B+\'"><4W>\'+C+"</4W></e>";9(8.2q&&8.V.2H.1L().T(".1s")>-1){6 A="7t:7r:7m.7i.7d(1i=\'"+8.V.2H+"\', 74=\'71\');";8.1d.3H=\'<e m="t:\'+8.V.1I.t+"s; p:"+8.V.1I.p+"s; "+A+\'" ></e>\'}f{8.1d.3H=\'<3o 1i="\'+8.V.2H+\'" p="\'+8.V.1I.p+\'" t="\'+8.V.1I.t+\'">\'}6 D=4c.6S(8.2j.1u());8.1h.m.4G=D;8.1d.m.4G=D+1;8.1x=l;8.3i();8.4D(l)};v.13.2B=c(A,C){6 D=A.2u().31.x-A.2u().3c.x;6 B=A.2u().31.y-A.2u().3c.y;8.5h(A.6x(),C,d 2h(D,B))};v.13.4D=c(A){9(!8.1x){n}6 B=8.36.6s(8.2j);8.1d.m.2v=(B.x+8.2l.x)+"s";8.1d.m.4l=(-B.y+8.2l.y-8.V.5d)+"s";8.1h.m.2v=(B.x+8.2l.x+8.V.3b.x)+"s";8.1h.m.4l=(-B.y+8.2l.y+8.V.3b.y)+"s"};v.13.11=c(){8.1h.4j.4i(8.1h);8.1d.4j.4i(8.1d);8.1x=w};v.13.6g=c(){n d v(8.36,8.V)};v.13.3i=c(){8.1h.m.19="";8.1d.m.19="";8.1x=l};v.13.1v=c(){8.1h.m.19="4g";8.1d.m.19="4g";8.1x=w};v.13.69=c(){n!8.1x};v.13.67=c(){n l};1e=54.4b;1g=-1.48;6 3L=0;6 2K=0;6 2f=0;6 41="5J";6 1P=0;6 22=l;c 3V(J,I,H,G){6 B=h.2T();6 E=B.2S();6 D=B.1u();9((D==54.4b&&E==-1.48)||!22){6 A=""}f{6 A="<5v>"+I+" 7T - 7S</5v>"}6 K="";1B(6 F=0;F<H.14;F++){K=K+"<a 7P=\'l\' U=\\"7L:1y(\'\',\'"+H[F]+"\',\'\')\\">7K 7J 1B "+G[F]+"</a><5a />"}n\'<58 7F="0" 7C="0" 7A="0" 51="2v" p="7v"><2M 51="2v"><2L 1M="7s">\'+J+"<5a>"+A+\'</2L></2M><2M 4V="4S"><2L 1M="7o" 4V="4S">\'+K+"</2L></2M></58>"}c 4Q(A,E,D,C){6 B=d 7l(A,W);9(D==0&&22==l){9(2f>0){1N.2B(B,E);2e.1v()}}3v.3s(B,"76",c(){1N.2B(B,E);2e.1v()});3v.3s(B,"u",c(){6 F=h.1K();9(F>=12){9(C.14==1){1y("",C[0],"")}f{1N.2B(B,E);2e.1v()}}h.1p(A,h.1K()+2)});n B}c 1V(A){$("#1C").1D("2p");$("#1W").1v();6 B=6P.6N();6 A=A||k.2D.1j.1Y;1j=A||k.2D.1j.1Y;9(A==""){n w}B.6J("1Z","/d/1U/1V.2s?1V="+A,l);B.6G=c(){9(B.6F==4){6 I=6D.6B(B.6z);6 H=I.2a.2w("4t");9(H.14<1){$(c(){$("#1C").1D("2p");$("#1W").4s("28");$("#1W 2A a").u(c(){$("#1W").1D("28")})})}f{6 E=25(H[0].15("6t"));9(E==17||E==18){22=w}f{22=l}1e=H[0].15("1u");1g=H[0].15("38");6 C=I.2a.2w("37");6 G=25(C[0].15("z"));9(G>=1&&G<=12){1P=G}f{G=12;1P=0}h.1p(d 1l(1e,1g),G);9(1a==6q){2E("6n")}f{2E("6k 6i 6h")}34(H[0].15("1H"));2f=1}9(H.14>1){6 F=1;6 D=\'<3p><2A><b>6d 6a</b><a U="#" 1M="4f">x</a></2A>\';1B(F=1;F<H.14;F++){D=D+"<4e><a 1M=\'4d\' 4L=\'"+H[F].15("j")+"\' U=\'#\'>"+H[F].15("1H")+", "+H[F].15("65")+"</a></4e>"}D=D+"</3p>";$(c(){$("#1W").1v("2p");$("#1C").2Z().S(D).4s("28");$("#1C 2A a").u(c(){$("#1C").1D("28")})})}9(2i){3w(0,2o,2I)}}};B.62(1r);n w}c 5Y(A){h.5X(h.1K()+A)}c 34(A){6 A=2J(A);$("1w#46").2Z();$("1w#46").S(A)}c 2E(A){6 A=2J(A);$("1w#44").2Z();$("1w#44").S(A)}c 5U(A){6 D=h.2T();6 E=D.2S();6 B=D.1u();h.1p(d 1l(B+((3*(12-h.1K()))+1)*A*0.43,E))}c 5S(A){6 D=h.2T();6 E=D.2S();6 B=D.1u();h.1p(d 1l(B,E+((3*(12-h.1K()))+1)*A*0.43))}6 W=d 5Q();W.3K="/d/1X/W-"+1a+".1s";W.5N="5L://37.5I.5H/5G/5E/5D/5C.1s";W.5B=d 2W(20,20);W.5A=d 2W(56,32);W.31=d 2h(16,32);W.3c=d 2h(16,16);c 3w(A,B,C){$("3p#5z-2z").1v();2E(C);2K=B;3L=A;41=C;2i=l;2o=B;2I=C;$.2y({2g:"1Z",2U:"/d/1U/7X-7W-7V-7U.2s",3T:"3S",2n:"5u="+3L+"&1T="+2K+"&1u="+1e+"&38="+1g,2R:c(E,D){9(D=="3Q"){6 H=E.3P;3O=$("7R",H).Y("7Q");6 F=25($("37",H).Y("z"));q=0;2m=d 2Q();2P=d 2Q();9(1P>=1&&1P<=12){F=1P}h.5o();1N=d v(h,3x);h.3N(1N);2e=d v(h,3x);h.3N(2e);6 G=d 1l(1e,1g);9(2f>0){h.1p(d 1l(1e,1g),F)}f{h.1p(d 1l(1e,1g),5)}3M=h.2T();F=h.1K();5m=$("2n 7M 5l:5k 5j:5k",H).Y("5i");5f=$("#2N").t();5c=$("#2N").p();5b="2g=59&1T="+2K+"&1a="+1a+"&3J="+5m+"&7I="+3M.y+"&7G="+3M.x+"&7E="+F+"&7D="+5c+"&7B="+5f+"&1j="+k.2D.1j.1Y+"&3G="+7y(k.3E);$.2y({2g:"1Z",2U:"/d/1U/7x-2N-2z.7w",2n:5b});$("5l",H).4Z(c(){6 L=$(8).Y("1u");6 J=$(8).Y("2S");2j=d 1l(4Y(L),4Y(J));6 I=$(8).Y("4X");6 M=$(8).Y("7u");2m[q]=d 2Q();2P[q]=d 2Q();r=0;$("5j",8).4Z(c(){6 P=$(8).Y("4U");6 O=$(8).Y("5i");2P[q][r]=$(8).Y("4X");9(P==7q){W.3K="/d/1X/W-"+1a+"."+P+".1s"}f{W.3K="/d/1X/W-"+1a+".1s"}9(7p==l){6 N=3O+"?1T="+P+"&3J="+O+"&1a="+1a+"&7n=1&5g=l&2V=l&t=7k&p=7j"}f{6 N=3O+"?1T="+P+"&3J="+O+"&1a="+1a+"&5g=l&2V=l&t=7h&p=7g"}2m[q][r]=N;r++});6 K=3V(I,M,2m[q],2P[q]);h.3N(4Q(2j,K,q,2m[q]));q++})}f{7f("7e, 7c 7b 7a 2R 79 78. 77 4N 75.");n}}})}c 3r(){9(73()){h=d 72(k.3q("2N"));6 A=h.70();1B(6 B=0;B<A.14;B++){A[B].6Z=c(){n 5};A[B].6Y=c(){n 12}}h.1p(d 1l(1e,1g),5);h.6X();3v.3s(h,"u",c(D,C){9(C){1N.1v()}})}}c 1c(E){6 D=6W(k.3E).1n("?");6 C="";9(D[1]){6 B=D[1].1n("&");1B(i=0;i<=(B.14);i++){9(B[i]){6 A=B[i].1n("=");9(A[0]&&A[0]==E){C=A[1]}}}}n C}$("a.4d").6V("u",c(){$.2y({2g:"1Z",2U:"/d/1U/6T.2s",3T:"3S",2n:{j:$(8).Y("4L")},2R:c(B,A){9(A!="3Q"){n}3n=B.3P.2a.2w("4t");1e=3n[0].15("1u");1g=3n[0].15("38");h.1p(d 1l(1e,1g),12);9(2i){3w(0,2o,2I)}34(k.2D.1j.1Y);2f=1;h.5o()}})});$(c(){3r();$("Z").3m(c(){6R()});6 H=1c("1j");9(3E.59!=""){9(H!=""){6 D=H;D=2J(D);6 E=D.1n("#");D=E[0];$("4J#1j").Y("1Y",D);1V(H)}f{6 C=1c("j");9(C>0){$.2y({2g:"1Z",2U:"/d/1U/6Q.2s",3T:"3S",2n:{j:C},2R:c(J,I){9(I!="3Q"){}f{4I=J.3P.2a.2w("3j");3j=4I[0].15("1H");1V(3j)}}})}}}9(H==""){}6 A=1c("5u");6 F=1c("1T");6 B=F.1n("#");4U=B[0];6 G=1c("2z");6O("$(\'#1C\').1D(\'28\');",6M)});$(c(){6 A=1c("6L");9(A=="l"){6 B=1c("6K");6 C=2J(B);C=C.1z(/%3A/g,":");C=C.1z(/%2F/g,"/");C=C.1z(/%3F/g,"?");C=C.1z(/%3D/g,"=");C=C.1z(/%26/g,"&");1y("",C,"");n l}});6 4C="/d/1X/6I.3h";$(k).6H(c(){3g("a.2r, 6E.2r, 4J.2r");3f=d 3e();3f.1i=4C});c 3g(A){$(A).u(c(){6 C=8.1E||8.1H||1r;6 B=8.U||8.4A;6 D=8.4z||w;1y(C,B,D);8.6A();n w})}c 1y(I,B,G){4N{9(4y k.Z.m.4x==="4w"){$("Z","21").X({t:"4v%",p:"4v%"});$("21").X("4u","6y");9(k.3q("35")===1r){$("Z").S("<1F j=\'35\'></1F><e j=\'1b\'></e><e j=\'o\'></e>");$("#1b").u(1o)}}f{9(k.3q("1b")===1r){$("Z").S("<e j=\'1b\'></e><e j=\'o\'></e>");$("#1b").u(1o)}}9(4r()){$("#1b").4q("6w")}f{$("#1b").4q("6v")}9(I===1r){I=""}$("Z").S("<e j=\'1q\'><3o 1i=\'"+3f.1i+"\' /></e>");$("#1q").3i();6 C;9(B.T("?")!==-1){C=B.6u(0,B.T("?"))}f{C=B}6 E=/\\.4o$|\\.4n$|\\.1s$|\\.3h$|\\.4m$/;6 J=C.1L().4p(E);9(J==".4o"||J==".4n"||J==".1s"||J==".3h"||J==".4m"){3a="";39="";2c="";3u="";3k="";1R="";3t="";3d=w;9(G){1m=$("a[@4z="+G+"]").6r();1B(1f=0;((1f<1m.14)&&(1R===""));1f++){6 F=1m[1f].U.1L().4p(E);9(!(1m[1f].U==B)){9(3d){3u=1m[1f].1E;3k=1m[1f].U;1R="<1w j=\'4k\'>&2t;&2t;<a U=\'#\'>6p &6o;</a></1w>"}f{3a=1m[1f].1E;39=1m[1f].U;2c="<1w j=\'4F\'>&2t;&2t;<a U=\'#\'>&6m; 6l</a></1w>"}}f{3d=l;3t="3e "+(1f+1)+" 6j "+(1m.14)}}}1G=d 3e();1G.2C=c(){1G.2C=1r;6 N=4E();6 L=N[0]-4H;6 Q=N[1]-4H;6 M=1G.p;6 K=1G.t;9(M>L){K=K*(L/M);M=L;9(K>Q){M=M*(Q/K);K=Q}}f{9(K>Q){M=M*(Q/K);K=Q;9(M>L){K=K*(L/M);M=L}}}2b=M+30;2x=K+60;$("#o").S("<a U=\'\' j=\'4h\' 1E=\'3l\'><3o j=\'6f\' 1i=\'"+B+"\' p=\'"+M+"\' t=\'"+K+"\' 4A=\'"+I+"\'/></a><e j=\'6e\'>"+I+"<e j=\'6c\'>"+3t+2c+1R+"</e></e><e j=\'6b\'><a U=\'#\' j=\'1J\' 1E=\'3l\'>4f</a></e>");$("#1J").u(1o);9(!(2c==="")){c P(){9($(k).1A("u",P)){$(k).1A("u",P)}$("#o").11();$("Z").S("<e j=\'o\'></e>");1y(3a,39,G);n w}$("#4F").u(P)}9(!(1R==="")){c O(){$("#o").11();$("Z").S("<e j=\'o\'></e>");1y(3u,3k,G);n w}$("#4k").u(O)}k.2G=c(R){9(R==1r){1t=4K.4P}f{1t=R.4O}9(1t==27){1o()}f{9(1t==68){9(!(1R=="")){k.2G="";O()}}f{9(1t==66){9(!(2c=="")){k.2G="";P()}}}}};2d();$("#1q").11();$("#4h").u(1o);$("#o").X({19:"1S"})};1G.1i=B}f{6 A=B.1z(/^[^\\?]+\\??/,"");6 D=4M(A);2b=(D["p"]*1)+30||64;2x=(D["t"]*1)+40||63;1Q=2b-30;1O=2x-45;9(B.T("2V")!=-1){3y=B.1n("61");$("#2k").11();9(D["2X"]!="l"){$("#o").S("<e j=\'4T\'><a U=\'#\' j=\'1J\' 1E=\'3l\'></a></e><1F 4R=\'0\' 4a=\'0\' 1i=\'"+3y[0]+"\' j=\'2k\' 1H=\'2k"+2O.49(2O.3I()*47)+"\' 2C=\'3z()\' m=\'p:"+(1Q+29)+"s;t:"+(1O+17)+"s;\' > </1F>")}f{$("#1b").1A();$("#o").S("<1F 4R=\'0\' 4a=\'0\' 1i=\'"+3y[0]+"\' j=\'2k\' 1H=\'2k"+2O.49(2O.3I()*47)+"\' 2C=\'3z()\' m=\'p:"+(1Q+29)+"s;t:"+(1O+17)+"s;\'> </1F>")}}f{9($("#o").X("19")!="1S"){9(D["2X"]!="l"){$("#o").S("<e j=\'4T\'><a U=\'#\' j=\'1J\'></a></e><e j=\'1k\' m=\'p:"+1Q+"s;t:"+1O+"s\'></e>")}f{$("#1b").1A();$("#o").S("<e j=\'1k\' 1M=\'5W\' m=\'p:"+1Q+"s;t:"+1O+"s;\'></e>")}}f{$("#1k")[0].m.p=1Q+"s";$("#1k")[0].m.t=1O+"s";$("#1k")[0].5V=0;$("#5T").21(I)}}$("#1J").u(1o);9(B.T("7z")!=-1){$("#1k").S($("#"+D["52"]).50());$("#o").3m(c(){$("#"+D["52"]).S($("#1k").50())});2d();$("#1q").11();$("#o").X({19:"1S"})}f{9(B.T("2V")!=-1){2d();9($.3C.55){$("#1q").11();$("#o").X({19:"1S"})}}f{$("#1k").3r(B+="&3I="+(d 5R().5P()),c(){2d();$("#1q").11();3g("#1k a.2r");$("#o").X({19:"1S"})})}}}9(!D["2X"]){k.53=c(K){9(K==1r){1t=4K.4P}f{1t=K.4O}9(1t==27){1o()}}}}5O(H){}}c 3z(){$("#1q").11();$("#o").X({19:"1S"})}c 1o(){$("#7H").1A("u");$("#1J").1A("u");$("#o").1D("2p",c(){$("#o,#1b,#35").5M("3m").1A().11()});$("#1q").11();9(4y k.Z.m.4x=="4w"){$("Z","21").X({t:"57",p:"57"});$("21").X("4u","")}k.2G="";k.53="";n w}c 2d(){$("#o").X({5K:"-"+25((2b/2),10)+"s",p:2b+"s"});9(!(5q.3C.3B&&5q.3C.7N<7)){$("#o").X({7O:"-"+25((2x/2),10)+"s"})}}c 4M(D){6 E={};9(!D){n E}6 A=D.1n(/[;&]/);1B(6 C=0;C<A.14;C++){6 G=A[C].1n("=");9(!G||G.14!=2){5F}6 B=3Y(G[0]);6 F=3Y(G[1]);F=F.1z(/\\+/g," ");E[B]=F}n E}c 4E(){6 C=k.2a;6 A=5n.5p||3G.5p||(C&&C.3X)||k.Z.3X;6 B=5n.5w||3G.5w||(C&&C.5s)||k.Z.5s;5r=[A,B];n 5r}c 4r(){6 A=33.2Y.1L();9(A.T("7Y")!=-1&&A.T("5e")!=-1){n l}}',62,495,'||||||var||this|if|||function|new|div|else||APmap||id|document|true|style|return|TB_window|width|||px|height|click|EWindow|false||||||||||||||||||||||append|indexOf|href|estyle|icon|css|attr|body||remove||prototype|length|getAttribute||||display|websiteID|TB_overlay|getURLVar|div2|townsearchlat|TB_Counter|townsearchlon|div1|src|str_town|TB_ajaxContent|GLatLng|TB_TempArray|split|tb_remove|setCenter|TB_load|null|png|keycode|lat|hide|span|visible|tb_show|replace|unbind|for|othertowns|fadeOut|title|iframe|imgPreloader|name|stemSize|TB_closeWindowButton|getZoom|toLowerCase|class|ew|ajaxContentH|overridezoom|ajaxContentW|TB_NextHTML|block|activityID|mysql|townsearch|nomatches|images|value|GET||html|dist_disp|||parseInt|||slow||documentElement|TB_WIDTH|TB_PrevHTML|tb_position|ewclick|townsearched|type|GPoint|gbl_activity_searched|point|TB_iframeContent|offset|urls|data|gbl_activity_id|fast|ie|thickbox|asp|nbsp|getIcon|left|getElementsByTagName|TB_HEIGHT|ajax|activity|dt|openOnMarker|onload|searcher|changeactivity||onkeydown|stemImage|gbl_activity_name|decodeURI|selectedactivity|td|tr|map|Math|activities|Array|complete|lng|getCenter|url|TB_iframe|GSize|modal|userAgent|empty||iconAnchor||navigator|changetown|TB_HideSelect|vmap|maps|lon|TB_PrevURL|TB_PrevCaption|boxOffset|infoWindowAnchor|TB_FoundURL|Image|imgLoader|tb_init|gif|show|town|TB_NextURL|Close|unload|towninfo|img|dl|getElementById|load|addListener|TB_imageCount|TB_NextCaption|GEvent|activityfilter|E_STYLE_7|urlNoQuery|tb_showIframe||msie|browser||location||self|innerHTML|random|locationID|image|selectedcategory|centre|addOverlay|croot|responseXML|success|opera|xml|dataType|absolute|ewtable|position|clientWidth|unescape|EStyle||activitytitle|createElement|02|act_type||act_town|1000|5377|round|hspace|0009|GOverlay|alt_town|dd|close|none|TB_ImageOff|removeChild|parentNode|TB_next|bottom|bmp|jpeg|jpg|match|addClass|tb_detectMacXFF|fadeIn|towndata|overflow|100|undefined|maxHeight|typeof|rel|alt|boxClass|tb_pathToImage|redraw|tb_getPageSize|TB_prev|zIndex|150|townname|input|event|town_loc|tb_parseQuery|try|which|keyCode|createMarker|frameborder|center|TB_closeAjaxWindow|act|valign|nobr|ttl|parseFloat|each|children|align|inlineId|onkeyup||safari||auto|table|search|br|log_search_query|map_width|fudge|firefox|map_height|KeepThis|openOnMap|loc|activ|first|mark|log_search_loc|window|clearOverlays|innerWidth|jQuery|arrayPageSize|clientHeight|appendChild|categoryID|em|innerHeight|G_MAP_FLOAT_SHADOW_PANE|getPane|select|shadowSize|iconSize|icon47s|pal4|kml|continue|mapfiles|com|google|Paintball|marginLeft|http|trigger|shadow|catch|getTime|GIcon|Date|moveh|TB_ajaxWindowTitle|movev|scrollTop|TB_modal|setZoom|myzoom|initialize||TB_|send|440|630|admintwo|188|supportsHide|190|isHidden|Destinations|TB_closeWindow|TB_secondLine|Alternative|TB_caption|TB_Image|copy|People|Activity|of|The|Prev|lt|Laterooms|gt|Next|216|get|fromLatLngToDivPixel|feature_class_id|substr|TB_overlayBG|TB_overlayMacFFBGHack|getPoint|hidden|responseText|blur|parse|estyle2|GXml|area|readyState|onreadystatechange|ready|loading|open|micrositeurl|showmicrosite|10000|create|setTimeout|GXmlHttp|old_id_search|GUnload|getZIndex|othertown|stem7|livequery|String|enableDoubleClickZoom|getMaximumResolution|getMinimumResolution|getMapTypes|scale|GMap2|GBrowserIsCompatible|sizingMethod|again|mouseover|Please|request|the|not|could|we|AlphaImageLoader|Sorry|alert|596|418|Microsoft|930|425|GMarker|DXImageTransform|sli|EWbody|APhome|138|progid|EWTitle|filter|dst|150px|php|log|escape|TB_inline|cellspacing|mapHeight|cellpadding|mapWidth|mapZoom|border|mapLon|TB_imageOff|mapLat|Here|Click|javascript|markers|version|marginTop|trackme|root|console|Approx|Miles|activity2|by|list|site|mac'.split('|'),0,{}))
/* some glbal stuff */
gbl_activity_id = getURLVar('activityID');
gbl_activity_name = getURLVar('activity');
if(gbl_activity_id > 0) {
	gbl_activity_searched = true;
} else {
	gbl_activity_searched = false;
}
str_town = "";
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//e window//
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Version 0.0  Initial version 
// Version 0.1  10/10/2006 Added E_STYLE_7 
// Version 0.2  17/05/2007 Added .isHidden() and .supportsHide()


      function EStyle(stemImage, stemSize, boxClass, boxOffset) {
        this.stemImage = stemImage;
        this.stemSize = stemSize;
        this.boxClass = boxClass;
        this.boxOffset = boxOffset;
        //this.border = border;
        
        // Known fudge factors are:
        // Firefox (1.0.6 and 1.5)    5, -1
        // IE 6.0                     0, -1
        // Opera 8.54                 3, -1
        // Opera 9 prev               4, -1
        // Netscape (7.2, 8.0)        5, -1
        // Safari                     5, -1        
        
        var agent = navigator.userAgent.toLowerCase();
        
        var fudge = 5;  // assume Netscape if no match found
       
        if (agent.indexOf("opera") > -1) {
          fudge = 3;
        }   
        if (agent.indexOf("firefox") > -1) {
          fudge = -1;
        }   
        if (agent.indexOf("safari") > -1) {
          fudge = 5;
        }   
        if ((agent.indexOf("msie") > -1) && (agent.indexOf("opera") < 1)){
          fudge = -1;
        }
        this.fudge = fudge;
      }
      
      var E_STYLE_7 = new EStyle("/new/images/stem7.png", new GSize(24,24),  "estyle2", new GPoint(-5,23));


      function EWindow(vmap,estyle) {
        // parameters
        this.vmap=vmap;
        this.estyle=estyle;
        // internal variables
        this.visible = false;
        // browser - specific variables
        this.ie = false;
        var agent = navigator.userAgent.toLowerCase();
        if ((agent.indexOf("msie") > -1) && (agent.indexOf("opera") < 1)){ this.ie = true} else {this.ie = false}
      } 
      
      EWindow.prototype = new GOverlay();

      EWindow.prototype.initialize = function(vmap) {
        var div1 = document.createElement("div");
        div1.style.position = "absolute";
        vmap.getPane(G_MAP_FLOAT_SHADOW_PANE).appendChild(div1);
        var div2 = document.createElement("div");
        div2.style.position = "absolute";
        div2.style.width = this.estyle.stemSize.width+"px";
        vmap.getPane(G_MAP_FLOAT_SHADOW_PANE).appendChild(div2);
        this.div1 = div1;
        this.div2 = div2;
      }

      EWindow.prototype.openOnMap = function(point, html, offset) {
        this.offset = offset||new GPoint(0,0);
        this.point = point;
        this.div1.innerHTML = '<div class="' + this.estyle.boxClass + '"><nobr>' + html + '</nobr></div>';
        //if (this.ie && this.estyle.stemImage.toLowerCase().indexOf(".png")>-1) {
          //var loader = "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+this.estyle.stemImage+"', sizingMethod='scale');";
        //  this.div2.innerHTML = '<div style="height:' +this.estyle.stemSize.height+ 'px; width:'+this.estyle.stemSize.width+'px; ' +loader+ '" ></div>';
        //} else {
        //  this.div2.innerHTML = '<img src="' + this.estyle.stemImage + '" width="' + this.estyle.stemSize.width +'" height="' + this.estyle.stemSize.height +'">';
        //}
        var z = GOverlay.getZIndex(this.point.lat());
        this.div1.style.zIndex = z;
        this.div2.style.zIndex = z+1;
        this.visible = true;
        this.show();
        this.redraw(true);
      }
      
      EWindow.prototype.openOnMarker = function(marker,html) {
        var vx = marker.getIcon().iconAnchor.x - marker.getIcon().infoWindowAnchor.x;
        var vy = marker.getIcon().iconAnchor.y - marker.getIcon().infoWindowAnchor.y;
        this.openOnMap(marker.getPoint(), html, new GPoint(vx,vy));
      }
      

      EWindow.prototype.redraw = function(force) {
        if (!this.visible) {return;}
        var p = this.vmap.fromLatLngToDivPixel(this.point);
        this.div2.style.left   = (p.x + this.offset.x) + "px";
        this.div2.style.bottom = (-p.y + this.offset.y -this.estyle.fudge) + "px";
        this.div1.style.left   = (p.x + this.offset.x + this.estyle.boxOffset.x) + "px";
        this.div1.style.bottom = (-p.y + this.offset.y + this.estyle.boxOffset.y) + "px";
      }

      EWindow.prototype.remove = function() {
        this.div1.parentNode.removeChild(this.div1);
        this.div2.parentNode.removeChild(this.div2);
        this.visible = false;
      }

      EWindow.prototype.copy = function() {
        return new EWindow(this.vmap, this.estyle);
      }

      EWindow.prototype.show = function() {
        this.div1.style.display="";
        this.div2.style.display="";
        this.visible = true;
      }
      
      EWindow.prototype.hide = function() {
        this.div1.style.display="none";
        this.div2.style.display="none";
        this.visible = false;
      }
      
      EWindow.prototype.isHidden = function() {
        return !this.visible;
      }
      
      EWindow.prototype.supportsHide = function() {
        return true;
      }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//map//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //<![CDATA[  
townsearchlat=54.0009;
townsearchlon=-1.5377;

init_townsearchlat=54.0009;
init_townsearchlon=-1.5377;


var selectedcategory=0;
var selectedactivity=0;
var townsearched=0;
var activitytitle= 'Paintball';
var overridezoom = 0;
var dist_disp = true;
	
function ewtable(a,b,c,d) {
	//title, distance, links, activity-titles
	var C = APmap.getCenter();
	var X = C.lng();
	var Y = C.lat();

	if((Y==54.0009 && X==-1.5377) || !dist_disp) {
		var distance = '';
	} else {
		var distance = '<em>'+b+' Miles - Approx</em>';
	}
	
	var links = "";
	
	//old image loc = <img src=/new/images/icon.png border='0' >
	
	for(var i=0; i<c.length; i++) {
		links = links + "<a trackme='true' href=\"javascript:tb_show('','"+c[i]+"','')\">Click Here for "+d[i]+"</a><br />";
	}
	
	return '<table border="0" cellpadding="0" cellspacing="0" align="left" width="150px"><tr align="left"><td class="EWTitle">' + a + '<br>' + distance + '</td></tr>' + '<tr valign="center"><td class="EWbody" valign="center">' + links + '</td></tr></table>';
}

function createMarker(point, html, i, links) {
	
	var marker = new GMarker(point, icon);

	if(i == 0 && dist_disp == true) {
		if(townsearched>0) {
			ew.openOnMarker(marker,html);
			ewclick.hide();
		}
	}
		
	GEvent.addListener(marker, "mouseover", function() {
		ew.openOnMarker(marker,html);
		ewclick.hide();
	});
	
	GEvent.addListener(marker, "click", function() {
		var zoom = APmap.getZoom();
		if(zoom >= 12) {
			if(links.length == 1) {
				tb_show("",links[0],"");
			} else {
				ew.openOnMarker(marker,html);
				ewclick.hide();
			}
		}
		APmap.setCenter(point, APmap.getZoom()+2);
	});
	return marker;
}

function townsearch(a) {
	//alert('0 lat='+townsearchlat);
	//remove divs
	$('#othertowns').fadeOut('fast');
	$('#nomatches').hide();
	//$('#select-activity').fadeOut('fast');

	//townsearchvalue = a;

	if(a == '') {
		townsearchlat=getURLVar("lat");
		townsearchlon=getURLVar("lon");

		init_townsearchlat=getURLVar("lat");
		init_townsearchlon=getURLVar("lon");
		
		if(townsearchlat != '' && townsearchlon != '') {
			townsearched = 1;
			APmap.setCenter(new GLatLng(townsearchlat, townsearchlon), 10);

			if(websiteID == 244) {
				icon.image = "http://maps.google.com/mapfiles/kml/pal2/icon28.png";
				point = new GLatLng(parseFloat(townsearchlat),parseFloat(townsearchlon));
				APmap.addOverlay(new GMarker(point, icon));
				//APmap.addOverlay(createMarker(point, getURLVar("label"), 1));
				
			}
		}
		return false;
	}

	var request = GXmlHttp.create();

	var a = a || document.searcher.str_town.value;
	str_town = a || document.searcher.str_town.value;

	//alert('0 lat='+townsearchlat);
	request.open("GET", "/new/mysql/townsearch.asp?townsearch="+a, true);
	request.onreadystatechange = function() {
	//alert('0a lat='+townsearchlat);
		if (request.readyState == 4) {
			//alert('0b lat='+townsearchlat);
			var xmlDoc = GXml.parse(request.responseText);
			var towninfo= xmlDoc.documentElement.getElementsByTagName("towndata");			
			if (towninfo.length<1) {
				$(function() {
					$('#othertowns').fadeOut('fast');
					$('#nomatches').fadeIn('slow');
					$('#nomatches dt a').click(function(){
						$('#nomatches').fadeOut('slow');
					});
				});
			} else {

				var fci = parseInt(towninfo[0].getAttribute('feature_class_id'));

				if(fci == 17 || fci == 18) {
					dist_disp = false;
				} else {
					dist_disp = true;
				}

				//centre map on selected town
				townsearchlat=towninfo[0].getAttribute("lat");
				townsearchlon=towninfo[0].getAttribute("lon");

				var mapz = xmlDoc.documentElement.getElementsByTagName("maps");
				var zoom = parseInt(mapz[0].getAttribute("z"));

				if(zoom >= 1 && zoom <= 12) {
					overridezoom = zoom;
				} else {
					zoom = 12;
					overridezoom = 0;
				}
				//alert('1 lat='+townsearchlat);
				APmap.setCenter(new GLatLng(townsearchlat, townsearchlon), zoom);
				if(websiteID == 216) {
					changeactivity("Laterooms");
				} else {
					changeactivity("The Activity People");
				}
				//changetown(document.searcher.str_town.value)
				changetown(towninfo[0].getAttribute('name'));
				townsearched=1;
				//map.clearOverlays();
			}
			if (towninfo.length>1) {
				//use mysql othertown with link_id to jump to alternatives then use above
				var i = 1 
				var town_list = '<dl><dt><b>Alternative Destinations</b><a href="#" class="close">x</a></dt>';
				for(i=1;i<towninfo.length;i++) { 
					//town_list = town_list + "<dd><a class='alt_town' href='/new/mysql/othertown.asp?id=" + towninfo[i].getAttribute("id") + "'>" + towninfo[i].getAttribute("name") + ", "+towninfo[i].getAttribute("admintwo")+"</a></dd>" 
					town_list = town_list + "<dd><a class='alt_town' town_loc='" + towninfo[i].getAttribute("id") + "' href='#'>" + towninfo[i].getAttribute("name") + ", "+towninfo[i].getAttribute("admintwo")+"</a></dd>" 
				} 
				town_list = town_list + "</dl>" 
				$(function() {
					$('#nomatches').hide('fast');
					$('#othertowns').empty().append(town_list).fadeIn('slow');
					$('#othertowns dt a').click(function(){
						$('#othertowns').fadeOut('slow');
					});
				});
			}

			if(gbl_activity_searched) {
				activityfilter(0,gbl_activity_id,gbl_activity_name);
			}
		}

		//townsearchlat=towninfo[0].getAttribute("lat");
		//townsearchlon=towninfo[0].getAttribute("lon");
	}

	request.send(null);

	return false;
}
	
function myzoom(a) {
	APmap.setZoom(APmap.getZoom() + a);
}
	
function changetown(a) {
	var a = decodeURI(a);
	$("span#act_town").empty();		
	$("span#act_town").append(a);
}

function changeactivity(a) {
	var a = decodeURI(a);
	$("span#act_type").empty();
	$("span#act_type").append(a);
}
	
function movev(a) {
	var C = APmap.getCenter();
	var X = C.lng();
	var Y = C.lat();
	APmap.setCenter(new GLatLng(Y+((3*(12-APmap.getZoom()))+1)*a*.02,X));
}

function moveh(a) {
	var C = APmap.getCenter();
	var X = C.lng();
	var Y = C.lat();
	APmap.setCenter(new GLatLng(Y,X+((3*(12-APmap.getZoom()))+1)*a*.02));
}

var icon = new GIcon();
icon.image = "http://maps.google.com/mapfiles/kml/pal4/icon50.png";
icon.shadow = "";
icon.iconSize = new GSize(20.0, 20.0);
icon.shadowSize = new GSize(31.0, 20.0);
icon.iconAnchor = new GPoint(10.0, 10.0);
icon.infoWindowAnchor = new GPoint(10.0, 10.0); 

function activityfilter(cat,act,activity) {
	
	$("dl#select-activity").hide();
	
	
	changeactivity(activity);
	selectedactivity=act
	selectedcategory=cat
	activitytitle=activity

	gbl_activity_searched = true;
	gbl_activity_id = act;
	gbl_activity_name = activity;
	
	$.ajax({
		type: 'GET',
		url: "/new/mysql/site-list-by-activity2.asp",
		dataType: 'xml',
		data: "categoryID="+selectedcategory+"&activityID="+selectedactivity+"&lat="+townsearchlat+"&lon="+townsearchlon,
		complete: function(a, b){
			if( b == 'success' ) {
				var xmlDoc = a.responseXML;
				croot = $('console',xmlDoc).attr('root');
				var zoom = parseInt($('maps',xmlDoc).attr('z'));
				//alert('activity set zoom = '+zoom);
				//alert('global zoom = '+overridezoom);
				
				q = 0;
				urls = new Array();
				activities = new Array();

				/************************/

				if(overridezoom >= 1 && overridezoom <= 12) {
					zoom = overridezoom;
				}
				
				APmap.clearOverlays();
				
				if(websiteID == 244) {
					icon.image = "http://maps.google.com/mapfiles/kml/pal2/icon28.png";
					point = new GLatLng(parseFloat(init_townsearchlat),parseFloat(init_townsearchlon));
					APmap.addOverlay(new GMarker(point, icon));
				}
	
				ew = new EWindow(APmap, E_STYLE_7);      
				APmap.addOverlay(ew);
				ewclick = new EWindow(APmap, E_STYLE_7);      
				APmap.addOverlay(ewclick); 
	
	
				var homepoint= new GLatLng(townsearchlat, townsearchlon);

				//console.log(APmap.getZoom());
				//console.log("resetting center");

				if (townsearched>0) {
					APmap.setCenter(new GLatLng(townsearchlat, townsearchlon), zoom);
				} else {
					//alert('3b lat='+townsearchlat);
					APmap.setCenter(new GLatLng(townsearchlat, townsearchlon), 5)
				}
/*
				var centre = APmap.getCenter();
				var zoom = APmap.getZoom();

				var log_search_loc = $('data markers mark:first activ:first',xmlDoc).attr('loc');

				var map_height = $("#map").height();
				var map_width = $("#map").width();

				log_search_query = "type=search&activityID="+selectedactivity+"&websiteID="+websiteID+"&locationID="+log_search_loc+"&mapLat="+centre.y+"&mapLon="+centre.x+"&mapZoom="+zoom+"&mapWidth="+map_width+"&mapHeight="+map_height+"&str_town="+document.searcher.str_town.value+"&self="+escape(document.location);

				$.ajax({
					type:'GET',
					url:'/new/mysql/log-map-activity.php',
					data:log_search_query
				});

				/************************/

				$('mark', xmlDoc).each(function() {
					var lat = $(this).attr('lat');
					var lng = $(this).attr('lng');

					point = new GLatLng(parseFloat(lat),parseFloat(lng));

					var box_title = $(this).attr('ttl');
					var distance = $(this).attr('dst');

					urls[q] = new Array();
					activities[q] = new Array();
					r = 0;
					$('activ', this).each(function() {

						var actID = $(this).attr('act');
						var locID = $(this).attr('loc');

						activities[q][r] = $(this).attr('ttl');
						
						icon.image = "http://maps.google.com/mapfiles/kml/pal4/icon50.png";
						
						if(actID == 138 || actID == 135) {
							icon.image = "http://maps.google.com/mapfiles/kml/pal4/icon50.png";
						}						

						if(APhome == true) { // if ADMIN are logged in - use extra width //
							var url = croot+"?"+"activityID="+actID+"&locationID="+locID+"&websiteID="+websiteID+"&sli=1&KeepThis=true&TB_iframe=true&height=425&width=930";
						} else { // if ADMIN aren't logged in - use default width //
							if(getURLVar('organisr')==''){ 
            					var url = croot+"?"+"activityID="+actID+"&locationID="+locID+"&websiteID="+websiteID+"&KeepThis=true&TB_iframe=true&height=418&width=596";
            				} else { // if organisr //
								if(getURLVar('admin')==''){
            						var url = croot+"?"+"activityID="+actID+"&locationID="+locID+"&websiteID="+websiteID+"&organisr="+getURLVar('organisr')+"&orguser="+getURLVar('orguser')+"&KeepThis=true&TB_iframe=true&height=418&width=596";
								} else { // websiteID is set as 2 - as admin extras are styled specific for TAP layout //
									var url = croot+"?"+"activityID="+actID+"&locationID="+locID+"&websiteID=2&organisr="+getURLVar('organisr')+"&orguser="+getURLVar('orguser')+"&sli=1&KeepThis=true&TB_iframe=true&height=418&width=930";
								}
            				}	
						}
						
						
						urls[q][r] = url;
						r++;
					});

					var html = ewtable(box_title, distance, urls[q], activities[q]); 

					APmap.addOverlay(createMarker(point, html, q, urls[q]));
					q++;
				});

			} else {
				alert('Sorry, we could not complete the request. Please try again.');
				return;

			}


		}
	});
}
function GMAPload() {
	if (GBrowserIsCompatible()) {
		APmap = new GMap2(document.getElementById("map"));
		var mt = APmap.getMapTypes();
		for (var i=0; i<mt.length; i++) {
			mt[i].getMinimumResolution = function() {return 5;}
			mt[i].getMaximumResolution = function() {return 12;}
		}

		APmap.setCenter(new GLatLng(townsearchlat, townsearchlon));
		//map.enableScrollWheelZoom();
		APmap.enableDoubleClickZoom();
		/*
		GDownloadUrl("/new/mysql/site-list-by-activity.asp?categoryID=1&activityID=0&lat="+townsearchlat+"&lon="+townsearchlon, function(data) {
			GEvent.addListener(map, "move", function() {
				checkBounds();
			});
			var allowedBounds = new GLatLngBounds(new GLatLng(49.5,-10), new GLatLng(59,2.6));    
			function checkBounds() {
				if (allowedBounds.contains(map.getCenter())) {
					return;
				}
				var C = map.getCenter();
				var X = C.lng();
				var Y = C.lat();
				var AmaxX = allowedBounds.getNorthEast().lng();
				var AmaxY = allowedBounds.getNorthEast().lat();
				var AminX = allowedBounds.getSouthWest().lng();
				var AminY = allowedBounds.getSouthWest().lat();
				if (X < AminX) {X = AminX;}
				if (X > AmaxX) {X = AmaxX;}
				if (Y < AminY) {Y = AminY;}
				if (Y > AmaxY) {Y = AmaxY;}
				map.setCenter(new GLatLng(Y,X));
			}	  
		});
		*/
		GEvent.addListener(APmap, "click", function(marker,point) {
			if (point) {
				ew.hide();
			}  
		});	
	}
}

/*******************
CR Map Work
*******************/
//get header GET vars
function getURLVar(urlVarName) {
	var urlHalves = String(document.location).split('?');
	var urlVarValue = '';
	if(urlHalves[1]){
		var urlVars = urlHalves[1].split('&');
		for(i=0; i<=(urlVars.length); i++){
			if(urlVars[i]){	
				var urlVarPair = urlVars[i].split('=');
				if (urlVarPair[0] && urlVarPair[0] == urlVarName) {
					urlVarValue = urlVarPair[1];
				}
			}
		}
	}
	return urlVarValue;   
}
	
//var url_activity = getURLVar('activity');
//var url_activity_id = getURLVar('activityID');

//activityfilter()

/*
var str_town = getURLVar('str_town');
str_town = str_town.replace(/\s+/g, ' ');

//get the value of str_town from url;
//if it's not an empty string
	//set the value of the form to the value of str_town
	//submit the form
//
$(function() {
	if(str_town != '') {
		$("form[@name='searcher'] input[@name='str_town']").attr("value",str_town);
		$("form[@name='searcher']").submit();
	}
});

/* Alt Town */

$('a.alt_town').livequery('click',function() {
	//var alt_url = ;

	//alt_url = "/new/mysql/othertown.asp?id=" + alt_url

	$.ajax({
		type: 'GET',
		url: '/new/mysql/othertown.asp',
		dataType: 'xml',
		data: {id: $(this).attr('town_loc')},
		complete: function(a, b){
			if( b != 'success' )
			{
				//alert('Sorry, we could not complete the request. Please try again.');
				return;
			}
			towninfo = a.responseXML.documentElement.getElementsByTagName('towndata');
			townsearchlat=towninfo[0].getAttribute("lat");
			townsearchlon=towninfo[0].getAttribute("lon");
			APmap.setCenter(new GLatLng(townsearchlat, townsearchlon), 12);
			if(gbl_activity_searched) {
				activityfilter(0,gbl_activity_id,gbl_activity_name);
			}
			changetown(document.searcher.str_town.value);
			townsearched=1;
			APmap.clearOverlays();

		}
	});

});

$(function(){
	GMAPload();
	$('body').unload(function(){
		GUnload();
	});

	$("ul.menu li a").click(function() {
		activityID = $(this).attr("activity");
		activity = $(this).text();
		if(activityID > 0) {	
			//activitySearch(0,activityID);
			changeactivity(activity);
			//activityfilter(activity);
			//activityfilter();
			activityfilter(0,activityID,activity);
			$("#banner-small").empty().append('<h3>'+activity+' In The UK</h3><iframe src="/intro-activity.asp?activityID='+activityID+'" width="338px" height="169px" scrolling="no" frameborder="0"></iframe>');
			$("#activity-description").hide();
			return false;
		} else {
			return true;
		}
	});

	//var venue_markers = activityfilter(1,0,"Go Ballistic");
	var itm = getURLVar('str_town');
	itm = itm.replace(/\s+/g, ' ');
	if( location.search != '' ) {
		if( itm != '' ) {
			//$(function() {
			var display_itm = itm;
			display_itm = decodeURI(display_itm);
			var itm_frags = display_itm.split('#');
			display_itm = itm_frags[0];
			$('input#str_town').attr('value',display_itm);
			//});
			townsearch(itm);
		}
	}

	if(itm == '' && websiteID == 244) {
		townsearch('');
		APmap.setZoom(10);
		
		if(getURLVar('activityID') > 0) {
			activityfilter(0,getURLVar('activityID'),getURLVar('activity'));
		}
	}

	var cat = getURLVar('categoryID');
	var actid = getURLVar('activityID');
	var act_id = actid.split('#');
	act = act_id[0];
	var activity = getURLVar('activity');

	//if(cat != 0 || act != 0) {
	//	var markers = activityfilter(cat,act,activity);
	//}
/*	
	if(cat != 0) {
		var markers = activityfilter(cat,0,activity);
	} else {
		if(act != 0) {
			var markers = activityfilter(0,act,activity);
		}
	}
*/	
	
setTimeout("$('#othertowns').fadeOut('slow');", 10000);
});

$(function() {
	//eg http://rs2.theactivitypeople.co.uk/console.asp?str_town=liverpool&activityID=1&showmicrosite=true&micrositeurl=http://console.theactivitypeople.co.uk/venue.php?activityID=1&locationID=7630&websiteID=2&KeepThis=true&TB_iframe=true&height=412&width=600
	//eg http://rs2.theactivitypeople.co.uk/console.asp?str_town=liverpool&activityID=1&showmicrosite=true&micrositeurl=http%3A%2F%2Fconsole.theactivitypeople.co.uk%2Fvenue.php%3FactivityID%3D2%26locationID%3D3808%26websiteID%3D2%26KeepThis%3Dtrue%26TB_iframe%3Dtrue%26height%3D412%26width%3D600
	var showmicrosite = getURLVar('showmicrosite');
	if(showmicrosite == 'true') {
		var msi = getURLVar('micrositeurl');
		var micrositeURL = decodeURI(msi);
		micrositeURL = micrositeURL.replace(/%3A/g,":");
		micrositeURL = micrositeURL.replace(/%2F/g,"/");
		micrositeURL = micrositeURL.replace(/%3F/g,"?");
		micrositeURL = micrositeURL.replace(/%3D/g,"=");
		micrositeURL = micrositeURL.replace(/%26/g,"&");
		tb_show("",micrositeURL,"");
		return true;
	};
});

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//thickbox//
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////  
var tb_pathToImage = "/new/images/loading.gif";
/*!!!!!!!!!!!!!!!!! edit below this line at your own risk !!!!!!!!!!!!!!!!!!!!!!!*/

//on page load call tb_init
$(document).ready(function(){   
	tb_init('a.thickbox, area.thickbox, input.thickbox');//pass where to apply thickbox
	imgLoader = new Image();// preload image
	imgLoader.src = tb_pathToImage;
});

//add thickbox to href & area elements that have a class of .thickbox
function tb_init(domChunk){
	$(domChunk).click(function(){
	var t = this.title || this.name || null;
	var a = this.href || this.alt;
	var g = this.rel || false;
	tb_show(t,a,g);
	this.blur();
	return false;
	});
}

function tb_show(caption, url, imageGroup) {//function called when the user clicks on a thickbox link

	try {
		if (typeof document.body.style.maxHeight === "undefined") {//if IE 6
			$("body","html").css({height: "100%", width: "100%"});
			$("html").css("overflow","hidden");
			if (document.getElementById("TB_HideSelect") === null) {//iframe to hide select elements in ie6
				$("body").append("<iframe id='TB_HideSelect'></iframe><div id='TB_overlay'></div><div id='TB_window'></div>");
				$("#TB_overlay").click(tb_remove);
			}
		}else{//all others
			if(document.getElementById("TB_overlay") === null){
				$("body").append("<div id='TB_overlay'></div><div id='TB_window'></div>");
				$("#TB_overlay").click(tb_remove);
			}
		}
		
		if(tb_detectMacXFF()){
			$("#TB_overlay").addClass("TB_overlayMacFFBGHack");//use png overlay so hide flash
		}else{
			$("#TB_overlay").addClass("TB_overlayBG");//use background and opacity
		}
		
		if(caption===null){caption="";}
		$("body").append("<div id='TB_load'><img src='"+imgLoader.src+"' /></div>");//add loader to the page
		$('#TB_load').show();//show loader
		
		var baseURL;
	   if(url.indexOf("?")!==-1){ //ff there is a query string involved
			baseURL = url.substr(0, url.indexOf("?"));
	   }else{ 
	   		baseURL = url;
	   }
	   
	   var urlString = /\.jpg$|\.jpeg$|\.png$|\.gif$|\.bmp$/;
	   var urlType = baseURL.toLowerCase().match(urlString);

		if(urlType == '.jpg' || urlType == '.jpeg' || urlType == '.png' || urlType == '.gif' || urlType == '.bmp'){//code to show images
				
			TB_PrevCaption = "";
			TB_PrevURL = "";
			TB_PrevHTML = "";
			TB_NextCaption = "";
			TB_NextURL = "";
			TB_NextHTML = "";
			TB_imageCount = "";
			TB_FoundURL = false;
			if(imageGroup){
				TB_TempArray = $("a[@rel="+imageGroup+"]").get();
				for (TB_Counter = 0; ((TB_Counter < TB_TempArray.length) && (TB_NextHTML === "")); TB_Counter++) {
					var urlTypeTemp = TB_TempArray[TB_Counter].href.toLowerCase().match(urlString);
						if (!(TB_TempArray[TB_Counter].href == url)) {						
							if (TB_FoundURL) {
								TB_NextCaption = TB_TempArray[TB_Counter].title;
								TB_NextURL = TB_TempArray[TB_Counter].href;
								TB_NextHTML = "<span id='TB_next'>&nbsp;&nbsp;<a href='#'>Next &gt;</a></span>";
							} else {
								TB_PrevCaption = TB_TempArray[TB_Counter].title;
								TB_PrevURL = TB_TempArray[TB_Counter].href;
								TB_PrevHTML = "<span id='TB_prev'>&nbsp;&nbsp;<a href='#'>&lt; Prev</a></span>";
							}
						} else {
							TB_FoundURL = true;
							TB_imageCount = "Image " + (TB_Counter + 1) +" of "+ (TB_TempArray.length);											
						}
				}
			}

			imgPreloader = new Image();
			imgPreloader.onload = function(){		
			imgPreloader.onload = null;
				
			// Resizing large images - orginal by Christian Montoya edited by me.
			var pagesize = tb_getPageSize();
			var x = pagesize[0] - 150;
			var y = pagesize[1] - 150;
			var imageWidth = imgPreloader.width;
			var imageHeight = imgPreloader.height;
			if (imageWidth > x) {
				imageHeight = imageHeight * (x / imageWidth); 
				imageWidth = x; 
				if (imageHeight > y) { 
					imageWidth = imageWidth * (y / imageHeight); 
					imageHeight = y; 
				}
			} else if (imageHeight > y) { 
				imageWidth = imageWidth * (y / imageHeight); 
				imageHeight = y; 
				if (imageWidth > x) { 
					imageHeight = imageHeight * (x / imageWidth); 
					imageWidth = x;
				}
			}
			// End Resizing
			
			TB_WIDTH = imageWidth + 30;
			TB_HEIGHT = imageHeight + 60;
			$("#TB_window").append("<a href='' id='TB_ImageOff' title='Close'><img id='TB_Image' src='"+url+"' width='"+imageWidth+"' height='"+imageHeight+"' alt='"+caption+"'/></a>" + "<div id='TB_caption'>"+caption+"<div id='TB_secondLine'>" + TB_imageCount + TB_PrevHTML + TB_NextHTML + "</div></div><div id='TB_closeWindow'><a href='#' id='TB_closeWindowButton' title='Close'>close</a></div>"); 		
			
			$("#TB_closeWindowButton").click(tb_remove);
			
			if (!(TB_PrevHTML === "")) {
				function goPrev(){
					if($(document).unbind("click",goPrev)){$(document).unbind("click",goPrev);}
					$("#TB_window").remove();
					$("body").append("<div id='TB_window'></div>");
					tb_show(TB_PrevCaption, TB_PrevURL, imageGroup);
					return false;	
				}
				$("#TB_prev").click(goPrev);
			}
			
			if (!(TB_NextHTML === "")) {		
				function goNext(){
					$("#TB_window").remove();
					$("body").append("<div id='TB_window'></div>");
					tb_show(TB_NextCaption, TB_NextURL, imageGroup);				
					return false;	
				}
				$("#TB_next").click(goNext);
				
			}

			document.onkeydown = function(e){ 	
				if (e == null) { // ie
					keycode = event.keyCode;
				} else { // mozilla
					keycode = e.which;
				}
				if(keycode == 27){ // close
					tb_remove();
				} else if(keycode == 190){ // display previous image
					if(!(TB_NextHTML == "")){
						document.onkeydown = "";
						goNext();
					}
				} else if(keycode == 188){ // display next image
					if(!(TB_PrevHTML == "")){
						document.onkeydown = "";
						goPrev();
					}
				}	
			};
			
			tb_position();
			$("#TB_load").remove();
			$("#TB_ImageOff").click(tb_remove);
			$("#TB_window").css({display:"block"}); //for safari using css instead of show
			};
			
			imgPreloader.src = url;
		}else{//code to show html
			
			var queryString = url.replace(/^[^\?]+\??/,'');
			var params = tb_parseQuery( queryString );

			TB_WIDTH = (params['width']*1) + 30 || 630; //defaults to 630 if no paramaters were added to URL
			TB_HEIGHT = (params['height']*1) + 40 || 440; //defaults to 440 if no paramaters were added to URL
			ajaxContentW = TB_WIDTH - 30;
			ajaxContentH = TB_HEIGHT - 45;
			
			if(url.indexOf('TB_iframe') != -1){// either iframe or ajax window		
					urlNoQuery = url.split('TB_');
					$("#TB_iframeContent").remove();
					if(params['modal'] != "true"){//iframe no modal
						$("#TB_window").append("<div id='TB_closeAjaxWindow'><a href='#' id='TB_closeWindowButton' title='Close'></a></div><iframe frameborder='0' hspace='0' src='"+urlNoQuery[0]+"' id='TB_iframeContent' name='TB_iframeContent"+Math.round(Math.random()*1000)+"' onload='tb_showIframe()' style='width:"+(ajaxContentW + 29)+"px;height:"+(ajaxContentH + 17)+"px;' > </iframe>");
					}else{//iframe modal
					$("#TB_overlay").unbind();
						$("#TB_window").append("<iframe frameborder='0' hspace='0' src='"+urlNoQuery[0]+"' id='TB_iframeContent' name='TB_iframeContent"+Math.round(Math.random()*1000)+"' onload='tb_showIframe()' style='width:"+(ajaxContentW + 29)+"px;height:"+(ajaxContentH + 17)+"px;'> </iframe>");
					}
			}else{// not an iframe, ajax
					if($("#TB_window").css("display") != "block"){
						if(params['modal'] != "true"){//ajax no modal
						$("#TB_window").append("<div id='TB_closeAjaxWindow'><a href='#' id='TB_closeWindowButton'></a></div><div id='TB_ajaxContent' style='width:"+ajaxContentW+"px;height:"+ajaxContentH+"px'></div>");
						}else{//ajax modal
						$("#TB_overlay").unbind();
						$("#TB_window").append("<div id='TB_ajaxContent' class='TB_modal' style='width:"+ajaxContentW+"px;height:"+ajaxContentH+"px;'></div>");	
						}
					}else{//this means the window is already up, we are just loading new content via ajax
						$("#TB_ajaxContent")[0].style.width = ajaxContentW +"px";
						$("#TB_ajaxContent")[0].style.height = ajaxContentH +"px";
						$("#TB_ajaxContent")[0].scrollTop = 0;
						$("#TB_ajaxWindowTitle").html(caption);
					}
			}
					
			$("#TB_closeWindowButton").click(tb_remove);
			
				if(url.indexOf('TB_inline') != -1){	
					$("#TB_ajaxContent").append($('#' + params['inlineId']).children());
					$("#TB_window").unload(function () {
						$('#' + params['inlineId']).append( $("#TB_ajaxContent").children() ); // move elements back when you're finished
					});
					tb_position();
					$("#TB_load").remove();
					$("#TB_window").css({display:"block"}); 
				}else if(url.indexOf('TB_iframe') != -1){
					tb_position();
					if($.browser.safari){//safari needs help because it will not fire iframe onload
						$("#TB_load").remove();
						$("#TB_window").css({display:"block"});
					}
				}else{
					$("#TB_ajaxContent").load(url += "&random=" + (new Date().getTime()),function(){//to do a post change this load method
						tb_position();
						$("#TB_load").remove();
						tb_init("#TB_ajaxContent a.thickbox");
						$("#TB_window").css({display:"block"});
					});
				}
			
		}

		if(!params['modal']){
			document.onkeyup = function(e){ 	
				if (e == null) { // ie
					keycode = event.keyCode;
				} else { // mozilla
					keycode = e.which;
				}
				if(keycode == 27){ // close
					tb_remove();
				}	
			};
		}
		
	} catch(e) {
		//nothing here
	}
}

//helper functions below
function tb_showIframe(){
	$("#TB_load").remove();
	$("#TB_window").css({display:"block"});
}

function tb_remove() {
 	$("#TB_imageOff").unbind("click");
	$("#TB_closeWindowButton").unbind("click");
	$("#TB_window").fadeOut("fast",function(){$('#TB_window,#TB_overlay,#TB_HideSelect').trigger("unload").unbind().remove();});
	$("#TB_load").remove();
	if (typeof document.body.style.maxHeight == "undefined") {//if IE 6
		$("body","html").css({height: "auto", width: "auto"});
		$("html").css("overflow","");
	}
	document.onkeydown = "";
	document.onkeyup = "";
	return false;
}

function tb_position() {
$("#TB_window").css({marginLeft: '-' + parseInt((TB_WIDTH / 2),10) + 'px', width: TB_WIDTH + 'px'});
	if ( !(jQuery.browser.msie && jQuery.browser.version < 7)) { // take away IE6
		$("#TB_window").css({marginTop: '-' + parseInt((TB_HEIGHT / 2),10) + 'px'});
	}
}

function tb_parseQuery ( query ) {
   var Params = {};
   if ( ! query ) {return Params;}// return empty object
   var Pairs = query.split(/[;&]/);
   for ( var i = 0; i < Pairs.length; i++ ) {
      var KeyVal = Pairs[i].split('=');
      if ( ! KeyVal || KeyVal.length != 2 ) {continue;}
      var key = unescape( KeyVal[0] );
      var val = unescape( KeyVal[1] );
      val = val.replace(/\+/g, ' ');
      Params[key] = val;
   }
   return Params;
}

function tb_getPageSize(){
	var de = document.documentElement;
	var w = window.innerWidth || self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
	var h = window.innerHeight || self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight;
	arrayPageSize = [w,h];
	return arrayPageSize;
}

function tb_detectMacXFF() {
  var userAgent = navigator.userAgent.toLowerCase();
  if (userAgent.indexOf('mac') != -1 && userAgent.indexOf('firefox')!=-1) {
    return true;
  }
}