var linkimage, ascfile, curgcm, sc, year2use="", curregion;

var usextents = "{'United States': [-15282026.301599186, 2654753.7293561134, -6051989.3644948751, 6559966.454733544], 'Hawaii': [-17932854.46737795, 2067021.4485126254, -17132323.406277552, 2601389.1426509675], 'Alaska': [-23840942.677121371, 6412252.2814209685, -10442039.774468124, 11882178.683402408], 'Mississippi': [-10267572.197665764, 3488975.3208461921, -9737002.0611498151, 4205655.9809523597], 'Oklahoma': [-11649029.797482174, 3947173.7373735039, -10326597.854284296, 4471063.7207484068], 'Delaware': [-8458720.622777177, 4629160.6124785459, -8331587.4208159018, 4857014.8046629634], 'Minnesota': [-11100444.401369253, 5327075.3978246059, -9692411.9624298364, 6402012.2711380143], 'Illinois': [-10290702.265615406, 4387400.5053383727, -9635181.0707942229, 5288659.0015026629], 'Arkansas': [-10639237.759903897, 3863376.4565736917, -9871260.2617969476, 4402431.9855947057], 'New Mexico': [-12261569.893414104, 3626576.181991423, -11341749.021488445, 4488705.5404309742], 'Indiana': [-9892814.6209165305, 4511868.5546576465, -9350926.1517961584, 5162349.926288127], 'Maryland': [-8962939.9027986694, 4554998.4008886768, -8240353.6336744968, 4842500.5210815407], 'Louisiana': [-10557977.419806644, 3335151.6814453951, -9822039.8965628743, 3936127.3484027409], 'Idaho': [-13263683.06577863, 5089769.5049510598, -12147902.99040609, 6346930.2016880261], 'Wyoming': [-12573740.641095888, 4972140.6265711198, -11368439.224137021, 5662926.3878735062], 'Tennessee': [-10240232.06108591, 4147171.5319504878, -8901121.0838858318, 4410627.6015689382], 'Arizona': [-12901213.086165866, 3626433.7499088207, -12019589.247755034, 4489047.0276592216], 'Iowa': [-10944332.725078277, 4888615.9404681865, -9843910.355542982, 5420870.8112658542], 'Michigan': [-10330878.050315892, 5051249.0509769469, -8907301.8295833766, 6201289.6451392155], 'Kansas': [-11543473.051180189, 4409555.0074298969, -10343813.178383756, 4895977.8679250916], 'Utah': [-12824737.029461132, 4391656.501887558, -12007947.960907759, 5208713.364632708], 'Virginia': [-9534425.23624539, 4347973.4988717381, -8155258.9269082947, 4814328.5958565427], 'Oregon': [-14121979.808642801, 5117583.1606281362, -12704636.554260693, 5865479.8156050388], 'Connecticut': [-8262053.2837687135, 4999451.464703979, -7934687.9908392299, 5180303.3601294011], 'Montana': [-13353916.561029788, 5467383.1452529076, -11148238.468291711, 6326344.7987612551], 'California': [-14083911.870737141, 3750678.7834504107, -12463454.55989508, 5245556.6647860995], 'Massachusetts': [-8287723.5835463367, 5030825.7034771666, -7676934.3111661589, 5311903.1594774537], 'West Virginia': [-9328437.551414175, 4434991.7471853532, -8523847.7290480155, 4991154.7482713275], 'South Carolina': [-9372200.0961019527, 3745864.7580911852, -8651859.5740786176, 4221509.9984886143], 'New Hampshire': [-8134300.7487524021, 5240077.455112, -7816398.2826033486, 5695845.5567757785], 'Wisconsin': [-10533870.942271963, 5189705.0844513699, -9483785.3540992383, 5982654.4537124736], 'Vermont': [-8235185.6637644647, 5242558.9198229285, -7896382.3466549069, 5647086.2719060509], 'Georgia': [-9623029.5546598211, 3511620.6134204478, -8910654.3298240956, 4204759.7201275872], 'North Dakota': [-11867941.977234328, 5732822.6020151693, -10464408.99610427, 6310379.116264808], 'Pennsylvania': [-9127715.3923684377, 4797322.7058085175, -8153923.4506992912, 5225127.6385312956], 'Florida': [-9871924.2477414832, 2821454.869155793, -8791589.8622759003, 3682091.7058127667], 'Kentucky': [-10155488.082078397, 4344036.9831355968, -8939710.5106463768, 4766359.4596413467], 'Rhode Island': [-8025529.6414045235, 5052119.6438256949, -7892946.4072363349, 5170628.2983935103], 'Nebraska': [-11829624.527665278, 4835420.7605555784, -10358673.298436727, 5343846.521504459], 'Missouri': [-10820877.964261249, 4257371.6061032061, -9758327.7279084846, 5001743.290166338], 'Ohio': [-9554883.6467052847, 4603008.1950645931, -8844589.0104126334, 5196901.0541246198], 'Alabama': [-9916113.4306005649, 3494262.8065716014, -9378266.2245747764, 4205410.4335984979], 'New York': [-9114175.5384200513, 4893872.2620456554, -7763756.9289553249, 5667464.2433754187], 'South Dakota': [-11824530.437078314, 5199765.6108188154, -10494187.946969813, 5811306.2747510495], 'Colorado': [-12315516.888383854, 4401287.9012737302, -11180986.972065607, 5051392.2022152487], 'New Jersey': [-8460278.1067434605, 4691518.7104688827, -8181660.4969185703, 5086297.0369795477], 'Washington': [-14176739.474861607, 5668631.453332711, -12723827.228435494, 6314617.6611390496], 'North Carolina': [-9577370.8528971821, 3986562.0163002289, -8210208.2258075709, 4407596.1492451932], 'District of Columbia': [-8593947.0929744281, 4686729.9353297539, -8553784.0063063074, 4726843.7394509288], 'Texas': [-12108328.931568637, 2890986.9846269111, -10173096.564319963, 4459065.2281600004], 'Nevada': [-13504840.13885493, 4099936.1218304145, -12546924.493699733, 5225774.3267130954], 'Maine': [-8052473.3221162241, 5278758.3189929565, -7312800.7387371557, 6063468.9237791831]}";
//var usimagesize = "{'United States': [1500, 634], 'Hawaii': [1500, 1000], 'Alaska': [1500, 612], 'Mississippi': [1112, 1500], 'Oklahoma': [1500, 594], 'Delaware': [838, 1500], 'Minnesota': [1500, 1145], 'Illinois': [1093, 1500], 'Arkansas': [1500, 1053], 'New Mexico': [1500, 1407], 'Indiana': [1250, 1500], 'Maryland': [1500, 597], 'Louisiana': [1500, 1227], 'Idaho': [1331, 1500], 'Wyoming': [1500, 860], 'Tennessee': [1500, 295], 'Arizona': [1500, 1467], 'Iowa': [1500, 726], 'Michigan': [1500, 1212], 'Kansas': [1500, 608], 'Utah': [1500, 1500], 'Virginia': [1500, 1037], 'Oregon': [1500, 792], 'Connecticut': [1500, 829], 'Montana': [1500, 584], 'California': [1500, 1384], 'Massachusetts': [1500, 689], 'West Virginia': [1500, 1037], 'South Carolina': [1500, 991], 'New Hampshire': [1047, 1500], 'Wisconsin': [1500, 1132], 'Vermont': [1258, 1500], 'Georgia': [1500, 1460], 'North Dakota': [1499, 618], 'Pennsylvania': [1500, 659], 'Florida': [1499, 1196], 'Kentucky': [1500, 521], 'Rhode Island': [1500, 1342], 'Nebraska': [1500, 518], 'Missouri': [1500, 1050], 'Ohio': [1500, 1254], 'Alabama': [1134, 1500], 'New York': [1500, 860], 'South Dakota': [1499, 688], 'Colorado': [1500, 860], 'New Jersey': [1060, 1500], 'Washington': [1500, 666], 'North Carolina': [1500, 462], 'District of Columbia': [1500, 1500], 'Texas': [1500, 1216], 'Nevada': [1278, 1500], 'Maine': [1415, 1500]}";

var usinregions = "['United States', 'Alaska', 'Alabama', 'Arizona', 'Arkansas', 'California', 'Colorado', 'Connecticut', 'Delaware', 'District of Columbia', 'Florida', 'Georgia', 'Hawaii', 'Idaho', 'Illinois', 'Indiana', 'Iowa', 'Kansas', 'Kentucky', 'Louisiana', 'Maine', 'Maryland', 'Massachusetts', 'Michigan', 'Minnesota', 'Mississippi', 'Missouri', 'Montana', 'Nebraska', 'Nevada', 'New Hampshire', 'New Jersey', 'New Mexico', 'New York', 'North Carolina', 'North Dakota', 'Ohio', 'Oklahoma', 'Oregon', 'Pennsylvania', 'Rhode Island', 'South Carolina', 'South Dakota', 'Tennessee', 'Texas', 'Utah', 'Vermont', 'Virginia', 'Washington', 'West Virginia', 'Wisconsin', 'Wyoming']";

