try
{
    wedebug.addLogger("map", "MapController");
}
catch(e)
{
    alert(e.message);
}
 
var MapController = {};
MapController.Styles = {
    REGULAR : 0,
    AERIAL : 1,
    HYBRID : 2,
    BIRDS_EYE : 3        
};

Object.extend(GLMap.prototype, AbstractMapController);

Object.extend(GLMap.prototype, {
    m_glMap : null,
    m_controlPane : null,
    m_drawingPane : null,
    m_controlPanePosition : {left:0, top:0},    
    m_currentLevel : 2,
    m_lat : 59.90891042881661,
    m_lon : 10.789260864257801,
    m_initLat : 64.47,
    m_initLon : 11.50,
    m_initLevel : 15,
    m_onChangeView : null,
    m_onContextMenuEvent : null,
    m_onMapStyleChange : null,
    m_onBeginPan : null,
    m_onEndPan : null,
    m_onBeginZoomRect : null,
    m_onEndZoomRect : null,
    m_onEndSlide : null,
    m_onBeginSlide : null,
    m_onPan : null,
    m_onResize : null,
    m_mapMarkers : null,
    m_mapStyle : null,
    m_customerId : null,
    m_fitMap : true,
    m_navigationDisabled : false,
    m_season : 'sommer',
    
    m_osloLat : [59.81691, 59.81734, 59.81813, 59.82537, 59.82484, 59.82298, 59.82343, 59.82494, 59.82588, 59.82620, 59.82367, 59.82349, 59.82954, 59.83053, 59.83929, 59.85107, 59.87719, 59.87593, 59.88371, 59.88441, 59.89462, 59.90941, 59.91071, 59.91407, 59.91470, 59.91405, 59.91468, 59.91632, 59.91732, 59.91797, 59.91771, 59.91876, 59.92173, 59.92246, 59.92350, 59.92441, 59.92518, 59.92709, 59.92786, 59.92963, 59.93123, 59.93255, 59.93459, 59.93579, 59.93925, 59.94240, 59.94280, 59.94566, 59.94784, 59.95187, 59.95230, 59.95303, 59.95354, 59.95371, 59.95626, 59.95723, 59.95856, 59.96163, 59.96267, 59.96483, 59.96634, 59.97051, 59.97432, 59.97661, 59.97698, 59.97671, 59.97770, 59.97674, 59.97686, 59.97754, 59.97860, 59.98552, 59.99223, 59.99403, 59.99639, 59.99672, 59.99462, 59.99365, 59.99552, 59.99804, 60.00064, 60.00014, 59.99932, 59.99977, 59.99991, 59.99936, 60.00850, 60.01579, 60.01726, 60.02602, 60.03843, 60.05177, 60.06503, 60.07624, 60.07728, 60.08286, 60.09214, 60.09394, 60.10068, 60.10983, 60.11678, 60.12870, 60.13162, 60.13459, 60.13518, 60.13277, 60.13353, 60.12580, 60.12586, 60.12531, 60.12519, 60.12286, 60.12117, 60.11940, 60.11991, 60.11966, 60.12019, 60.12059, 60.12154, 60.12172, 60.12365, 60.12504, 60.12573, 60.12526, 60.12326, 60.12303, 60.12161, 60.12081, 60.11833, 60.11285, 60.11218, 60.11180, 60.10609, 60.10496, 60.10103, 60.09955, 60.09917, 60.09860, 60.09856, 60.09777, 60.09268, 60.08689, 60.08659, 60.08403, 60.07893, 60.07827, 60.07714, 60.07484, 60.07060, 60.06755, 60.06689, 60.06610, 60.06575, 60.06421, 60.06467, 60.06436, 60.06515, 60.06489, 60.06429, 60.05371, 60.04309, 60.04054, 60.03783, 60.03693, 60.03563, 60.03328, 60.03026, 60.02976, 60.02912, 60.02736, 60.02110, 60.01813, 60.01788, 60.01734, 60.01791, 60.02211, 60.02327, 60.02315, 60.02148, 60.01985, 60.01780, 60.00969, 60.00846, 60.00610, 59.99799, 59.99815, 59.99714, 59.99964, 60.00179, 59.99616, 59.99552, 59.99566, 59.99491, 59.99301, 59.98677, 59.98558, 59.98442, 59.98078, 59.98053, 59.98072, 59.98023, 59.98099, 59.98398, 59.98455, 59.98372, 59.97712, 59.97705, 59.96955, 59.96552, 59.96286, 59.95484, 59.95260, 59.95321, 59.94924, 59.94803, 59.94694, 59.94778, 59.94687, 59.94598, 59.94572, 59.94318, 59.94180, 59.94116, 59.93486, 59.92653, 59.92045, 59.91937, 59.91228, 59.91162, 59.91127, 59.90041, 59.89682, 59.88496, 59.87528, 59.86989, 59.86475, 59.86010, 59.85206, 59.84493, 59.83684, 59.83631, 59.83489, 59.83170, 59.83133, 59.82693, 59.82773, 59.82776, 59.82679, 59.82710, 59.82629, 59.82609, 59.82620, 59.82548, 59.82368, 59.82204, 59.82102, 59.81815, 59.81703, 59.81575, 59.81434, 59.81216, 59.81104, 59.81204, 59.81297, 59.81306, 59.81232, 59.80946, 59.81198, 59.81529, 59.81685, 59.81616, 59.81699, 59.81691],
    m_osloLon : [10.83369, 10.83169, 10.81725, 10.81244, 10.80450, 10.79843, 10.78920, 10.78261, 10.78091, 10.77675, 10.77244, 10.77156, 10.76478, 10.76156, 10.74400, 10.73995, 10.73097, 10.68893, 10.66064, 10.65808, 10.65387, 10.64777, 10.64253, 10.63988, 10.63553, 10.63506, 10.63304, 10.63298, 10.63427, 10.63309, 10.63123, 10.63006, 10.62936, 10.62578, 10.62532, 10.62596, 10.62746, 10.62543, 10.62708, 10.62647, 10.63107, 10.63299, 10.63402, 10.63531, 10.63161, 10.63341, 10.63289, 10.63581, 10.63561, 10.63387, 10.63304, 10.63403, 10.63353, 10.63205, 10.63083, 10.63175, 10.62995, 10.62758, 10.62357, 10.62444, 10.62051, 10.61817, 10.61395, 10.61045, 10.60385, 10.60370, 10.59622, 10.59395, 10.59165, 10.59027, 10.59025, 10.57878, 10.56570, 10.55948, 10.55692, 10.55585, 10.55218, 10.54912, 10.54526, 10.54399, 10.53380, 10.52968, 10.52841, 10.52754, 10.52266, 10.51795, 10.50366, 10.49021, 10.48916, 10.50276, 10.52201, 10.54276, 10.56337, 10.58077, 10.59731, 10.59278, 10.59184, 10.59212, 10.58836, 10.57999, 10.57278, 10.59522, 10.60081, 10.61047, 10.61906, 10.64515, 10.68032, 10.69737, 10.69842, 10.69986, 10.70447, 10.70493, 10.70385, 10.70726, 10.71477, 10.71615, 10.71703, 10.71688, 10.71980, 10.72497, 10.73165, 10.73248, 10.73712, 10.74026, 10.74418, 10.74689, 10.74830, 10.75123, 10.75232, 10.76785, 10.76840, 10.76621, 10.75711, 10.75593, 10.75475, 10.75534, 10.75762, 10.75796, 10.75916, 10.76205, 10.76710, 10.77063, 10.77233, 10.77481, 10.77796, 10.77902, 10.77864, 10.78232, 10.78470, 10.78802, 10.79385, 10.79691, 10.80157, 10.80937, 10.81045, 10.81208, 10.81561, 10.81927, 10.81976, 10.81656, 10.81803, 10.81696, 10.81810, 10.81464, 10.81280, 10.81205, 10.81316, 10.81240, 10.81340, 10.81200, 10.81542, 10.81921, 10.82064, 10.82139, 10.82217, 10.82350, 10.82526, 10.82693, 10.82875, 10.82921, 10.83204, 10.83314, 10.83571, 10.83704, 10.83808, 10.83910, 10.84252, 10.84311, 10.84959, 10.85821, 10.86331, 10.86429, 10.86605, 10.86714, 10.87516, 10.87540, 10.88293, 10.89337, 10.90433, 10.90591, 10.90740, 10.91267, 10.91629, 10.91820, 10.92565, 10.93057, 10.93106, 10.93751, 10.93807, 10.93705, 10.94129, 10.94334, 10.94433, 10.95138, 10.94763, 10.94608, 10.94499, 10.94244, 10.94272, 10.94206, 10.94584, 10.94306, 10.94246, 10.92912, 10.92148, 10.91913, 10.91781, 10.91573, 10.91481, 10.91521, 10.91188, 10.91142, 10.90762, 10.90988, 10.90715, 10.90934, 10.91233, 10.92155, 10.92651, 10.93119, 10.93367, 10.93520, 10.93660, 10.93300, 10.92716, 10.92303, 10.91703, 10.91477, 10.91326, 10.91079, 10.91094, 10.90679, 10.90105, 10.89649, 10.89677, 10.89180, 10.89157, 10.88907, 10.88760, 10.88294, 10.88188, 10.87985, 10.87885, 10.87378, 10.86889, 10.86313, 10.85584, 10.84790, 10.84604, 10.84597, 10.83730, 10.83566, 10.83369],
    m_drammenLat : [59.66862, 59.66801, 59.66826, 59.66943, 59.66786, 59.66899, 59.66770, 59.66586, 59.67038, 59.67169, 59.67054, 59.66818, 59.66774, 59.66078, 59.65957, 59.65499, 59.64111, 59.64328, 59.64379, 59.64368, 59.64252, 59.64134, 59.64126, 59.64044, 59.65394, 59.65835, 59.66410, 59.66665, 59.66992, 59.67174, 59.67351, 59.67533, 59.67618, 59.67507, 59.67506, 59.67998, 59.68126, 59.68360, 59.68724, 59.68783, 59.68694, 59.68915, 59.69073, 59.69299, 59.69569, 59.69960, 59.69993, 59.70102, 59.70428, 59.70493, 59.70953, 59.71105, 59.71400, 59.71416, 59.72892, 59.73046, 59.73085, 59.73058, 59.73055, 59.73738, 59.74227, 59.74548, 59.75006, 59.74858, 59.74832, 59.74860, 59.75276, 59.75294, 59.75509, 59.76453, 59.77160, 59.77528, 59.78327, 59.79811, 59.80329, 59.80633, 59.80946, 59.81118, 59.81463, 59.81601, 59.81214, 59.80805, 59.80446, 59.80197, 59.79907, 59.79912, 59.79763, 59.79670, 59.78798, 59.78776, 59.77861, 59.77800, 59.77636, 59.77571, 59.77521, 59.77504, 59.77339, 59.77312, 59.76441, 59.76466, 59.76278, 59.76417, 59.76482, 59.76180, 59.76153, 59.76165, 59.75860, 59.75699, 59.75785, 59.75711, 59.75273, 59.75341, 59.75027, 59.74937, 59.74427, 59.74465, 59.74361, 59.74023, 59.74026, 59.73922, 59.73221, 59.72634, 59.71258, 59.70844, 59.70364, 59.70247, 59.70194, 59.69128, 59.68966, 59.68269, 59.68237, 59.68079, 59.67992, 59.67747, 59.67482, 59.66824, 59.67059, 59.67163, 59.67100, 59.67242, 59.67304, 59.67370, 59.67351, 59.67383, 59.67337, 59.67351, 59.67329, 59.67381, 59.67247, 59.66641, 59.66965, 59.67005, 59.67109, 59.67128, 59.66806, 59.66623, 59.66484, 59.66436, 59.66707, 59.66659, 59.66813, 59.67180, 59.67093, 59.67026, 59.66867, 59.66862],
    m_drammenLon : [10.18466, 10.17983, 10.17786, 10.17421, 10.16627, 10.15939, 10.15745, 10.15718, 10.13970, 10.13590, 10.11545, 10.11406, 10.11300, 10.11156, 10.10863, 10.09674, 10.08763, 10.07925, 10.07892, 10.05072, 10.04524, 10.04314, 10.04090, 10.03750, 10.02477, 10.01825, 10.00539, 10.01387, 10.01579, 10.01233, 10.01446, 10.02348, 10.02597, 10.03121, 10.03350, 10.04528, 10.05075, 10.06067, 10.06671, 10.06761, 10.07090, 10.07179, 10.07186, 10.07367, 10.07230, 10.07517, 10.07462, 10.07604, 10.07653, 10.07798, 10.07975, 10.08207, 10.08438, 10.08394, 10.07880, 10.08021, 10.09001, 10.09333, 10.10084, 10.10587, 10.10768, 10.10732, 10.10950, 10.11724, 10.12627, 10.12922, 10.11258, 10.10796, 10.10650, 10.11035, 10.10963, 10.10831, 10.10748, 10.10775, 10.10921, 10.10766, 10.10367, 10.10317, 10.09917, 10.10698, 10.11153, 10.12156, 10.13607, 10.14126, 10.14364, 10.14452, 10.14751, 10.14797, 10.16783, 10.16930, 10.16702, 10.16587, 10.16760, 10.17102, 10.17121, 10.17353, 10.17871, 10.18074, 10.18647, 10.19711, 10.19622, 10.19996, 10.20562, 10.20680, 10.20869, 10.21035, 10.21095, 10.21254, 10.21515, 10.21733, 10.22177, 10.22530, 10.22723, 10.22724, 10.23228, 10.23419, 10.23669, 10.24076, 10.25071, 10.25437, 10.27108, 10.28206, 10.29346, 10.30107, 10.31448, 10.31960, 10.32340, 10.31986, 10.32267, 10.31289, 10.31183, 10.31140, 10.30985, 10.31030, 10.30765, 10.30294, 10.28580, 10.28338, 10.27167, 10.26976, 10.26469, 10.25981, 10.25809, 10.25658, 10.25562, 10.25497, 10.25383, 10.25003, 10.24339, 10.23861, 10.23232, 10.23098, 10.23053, 10.22450, 10.22256, 10.22363, 10.22280, 10.21529, 10.21300, 10.21037, 10.20979, 10.19218, 10.19130, 10.18757, 10.18544, 10.18466],
    m_aalesundLat : [62.47727, 62.47296, 62.47376, 62.47475, 62.47550, 62.47761, 62.47980, 62.48005, 62.47948, 62.47298, 62.47163, 62.46854, 62.46713, 62.45956, 62.46056, 62.45682, 62.45479, 62.45220, 62.45037, 62.44797, 62.44721, 62.44747, 62.44717, 62.44416, 62.43278, 62.41762, 62.41705, 62.41397, 62.41069, 62.40118, 62.39436, 62.41466, 62.42513, 62.43239, 62.43113, 62.43001, 62.43180, 62.43224, 62.43510, 62.43854, 62.44481, 62.44809, 62.45734, 62.45868, 62.45898, 62.44817, 62.44545, 62.45317, 62.47511, 62.47891, 62.48771, 62.48915, 62.50351, 62.50924, 62.51628, 62.52005, 62.52233, 62.52258, 62.52377, 62.52508, 62.51921, 62.50916, 62.50465, 62.50180, 62.49277, 62.48443, 62.48463, 62.47969, 62.47727],
    m_aalesundLon : [6.44474, 6.44515, 6.45062, 6.46199, 6.46577, 6.47247, 6.48584, 6.49571, 6.51657, 6.51718, 6.51344, 6.51881, 6.51694, 6.52779, 6.53391, 6.54114, 6.54357, 6.54521, 6.54072, 6.53735, 6.53977, 6.54383, 6.54884, 6.55498, 6.57127, 6.52153, 6.51968, 6.43840, 6.42586, 6.38945, 6.36339, 6.36498, 6.37594, 6.36609, 6.32862, 6.32158, 6.31569, 6.29556, 6.29490, 6.30035, 6.26895, 6.25826, 6.22798, 6.19169, 6.18329, 6.14882, 6.10258, 6.05515, 6.06837, 6.08800, 6.13353, 6.13723, 6.16731, 6.19100, 6.22203, 6.23869, 6.27201, 6.28856, 6.36945, 6.46264, 6.46404, 6.45493, 6.43430, 6.43811, 6.43151, 6.43690, 6.43896, 6.44453, 6.44474],
    m_trondheimLat : [63.31497, 63.31618, 63.31461, 63.31502, 63.31668, 63.32079, 63.32081, 63.32596, 63.32961, 63.32935, 63.33979, 63.33898, 63.34072, 63.34407, 63.34507, 63.34442, 63.34157, 63.33825, 63.33240, 63.33048, 63.33381, 63.34046, 63.34153, 63.35398, 63.35791, 63.36048, 63.37298, 63.38327, 63.41218, 63.42449, 63.45457, 63.46234, 63.46389, 63.48338, 63.49558, 63.49984, 63.50431, 63.50920, 63.51269, 63.51659, 63.49630, 63.49529, 63.46956, 63.44634, 63.42965, 63.42640, 63.42313, 63.41976, 63.41845, 63.41391, 63.41176, 63.40856, 63.40965, 63.40393, 63.39983, 63.39923, 63.39871, 63.39275, 63.38864, 63.37808, 63.37476, 63.37355, 63.37410, 63.37371, 63.37367, 63.37098, 63.36512, 63.36441, 63.36374, 63.36170, 63.35918, 63.35709, 63.35622, 63.35391, 63.35263, 63.36248, 63.35491, 63.34738, 63.34538, 63.33019, 63.32617, 63.31594, 63.31371, 63.30679, 63.30820, 63.31195, 63.31416, 63.31506, 63.31613, 63.31788, 63.31792, 63.32683, 63.33188, 63.33414, 63.33349, 63.33425, 63.33561, 63.33508, 63.33815, 63.33984, 63.34003, 63.33853, 63.33893, 63.33859, 63.33848, 63.33902, 63.33886, 63.33935, 63.33912, 63.34021, 63.34076, 63.33986, 63.33750, 63.33910, 63.33921, 63.33676, 63.33269, 63.33104, 63.32962, 63.32438, 63.31909, 63.31764, 63.31371, 63.30713, 63.30574, 63.30453, 63.30279, 63.30468, 63.31162, 63.31721, 63.31964, 63.32029, 63.32194, 63.32241, 63.31824, 63.31681, 63.31540, 63.31456, 63.31329, 63.31274, 63.31244, 63.31079, 63.30664, 63.30476, 63.30404, 63.30526, 63.30493, 63.30757, 63.30916, 63.31497],
    m_trondheimLon : [10.29524, 10.28711, 10.28661, 10.28102, 10.28016, 10.27486, 10.27267, 10.26092, 10.25850, 10.26015, 10.25495, 10.25283, 10.24443, 10.21803, 10.21232, 10.20432, 10.19372, 10.18921, 10.18659, 10.16391, 10.14308, 10.10139, 10.09473, 10.07204, 10.06487, 10.05444, 10.00353, 10.00777, 10.01972, 10.02969, 10.05412, 10.10616, 10.11212, 10.18750, 10.23479, 10.27279, 10.31278, 10.35656, 10.41855, 10.48858, 10.54742, 10.55035, 10.53932, 10.57106, 10.59558, 10.59197, 10.59561, 10.59590, 10.59011, 10.58647, 10.58312, 10.58954, 10.60295, 10.61143, 10.61205, 10.61161, 10.61648, 10.61061, 10.61160, 10.62252, 10.60912, 10.61037, 10.61360, 10.61484, 10.62814, 10.64611, 10.65039, 10.65527, 10.65714, 10.65872, 10.65759, 10.64598, 10.64542, 10.63818, 10.63867, 10.67183, 10.68276, 10.69946, 10.70004, 10.68729, 10.68897, 10.70361, 10.70979, 10.72517, 10.72054, 10.68852, 10.66851, 10.63516, 10.62610, 10.61520, 10.60751, 10.57075, 10.55325, 10.54775, 10.54398, 10.54368, 10.54110, 10.53571, 10.51344, 10.51028, 10.50889, 10.50254, 10.49658, 10.49663, 10.49595, 10.49219, 10.49143, 10.48991, 10.48935, 10.48089, 10.47033, 10.46760, 10.45023, 10.44735, 10.44310, 10.44270, 10.43375, 10.43288, 10.42703, 10.39606, 10.40238, 10.40295, 10.40294, 10.40410, 10.40211, 10.40148, 10.39950, 10.39566, 10.38576, 10.36235, 10.36032, 10.35710, 10.35683, 10.35532, 10.33270, 10.33393, 10.32990, 10.33081, 10.33460, 10.33386, 10.33172, 10.32731, 10.32364, 10.31983, 10.31411, 10.30668, 10.30370, 10.29944, 10.29116, 10.29524],
    m_stavangerLat : [58.93371, 58.93480, 58.93764, 58.93321, 58.92825, 58.92743, 58.93319, 58.94053, 58.94608, 58.95606, 58.96026, 58.96126, 58.96605, 58.96962, 58.97819, 58.97619, 58.97645, 58.97787, 58.97891, 58.97652, 58.97489, 58.97176, 58.97376, 58.97370, 58.97766, 58.97793, 58.98344, 58.99030, 58.99561, 59.00212, 59.01449, 59.02035, 59.02442, 59.03967, 59.04946, 59.05989, 59.05996, 59.06016, 59.04596, 59.03278, 58.98663, 58.96868, 58.96679, 58.96470, 58.95224, 58.94599, 58.93000, 58.91249, 58.89002, 58.88488, 58.88481, 58.88948, 58.88857, 58.89410, 58.89461, 58.90804, 58.91429, 58.92753, 58.93370, 58.93371],
    m_stavangerLon : [5.69395, 5.69203, 5.68902, 5.68225, 5.66447, 5.64630, 5.63296, 5.63024, 5.61883, 5.61394, 5.60796, 5.59472, 5.58381, 5.56561, 5.59123, 5.60727, 5.61356, 5.61493, 5.62101, 5.62305, 5.63073, 5.64237, 5.65099, 5.66330, 5.66238, 5.66305, 5.65884, 5.64741, 5.65252, 5.67129, 5.68348, 5.71172, 5.73133, 5.72291, 5.71552, 5.73720, 5.74952, 5.78394, 5.79103, 5.78511, 5.86341, 5.83948, 5.80676, 5.80404, 5.78790, 5.77982, 5.77412, 5.76789, 5.75990, 5.75807, 5.74849, 5.72680, 5.72505, 5.69806, 5.69599, 5.69294, 5.68180, 5.69633, 5.70285, 5.69395],
    
    m_zoomLevels : $R(0,13).toArray(),
    
    m_stateManager : null,
    /**
    * Constructor for controller.
    * @argument divId : id of div used to intercept events of underlying maps
    * @argument [level] : initial zoom level. Default 2. 
    */
    base_initialize : GLMap.prototype.initialize,
    initialize : function(
        /*string*/t_divId, 
        /*number*/t_level, 
        /*number*/t_lat, 
        /*number*/t_lon,
        /*number*/t_style,
        /*string*/t_customerId,
        /*bool*/t_disableNavigation,
        /*bool*/t_fitMap,
        /*string*/t_drawingDivId)
    {   
        //To disable navigation is VE. Use LoadMap argument.
        this.m_navigationDisabled = (typeof t_disableNavigation != "undefined") ? t_disableNavigation : false;
        this.m_controlPane = $(t_divId);
        this.m_drawingPane = $(t_drawingDivId);
        this.m_stateManager = new StateManager(this.m_controlPane, this);
        var pos = Position.cumulativeOffset(this.m_controlPane);
        this.m_controlPanePosition = {left:pos[0], top:pos[1]};
        this.m_fitMap = (typeof t_fitMap != "undefined") ? t_fitMap : true;
        this.m_mapStyle = t_style;
        
        this.m_onContextMenuEvent = this.addEventType("oncontextmenu");  
        this.m_onMapStyleChange = this.addEventType("onmapstylechange");
        this.m_onChangeView = this.addEventType("onchangeview");
        this.m_onBeginPan = this.addEventType("onbeginpan");
        this.m_onEndPan = this.addEventType("onendpan");
        this.m_onBeginZoomRect = this.addEventType("onbeginzoomrect");
        this.m_onEndZoomRect = this.addEventType("onendzoomrect");
        this.m_onPan = this.addEventType("onpan");
        this.m_onResize = this.addEventType("onresize");
        this.m_onEndSlide = this.addEventType("onendslide");
        this.m_onBeginSlide = this.addEventType("onbeginslide");
             
        this.m_initLat = t_lat;
        this.m_initLon = t_lon;
        this.m_initLevel = t_level;
        this.m_customerId = t_customerId;
        this.base_initialize(t_level,t_lat,t_lon,t_style);
        
//        if( this.m_fullScreen )
//        {
//            this.m_glMap.resize();
//        }
//        
        //Add mapmovedlistener which triggers events when animation pan is finished.
        map.addmapPannedListener(this);
        this._fit(true);
        
        this.m_currentLevel = t_level;
        this.m_lat = t_lat;
        this.m_lon = t_lon;
        
        this.m_mapStyle = this.getMapStyle();
        //alert("TODO: Create StateManager. Add default events"); this._interceptEvents();  
        
        this.m_stateManager.addState("MapController.PAN");
        this.m_stateManager.addState("MapController.ZOOM");
        
        wedebug.assert($defined(MapController.PAN), "State MapController.PAN not initialized.");
        
        this.m_stateManager.setState(MapController.PAN);
        this.m_stateManager.addStateListener(MapController.PAN, this._statePanCallback.bind(this));
        this.m_stateManager.addStateListener(MapController.ZOOM, this._stateZoomCallback.bind(this));
        this.m_stateManager.addGlobalStateListener(this._stateGlobalCallback.bind(this));
        
        this.m_mapMarkers = new MapMarkers(this.m_controlPane); 
        
        this.logMapRequest(t_customerId, this);
        this.addEventListener("onchangeview", this.logMapRequest.bind(this, t_customerId, this));
        
        this._setOwners({lat:t_lat,lon:t_lon}, t_style, t_level);
        this.addEventListener("onchangeview", this._setOwners.bind(this));        
    },
    
    getDrawingPane : function()
    {
        return this.m_drawingPane;
    },
    
    getSeason : function(){
        return this.m_season;
    },
    setState : function(t_state)
    {
        this.m_stateManager.setState(t_state);
        return t_state == this.m_stateManager.getState();
    },
    
    setStateAndCursor : function(t_state)
    {
        this.m_stateManager.setState(t_state);
        if(t_state == MapController.ZOOM)
            $('controllerNavigationPane').style.cursor = "default";
        else
            $('controllerNavigationPane').style.cursor = "move";
        return t_state == this.m_stateManager.getState();
    },
    
    getState : function()
    {
        return this.m_stateManager.getState();
    },
    
    addGlobalStateListener : function(t_callback)
    {
        this.m_stateManager.addGlobalStateListener(t_callback);
    },
    
    addStateListener : function(t_states, t_callback)
    {
        this.m_stateManager.addStateListener( t_states, t_callback );
    },
    
    toggleSeason : function(season){
        //alert(season);
        if(season == 'v'){
            map.WMSLayers = [
            {'name' : 'Lys_status', 'visible' : true},
            {'name' : 'Skoyting_status', 'visible' : true},
            {'name' : 'Tospor_status', 'visible' : true},
            {'name' : 'Normal', 'visible' : false},
            {'name' : 'Tospor', 'visible' : true},
            {'name' : 'Kommuneskogen', 'visible' : false},
            {'name' : 'Markagrense', 'visible' : false},
            {'name' : 'Lys', 'visible' : true},
            {'name' : 'Skoyting', 'visible' : true},
            {'name' : 'Scooter', 'visible' : true},
            {'name' : 'Skiforeningen', 'visible' : true},
            {'name' : 'StilleOmr', 'visible' : false},
            {'name' : 'FriOmrHund', 'visible' : false},
            {'name' : 'TurstiMarka_Natur', 'visible' : false},
            {'name' : 'Skogsbilveier', 'visible' : false},
            {'name' : 'Sykkelruter', 'visible' : false},
            {'name' : 'TurstiMarka', 'visible' : false},
            {'name' : 'TurstierBy', 'visible' : false},
            {'name' : 'TurveierBy', 'visible' : false}
            ];
            $('loypelegend').style.display = 'block';
            this.m_season = 'vinter';
            map._setSelectedLayer("","");
        }
        else{
            map.WMSLayers = [
            {'name' : 'Lys_status', 'visible' : false},
            {'name' : 'Skoyting_status', 'visible' : false},
            {'name' : 'Tospor_status', 'visible' : false},
            {'name' : 'Normal', 'visible' : false},
            {'name' : 'Tospor', 'visible' : false},
            {'name' : 'Kommuneskogen', 'visible' : false},
            {'name' : 'Markagrense', 'visible' : false},
            {'name' : 'Lys', 'visible' : false},
            {'name' : 'Skoyting', 'visible' : false},
            {'name' : 'Scooter', 'visible' : false},
            {'name' : 'Skiforeningen', 'visible' : false},
            {'name' : 'StilleOmr', 'visible' : false},
            {'name' : 'FriOmrHund', 'visible' : false},
            {'name' : 'TurstiMarka_Natur', 'visible' : true},
            {'name' : 'Skogsbilveier', 'visible' : true},
            {'name' : 'Sykkelruter', 'visible' : true},
            {'name' : 'TurstiMarka', 'visible' : true},
            {'name' : 'TurstierBy', 'visible' : true},
            {'name' : 'TurveierBy', 'visible' : true}
            ];
            $('loypelegend').style.display = 'none';
            this.m_season = 'sommer';
            map._setSelectedLayer("","");
        }
        parent.poiController.deselectAll();
        map._createWMSLayer();
    },
    
    print : function(){
        var layers = map.getLoypeLayers();
        var points = parent.poiController._getCheckedPoiTypes();
        var sResult = parent.poiController.m_searchresultPOI;
        var bb = map.getBoundingBox();
        var mapScheme = map.getMapStyle();
        window.open('MapPrint.aspx?s=' + mapScheme + '&l=' 
                            + layers + '&p=' + points + '&minX='+ bb.minX + '&minY=' 
                            + bb.minY + '&maxX=' + bb.maxX + '&maxY=' 
                            + bb.maxY + '&season='+this.m_season+'&sID='
                            +map.selectedLayer + '&no=' + sResult.no + '&ea=' + sResult.ea + '&t=' + sResult.t
                            );
    },
              
    _fit : function(t_init){
        if(!this.m_fitMap)
        {
            if( t_init )
            {            
                var t_width = Element.getWidth(this.m_controlPane), t_height = Element.getHeight(this.m_controlPane);                
                this.resize(t_width, t_height);
            }
            return;
        }
        
        var t_size = Utilities.Window.getSize();            
        var t_width, t_height;
        
        if(this.m_fullScreen)
        {
            this.resize();
            
            Element.setStyle( 
                $("contentContainer"),
                {
                    "width" : "100%",
                    "height" : "100%"
                }
            );
            
            var t_menuWidth = this.m_viewOffset != null ? this.m_viewOffset.menuWidth : 0;
            t_width = t_size.width - t_menuWidth;
            t_height = t_size.height;         
            Element.setStyle($("mapWrap"), {width : t_width + "px", height: t_height + "px"});            
        }
        else
        {
            // firefox did not handle this
            var t_offsetTop = 0;
            t_wrapper = $("mapWrapper");
            if(t_wrapper!=null)
            {
                t_offsetTop = t_wrapper.offsetTop;
            }

            var t_menuWidth = this.m_viewOffset != null ? this.m_viewOffset.menuWidth : 0;
            t_width = t_size.width - t_menuWidth - 2;
            t_height = t_size.height - t_offsetTop - 2;
            
            if( t_height > 0 && t_width > 0 )
            {
                Element.setStyle($("mapWrap"), {width : t_width + "px", height: t_height + "px"});
            
                Element.setStyle( 
                    $("contentContainer"),
                    {
                        "width" : t_width + t_menuWidth + "px",
                        "height" : t_height + "px"
                    }
                );
            }
        }
        
        this.resize(t_width,t_height);
        
        this.m_onResize.fire(this.m_fullScreen);
            
        if( typeof t_init == "undefined" ||
            t_init == false )
        {
            //TODO: Check if the init-check affects application...
            this.m_onChangeView.fire(
                    this.getCenter(),
                    this.getMapStyle(),
                    this.m_currentLevel,
                    this.getViewport(),
                    this.getType()
                ); 
        }                
    },
        
    /**
    * Function for resetting map to constructor argument values.
    */
    reset : function()
    {
        this.setCenter(this.m_initLat, this.m_initLon, this.m_initLevel);
    },
    
    setInitialPosition : function(lat, lon, t_level)
    {
        this.m_initLevel = t_level;
        this.m_initLat = lat;
        this.m_initLon = lon;
    },
    
    getControlPane : function()
    {
        return this.m_controlPane;
    },
    
    /**
    * Method for changing map presentation.
    * @argument style constant from MapController.Styles
    * @returns true if style is valid style and style is changed. Otherwise false.
    */
    _beToggleLevel : 2,
    _centerBeforeBirdseye : null,
    base_setMapStyle : GLMap.prototype.setMapStyle,
    setMapStyle : function(t_style)
    {   
        var t_retval = false;
        if( t_style == MapController.Styles.REGULAR ||  
            t_style == MapController.Styles.AERIAL  ||  
            t_style == MapController.Styles.HYBRID )
        {
            this.base_setMapStyle(t_style);
            this.m_onMapStyleChange.fire(t_style);
            this.m_mapStyle = t_style;
            t_retval = true;                            
        }
        return t_retval;        
    },
    
    //override method from AbstractMapController
    //_offsetWidth : 0,    
    internal_setViewOffset : function(t_offset)
    {        
        this.m_viewOffset = t_offset;
        //t_offset.x = (t_offset.x>0) ? t_offset.x - t_offset.navigationMenuWidth : 0;
        
        //Move left edge of wrapper
        var t_size = Utilities.Window.getSize(); 
        var t_width = Element.getWidth($("mapWrapper")) - t_offset.menuWidth;
        var t_height = t_size.height;
        t_height -= $('mapWrapper').offsetTop + ((this.m_fullScreen) ? 0 : 6);
        
        if ( t_width > 0 && t_height > 0 )
        {
            Element.setStyle($("mapWrap"), {left : (t_offset.menuWidth)+ "px", width : (t_width) + "px", height: t_height + "px"});
        
            this.resize(t_width, t_height);        
        }    
    },
    
    getMapStyle : function()
    {
        return this.m_mapStyle;
    },
    
    isBirdseyeAvailable : function()
    {
        return false;
    },
    
    base_setZoomLevel : GLMap.prototype.setZoomLevel,
    setZoomLevel : function(t_level, t_fromSlider)
    {
        if( this.m_zoomLevels.indexOf(t_level) != -1 )
        {      
            this.m_currentLevel = t_level;
            this.base_setZoomLevel( t_level);     
            this.m_onChangeView.fire(
                    this.getCenter(),
                    this.getMapStyle(),
                    this.m_currentLevel,
                    this.getViewport(),
                    this.getType()
                );            
        }        
    },
    
    /**
    * Function for retrieving all valid zoom level values
    * @returns array of zoom levels from most detailed to biggest scale
    */
    getZoomLevels : function()
    {
        return this.m_zoomLevels;
    },
    
    _isPanning : false,
    base_pan : GLMap.prototype.pan,
    pan : function(xdir, ydir)
    {
        wedebug.log("map", "pan: " + [xdir,ydir]);
        this.m_onBeginSlide.fire();
        this._isPanning = true;
        
        this.base_pan(xdir,ydir);        
    },
    
    _endPan : function()
    {
        if(this._isPanning)
        {
            this.m_onChangeView.fire(
                this.getCenter(),
                this.getMapStyle(),
                this.m_currentLevel,
                this.getViewport(),
                this.getType()
            );
        
            this.m_onEndSlide.fire(this.getType());
            this._isPanning = false;
        }
    },
        
    /*
    Function for setting maps center point
    @argument lat center latitude
    @argument lon center longitude
    [@argument zoom_level]
    */
    setCenter : function(lat,lon,t_zoomLevel)
    {
        //TODO:Make center offset mechanism. Might be useful because of left menu. (
        var t_position = {
            level : $defined(t_zoomLevel)?t_zoomLevel:this.m_currentLevel,
            lat : lat,
            lon : lon
        };
        
        this.centerAndZoom(t_position);
        this.m_currentLevel = t_position.level;
        
        this.m_onChangeView.fire(
            this.getCenter(),
            this.getMapStyle(),
            this.m_currentLevel,
            this.getViewport(),
            this.getType()
        );
    },
    
    /**
    Function for check if point is inside viewport. (ignores left menu if any).
    */
    isInside : function(lat, lon, left, top, right, bottom)
    {
        var l = (typeof left != "undefined") ? left : 0;
        var t = (typeof top != "undefined") ? top : 0;
        var r = (typeof right != "undefined") ? right : Element.getWidth(this.m_controlPane);
        var b = (typeof bottom != "undefined") ? bottom : Element.getHeight(this.m_controlPane);
    
        var t_bottomright = this.getPixelLatLon({x:r,y:b});
        var t_topleft = this.getPixelLatLon({x:l, y:t});
        
        //alert([lat, lon, t_topleft.lat, t_topleft.lon, t_bottomright.lat, t_bottomright.lon]);
        return lat <= t_topleft.lat && lat >= t_bottomright.lat && lon >= t_topleft.lon && lon <= t_bottomright.lon;
    },
    
    /**
    Function returning latlon of pixel
    */
    base_getPixelLatLon : GLMap.prototype.getPixelLatLon,
    getPixelLatLon : function(/*x, y || pixel.x&y*/)
    {
        if( arguments.length == 2 )
        {
            return this.base_getPixelLatLon({x:arguments[0],y:arguments[1]});        
        }
        else
        {
            return this.base_getPixelLatLon(arguments[0]);     
        }
    },
    
    setHotspot : function(t_icon, t_lat, t_lon, t_xOffset, t_yOffset, t_title, t_content, t_collectionId,t_type,t_url1,t_url2,t_url3,t_visible)
    {
        var t_id = typeof t_collectionId == "undefined" ? 'hotspot' : t_collectionId;
        this.setHotspots( t_id,  
            [[  'hotspot_1', //id 
                t_icon, //icon
                t_lat,   //northing
                t_lon,   //easting
                $defined(t_title) ? t_title: t_lat + ", " + t_lon, //title
                $defined(t_content) ? t_content : "", //description
                Prototype.emptyFunction,
                undefined,
                undefined,
                $defined(t_xOffset) ? t_xOffset : 0,
                $defined(t_yOffset) ? t_yOffset : 0]],
                $defined(t_type) ? t_type: "",
                $defined(t_url1) ? t_url1: "",
                $defined(t_url2) ? t_url2: "",
                $defined(t_url3) ? t_url3: "",
                $defined(t_visible) ? t_visible: ""
                );
    },
    
    /**
    * Function for adding array of map markers.
    * Array values
    * 0: icon, 
    * 1: northing, 
    * 2: easting, 
    * 3: title, 
    * 4: description,
    * 5: callback function
    *    lowerbound, //optional
    *    upperbound, //optional
    *    iconXOffset, //optional
    '    iconYOffset
    */
    setHotspots : function(t_listingname, t_arrMarkers, t_upperLevel) //optional
    {
        wedebug.log("map", "-> setHotspots: " + [t_listingname, t_arrMarkers, t_upperLevel]);
        
        var t_clearMethods = [this.clearHotspots.bind(this)];        
        this.m_mapMarkers.clear(
            t_listingname,
            t_clearMethods);
        
        this.m_mapMarkers.begin(t_listingname, t_upperLevel);
        var i,t_length = t_arrMarkers.length;
        for(i=0; i<t_length; i++)
        {
            var t_arrLength = t_arrMarkers[i].length;
            this.m_mapMarkers.add(
                t_arrMarkers[i][0],
                t_arrMarkers[i][1],
                t_arrMarkers[i][2],
                t_arrMarkers[i][3],
                t_arrMarkers[i][4],
                t_arrMarkers[i][5],
                t_arrMarkers[i][6],
                (t_arrLength > 7) ? t_arrMarkers[i][7] : undefined,
                (t_arrLength > 8) ? t_arrMarkers[i][8] : undefined,
                (t_arrLength > 9) ? t_arrMarkers[i][9] : undefined,
                (t_arrLength > 10) ? t_arrMarkers[i][10] : undefined,
                (t_arrLength > 11) ? t_arrMarkers[i][11] : undefined,
                (t_arrLength > 12) ? t_arrMarkers[i][12] : undefined,
                (t_arrLength > 13) ? t_arrMarkers[i][13] : undefined,
                (t_arrLength > 14) ? t_arrMarkers[i][14] : undefined,
                (t_arrLength > 15) ? t_arrMarkers[i][15] : undefined
            );
        }
        this.m_mapMarkers.end();
        var t_arrCanvas = [this.addHotspot.bind(this)];           
        this.m_mapMarkers.draw(t_listingname, t_arrCanvas);
    },
    
    removeHotspots : function(t_listingname)
    {
        wedebug.log("map", "-> removeHotspots: " + t_listingname);
        var t_clearFuncs = [];
        t_clearFuncs.push(this.clearHotspots.bind(this));
        this.m_mapMarkers.clear(t_listingname, t_clearFuncs);
    },
    
    setViewport : function(t_west, t_south, t_east, t_north, zoffset)
    {
        if(!zoffset){
            var zoffset = 0;       
        }
        wedebug.log("map", "-> setMapView: " + [t_west, t_south, t_east, t_north]);                
        wedebug.assert("map", t_east > t_west && t_north > t_south, "Invalid bbox (west, south, east, north): " + [t_west, t_south, t_east, t_north]);
                        
        //var min = decimalDegreesToUTM({x:t_west, y:t_south});
        //var max = decimalDegreesToUTM({x:t_east, y:t_north});
        
        //map.centerAndZoomOnBoundingBoxUTM(min.x, min.y, max.x, max.y);
        map.centerAndZoomOnBoundingBoxUTM(t_west, t_south, t_east, t_north, zoffset);
        this.m_currentLevel = map.getZoomLevel(); 
        map._createWMSLayer();
        parent.poiController._createRequest();
    },
    
    setMarker : function(
        icon, 
        northing, 
        easting, 
        title, //optional
        description, //optional
        lowerbound, //optional
        upperbound, //optional
        iconXOffset, //optional
        iconYOffset ) //optional
    {
        alert("MapController.setMarker");
    },
            
    getWidth : function()
    {        
        return Element.getWidth(this.m_controlPane);
    },
    
    getHeight : function()
    {
        return Element.getHeight(this.m_controlPane);
    },
    
    getMapProvider : function()
    {
        return this.getType();    
    },
        
    /**
	Callback for onchangeview that changes map rights icon.
	*/
	_setOwners : function(t_centerPoint, t_mapStyle, t_zoomLevel)
	{
	
	    var t_lat = [this.m_osloLat, this.m_drammenLat, this.m_stavangerLat, this.m_aalesundLat, this.m_trondheimLat];
	    var t_lon = [this.m_osloLon, this.m_drammenLon, this.m_stavangerLon, this.m_aalesundLon, this.m_trondheimLon];
	    var t_url = ['Resource/Map/media/interface/norkartosk.gif', 'Resource/Map/media/interface/cp_drammen.gif', 'Resource/Map/media/interface/cp_stavanger.gif', 'Resource/Map/media/interface/cp_alesund.gif', 'Resource/Map/media/interface/cp_trondheim.gif'];
	
        var t_sk = true;
        
        if( t_zoomLevel <= 4 )
        {
            var t_kommune, t_length = t_lat.length;
            for( t_kommune=0; t_kommune<t_length; t_kommune++ )
            {
                var i, j=0 ;
                var t_oddNodes=false;
                
                var t_kommuneLat = t_lat[t_kommune];
                var t_kommuneLon = t_lon[t_kommune];
                var t_polySides = t_kommuneLat.length;
                //alert([t_polySides, t_kommuneLat[0], t_kommuneLon[0]]);
                for (i=0; i<t_polySides; i++) 
                {
                    j++; if (j==t_polySides) j=0;			
                    if (t_kommuneLon[i]<t_centerPoint.lon && t_kommuneLon[j]>=t_centerPoint.lon
    	                ||  t_kommuneLon[j]<t_centerPoint.lon && t_kommuneLon[i]>=t_centerPoint.lon) 
                    {
    	                if (t_kommuneLat[i]+(t_centerPoint.lon-t_kommuneLon[i])/(t_kommuneLon[j]-t_kommuneLon[i])*(t_kommuneLat[j]-t_kommuneLat[i])<t_centerPoint.lat) 
    	                {   
    		                t_oddNodes=!t_oddNodes; 
    	                }
                    }
                }
                
                try
                {
                    if( t_oddNodes )
                    {
                        $("copy").style.backgroundImage = "url(" + t_url[t_kommune] + ")";
                        t_sk = false;
                        break;
                    }                    
                }
                catch(e){}
            }
        }
        
        if( t_sk )
        {
            try
            {                    
                $("copy").style.backgroundImage = "url(Resource/Map/media/interface/norkartsk.gif)";
            }
            catch(e) {}
        }
        
	},
	
	_statePanCallback : function(t_eventDetails)
	{
	    switch(t_eventDetails.eventType)
	    {   
	        case StateManager.Mouse.CONTEXT_MENU:
	            //this._onContextMenu(t_eventDetails);
	            break;
	        case StateManager.Mouse.MOVE:
	            this._onMouseMovePan(t_eventDetails);
	            break;
	        case StateManager.Mouse.DOWN: 
	            this._onMouseDownPan(t_eventDetails);
	            break;
	        case StateManager.Mouse.UP:
	            this._onMouseUpPan(t_eventDetails);
	            break;
	        case StateManager.Mouse.OUT:
	            this._onMouseOutPan(t_eventDetails);
	            break;
	        case StateManager.Mouse.DOUBLE_CLICK:
	            this._onDblClick(t_eventDetails);
	            break;
	        case StateManager.Mouse.WHEEL:
	            this._onZoom(t_eventDetails);
	            break;
	    }
	},
	
	_stateZoomCallback : function( t_eventDetails )
	{
	    switch(t_eventDetails.eventType)
	    {   
	        case StateManager.Mouse.CONTEXT_MENU:
	            this._onContextMenu(t_eventDetails);
	            break;
	        case StateManager.Mouse.MOVE:
	            this._onMouseMoveZoom(t_eventDetails);
	            break;
	        case StateManager.Mouse.DOWN: 
	            this._onMouseDownZoom(t_eventDetails);
	            break;
	        case StateManager.Mouse.UP:
	            this._onMouseUpZoom(t_eventDetails);
	            break;
	        case StateManager.Mouse.OUT:
	            this._onMouseOutZoom(t_eventDetails);
	            break;
	        case StateManager.Mouse.DOUBLE_CLICK:
	            this._onDblClick(t_eventDetails);
	            break;
	        case StateManager.Mouse.WHEEL:
	            this._onZoom(t_eventDetails);
	            break;
	    }
	},
	
	_stateGlobalCallback : function(t_eventDetails)
	{
	    switch(t_eventDetails.eventType)
	    {
	        case StateManager.Mouse.DOWN: 	 
	            if( t_eventDetails.event.button == StateManager.Button.MIDDLE &&
	                this.getState() != MapController.ZOOM )
	            {
	                this.setState(MapController.ZOOM);
	                this._zoomStart = t_eventDetails;
	            }
	            break;
	    }
	},
//    
//    /* Event handling */
//    _interceptEvents : function()
//    {
//        //Catch events.
//        Event.observe(this.m_controlPane, "contextmenu",
//            this._onContextMenu.bind(this)
//        );  
//        
////        Event.observe(this.m_controlPane, "mouseover", 
////            (function(event)
////            {                
////               this._onMouseOver.bind(this)(event);
////            }).bind(this)
////        ); 
//        
//        Event.observe(this.m_controlPane, "mousemove", 
//            (function(event)
//            {     
//                this._onMouseMove.bind(this)(event);                
//            }).bind(this)
//        );
//        
//        Event.observe(this.m_controlPane, "mousedown",
//            (function(event)
//            {
//                this._onMouseDown.bind(this)(event);
//            }).bind(this)
//        );
//        
//        Event.observe(this.m_controlPane, "mouseup",
//            (function(event)
//            {
//                this._onMouseUp.bind(this)(event);
//            }).bind(this)
//        );
//        
//        Event.observe(this.m_controlPane, "mouseout",
//            (function(event)
//            {
//                this._onMouseOut.bind(this)(event);                
//            }).bind(this)
//        );
//        
//        Event.observe(this.m_controlPane, "dblclick",
//            (function(event)
//            {
//                this._onDblClick.bind(this)(event);                
//            }).bind(this)
//        );
//        
//        /*C&P ajaxmap.js:239*/
//        if (this.m_controlPane.addEventListener) {
//			this.m_controlPane.addEventListener('DOMMouseScroll', this._onWheel.bind(this), false);
//		}
//        this.m_controlPane.onmousewheel = this._onWheel.bind(this);
//    },
    
    /**
    * Callback-function when div is right clicked (GLMap).
    */
    _onContextMenu : function(t_eventDetails)
    {                
        wedebug.log("map", "_onContextMenu: isLeftClick:" + t_eventDetails.isLeftClick);
        
        try
        {       
            var t_offset = Position.realOffset(this.m_controlPane);
            
            this.m_onContextMenuEvent.fire(
                this.getType(),
                t_eventDetails.x,
                t_eventDetails.y,
                t_offset[0],
                t_offset[1],
                t_eventDetails.lat,
                t_eventDetails.lon);
        }
        catch(e)
        {
            wedebug.log("map", "Exception triggering event: " + e.message, "error");
        }
    },    
        
    _onZoom : function(t_eventDetails)
    {
        //t_delta is < 0 if zoom out. Otherwise zoom in.                 
        var t_level = this.m_currentLevel + ((t_eventDetails.wheelDelta<0)?1:-1);    
        
        if( this.m_zoomLevels.indexOf(t_level) != -1 && map.navigate)
        {
            this.setZoomLevel(t_level);
            this.m_onChangeView.fire(
                this.getCenter(),
                this.getMapStyle(),
                this.m_currentLevel,
                this.getViewport(),
                this.getType()
            );  
        }          
    },    
        
    _panEventFired : false,
//    _lastX : null,
//    _lastY : null,
    _onMouseMovePan : function(t_eventDetails)
    {      
        this.internal_onMouseMove(t_eventDetails.event);
        if( t_eventDetails.isMouseDown && !this._panEventFired )
        {
            this.m_onBeginPan.fire(this.getType());
            this._panEventFired = true;            
        }
        
        //Trigger pan event.
        if( t_eventDetails.isMouseDown )
        {
            this.m_onPan.fire(t_eventDetails.moveX, t_eventDetails.moveY);
        }
    },
    
//    _isMouseDown : false,
    _onMouseDownPan : function(t_eventDetails)
    {
        this.internal_onMouseDown(t_eventDetails.event);
    },
        
    _onMouseOutPan : function(t_eventDetails)
    {
        this.internal_onMouseOut(t_eventDetails.event);
        if( t_eventDetails.isMouseDown )
        {
            var t_level = this.getZoomLevel();
            
            this.m_onChangeView.fire(
                this.getCenter(),
                this.getMapStyle(),
                this.m_currentLevel,
                this.getViewport(),
                this.getType()
            );
            
            if( this._panEventFired )
            {
                this._panEventFired = false;
                this.m_onEndPan.fire(this.getType()); //En exception her gjorde at ikke meny ble "markert"
            }
        }
    },
    
    _onMouseUpPan : function(t_eventDetails)
    {
        this.internal_onMouseUp(t_eventDetails.event);
        
        if( t_eventDetails.event.button != StateManager.Button.RIGHT )
        {
            this.m_onChangeView.fire(
                this.getCenter(),
                this.getMapStyle(),
                this.m_currentLevel,
                this.getViewport(),
                this.getType()
            );
        }
         
        if( this._panEventFired )
        {
            this._panEventFired = false;
            this.m_onEndPan.fire(this.getType()); //En exception her gjorde at ikke meny ble "markert"
        }        
    },
    
    _zoomStart : null,
    _zoomRectangleDivId : "zoomVisual",
    _zoomEventFired : false,
    _onMouseDownZoom : function(t_eventDetails)
    {
        //if( t_eventDetails.event.button == StateManager.Button.LEFT && t_eventDetails.event.button == StateManager.Button.MIDDLE )
        //{
            this._zoomStart = t_eventDetails;
        //}
    },
    
    _onMouseMoveZoom : function(t_eventDetails)
    {      
        if( t_eventDetails.isMouseDown )
        {
            if( !this._zoomEventFired )
            {
                this.m_onBeginZoomRect.fire(this.getType());
                this._zoomEventFired = true;
            }
            
            //alert(this._zoomStart);
            var t_left = Math.min(this._zoomStart.x, t_eventDetails.x);
            var t_right = Math.max(this._zoomStart.x, t_eventDetails.x);
            var t_top = Math.min(this._zoomStart.y, t_eventDetails.y);
            var t_bottom = Math.max(this._zoomStart.y, t_eventDetails.y);
            
            var t_zoomRect = $(this._zoomRectangleDivId);
            if( t_zoomRect != null )
            {
                Element.remove(t_zoomRect);
            }
            
            
            t_zoomRect = $dom("div");
            t_zoomRect.id = this._zoomRectangleDivId;
            Element.setStyle(t_zoomRect,
                {
                    "position" : "absolute",
                    "left" : t_left + "px",
                    "top" : t_top + "px",
                    "width" : t_right - t_left + "px",
                    "height" : t_bottom - t_top + "px",
                    "border" : "2px dashed Red",
                    "background-color" : "Transparent"
                }
            );
            
            var blocker = $dom("div");
            blocker.id = 'blocker';
            Element.setStyle(blocker,
                {
                    "position" : "absolute",
                    "left" : 0 + "px",
                    "top" : 0 + "px",
                    "width" : 100 + "%",
                    "height" : 100 + "%",
                    "border" : "2px dashed Red",
                    "background-color" : "green"
                }
            );
            
            //$('controllerNavigationPane').appendChild(blocker);
            this.m_drawingPane.appendChild(t_zoomRect);
            
        }
    },   
     
    _onMouseOutZoom : function(t_eventDetails)
    {
        if( t_eventDetails.isMouseDown )
        {
            this._zoomStart = null;
            
            var t_zoomRect = $(this._zoomRectangleDivId);
            if( t_zoomRect != null )
            {
                Element.remove(t_zoomRect);
            }
            
            this.m_onEndZoomRect.fire(this.getType());
            this._zoomEventFired = false;
        }
    },
    
    _onMouseUpZoom : function(t_eventDetails)
    {
        if( this._zoomStart != null )
        {
            if( this._zoomStart.lat != t_eventDetails.lat && this._zoomStart.lon != t_eventDetails.lon )
            {
                var t_west = Math.min(this._zoomStart.lon, t_eventDetails.lon);
                var t_east = Math.max(this._zoomStart.lon, t_eventDetails.lon);
                var t_south = Math.min(this._zoomStart.lat, t_eventDetails.lat);
                var t_north = Math.max(this._zoomStart.lat, t_eventDetails.lat);
                
                if( Math.abs(this._zoomStart.x - t_eventDetails.x) > 25 &&
                    Math.abs(this._zoomStart.y - t_eventDetails.y) > 25 )
                {
                    this.setViewport(t_west, t_south, t_east, t_north);
                }
            }
            
            var t_zoomRect = $(this._zoomRectangleDivId);
            if( t_zoomRect != null )
            {
                Element.remove(t_zoomRect);
            }
            
            this.m_onEndZoomRect.fire(this.getType()); 
            this._zoomEventFired = false;           
        }
    },
    
    _onDblClick : function(t_eventDetails)
    {
        this.onDblClick();
        this.m_currentLevel = map.getZoomLevel();            
        this.m_onChangeView.fire(
            this.getCenter(),
            this.getMapStyle(),
            this.m_currentLevel,
            this.getViewport(),
            this.getType()
        );
    },
        
    //mapMoved({x/y})
    //map.addmapMovedListener   
    mapPanned : function(direction)
    {
        //TODO: Implement trigger for VE onendslide
        this._endPan();
    }   
});
Object.extend(GLMap.prototype, new AbstractEventTrigger()); //Extend with methods to make object an eventtrigger