var worldextents = "{'Global': [-25438243.01329998,-18559857.084811613,26847130.31865195,20184543.812368333], 'Canada': [-26521426.386175606, 4272221.3595139068, 4946728.4353383686, 19124181.41111242], 'Sao Tome and Principe': [657973.30847069446, -13434.57769513369, 845137.55731105618, 236169.20897658906], 'Turkmenistan': [5415372.4201852223, 4093375.5073287319, 7832717.4153740257, 5384270.1679262733], 'Lithuania': [1935102.6509888987, 7040714.0408604415, 3353633.1345746438, 7694810.7814077754], 'Cambodia': [11304497.613046104, 1084192.29230687, 12073252.990862552, 1724831.1366934394], 'St Vincent Grenadines': [-6850266.5092316633, 1456290.8261926461, -6786254.3168392526, 1520379.2180361913], 'Switzerland': [434201.10361975688, 5675827.9782567704, 1347073.2665902337, 6131913.2824307634], 'Ethiopia': [3498352.5325649031, 250997.85251297371, 5463890.1164965946, 1772786.2075534523], 'Aruba': [-7856045.7423941428, 1338858.4092752133, -7728534.8815729823, 1466651.4346864198], 'Swaziland': [3367258.5750328996, -3201196.4957681769, 3646268.0781539637, -2922123.6372088827], 'Argentina': [-8786080.8718092274, -7761340.1386985201, -5403546.5699463841, -2144435.6410284173], 'Bolivia': [-7910322.5270392131, -2728118.0380348493, -6279881.288457294, -966369.55835512839], 'Cameroon': [888023.34761435492, 85221.325147548429, 1895869.492669597, 1599689.1143903837], 'Burkina Faso': [-738641.11437496077, 960649.69368155987, 349645.62403506384, 1793089.7951185086], 'Ghana': [-425740.30798513727, 453812.65200453857, 203846.70523583057, 1336898.7089998138], 'Saudi Arabia': [3558485.922211905, 1620393.5209680414, 6518362.6423958335, 3959173.4357213955], 'Yemen': [4619915.366301666, 1296732.8692862189, 6178235.625390335, 2205764.4344560928], 'Japan': [13269085.251774348, 2574089.8901576144, 16732855.097350402, 5880711.1404985031], 'Cape Verde': [-2866270.5738190305, 1610515.6955501181, -2476395.0879637571, 2000413.4046510891], 'Slovenia': [1309651.1588892257, 5601821.213372794, 2030411.4481183623, 5962267.8657627786], 'Guatemala': [-10338607.033606855, 1485106.9778589224, -9754173.4079647828, 2069187.5936604582], 'Zimbabwe': [2693999.5020428188, -2622149.028085114, 3818730.1720706224, -1695853.6894388136], 'Turks Caicos Islands': [-8082158.0906275641, 2448061.276650446, -7947681.5293266326, 2515233.5668030581], 'Kuwait': [5144245.4263334395, 3296611.1790769529, 5431450.3523915252, 3583642.6669743438], 'Jordan': [3753926.0852813725, 3339712.8515298693, 4484577.1337048756, 3998211.0257325112], 'Dominica': [-6851850.3411149988, 1706517.3675870788, -6812980.6830419097, 1767003.6310070653], 'Liberia': [-1312890.6606487648, 411380.30800603173, -746392.25876738457, 1040964.5832892999], 'Maldives': [8067712.0556646101, -165730.60207513697, 8241324.858932131, 889856.30935311969], 'Jamaica': [-8763825.5988870617, 1968308.275483401, -8434640.0636119097, 2166019.6450345055], 'Oman': [5635159.1305377623, 1789555.8591137733, 6778747.6824303232, 3135442.8660996738], 'Tanzania': [3145581.5461681709, -1424249.5544913032, 4593080.3992890418, 23105.702961061819], 'Martinique': [-6854851.4973196108, 1567262.6475689718, -6725936.9617662029, 1696190.7856598641], 'Ivory Coast': [-1052756.3623135972, 397605.56837550469, -170476.42142736912, 1280369.1236925588], 'Christmas Island': [11740520.258011678, -1237989.931331906, 11803471.387287913, -1112727.0242742305], 'French Guiana': [-6147013.1934618941, 195214.17256705606, -5708306.5499204937, 696586.97763763042], 'Monaco': [764914.35469060007, 5384101.4569680737, 849968.98741467355, 5469728.5708641196], 'Wallis and Futuna': [-19892271.523916919, -1642054.6487544586, -19570397.786076561, -1449136.4411516357], 'Palau Pacific Islands': [14909824.561583275, 774395.40020202578, 15035344.530109253, 900219.61564430466], 'Andorra': [82624.220214705172, 5151865.5133667756, 251634.79637548048, 5321144.0559750404], 'Albania': [2047415.6981759837, 4762139.495227579, 2461596.8868639558, 5343783.6883936971], 'West Bank': [3814212.8126904322, 3617001.9297855655, 4033911.54824663, 3911134.1189495339], 'Macau': [12628994.323502202, 2507570.6645400897, 12695686.748181133, 2575786.2965270784], 'United Arab Emirates': [5668017.1755680013, 2541944.4953781003, 6355171.4192545619, 3091440.7186777745], 'Guam': [16081555.495785596, 1452928.9913611598, 16145608.255545814, 1581091.0731514276], 'India': [7205723.6824016767, 506587.20100348903, 11220408.872705275, 4519027.5656622443], 'Azerbaijan': [4797807.2329500709, 4543712.5113673564, 5778329.3473093677, 5197196.723193571], 'Lesotho': [2965237.761866325, -3652170.4896898642, 3324755.7968884814, -3292591.2697831183], 'Kenya': [3671066.1119171632, -625534.23079921433, 4734953.1946876328, 626112.78547694406], 'South Korea': [13940365.845324447, 3844817.8764892174, 14557641.094412046, 4771973.7504340066], 'Tajikistan': [7247066.3668497726, 4325920.9520858433, 8616293.3772995993, 5130964.8095025169], 'Cen African Republic': [1458684.8675515535, 157694.68597634096, 3161224.5496405838, 1354742.6160666936], 'Turkey': [2351814.2762497547, 4170807.4231373831, 5496789.6245469237, 5299108.5357219009], 'Afghanistan': [6449697.3721194742, 3297675.1704652198, 8635377.5163428374, 4729422.0789865283], 'Bangladesh': [9734196.9455200695, 2283964.4679737501, 10415810.966959562, 3171511.8186887503], 'Mauritania': [-2094964.4004390808, 1536586.8823948477, -351353.52058015182, 3281985.7476652157], 'Solomon Islands': [17221304.779534038, -1383594.1839764621, 18680014.63732139, -686393.47437215236], 'Gaza Strip': [3767270.1811762755, 3624775.4696122836, 3913795.7178973909, 3771239.2341075796], 'San Marino': [1304602.2293421431, 5383566.1769734928, 1478539.4645193408, 5470227.8676053993], 'French Polynesia': [-16977247.442739364, -2103830.1222626586, -15305080.364766596, -881795.11037772836], 'France': [-1083998.8364006162, 4908299.0550394813, 1642473.8382819043, 6815424.2724672072], 'Rwanda': [3155582.3160501341, -347816.0197489066, 3468199.70115428, -97576.20501678143], 'Slovakia': [1581034.5694338661, 5998158.6505507417, 2816795.8176705632, 6473074.2074412853], 'Somalia': [4431437.7461876739, -320418.47615993919, 5813414.4515404366, 1442034.8462984709], 'Peru': [-9173922.2532396484, -2222520.0750312093, -7522535.1585739711, 127495.99307535567], 'Laos': [11052188.828354124, 1452113.2255164094, 12103755.947292047, 2636395.0540113114], 'Nauru': [18532521.668842435, -116429.1001631121, 18593547.435174718, 4973.805256339816], 'Seychelles': [5047827.072280773, -1097844.2493804311, 6307914.4496860001, -465938.56374158151], 'Norway': [-2012266.1665536091, 7637703.0929473694, 6025965.8234797297, 11803903.182041375], 'Malawi': [3590437.829458138, -2036705.0411758902, 4036278.6847110665, -948369.80010218953], 'Cook Islands': [-18557904.912886556, -2592270.9405077235, -17452769.175405372, -1094865.1790425524], 'Benin': [30074.939401415766, 625108.43007996539, 471834.54001245636, 1447344.4491914771], 'Western Sahara': [-2064351.0322412562, 2276479.1804974475, -828830.84129259293, 3305870.9195900499], 'Cuba': [-9589123.596181307, 2184855.3905543946, -8109193.8011198342, 2722593.5438130056], 'Montenegro': [1930585.6365941705, 5063246.8386237947, 2355917.4246410155, 5488568.5016399948], 'F S Micronesia': [17548801.847466774, 543703.40726725222, 18240724.239873212, 794799.67574904452], 'Togo': [-73529.829225903522, 631839.32473079849, 241271.55133482089, 1325512.8281782214], 'Virgin Islands': [-7240753.5723642092, 1975665.2224521607, -7175076.017282228, 2040960.3346730447], 'China': [6685594.7353489008, 1722512.4122191933, 16531800.681448309, 7486552.1223791279], 'Armenia': [4683248.8036216842, 4623650.4390886454, 5335987.9968315363, 5113269.1478235871], 'Dominican Republic': [-8117168.2173572192, 1961136.041660242, -7522867.8583191484, 2291402.895422854], 'Ukraine': [1735722.4871156947, 5377752.0592836104, 5223770.4612384923, 6980532.6221976606], 'Tonga': [-19557847.458845396, -2473038.8875097726, -19292656.916450478, -2074380.6757275905], 'Finland': [990951.39148562402, 8108827.3366565257, 4744276.3693530262, 11415786.406910721], 'Libya': [765494.12468485709, 2044433.5296234475, 3075535.4412191715, 4073533.8732550205], 'Cayman Islands': [-9077727.0129961185, 2151438.6093881917, -9011584.8817637451, 2217448.9629752608], 'Mauritius': [6274197.1466132784, -2402330.4122182461, 7140508.0278331274, -2202628.4506814843], 'Liechtenstein': [965211.18376296305, 5937067.4735622527, 1149875.3915501505, 6029311.6192813376], 'Vietnam': [11284296.254946146, 844305.8401895219, 12261111.006827455, 2798973.0012709], 'British Virgin Islands': [-7245937.9286151482, 2030157.8413995814, -7114202.3118289784, 2162414.0655082143], 'Mali': [-1563146.3228500923, 1008058.4612110255, 676306.09435523103, 3048964.2178793517], 'Russia': [-59243043.577269301, 4332837.0794255538, 59322086.997652583, 17716433.148690868], 'Bulgaria': [2242238.5246352875, 4979817.2641025037, 3435740.0452799611, 5576682.3767236928], 'United States': [-15319170.292859599, 2602248.6936588953, -5994255.7258803826, 6581098.2005631691], 'Romania': [1883429.3433794221, 5340065.7857424915, 3683514.4279205902, 6240958.0231508678], 'Angola': [1175067.4337939997, -2197596.5679604653, 2834136.7281459058, -344518.73936501378], 'Chad': [1341552.8045510559, 665393.4651454488, 2833279.9023168106, 2809527.5679560155], 'South Africa': [1049917.7831207227, -6152777.8650192767, 4744042.2480087709, -2301995.9193684445], 'Tokelau': [-19150326.137044709, -1065843.8549990372, -19088277.255259316, -1002557.7316702005], 'Nicaragua': [-9838101.7009958755, 1140623.432338373, -9196916.0965418648, 1781978.3814534121], 'Sweden': [130741.32634786516, 7143977.4075992974, 3825763.6848298893, 11125199.922865881], 'Qatar': [5601595.8934451947, 2799562.4079116508, 5808854.4563471992, 3076041.3807258778], 'Malaysia': [10936570.264726879, 7966.7171656473656, 13444948.526835294, 886004.54422807391], 'Austria': [758523.51643229392, 5744560.8053526292, 2247450.8975141104, 6396263.0810738439], 'Man Isle of': [-607671.44219797105, 7164428.4085849915, -394048.64012809115, 7271371.4751230096], 'Mozambique': [3227123.1570761134, -3243837.0240859431, 4678653.0742467521, -996922.80968328239], 'Uganda': [3243190.8170748646, -208396.43961972598, 3993274.9561690222, 542599.14988478506], 'Hungary': [1526097.9244884113, 5665215.5977507327, 2816097.9228465087, 6310857.9318967406], 'Niger': [-136687.07659395592, 1184223.7388387474, 1961155.138995755, 2800354.4319647821], 'Brazil': [-8706337.575407939, -4314331.7252504649, -3426067.1477782498, 897466.87264658581], 'Falkland Islands': [-7027505.8424531007, -6907035.7604379086, -6218696.3724121433, -6604759.9728245605], 'Faroe Islands': [-949225.50302486343, 8604402.3536453974, -553124.26228747261, 9000377.9517625235], 'Guinea': [-1754363.9561947223, 740659.39586914401, -793688.30403422657, 1485188.4384631519], 'Panama': [-9344328.5605952311, 760397.17092252884, -8521849.3510884903, 1140189.8926301708], 'Costa Rica': [-9600637.7793870773, 869119.85078820924, -9156333.6391999163, 1313079.8085709396], 'Luxembourg': [551038.82960761792, 6259025.0294894166, 840806.03905305616, 6549205.2823824454], 'American Samoa': [-19040020.270568643, -1635137.7358872194, -18975558.753066652, -1570647.9330185622], 'Bahamas': [-8875981.0267841183, 2284105.6779333567, -7987701.9551137099, 3172044.6769953878], 'Gibraltar': [-622923.26836896501, 4296464.5998957204, -545969.54474633792, 4373788.3491101004], 'Ireland': [-1388037.6340887425, 6570070.3754010275, -447373.59722186753, 7510580.962574481], 'Pakistan': [6433776.4481168715, 2581153.6397711011, 8984741.7583062649, 4620967.2897335151], 'Nigeria': [182467.28335892301, 376818.48994490044, 1767067.3544428148, 1644147.7977502688], 'Ecuador': [-10360220.528394295, -661044.55318992352, -8229641.6448707264, 215473.37681217337], 'Czech Republic': [1043321.8167679339, 6158661.7517386461, 2407930.7321343129, 6742427.5505264234], 'Brunei': [12679936.44640146, 435387.0617322097, 12868056.844153598, 623397.24474612775], 'Australia': [11497108.09102563, -7743951.3300804859, 18738089.024755154, -738324.53501495451], 'Iran': [4529741.5812665103, 2753218.0297765178, 7437609.4174181446, 4989031.6742312713], 'Algeria': [-1328066.0598279028, 1948555.9813528557, 1665630.7380151101, 4657235.5513723176], 'Midway Islands': [-19766557.701460619, 3245438.0005515823, -19696399.429071296, 3315526.5954802935], 'El Salvador': [-10100264.041170798, 1449287.7474545755, -9714261.9293669201, 1642358.633843242], 'Tuvalu': [19566188.689601198, -1026704.1799554782, 20008010.780933224, -648227.49584361678], 'Zaire': [1194375.6100470854, -1647999.7142813813, 3649951.2127991342, 743930.95579931571], 'Marshall Islands': [17970878.456536114, 547095.37674760667, 18987995.455683634, 1755214.8292169559], 'Chile': [-13307665.904536787, -7897638.4007978737, -6222496.1306307679, -1635218.8839371265], 'Puerto Rico': [-7539408.0164761674, 1968328.0364701278, -7210259.8481868934, 2165798.3855760805], 'Netherlands Antilles': [-7749190.6631048145, 1342300.3631251983, -7557145.6483782977, 1406160.071173439], 'Kiribati': [-17595023.72662092, 160347.89629667473, -17470353.25968425, 284910.51136790542], 'Haiti': [-8324944.3028154895, 2019557.2153592019, -7927636.2053324133, 2350608.0912003564], 'Belize': [-9982142.8798170891, 1725623.6050606261, -9721222.0287783779, 2117435.1333738975], 'Sierra Leone': [-1528687.7616618145, 701000.41613449913, -1086622.4975972292, 1143068.4198493871], 'Georgia': [4248595.9351545842, 4984561.9384363247, 5437631.2514256034, 5493325.6057249531], 'Gambia': [-1922757.631518048, 1452417.3467959892, -1472054.7132977354, 1581436.0122243403], 'Philippines': [12881468.874189584, 457546.11507523799, 14225224.95093631, 2314958.3332571257], 'Guinea Bissau': [-1920925.3760579207, 1158001.0053590708, -1473822.5816679164, 1477418.7131745494], 'N Mariana Islands': [16192619.753652731, 1624987.7771052038, 16257050.399664991, 1753671.5266044186], 'Moldova': [2807771.5244978294, 5586783.7250593584, 3537906.979380758, 6225532.3672451386], 'Morocco': [-1726872.2164896936, 3118415.9605107876, 114464.50558516599, 4369212.1063746288], 'Croatia': [1311040.2734717219, 5112909.2283528028, 2363810.9304369129, 5990968.9838557811], 'Mongolia': [8554473.194301242, 4975066.9974637823, 14549775.109264065, 7006265.7832629103], 'Guernsey': [-353433.68634847045, 6265613.7132016951, -258222.13797809804, 6455432.2687560981], 'Thailand': [10722389.534685025, 509903.64938598516, 11877822.923124205, 2437474.5113725038], 'Namibia': [1110355.988170783, -3468491.5262683621, 3011399.4795004595, -1769579.8247986664], 'Grenada': [-6905689.9507935075, 1282558.2374395123, -6842133.691891714, 1409175.60046729], 'Iraq': [4084823.0228100484, 3305840.1359784529, 5657356.4037786936, 4579822.8284463473], 'Portugal': [-4100974.1340401862, 3742426.202766249, -71222.577512318734, 5323389.3746109707], 'Estonia': [1938512.9676586161, 7830491.4297424387, 3628709.0055084806, 8433706.0640038643], 'Uruguay': [-6612950.1798243579, -4204079.088169409, -5797848.3711383846, -3463260.1853015111], 'Mexico': [-13608852.136371046, 1493722.5108493727, -9209942.4930585846, 4036926.7212526961], 'Lebanon': [3856728.6177542922, 3878815.123215232, 4158382.8615864809, 4180423.3518856913], 'Uzbekistan': [5675462.1646173215, 4358507.1182843512, 8687062.3444875162, 5864398.7630328294], 'Tunisia': [682285.30131408537, 3442778.3166590952, 1433497.9987585836, 4570083.2289915085], 'Djibouti': [4603854.033137925, 1158171.8892358008, 4858822.7733500339, 1477019.8622277216], 'Greenland': [-19575402.550252408, 7661086.9450180558, 10069966.720046313, 19466427.651252192], 'Antigua and Barbuda': [-6906151.8035242278, 1852674.1772969565, -6841837.0049825544, 2047686.3305234814], 'Spain': [-2562803.5823537605, 3046239.1359229777, 1006426.601969325, 5607570.9126241058], 'Colombia': [-9237855.8751760665, -621706.49106732267, -7289972.9349550204, 1578726.5012327018], 'Reunion': [6111473.1651128549, -2458910.4623417268, 6245162.172621836, -2325086.2776587573], 'Burundi': [3155465.4129641945, -518610.1816931779, 3468353.4626612412, -205564.2637122341], 'Taiwan': [13079597.451347183, 2421875.379832889, 13693086.976243777, 2967060.8628451191], 'Cyprus': [3499786.4244570909, 4083549.3707458135, 3959113.6546428152, 4313306.2235862752], 'Madagascar': [4704509.6902739899, -3102789.530129387, 5761041.5446971087, -1186184.637055336], 'Italy': [364222.35676879628, 4267812.4870062061, 2476416.4834099212, 6126497.2249834761], 'Bhutan': [9792637.0969595704, 3045860.8113531745, 10356323.0876274, 3328006.1805615472], 'Sudan': [2242558.7648078543, 196534.44228202538, 4495254.476802337, 2708572.8287462336], 'Nepal': [8775329.2254716624, 2964292.9812345044, 9982793.2852989212, 3603331.6437307484], 'Malta': [1537157.6370053161, 4227875.0115958061, 1691280.0186065231, 4304849.1995262215], 'Bosnia Herzegovina': [1584821.9579344559, 5208080.6158953039, 2367122.9398126989, 5729140.2908889493], 'Netherlands': [177711.46514548053, 6509573.5812077951, 937448.39466094389, 7268461.1982694007], 'Suriname': [-6546746.3304638164, 133083.20110259642, -5920339.3854416125, 759067.4916448209], 'Anguilla': [-7079015.0325959157, 2033996.724554243, -6947143.1068742527, 2099791.0634748298], 'Venezuela': [-8284923.961565298, -26605.354944815161, -6519546.599708966, 1485897.7962378771], 'Israel': [3751621.1055162624, 3341053.6341298404, 4041116.3415409992, 3997294.7577658775], 'Svalbard': [-4680663.6687645502, 12294443.976280395, 9583172.7318051346, 16447244.581924964], 'Wake Island': [18529579.107480209, 2151433.4341927916, 18595409.318506885, 2217429.8388205972], 'Indonesia': [10244427.816546904, -1348664.8616223414, 16086286.8253974, 783991.07825203741], 'St Kitts and Nevis': [-7017935.1900620693, 1917334.4715157447, -6952591.2826163769, 1982638.8082662737], 'Iceland': [-3894029.6433335831, 9035076.0488197561, -335579.78585999226, 10222199.847479641], 'Zambia': [2285739.9303714647, -2169637.5809262022, 3893174.7005860535, -818505.43807037151], 'Senegal': [-2066382.6575709169, 1310715.2507172257, -1161309.8952946507, 1956606.9224928867], 'Papua New Guinea': [15526615.017990464, -1420986.9992209158, 17480697.154180318, -34945.195580499232], 'Trinidad and Tobago': [-6913702.2256032247, 1108294.9017730861, -6722765.1288457718, 1299336.3480503212], 'St Pierre and Miquelon': [-6307078.6538809212, 5851198.9874258768, -6216368.3515639296, 6033772.0967652788], 'Germany': [165964.42896386929, 5849385.2187838005, 2172520.6349188215, 7553254.073900382], 'Vanuatu': [18501815.567140043, -2381794.0833904957, 18958129.346855886, -1467504.9988728699], 'Western Samoa': [-19275669.797027744, -1642028.2458775977, -19018180.556539562, -1449127.8319236131], 'Denmark': [463634.80368069594, 7223300.2428784864, 2154090.084758637, 8010905.2708053319], 'Kazakhstan': [3514148.2235091319, 4785638.1637897883, 11354311.786450302, 7615315.0424758615], 'Poland': [1074820.0336330917, 6208364.853481357, 3211947.1875515035, 7429882.9213947048], 'Eritrea': [3939638.7441973966, 1303659.2093803058, 4910983.8095625918, 2080312.4869489034], 'Kyrgyzstan': [7363778.75637211, 4680573.8618094027, 9280667.2410462219, 5430824.8399653519], 'St Helena': [-672272.60031947622, -1868464.620342846, -607797.40835698182, -1740964.0993581878], 'Mayotte': [5005260.043586771, -1463232.5226377384, 5069153.2643687278, -1399158.1060479085], 'Montserrat': [-6962058.686591397, 1859176.3492288501, -6897084.6848694915, 1924378.9395821798], 'New Caledonia': [18143410.049321711, -2654016.2220562915, 18815176.11866216, -2250738.5552721741], 'New Zealand':[17559602.75966494,-6304803.614236092,20827438.592911925,-3883278.558162352], 'Macedonia': [2128838.3020935147, 4920539.5977390856, 2713982.9322986919, 5254669.2907935595], 'St Lucia': [-6854366.7751988387, 1509959.9673979031, -6726417.0994296549, 1638531.0324021557], 'North Korea': [13616761.986130068, 4455510.8666777648, 14769781.01827075, 5442737.9813743671], 'Sri Lanka': [8832124.7712961212, 582942.69568306208, 9146312.2479736693, 1149315.3281752968], 'Latvia': [1808365.0186285311, 7422956.0060157934, 3646999.3446318493, 8110911.7632846246], 'Guyana': [-6883957.4053486055, 57202.597620584202, -6195462.3645174401, 1060718.1098311529], 'Syria': [3808874.7346125143, 3717845.4961023759, 4875376.3864196101, 4555013.3173825303], 'Guadeloupe': [-6910871.1626257813, 1736570.114433869, -6781240.8155170809, 1931323.2271482244], 'Honduras': [-10020881.669368464, 1374679.7631364695, -9181444.0867092945, 1891055.0630808957], 'Byelarus': [2059248.6903805365, 6558698.8119485872, 4176823.9283008352, 7723089.6753948294], 'Myanmar': [10143773.91591792, 922616.78057779465, 11399772.682665261, 3516953.4947190857], 'Equatorial Guinea': [866887.57808890415, 31776.22586888478, 1304457.0895399284, 469416.67154239822], 'Egypt': [2546992.7867812524, 2371733.9779897844, 4300062.4790045079, 3844457.2511492055], 'Singapore': [11518239.702010337, 107932.65301789835, 11580660.607150808, 170399.58898401586], 'Serbia': [1904165.8083635869, 5039320.4583674166, 2772867.8871831144, 5907853.706893431], 'United Kingdom': [-1522097.4768114411, 6221528.8466754667, 800393.05774189928, 8764559.3503477704], 'Congo': [1170504.7442183027, -677758.36328263511, 2170398.7668689871, 510013.61113135557], 'Greece': [1954920.5553666463, 4031072.6374627603, 3389181.9760436541, 5226561.7679673126], 'Paraguay': [-7125769.1659906721, -3316224.2155012502, -5897569.3572101733, -2088412.5364161409], 'Gabon': [902498.39307295135, -489836.16774443834, 1714881.6163453246, 322546.70711431402], 'Comoros': [4770349.8057596069, -1412996.4622485517, 5025942.7851080829, -1221484.1233734929]}";
//var worldimagesize = "{'Global': [1500, 579], 'Canada': [1500, 707], 'Sao Tome and Principe': [1125, 1500], 'Turkmenistan': [1500, 800], 'Lithuania': [1500, 692], 'Cambodia': [1500, 1250], 'St Vincent Grenadines': [1500, 1500], 'Switzerland': [1500, 750], 'Ethiopia': [1500, 1161], 'Aruba': [1500, 1500], 'Swaziland': [1500, 1500], 'Argentina': [904, 1500], 'Bolivia': [1388, 1500], 'Cameroon': [1000, 1500], 'Burkina Faso': [1500, 1147], 'Ghana': [1071, 1500], 'Saudi Arabia': [1500, 1186], 'Yemen': [1500, 875], 'Japan': [1500, 1433], 'Cape Verde': [1500, 1500], 'Slovenia': [1500, 750], 'Guatemala': [1500, 1500], 'Zimbabwe': [1500, 1235], 'Turks Caicos Islands': [1500, 750], 'Kuwait': [1500, 1500], 'Jordan': [1500, 1350], 'Dominica': [1500, 833], 'Liberia': [1350, 1500], 'Maldives': [264, 1500], 'Jamaica': [1500, 900], 'Oman': [1275, 1500], 'Tanzania': [1500, 1500], 'Martinique': [1500, 1500], 'Ivory Coast': [1500, 1500], 'Christmas Island': [750, 1500], 'French Guiana': [1312, 1500], 'Monaco': [1500, 1500], 'Wallis and Futuna': [1500, 900], 'Palau Pacific Islands': [1500, 1500], 'Andorra': [1500, 1500], 'Albania': [1071, 1500], 'West Bank': [1125, 1500], 'Macau': [1500, 1500], 'United Arab Emirates': [1500, 1200], 'Guam': [750, 1500], 'India': [1500, 1500], 'Azerbaijan': [1500, 1000], 'Lesotho': [1500, 1500], 'Kenya': [1275, 1500], 'South Korea': [1000, 1500], 'Tajikistan': [1500, 882], 'Cen African Republic': [1500, 1055], 'Turkey': [1500, 538], 'Afghanistan': [1500, 982], 'Bangladesh': [1153, 1500], 'Mauritania': [1500, 1500], 'Solomon Islands': [1500, 717], 'Gaza Strip': [1500, 1500], 'San Marino': [1500, 750], 'French Polynesia': [1500, 1096], 'France': [1500, 1050], 'Rwanda': [1500, 1200], 'Slovakia': [1500, 576], 'Somalia': [1178, 1500], 'Peru': [1054, 1500], 'Laos': [1333, 1500], 'Nauru': [750, 1500], 'Seychelles': [1500, 750], 'Norway': [1500, 777], 'Malawi': [617, 1500], 'Cook Islands': [1108, 1500], 'Benin': [807, 1500], 'Western Sahara': [1500, 1250], 'Cuba': [1500, 545], 'Montenegro': [1500, 1500], 'F S Micronesia': [1500, 545], 'Togo': [681, 1500], 'Virgin Islands': [1500, 1500], 'China': [1500, 878], 'Armenia': [1500, 1125], 'Dominican Republic': [1500, 833], 'Ukraine': [1500, 689], 'Tonga': [1000, 1500], 'Finland': [1500, 1320], 'Libya': [1500, 1318], 'Cayman Islands': [1500, 1500], 'Mauritius': [1500, 346], 'Liechtenstein': [1500, 750], 'Vietnam': [750, 1500], 'British Virgin Islands': [1500, 1500], 'Mali': [1500, 1367], 'Russia': [1500, 170], 'Bulgaria': [1500, 750], 'United States': [1500, 641], 'Romania': [1500, 750], 'Angola': [1344, 1500], 'Chad': [1045, 1500], 'South Africa': [1440, 1500], 'Tokelau': [1500, 1500], 'Nicaragua': [1500, 1500], 'Sweden': [1396, 1500], 'Qatar': [1125, 1500], 'Malaysia': [1500, 525], 'Austria': [1500, 656], 'Man Isle of': [1500, 750], 'Mozambique': [970, 1500], 'Uganda': [1500, 1500], 'Hungary': [1500, 750], 'Niger': [1500, 1200], 'Brazil': [1500, 1481], 'Falkland Islands': [1500, 562], 'Faroe Islands': [1500, 1500], 'Guinea': [1500, 1064], 'Panama': [1500, 692], 'Costa Rica': [1500, 1500], 'Luxembourg': [1500, 1500], 'American Samoa': [1500, 1500], 'Bahamas': [1500, 1500], 'Gibraltar': [1500, 1500], 'Ireland': [1500, 1500], 'Pakistan': [1500, 1200], 'Nigeria': [1500, 1200], 'Ecuador': [1500, 617], 'Czech Republic': [1500, 642], 'Brunei': [1500, 1500], 'Australia': [1500, 1451], 'Iran': [1500, 1153], 'Algeria': [1500, 1357], 'Midway Islands': [1500, 1500], 'El Salvador': [1500, 750], 'Tuvalu': [1500, 1285], 'Zaire': [1500, 1461], 'Marshall Islands': [1263, 1500], 'Chile': [1500, 1327], 'Puerto Rico': [1500, 900], 'Netherlands Antilles': [1500, 500], 'Kiribati': [1500, 1500], 'Haiti': [1500, 1250], 'Belize': [1000, 1500], 'Sierra Leone': [1500, 1500], 'Georgia': [1500, 642], 'Gambia': [1500, 428], 'Philippines': [1086, 1500], 'Guinea Bissau': [1500, 1071], 'N Mariana Islands': [750, 1500], 'Moldova': [1500, 1312], 'Morocco': [1500, 1020], 'Croatia': [1500, 1250], 'Mongolia': [1500, 507], 'Guernsey': [750, 1500], 'Thailand': [900, 1500], 'Namibia': [1500, 1339], 'Grenada': [750, 1500], 'Iraq': [1500, 1214], 'Portugal': [1500, 588], 'Estonia': [1500, 535], 'Uruguay': [1500, 1363], 'Mexico': [1500, 867], 'Lebanon': [1500, 1500], 'Uzbekistan': [1500, 750], 'Tunisia': [1000, 1500], 'Djibouti': [1200, 1500], 'Greenland': [1500, 597], 'Antigua and Barbuda': [500, 1500], 'Spain': [1500, 1076], 'Colombia': [1328, 1500], 'Reunion': [1500, 1500], 'Burundi': [1500, 1500], 'Taiwan': [1500, 1333], 'Cyprus': [1500, 750], 'Madagascar': [827, 1500], 'Italy': [1500, 1320], 'Bhutan': [1500, 750], 'Sudan': [1346, 1500], 'Nepal': [1500, 794], 'Malta': [1500, 750], 'Bosnia Herzegovina': [1500, 1000], 'Netherlands': [1500, 500], 'Suriname': [1500, 1500], 'Anguilla': [1500, 750], 'Venezuela': [1500, 1285], 'Israel': [666, 1500], 'Svalbard': [1500, 437], 'Wake Island': [1500, 1500], 'Indonesia': [1500, 548], 'St Kitts and Nevis': [1500, 1500], 'Iceland': [1500, 500], 'Zambia': [1500, 1260], 'Senegal': [1500, 1071], 'Papua New Guinea': [1500, 1064], 'Trinidad and Tobago': [1500, 1500], 'St Pierre and Miquelon': [750, 1500], 'Germany': [1500, 1275], 'Vanuatu': [750, 1500], 'Western Samoa': [1500, 1125], 'Denmark': [1500, 700], 'Kazakhstan': [1500, 542], 'Poland': [1500, 857], 'Eritrea': [1500, 1200], 'Kyrgyzstan': [1500, 586], 'St Helena': [750, 1500], 'Mayotte': [1500, 1500], 'Montserrat': [1500, 1500], 'New Caledonia': [1500, 900], 'Macedonia': [1500, 857], 'St Lucia': [1500, 1500], 'North Korea': [1500, 1285], 'Sri Lanka': [833, 1500], 'Latvia': [1500, 562], 'Guyana': [1031, 1500], 'Syria': [1500, 1178], 'Guadeloupe': [1000, 1500], 'Honduras': [1500, 923], 'Byelarus': [1500, 825], 'Myanmar': [730, 1500], 'Equatorial Guinea': [1500, 1500], 'Egypt': [1500, 1260], 'Singapore': [1500, 1500], 'Serbia': [1500, 1500], 'United Kingdom': [1369, 1500], 'Congo': [1263, 1500], 'Greece': [1500, 1250], 'Paraguay': [1500, 1500], 'Gabon': [1500, 1500], 'Comoros': [1500, 1125]}";
var worldinregions = "['Global','Afghanistan', 'Albania', 'Algeria', 'American Samoa', 'Andorra', 'Angola', 'Anguilla', 'Antigua and Barbuda', 'Argentina', 'Armenia', 'Aruba', 'Australia', 'Austria', 'Azerbaijan', 'Bahamas', 'Bangladesh', 'Belize', 'Benin', 'Bhutan', 'Bolivia', 'Bosnia Herzegovina', 'Brazil', 'British Virgin Islands', 'Brunei', 'Bulgaria', 'Burkina Faso', 'Burundi', 'Byelarus', 'Cambodia', 'Cameroon', 'Canada', 'Cape Verde', 'Cayman Islands', 'Cen African Republic', 'Chad', 'Chile', 'China', 'Christmas Island', 'Colombia', 'Comoros', 'Congo', 'Cook Islands', 'Costa Rica', 'Croatia', 'Cuba', 'Cyprus', 'Czech Republic', 'Denmark', 'Djibouti', 'Dominica', 'Dominican Republic', 'Ecuador', 'Egypt', 'El Salvador', 'Equatorial Guinea', 'Eritrea', 'Estonia', 'Ethiopia', 'F S Micronesia', 'Falkland Islands', 'Faroe Islands', 'Finland', 'France', 'French Guiana', 'French Polynesia', 'Gabon', 'Gambia', 'Gaza Strip', 'Georgia', 'Germany', 'Ghana', 'Gibraltar', 'Greece', 'Greenland', 'Grenada', 'Guadeloupe', 'Guam', 'Guatemala', 'Guernsey', 'Guinea', 'Guinea Bissau', 'Guyana', 'Haiti', 'Honduras', 'Hungary', 'Iceland', 'India', 'Indonesia', 'Iran', 'Iraq', 'Ireland', 'Israel', 'Italy', 'Ivory Coast', 'Jamaica', 'Japan', 'Jordan', 'Kazakhstan', 'Kenya', 'Kiribati', 'Kuwait', 'Kyrgyzstan', 'Laos', 'Latvia', 'Lebanon', 'Lesotho', 'Liberia', 'Libya', 'Liechtenstein', 'Lithuania', 'Luxembourg', 'Macau', 'Macedonia', 'Madagascar', 'Malawi', 'Malaysia', 'Maldives', 'Mali', 'Malta', 'Man Isle of', 'Marshall Islands', 'Martinique', 'Mauritania', 'Mauritius', 'Mayotte', 'Mexico', 'Midway Islands', 'Moldova', 'Monaco', 'Mongolia', 'Montenegro', 'Montserrat', 'Morocco', 'Mozambique', 'Myanmar', 'N Mariana Islands', 'Namibia', 'Nauru', 'Nepal', 'Netherlands', 'Netherlands Antilles', 'New Caledonia', 'New Zealand', 'Nicaragua', 'Niger', 'Nigeria', 'North Korea', 'Norway', 'Oman', 'Pakistan', 'Palau Pacific Islands', 'Panama', 'Papua New Guinea', 'Paraguay', 'Peru', 'Philippines', 'Poland', 'Portugal', 'Puerto Rico', 'Qatar', 'Reunion', 'Romania', 'Russia', 'Rwanda', 'San Marino', 'Sao Tome and Principe', 'Saudi Arabia', 'Senegal', 'Serbia', 'Seychelles', 'Sierra Leone', 'Singapore', 'Slovakia', 'Slovenia', 'Solomon Islands', 'Somalia', 'South Africa', 'South Korea', 'Spain', 'Sri Lanka', 'St Helena', 'St Kitts and Nevis', 'St Lucia', 'St Pierre and Miquelon', 'St Vincent Grenadines', 'Sudan', 'Suriname', 'Svalbard', 'Swaziland', 'Sweden', 'Switzerland', 'Syria', 'Taiwan', 'Tajikistan', 'Tanzania', 'Thailand', 'Togo', 'Tokelau', 'Tonga', 'Trinidad and Tobago', 'Tunisia', 'Turkey', 'Turkmenistan', 'Turks Caicos Islands', 'Tuvalu', 'Uganda', 'Ukraine', 'United Arab Emirates', 'United Kingdom', 'United States', 'Uruguay', 'Uzbekistan', 'Vanuatu', 'Venezuela', 'Vietnam', 'Virgin Islands', 'Wake Island', 'Wallis and Futuna', 'West Bank', 'Western Sahara', 'Western Samoa', 'Yemen', 'Zaire', 'Zambia', 'Zimbabwe']";

var sidec = ["","January","February","March","April","May","June","July","August","September","October","November","December","","Annual","Dec-Feb","Mar-May","Jun-Aug","Sep-Nov"];
	
var transtoolon = true;
var lt;
var labels = new Array();

labels[0] = "";
labels[1] = "Data Source: PRISM Group, Oregon State University, created 4 Feb 2007.The PRISM Group retains rights to ownership of the data and information. <a href='http://www.prism.oregonstate.edu/' target='_blank'>http://www.prism.oregonstate.edu/</a>";
labels[2] = "Data Source: Base climate projections downscaled by <a href='http://www.engr.scu.edu/~emaurer/index.shtml' target='_blank'>Maurer, et al.</a> (2007) Santa Clara University. For more information see <a href='http://www.climatewizard.org/AboutUs.html' target='_blank'>About Us.</a>";
labels[3] = "Data Source: Historical Global 50km: Climatic Research Unit and the Tyndall Centre. Mitchell et. al. <a href='http://cru.csi.cgiar.org/PDF/mitchelljones.pdf' target='_blank'>http://cru.csi.cgiar.org/PDF/mitchelljones.pdf</a>";
labels[4] = "Data Source: Global climate model output, from the World Climate Research Programme's (WCRP's) Coupled Model Intercomparison Project phase 3 (CMIP3) multi-model dataset (Meehl et al., 2007), were downscaled as described by Maurer et al. (2009) using the bias-correction/spatial downscaling method (Wood et al., 2004) to a 0.5 degree grid, based on the 1950-1999 gridded observations of Adam and Lettenmaier (2003)."

function setupregions(){

    var usregionslist = eval('(' + usinregions + ')');
    
    for (var i = 0, il = usregionslist.length; i < il; i++) {
        reg = usregionslist[i];
        regdis = reg.replace("_", " ");
        document.getElementById('usregions').options[i] = new Option(regdis, reg, true);
    }
    
    var opts = document.getElementById('usregions').options;
    opts[0].selected = true;
    
    var worldregionslist = eval('(' + worldinregions + ')');
    
    for (var i = 0, il = worldregionslist.length; i < il; i++) {
        reg = worldregionslist[i];
        regdis = reg.replace("_", " ");
        document.getElementById('worldregions').options[i] = new Option(regdis, reg, true);
    }
    
    var opts = document.getElementById('worldregions').options;
    opts[0].selected = true;
}

function changemap(){
    updateregion();
}

function updateregion(){
	//console.info("inside updateregion");
    spaner = document.getElementById('grapher');
    desctext = "";

    historical = false;
    
    timelist = document.getElementsByName('timesel');
    reglist = document.getElementsByName('grouparea');
    
    sbox = document.getElementById('statbox');
    signi = document.getElementById('mapsig');
    avti = document.getElementById('mapdifference');   
   
    cvart = 0;
    cvarlist = document.getElementsByName('climatevar');
    for (i = 0; i < cvarlist.length; i++) {
        if (cvarlist[i].checked == true) {
            cvart = i;
            ccvar = cvarlist[i].value;
            cclab = document.getElementById('a' + ccvar).innerHTML;
        }
    }
    
    if (reglist[0].checked != true) {
        gcmlist = document.getElementById('gcmgroup');
        ogcmlist = document.getElementById('gcmgroupfull');
        gcmlist.style.display = '';
        ogcmlist.style.display = 'none';
        reg = document.getElementById('worldregions');
        regiv = document.getElementById('usregions');
        regiv.style.display = 'none';
        reg.style.display = '';
        reger = false;
        var extentdic = eval('(' + worldextents + ')');
        //var imagesizedic = eval('(' + worldimagesize + ')');
        if (timelist[0].checked == true) {
            yearvars = "[1951, 2002]";
            datasetval = "cru50k";
            urlRoot = "http://climatewizard.s3.amazonaws.com/global_country_1951_2002/"
            ccvar = ccvar.replace("ppt", "pptPct");
            historical = true;
            lt = 3;
            if (reg.value == "Global") {
                yearvars = "[1951, 2002]";
                //datasetval = "AR4_Global_50k";
                urlRoot = "http://climatewizard.s3.amazonaws.com/global_1951_2002/";
                sc = " ";
            }
        }
        else if (timelist[1].checked == true) {
            year2use = "the 2050s";
            yearvars = "[2040, 2069]";
            datasetval = "AR4_Global_50k";
            urlRoot = "http://climatewizard.s3.amazonaws.com/global_country_2040_2069/";
            sc = " ";
            lt = 4;
            ccvar = ccvar.replace("ppt", "pptPct");
            if (reg.value == "Global") {
                yearvars = "[2040, 2069]";
                datasetval = "AR4_Global_50k";
                urlRoot = "http://climatewizard.s3.amazonaws.com/global_2040_2069/";
                sc = " ";
            }
            gcmlist = document.getElementById('gcmgroupfull');
            ogcmlist = document.getElementById('gcmgroup');
            gcmlist.style.display = '';
            ogcmlist.style.display = 'none';
            //ccvar = ccvar.replace("ppt", "pptPct");
        
        }
        else {
            if (reg.value == "Global") {
				ccvar = ccvar.replace("ppt", "pptPct");
				year2use = "the 2080s";
                yearvars = "[2070, 2099]";
                datasetval = "AR4_Global_50k";
                urlRoot = "http://climatewizard.s3.amazonaws.com/global_2070_2099/";
                sc = " ";
                gcmlist = document.getElementById('gcmgroupfull');
                ogcmlist = document.getElementById('gcmgroup');
                gcmlist.style.display = '';
                ogcmlist.style.display = 'none';
            }
            else {
                ccvar = ccvar.replace("ppt", "pptPct");
                year2use = "the 2080s";
                yearvars = "[2070, 2099]";
                datasetval = "AR4_Global_50k";
                urlRoot = "http://climatewizard.s3.amazonaws.com/global_country_2070_2099/";
                sc = " ";
                gcmlist = document.getElementById('gcmgroupfull');
                ogcmlist = document.getElementById('gcmgroup');
                gcmlist.style.display = '';
                ogcmlist.style.display = 'none';
            }
        }
    }
    else {
        timelist[1].style.display = "";
        timelist[2].style.display = "";
        gcmlist = document.getElementById('gcmgroupfull');
        ogcmlist = document.getElementById('gcmgroup');
        gcmlist.style.display = '';
        ogcmlist.style.display = 'none';
        reg = document.getElementById('usregions');
        regiv = document.getElementById('worldregions');
        regiv.style.display = 'none';
        reg.style.display = '';
        reger = true;
        if (timelist[0].checked == true) {
            year2use = 0;
            spaner.style.display = "";
            var extentdic = eval('(' + usextents + ')');
            //var imagesizedic = eval('(' + usimagesize + ')');
            yearvars = "[1951, 2006]";
            datasetval = "prism";
            urlRoot = "http://climatewizard.s3.amazonaws.com/US_States_1951_2006/"
            ccvar = ccvar.replace("ppt", "pptPct");
            sc = " ";
            if (reg.value == "Alaska") {
                yearvars = "[1951, 2002]";
                datasetval = "cru50k";
            }
            if (reg.value == "Hawaii") {
                yearvars = "[1951, 2002]";
                datasetval = "cru50k";
            }
            if (reg.value == "United States") {
                urlRoot = "http://climatewizard.s3.amazonaws.com/US_1951_2006/"
                sc = " ";
            }
            historical = true;
            lt = 1;
        }
        else if (timelist[1].checked == true) {
            spaner.style.display = "none";
            year2use = "the 2050s";
            var extentdic = eval('(' + usextents + ')');
            //var imagesizedic = eval('(' + usaaimagesize + ')');
            yearvars = "[2040, 2069]";
            urlRoot = "http://climatewizard.s3.amazonaws.com/US_States_2040_2069/";
            datasetval = "AR4_US_12k";
            sc = " ";
            if (reg.value == "United States") {
                urlRoot = "http://climatewizard.s3.amazonaws.com/US_2040_2069/";
                sc = " ";
            }
            ccvar = ccvar.replace("ppt", "pptPct");
            lt = 2;
            if (reg.value == "Alaska") {
                datasetval = "AR4_Global_50k";
            }
            if (reg.value == "Hawaii") {
                datasetval = "AR4_Global_50k";
            }
            
            if (curgcm == "hadcm3") {
                curgcm = "ukmo_hadcm3.1";
            }
            if (curgcm == "csiro") {
                curgcm = "csiro_mk3_0.1";
            }
            if (curgcm == "miroc") {
                curgcm = "miroc3_2_medres.1";
            }
        }
        else if (timelist[2].checked == true) {
            spaner.style.display = "none";
            year2use = "the 2080s";
            var extentdic = eval('(' + usextents + ')');
            //var imagesizedic = eval('(' + usaaimagesize + ')');
            yearvars = "[2070, 2099]";
            urlRoot = "http://climatewizard.s3.amazonaws.com/US_States_2070_2099/";
            datasetval = "AR4_US_12k";
            sc = " ";
            if (reg.value == "United States") {
                urlRoot = "http://climatewizard.s3.amazonaws.com/US_2070_2099/";
                sc = " ";
            }
            ccvar = ccvar.replace("ppt", "pptPct");
            lt = 2;
            if (reg.value == "Alaska") {
                datasetval = "AR4_Global_50k";
            }
            if (reg.value == "Hawaii") {
                datasetval = "AR4_Global_50k";
            }
        }
    }
    	
	
    var yearlist = eval('(' + yearvars + ')');
    
    if (timelist[0].checked == true) {
        sbox.style.display = '';
        if (reglist[0].checked == true) {
            if (signi.checked == true) {
                desctext = historicalsig[cvart];
                
            }
            if (avti.checked == true) {
                desctext = historicalchange[cvart];
            }
        }
        else {
            if (signi.checked == true) {
                desctext = ghistoricalsig[cvart];
                
            }
            
            if (avti.checked == true) {
                desctext = ghistoricalchange[cvart];
            }
        }
        //Hide identify
		dojo.byId("identifyDiv").style.display = "none";
    }
    else {
		//Show Identify
		dojo.byId("identifyDiv").style.display = "";
		
        sbox.style.display = 'none';
        if (signi.checked == true) {
            //alert('dd');
            mapdd = document.getElementById('mapdifference');
            mapdd.checked = true;
            desctext = historicalsig[cvart];
            //alert(desctext);
        }
        
        desctext = futurechange[cvart];
        desctext = desctext.replace("[startYr]", yearlist[0]);
        desctext = desctext.replace("[endYr]", yearlist[1]);        
    }
    
    for (var i = 0; i < gcmlist.options.length; i++) {
        if (gcmlist.options[i].selected == true) {
            gcmlab = gcmlist.options[i].text;
            curgcm = gcmlist.options[i].value;
        }
    }
    
    curgcmsplit = curgcm.split("|");
    curgcm = curgcmsplit[0]; //gcmlist.value;    
        
    curregion = reg.value; //"Mississippi";
    
    maplist = document.getElementsByName('mapoption');
    for (i = 0; i < maplist.length; i++) {
        if (maplist[i].checked == true) {
            curmap = maplist[i].value;
            //alert(curmap);
            maplab = document.getElementById('a' + curmap).innerHTML;
            maplab = maplab.replace("Map of ", "");
            maplab = maplab.replace("Change", "Change in");
            if (i == 0) {
                desctext = mapofaverage[cvart];
            }
            //alert(maplab);
        }
    }
    
    co2list = document.getElementById('emmiscenario');
    
    curco2 = "_" + co2list.value;
    
    co2lab = curco2.toUpperCase();
    
    if (historical == true) {
        curgcm = "historical";
        curco2 = "";
        curmap = curmap.replace("depart_change", "trend_change_rate");
        co2list.disabled = true;
        gcmlist.disabled = true;
    }
    else {
        co2list.disabled = false;
        gcmlist.disabled = false;
    }
    
    middlestuff = "_" + datasetval + "_" + curgcm + curco2 + "_"
    
    if (curgcm == 'ensemble') {
        //ensvalsel = document.getElementById('ensemblenum');
        if (curgcmsplit[1] == undefined) {
            ensval = "50" + "_";
        }
        else {
        
            enindex = {
                "0": 0,
                "20": 1,
                "40": 2,
                "60": 3,
                "80": 4,
                "100": 5,
                "50": 6
            };
            
            if (cvart == 0) {
                desctext = tempensemble[enindex[curgcmsplit[1]]];
            }
            
            if (cvart == 1) {
                desctext = precipensemble[enindex[curgcmsplit[1]]];
            }
            
            ensval = curgcmsplit[1] + "_"; //ensvalsel.value + "_";
        }
        middlestuff = "_" + curgcm + "_" + ensval + datasetval + curco2 + "_"
        spaner.style.display = "none";
    }
    else {
        //spaner.style.display = "";	
    }
	
    mlist = document.getElementById('cycledropdown');
    
    startm = mlist.value;
    curr = curregion.replace(" ", " ").replace(" ", sc).replace(" ", sc).replace(" ", sc)
    baseimagefilename = urlRoot + (curr + "/" + ccvar + "/" + curgcm + curco2 + "/map_" + curmap + middlestuff + ccvar + "_" + startm + "_" + yearlist[0] + "_" + yearlist[1]);
    
    graphfilename = urlRoot + (curr + "/" + ccvar + "/" + curgcm + curco2 + "/graph_change_" + datasetval + "_" + curgcm + curco2 + "_" + ccvar + "_" + startm + "_" + yearlist[0] + "_" + yearlist[1]);
    //graphfilename = "graphs" + ("/graph_change_" + datasetval + "_" + curgcm + curco2 + "_" + ccvar + "_" + startm + "_" + yearlist[0] + "_" + yearlist[1]);
	
    graphfilenameshort = (graphfilename + "_small.png");
    graphfilenameshort = graphfilenameshort.replace("_historical", "");
    graphfilename = (graphfilename + ".png");
    graphfilename = graphfilename.replace("_historical", "");    
	
    imagefilename = baseimagefilename + "_noLegend.png";
    imagefilename = imagefilename.replace("_historical", "");
    legendfilename = baseimagefilename + "_legend.png";
    legendfilename = legendfilename.replace("_historical", "");    
    
    desctext = desctext.replace("[GCM Name]", gcmlab);
    desctext = desctext.replace("[Scenario Name]", co2lab.replace("_", ""));
    
    extext = document.getElementById('extratext');
    extext.innerHTML = desctext;
   	
	if(timelist[0].checked) {
		spaner.style.display = "";
		grap = document.getElementById('graph');
    	grap.src = graphfilenameshort;
	}
	
    toplab = cclab;
    
    mapt = document.getElementById('maptitle');
    submapt = document.getElementById('mapsubtitle');
    
    mapt.innerHTML = maplab + " " + sidec[startm] + " " + toplab.replace("Average", "") + " by " + year2use;
    submapt.innerHTML = "<br>Model: " + gcmlab + ", SRES emission scenario: " + co2lab.replace("_", "") + "<br /></span>";
    
    if (historical == true) {
        mapt.innerHTML = maplab + " " + sidec[startm] + " " + toplab.replace("Average", "") + " " + yearlist[0] + " - " + yearlist[1];
        submapt.innerHTML = "";
    }
    
    gcontent = '<img src="' + graphfilename + '" alt="" width="740" />';
    grapl = document.getElementById('graghlink');        
    grapl.href = graphfilename;   
   
    extentlist = extentdic[curregion];
    //imagesizelist = imagesizedic[curregion];
  
    linkimage = imagefilename.replace("_noLegend.png", ".png");
    ascfile = imagefilename.replace("_noLegend.png", ".asc");
    changecredit();
        
     //console.log("*******************");
     //console.log("ccvar - Measurement: " + ccvar);
     //console.log("curgcm - Model: " + curgcm);
     //console.log("curmap - MapOption: " + curmap);
     //if (curgcm == 'ensemble')console.log("ensval: " + ensval);
     //console.log("curco2 - Scenario: " + curco2);
     //console.log("middlestuff: " + middlestuff);
     //console.log("startm - Cycle: " + startm);
     //console.log("datasetval - AnalyisArea: " + datasetval);
     //console.log("yearlist - TimePeriod: " + yearlist);
     //console.log("*******************");    
	 
    var scenarioOptions = {
        WebFolder: '/ClimateChangeData',
        Legend: '_Legend',
        Delimeter: "_",
        MapOption: curmap,
        AnalyisArea: datasetval,
        Model: curgcm + (curgcm == 'ensemble' ? "_" + (ensval.split("_")[0]) : ""),
        Scenario: curco2.replace("_", ""),
        Measurement: (ccvar == "ppt" ? "pptPct" : ccvar),
        Cycle: startm,
        TimePeriod: yearlist[0] + "_" + yearlist[1]
    };
	   
    var extentToPass = new esri.geometry.Extent(extentlist[0], extentlist[1], extentlist[2], extentlist[3], new esri.SpatialReference({
        "wkid": 102113
    }));
	
    updateMapAndLegend(scenarioOptions, extentToPass);    
}
function showFactoids(cbox) {
	if(cbox.checked) {		
		var graphics = [];				
		for (var i = 0; i < factoids.length - 1; i++) {		
			var imageIcon = new esri.symbol.PictureMarkerSymbol("factoids/icons/" + factoids[i].icon, 30, 30).setOffset(-15, -15);
			var point = new esri.geometry.Point(factoids[i].lon, factoids[i].lat);
			var attr = {
				content: '<img style="padding:5px;" width="150px" height="100px" src="factoids/images/' + i + '.png" align="left">' + factoids[i].desc + '<br/>' + '<a href="' + factoids[i].hlink + '" target="_blank">Click Here For more information</a><img src="images/hide.png" align="right" width="12px" height="12px" title="Close" alt="Close" onclick="g_mouseout()"/>'
			};
			var graphic = new esri.Graphic(esri.geometry.geographicToWebMercator(point), imageIcon, attr, null);
			graphics.push(graphic);
		}
		
		for (var i = graphics.length - 1; i >= 0; i--) {
        	map.graphics.add(graphics[i]);
    	}
				
		dojo.connect(map.graphics, "onMouseOver", g_mouseover);
		//dojo.connect(map.graphics, "onMouseOut", g_mouseout);			
	} else {		
		if (iTip.isShowing) iTip.hide();
		map.graphics.clear();	
	}
}

function g_mouseout(evt) {	
	iTip.hide();	
}

function g_mouseover(evt){		
	iTip.setContent(evt.graphic.attributes.content);
    iTip.show(evt.screenPoint);
}

function changeOpacity(value){	
	climateChangeLayer.setOpacity(value);
}

function changeLayers(rdbtn){    
    if (rdbtn.value == "topo") {
        topoLayer.show();
        worldbaseLayer.hide();
        showMapCopyright(topoLayer);
    }
    else {
        worldbaseLayer.show();
        topoLayer.hide();
        showMapCopyright(worldbaseLayer);
    }
}

function updateMapAndLegend(scenarioOptions, extent){   
    climateChangeLayer.setScenarioOptions(scenarioOptions,false);
    //console.log("Legend: " + climateChangeLayer.getScenarioLegend());
    dojo.byId("legend").src = climateChangeLayer.getScenarioLegend();
	map.setExtent(extent);
}

function changecredit(){
    cred = document.getElementById('credit');
    cred.innerHTML = labels[lt];
}

function showMapCopyright(layer){
    if (layer.visible && layer.copyright) {
        dojo.byId("attribDiv").innerHTML = "Map data " + layer.copyright;
    }
}

//show map coordinates
function showCoords(val){
    var o = dojo.byId("coordsDiv");
    var ext = val.mapPoint || val;
    ext = esri.geometry.webMercatorToGeographic(ext);	
    o.innerHTML = "Lat: " +  ext.y.toFixed(2) + "&#176;&nbsp;Lon: " + ext.x.toFixed(2) + "&#176;"; 
}

function okit(inputval){
    if (inputval == 'map') {
        linky = linkimage;
    }
    else {
        linky = ascfile;
    }
    
    //var mine = window.open('http://faculty.washington.edu/girvetz/ClimateWizard_revision/download.html?link=' + linky, "_blank", "menubar=1,resizable=1,width=500,height=450");
	var mine = window.open('download.html?link=' + linky, "_blank", "menubar=1,resizable=1,width=500,height=450");
    
    if (mine) {
    
    }
    else {
        alert("A popup blocker is preventing the download page from appearing")
    }
}

//Printer Friendly
function printwin() {
	var pwin = window.open("print.html");
	if (!pwin) {
		alert("A popup blocker is preventing the print page from appearing");
		return;
	}		
		
	//var reflayer = "http://server.arcgisonline.com/ArcGIS/rest/services/Reference/World_Boundaries_and_Places_Alternate/MapServer";
	var reflayerurl = "http://www.climatewizard.org/ArcGIS/rest/services/TNC/TNCBasemap/MapServer";
	var tilelayer = topoLayer.visible?topoLayer:worldbaseLayer;
	var p_baselayer = tilelayer.url + "/export?transparent=true&f=image&format=png24&size="+ map.width + "," + map.height +"&bbox=" + dojo.string.substitute("${xmin},${ymin},${xmax},${ymax}", map.extent);
	var p_referencelayer = reflayerurl + "/export?transparent=true&f=image&format=png24&bboxSR=102113&imageSR=102113&size="+ map.width + "," + map.height +"&bbox=" + dojo.string.substitute("${xmin},${ymin},${xmax},${ymax}", map.extent);
	//console.log(p_referencelayer);
	var p_climate = climateChangeLayer.scenarioOptions.getImageUrl(map.extent, map.width, map.height);
	var p_legend = climateChangeLayer.getScenarioLegend();
	//var p_opacity = "opacity:" + climateChangeLayer.opacity + ";filter:alpha(opacity=" + climateChangeLayer.opacity + ");";	
	var content = [];
	var footer = [];
	footer.push("<table cellspacing='0' cellpadding='0' width='668px'><tr><td style='padding-left:5px;font-size:8pt;'>");
	
	content.push('<img style="position:absolute;top:0;left:0;border:1px solid #ccc;" src="' + p_baselayer + '"/>');
	content.push('<img style="position:absolute;top:0;left:0;border:1px solid #ccc;" src="' + p_climate + '"/>');
		
	//Global
	if (reglist[1].checked) {
		p_referencelayer += "&layers=show:0";
	}
	//USA
	else if (reglist[0].checked) {
		p_referencelayer += "&layers=show:1";	
	}
	
	content.push('<img style="position:absolute;top:0;left:0;border:1px solid #ccc;opacity:0.5;filter:alpha(opacity=50);" src="' + p_referencelayer + '"/>');
	
		
	/*
	if (curregion == "United States" || curregion == "Global") {
		content.push('<img style="position:absolute;top:0;left:0;border:1px solid #ccc;" src="' + p_baselayer + '"/>');
		content.push('<img style="position:absolute;top:0;left:0;border:1px solid #ccc;" src="' + p_climate + '"/>');	
	} else {
		content.push('<img style="position:absolute;top:0;left:0;border:1px solid #ccc;" src="' + p_baselayer + '"/>');
		content.push('<img style="position:absolute;top:0;left:0;border:1px solid #ccc;" src="' + p_climate + '"/>');		
		content.push('<img style="position:absolute;top:0;left:0;opacity:0.4;filter:alpha(opacity=40);border:1px solid #ccc" src="' + p_referencelayer + '"/>');					
	}
	
	content.push('<img style="position:absolute;top:0;left:0;border:1px solid #ccc;" src="' + p_baselayer + '"/>');
	content.push('<img style="position:absolute;top:0;left:0;border:1px solid #ccc;'+p_opacity+'" src="' + p_climate + '"/>');
	*/		
	content.push('<img style="position:absolute;top:215px;right:0;background-color:#fff;height:280px;width:75px;" src="' + p_legend + '"/>');
	content.push('<img style="position:absolute;top:469px;left:2px;width:56px;height:28px" src="images/poweredbyesri.png"/>');
	
	footer.push("<i>" + dojo.byId("attribDiv").innerHTML + "</i><br/>");
	footer.push(document.getElementById('credit').innerHTML+"</td>");	
	footer.push("<td><img width='124px' align='right' src='images/tnc_logo_white.jpg'/></td>");
	footer.push("</tr></table>");
	footer.push("<script></script>")
	
	setTimeout(function(){
		pwin.document.getElementById("content").style.width = map.width + "px";
		pwin.document.getElementById("header").innerHTML = document.getElementById('titlef').innerHTML;
		pwin.document.getElementById("content").innerHTML = content.join(""); 
		pwin.document.getElementById("footer").innerHTML =	footer.join("");	
		pwin.document.close();
	},1500);	
}

//infotip code
function infoTip(e,b,d,c){this.LOCATION={left:"left",right:"right",top:"top",bottom:"bottom"};this._isShowing=false;this._coords=null;this._height=0;this._width=0;this._location="top";this._padding=15;this._xOffset=d.x;this._yOffset=d.y;this._id=e;this._animationRef=null;this._animation=c;var a=dojo.doc.createElement("div");dojo.attr(a,{id:e,"class":b,style:"display:none"});dojo.doc.body.appendChild(a);this.getId=function(){return this._id};this.setPadding=function(f){this._padding=f};this.setLocation=function(f){this._location=f};this.setSize=function(f,g){dojo.style(this._id,{height:g+"px",width:f+"px"})};this.setContent=function(f){dojo.byId(this._id).innerHTML=f;dojo.style(this._id,"display","")};this.setClass=function(f){dojo.byId(this._id).className=f};this.show=function(g){this._coords=dojo.coords(this._id);this._height=this._coords.h;this._width=this._coords.w;var h,f;switch(this._location){case"left":h=g.y+this._yOffset-(this._height/2)+"px";f=g.x+this._xOffset-this._width-this._padding+"px";break;case"right":h=g.y+this._yOffset-(this._height/2)+"px";f=g.x+this._xOffset+this._padding+"px";break;case"bottom":h=g.y+this._yOffset+this._padding+"px";f=g.x+this._xOffset-(this._width/2)+"px";break;case"top":h=g.y+this._yOffset-this._height-this._padding+"px";f=g.x+this._xOffset-(this._width/2)+"px";break}dojo.style(this._id,{left:f,top:h,display:""});if(this._animation){if(this._animationRef!=null){this._animationRef.stop()}this._animationRef=dojo.fadeIn({node:this._id,duration:1000}).play()}this._isShowing=true};this.hide=function(){if(!this._isShowing){return}if(this._animation){this._animationRef=dojo.fadeOut({node:this._id,duration:800,onEnd:function(){this.node.style.display="none"}}).play()}else{dojo.style(this._id,"display","none")}this._isShowing=false};this.isShowing=function(){return this._isShowing}};
