var Map = {

	div: null,
	name: null,

	init: function(div_id, map_name){
		Map.div = $(div_id);
		Map.name = map_name;

		Map.setImg();
		Map.setMap();

	},
	
	setImg: function(){
		try{
		var html = [];
		var dots = [];
		var lbls = [];
		for(i=0;i<=28;i++){
			var ind = i<10?'0'+i:i;
			html.push('<img class="map" src="/img/map/map_'+ind+'.png" width="640" height="420" id="map_'+ind+'" '+(i!=0?'style="display: none;"':'')+' />');
			if(i>0){
				var t = Map.locations[ind].top-12;
				var l = Map.locations[ind].left-(Map.locations[ind].label.length*3);
				lbls.push('<a class="label" href="/places/'+Map.locations[ind].label+'" style="top:'+t+'px;left:'+l+'px;">'+Map.locations[ind].label+'</a>');
				dots.push('<img class="city" src="/img/map/city.png" width="7" height="7" style="top:'+Map.locations[ind].top+'px;left:'+Map.locations[ind].left+'px;" />');
			}
		}
		html.push('<img class="map" src="/img/dot.png" width="640" height="420" usemap="#'+Map.name+'" />');
		Map.div.innerHTML = html.join('') + dots.join('') + lbls.join('');
		}catch(e){console.log(e);}
			
	},
	
	setMap: function(){
		try{
		var map = document.createElement('MAP');
		map.name = Map.name;
		//map.setAttribute('name', Map.name);
		Event.observe(map,'mouseover', function(evt){Map.mouseover(evt)});
		Event.observe(map,'mouseout', function(evt){Map.mouseout(evt)});
		
		var html = [];
		for(i=1;i<Map.poly.length;i++){
			var p = Map.poly.length-i;
			var ind = p<10?'0'+p:p;
			html.push('<area href="/region/'+Map.locations[ind].id+'/'+Map.locations[ind].label+'" rel="map_'+ind+'" shape="poly" alt="'+Map.locations[ind].label+'" coords="'+Map.poly[i]+'" />');
		}
		map.innerHTML = html.join('');
		new Insertion.After(Map.div, map);
		}catch(e){console.log(e);}
		
	},
	
	mouseover: function(evt){
		var elm = Event.element(evt);
		
		if(elm.nodeName!='AREA'){
			return;
		}
		var img = elm.getAttribute('rel');
		$(img).show();
		
	},
	
	mouseout: function(evt){
		var elm = Event.element(evt);
		
		if(elm.nodeName!='AREA'){
			return;
		}
		var img = elm.getAttribute('rel');
		$(img).hide();
		
	},
	
	locations: {
		'01': {top:37, left: 50, label: 'Видин', id: 737},
		'02': {top:101, left: 94, label: 'Монтана', id: 3144},
		'03': {top:133, left: 126, label: 'Враца', id: 857},
		'04': {top:111, left: 233, label: 'Плевен', id: 3627},
		'05': {top:182, left: 300, label: 'Габрово', id: 944},
		'06': {top:164, left: 338, label: 'Велико Търново', id: 683},
		'07': {top:74, left: 349, label: 'Русе', id: 4102},
		'08': {top:99, left: 428, label: 'Разград', id: 3938},
		'09': {top:144, left: 420, label: 'Търговище', id: 4816},
		'10': {top:13, left: 485, label: 'Силистра', id: 4261},
		'11': {top:86, left: 549, label: 'Добрич', id: 1467},
		'12': {top:135, left: 569, label: 'Варна', id: 656},
		'13': {top:128, left: 468, label: 'Шумен', id: 5216},
		'14': {top:159, left: 235, label: 'Ловеч', id: 2786},
		'15': {top:193, left: 160, label: 'Софийска област', id: 4427},
		'16': {top:212, left: 97, label: 'София', id: 4427},
		'17': {top:228, left: 64, label: 'Перник', id: 3550},
		'18': {top:271, left: 45, label: 'Кюстендил', id:2694},
		'19': {top:316, left: 90, label: 'Благоевград', id: 299},
		'20': {top:292, left: 190, label: 'Пазарджик', id: 3483},
		'21': {top:368, left: 237, label: 'Смолян', id: 4384},
		'22': {top:298, left: 249, label: 'Пловдив', id: 3634},
		'23': {top:366, left: 306, label: 'Кърджали', id: 2676},
		'24': {top:320, left: 332, label: 'Хасково', id: 4894},
		'25': {top:253, left: 331, label: 'Стара Загора', id: 4491},
		'26': {top:217, left: 403, label: 'Сливен', id: 4350},
		'27': {top:250, left: 425, label: 'Ямбол', id: 5267},
		'28': {top:228, left: 523, label: 'Бургас', id: 569}
	},
	
	poly: [
	'',
	'437,188, 443,183, 446,188, 458,185, 461,181, 477,181, 480,185, 496,178, 503,176, 510,176, 523,188, 537,188, 548,185, 549,191, 561,196, 568,197, 570,203, 572,208, 568,210, 553,210, 552,217, 547,219, 547,230, 529,232, 530,240, 533,247, 543,247, 547,252, 552,252, 553,264, 559,269, 559,275, 559,279, 568,285, 573,292, 580,300, 588,307, 587,310, 579,312, 572,308, 568,310, 566,315, 555,313, 547,314, 539,322, 537,319, 535,315, 525,310, 522,304, 516,300, 511,296, 507,296, 500,301, 493,299, 489,296, 482,296, 477,291, 475,285, 477,280, 475,277, 477,273, 477,269, 472,269, 472,261, 467,258, 472,255, 477,252, 475,247, 469,245, 465,239, 462,231, 459,223, 454,217, 450,206, 446,201, 441,201, 439,201, 437,197, 439,191',
	'450,219, 452,219, 454,223, 465,247, 467,251, 473,251, 471,253, 465,255, 463,261, 465,261, 468,264, 469,272, 473,273, 471,280, 471,285, 473,294, 480,301, 480,304, 477,307, 477,310, 467,312, 463,316, 458,312, 454,316, 441,313, 438,318, 434,319, 429,312, 432,307, 432,300, 432,291, 427,289, 412,287, 405,283, 398,279, 395,275, 402,269, 405,261, 401,261, 395,258, 401,258, 402,252, 405,253, 411,252, 417,247, 418,243, 417,238, 418,236, 425,236, 432,234, 436,232, 440,226, 447,223',
	'360,201, 376,203, 382,198, 387,197, 385,191, 390,188, 405,176, 405,171, 410,171, 411,173, 418,174, 432,171, 436,174, 432,180, 434,183, 432,190, 436,193, 434,201, 436,203, 445,204, 450,213, 446,219, 438,224, 436,229, 429,231, 423,233, 415,234, 412,238, 413,243, 408,249, 402,247, 398,250, 399,255, 395,255, 392,258, 395,263, 399,266, 392,275, 389,272, 385,274, 378,269, 371,264, 370,258, 367,252, 369,247, 364,236, 367,234, 371,232, 371,229, 364,221, 365,214, 360,206',
	'276,208, 281,208, 286,204, 293,204, 296,201, 301,206, 319,208, 324,204, 328,210, 333,208, 337,210, 339,210, 341,206, 350,201, 355,201, 358,212, 360,214, 362,223, 366,229, 359,237, 362,242, 365,247, 363,253, 366,258, 368,267, 376,273, 381,277, 392,279, 395,283, 389,289, 390,304, 387,306, 382,310, 379,302, 373,296, 366,294, 353,302, 349,298, 342,289, 339,289, 339,287, 336,282, 333,282, 331,289, 324,287, 316,289, 317,296, 309,293, 300,285, 294,287, 282,285, 284,277, 294,279, 295,275, 294,273, 290,272, 290,263, 286,258, 290,258, 293,261, 298,258, 297,253, 292,251, 296,247, 296,245, 290,243, 284,244, 278,242, 276,238, 274,230, 276,221, 274,215, 274,208',	
	'305,339, 301,335, 301,329, 303,326, 309,318, 305,306, 312,298, 318,301, 321,298, 321,291, 329,292, 334,285, 336,289, 336,296, 339,296, 343,293, 353,307, 357,304, 367,296, 373,300, 380,313, 385,314, 387,310, 395,310, 392,293, 392,289, 398,283, 410,289, 429,294, 427,304, 424,312, 429,320, 434,326, 434,331, 432,335, 417,334, 413,336, 409,349, 398,347, 392,346, 385,351, 381,358, 385,364, 392,368, 390,374, 395,377, 395,382, 392,383, 395,386, 392,393, 392,400, 384,403, 376,403, 373,399, 366,399, 362,395, 363,392, 366,386, 360,383, 358,380, 357,374, 363,372, 364,367, 362,362, 355,359, 350,364, 344,366, 339,364, 339,362, 343,358, 341,351, 339,346, 332,344, 327,344, 316,340, 313,333, 309,333',
	'293,329, 290,336, 284,341, 280,344, 280,348, 282,353, 286,361, 284,366, 282,371, 276,372, 277,377, 276,380, 280,383, 284,379, 290,379, 292,384, 293,393, 290,396, 290,405, 298,413, 298,417, 306,419, 315,414, 328,411, 331,406, 337,408, 347,410, 350,407, 355,406, 357,403, 362,405, 365,408, 373,408, 371,403, 365,403, 359,397, 359,392, 361,386, 356,386, 354,379, 353,373, 359,369, 359,364, 355,364, 348,368, 339,369, 334,366, 334,362, 339,359, 339,355, 335,348, 328,348, 321,346, 314,344, 311,336, 309,342, 301,342, 297,338, 297,332, 296,330',
	'237,201, 224,201, 217,206, 214,206, 208,213, 211,219, 217,221, 221,226, 220,234, 214,238, 214,241, 211,244, 214,249, 217,252, 217,256, 217,261, 220,264, 221,271, 221,285, 226,289, 226,293, 222,294, 217,294, 217,296, 219,300, 217,304, 217,310, 219,314, 217,323, 222,323, 224,326, 228,326, 235,326, 242,324, 249,326, 252,335, 248,339, 251,341, 253,342, 253,349, 256,353, 260,344, 266,346, 265,341, 267,334, 273,332, 275,333, 281,340, 286,335, 290,326, 293,326, 300,326, 300,323, 304,319, 304,312, 301,306, 309,298, 298,289, 290,291, 282,289, 277,285, 279,279, 280,273, 286,273, 286,264, 284,258, 286,254, 288,254, 290,247, 279,247, 272,240, 270,233, 271,226, 273,223, 271,219, 270,214, 271,204, 263,210, 253,210, 245,212, 241,208',
	'178,372, 180,364, 180,363, 182,360, 181,357, 180,355, 181,348, 187,347, 193,349, 199,350, 203,344, 201,338, 205,334, 213,333, 213,326, 217,326, 224,330, 230,331, 233,329, 244,329, 248,332, 244,338, 244,342, 249,344, 248,350, 256,358, 259,353, 261,349, 268,349, 269,344, 269,338, 272,336, 275,340, 275,346, 277,350, 278,355, 282,360, 279,364, 281,368, 277,369, 270,370, 271,373, 274,378, 272,382, 281,387, 286,382, 288,385, 288,393, 286,394, 286,403, 275,400, 269,398, 263,393, 256,397, 252,403, 247,395, 245,392, 238,392, 233,388, 228,384, 228,376, 224,371, 219,371, 215,376, 204,376, 201,378, 198,372, 194,370, 189,373, 184,376',
	'161,271, 147,283, 147,288, 149,290, 149,296, 151,308, 145,313, 145,320, 149,330, 158,335, 169,344, 178,353, 178,347, 183,344, 193,344, 197,346, 199,341, 199,335, 203,331, 208,330, 211,325, 214,315, 217,312, 213,307, 212,302, 215,299, 213,296, 213,291, 221,290, 224,289, 220,285, 219,281, 217,272, 217,267, 213,264, 211,254, 211,251, 208,249, 208,244, 211,237, 207,237, 201,235, 201,228, 187,226, 187,233, 178,234, 178,239, 173,239, 164,233, 163,238, 165,244, 168,247, 178,247, 178,253, 173,256, 169,261, 168,265, 171,269, 171,273, 164,274',
	'58,296, 55,304, 53,316, 53,321, 60,330, 60,339, 69,344, 68,351, 60,359, 60,365, 60,372, 60,382, 60,393, 60,400, 84,403, 85,395, 90,391, 110,392, 130,397, 134,393, 142,392, 146,388, 153,387, 159,383, 164,387, 171,387, 174,384, 173,379, 175,367, 178,359, 171,351, 161,342, 148,334, 142,324, 140,313, 148,304, 144,289, 139,289, 137,285, 130,290, 127,298, 117,299, 112,304, 94,299, 88,296, 85,299, 84,304, 74,302, 71,306, 64,304, 60,301',
	'12,219, 17,221, 25,224, 25,229, 29,235, 35,240, 35,247, 39,253, 43,254, 46,260, 53,261, 58,258, 63,255, 69,258, 74,258, 78,255, 82,261, 90,262, 99,262, 101,267, 104,271, 102,277, 99,281, 99,284, 104,287, 109,286, 112,284, 117,290, 114,296, 112,300, 106,300, 99,296, 90,293, 82,296, 82,300, 74,299, 68,302, 62,298, 60,294, 56,294, 53,298, 51,304, 38,300, 26,292, 17,287, 17,281, 3,263, 9,262, 12,258, 12,254, 19,252, 20,243, 22,239, 21,233, 14,229, 12,225',
	'12,193, 17,190, 23,185, 35,186, 43,186, 48,193, 55,193, 71,208, 72,213, 76,213, 76,217, 80,219, 83,219, 83,223, 82,226, 82,228, 88,229, 94,236, 90,242, 88,247, 88,253, 88,258, 83,256, 78,252, 74,251, 74,255, 67,253, 62,251, 56,252, 52,257, 48,257, 46,252, 46,249, 40,247, 38,243, 37,236, 33,232, 28,229, 28,226, 28,222, 25,219, 12,217, 12,210, 17,206',
	'74,208, 82,208, 87,206, 92,188, 101,193, 110,193, 117,193, 123,195, 122,201, 117,206, 110,210, 108,216, 110,219, 113,224, 115,230, 118,235, 123,239, 124,244, 123,247, 117,247, 115,242, 114,236, 111,235, 106,234, 103,236, 102,238, 97,232, 92,228, 88,226, 87,222, 87,217, 83,215, 81,216, 80,210, 74,210',
	'43,183, 46,180, 49,168, 59,167, 63,159, 69,153, 71,142, 74,142, 78,148, 82,155, 90,156, 98,153, 106,149, 117,150, 115,157, 119,165, 123,167, 123,171, 126,174, 131,174, 132,165, 140,171, 147,165, 156,167, 167,171, 174,165, 173,171, 180,171, 179,183, 189,183, 188,193, 185,198, 186,201, 211,204, 207,208, 205,212, 206,218, 209,223, 216,225, 217,230, 216,234, 212,232, 208,233, 207,234, 203,232, 203,226, 201,223, 185,223, 184,225, 184,230, 177,231, 174,235, 165,230, 159,232, 159,238, 160,242, 163,247, 165,251, 174,250, 175,251, 163,263, 168,269, 167,270, 160,267, 141,285, 137,282, 131,284, 127,288, 126,292, 121,296, 119,294, 122,290, 120,286, 113,280, 106,283, 102,281, 106,276, 112,274, 104,266, 102,260, 99,258, 94,257, 93,255, 92,247, 95,244, 96,239, 100,240, 103,243, 106,241, 106,238, 110,238, 112,239, 112,245, 114,250, 119,251, 124,250, 127,246, 127,240, 124,235, 119,229, 116,222, 112,215, 118,208, 123,204, 128,193, 123,191, 114,189, 109,189, 103,191, 92,185, 88,187, 86,196, 85,203, 78,204, 69,204, 65,198, 59,191, 57,190, 50,189, 46,186',
	'171,161, 171,158, 177,159, 178,153, 177,147, 177,140, 189,135, 195,143, 208,136, 212,136, 221,140, 235,144, 242,143, 252,131, 257,129, 261,131, 266,134, 271,133, 279,122, 282,124, 286,132, 290,135, 287,143, 283,144, 273,143, 267,142, 267,147, 268,153, 264,160, 266,168, 259,171, 260,180, 260,188, 266,192, 272,200, 263,206, 252,206, 244,208, 240,201, 235,198, 226,198, 219,199, 217,202, 189,198, 191,195, 192,181, 191,179, 182,179, 183,174, 183,171, 179,169, 178,167, 180,164, 180,162',
	'480,73, 484,71, 492,80, 496,77, 505,80, 509,88, 517,86, 518,89, 513,93, 508,102, 510,112, 505,119, 508,125, 503,131, 505,141, 499,146, 494,153, 494,159, 498,163, 491,163, 485,169, 486,178, 482,181, 477,176, 467,178, 458,178, 452,183, 446,181, 443,178, 438,181, 436,178, 443,173, 445,167, 451,159, 446,153, 447,153, 454,149, 452,146, 452,143, 459,135, 454,130, 454,125, 459,118, 456,112, 454,109, 454,106, 461,105, 461,99, 459,96, 464,94, 466,88, 471,90, 473,86, 473,82, 482,82, 480,77',
	'520,92, 520,95, 513,96, 515,103, 513,107, 514,112, 509,118, 513,124, 512,129, 507,131, 511,143, 505,146, 498,153, 498,158, 505,163, 505,165, 505,167, 495,167, 491,171, 492,176, 498,171, 510,173, 524,185, 529,186, 542,183, 549,183, 555,189, 564,193, 568,192, 570,189, 568,171, 568,165, 574,153, 574,140, 577,136, 583,136, 584,125, 583,118, 578,115, 571,118, 568,122, 563,122, 559,112, 552,112, 551,106, 542,106, 540,102, 540,99, 538,99, 534,103, 528,103, 525,99, 526,93, 524,91',
	'498,69, 503,67, 506,61, 515,59, 522,52, 527,56, 532,52, 531,46, 535,48, 540,44, 540,38, 545,33, 551,37, 568,33, 574,46, 582,54, 608,64, 634,67, 633,77, 636,82, 634,84, 639,93, 635,102, 627,115, 621,112, 612,109, 600,112, 593,112, 587,118, 579,112, 575,112, 567,118, 560,110, 555,109, 554,105, 545,103, 543,99, 542,96, 538,94, 534,99, 531,102, 528,97, 530,92, 518,84, 511,84',
	'415,28, 429,26, 450,22, 471,14, 490,13, 497,18, 505,21, 516,28, 527,31, 545,28, 537,34, 537,40, 535,40, 535,46, 530,42, 528,43, 528,52, 526,50, 520,49, 513,56, 505,56, 501,63, 495,63, 496,73, 493,75, 484,67, 479,69, 475,69, 471,67, 468,61, 465,56, 460,52, 456,52, 454,56, 451,52, 446,49, 439,46, 439,42, 432,37, 426,42, 422,37, 417,37, 417,32',
	'382,103, 389,103, 392,102, 396,103, 401,99, 405,102, 411,107, 410,112, 413,115, 420,112, 421,115, 414,120, 409,124, 409,127, 412,133, 413,137, 418,137, 424,135, 422,129, 425,127, 431,127, 439,127, 444,127, 445,124, 450,127, 450,132, 454,136, 448,146, 442,153, 442,162, 438,169, 434,169, 431,167, 418,171, 413,165, 403,167, 402,174, 395,178, 388,176, 392,171, 387,165, 387,151, 392,146, 387,136, 388,130, 385,127, 379,125, 379,122, 376,119, 379,112, 383,109',
	'392,99, 388,93, 387,85, 392,84, 394,82, 399,80, 406,86, 410,86, 410,85, 419,84, 429,82, 433,74, 432,67, 429,63, 421,59, 409,61, 404,61, 401,59, 402,56, 408,54, 411,47, 418,40, 421,41, 425,45, 433,42, 435,44, 436,49, 447,54, 452,59, 459,56, 461,56, 466,67, 472,70, 477,77, 470,80, 469,85, 465,84, 461,91, 456,92, 454,95, 457,99, 457,102, 452,103, 448,109, 449,115, 454,118, 450,122, 444,119, 441,119, 442,124, 433,124, 429,122, 423,122, 419,127, 419,133, 415,131, 412,125, 415,122, 423,118, 425,112, 424,108, 417,108, 415,110, 415,106, 406,97, 400,94, 397,97, 396,99',	
	'326,84, 333,84, 339,79, 351,76, 392,35, 411,28, 414,33, 413,41, 407,46, 406,52, 398,54, 398,59, 402,64, 409,65, 419,63, 422,67, 429,67, 429,74, 425,79, 415,80, 406,82, 402,78, 396,77, 392,79, 388,82, 382,82, 381,86, 384,88, 385,94, 388,99, 384,100, 381,102, 378,103, 378,110, 375,115, 373,119, 375,124, 375,127, 372,124, 371,122, 366,119, 353,119, 349,117, 347,112, 343,115, 339,115, 333,112, 333,106, 332,102, 327,100, 324,94, 324,92, 327,90',
	'303,82, 310,88, 316,88, 321,85, 323,87, 319,92, 321,98, 329,106, 329,115, 340,119, 341,122, 344,120, 345,119, 349,122, 366,122, 373,130, 384,130, 385,133, 381,137, 389,144, 387,146, 384,149, 382,165, 387,171, 384,176, 384,178, 392,181, 392,184, 382,188, 380,190, 381,194, 375,199, 350,197, 344,201, 340,201, 339,197, 342,193, 338,189, 340,186, 339,183, 336,183, 334,183, 334,177, 337,171, 334,168, 327,165, 309,163, 308,159, 309,156, 306,155, 300,155, 290,156, 286,147, 290,146, 293,135, 300,131, 302,125, 302,120, 298,118, 295,117, 294,112, 290,112, 290,110, 296,110, 300,102, 302,95, 300,92, 300,87',
	'271,146, 278,148, 282,147, 284,153, 288,159, 306,158, 305,165, 309,168, 326,169, 332,171, 333,171, 330,176, 331,180, 330,185, 332,187, 335,187, 334,191, 337,194, 335,198, 336,203, 339,206, 335,206, 334,204, 332,206, 328,205, 326,201, 323,199, 321,201, 317,204, 308,203, 302,203, 298,199, 294,199, 290,201, 284,201, 279,206, 275,201, 275,197, 268,190, 263,185, 264,178, 263,173, 267,171, 269,167, 268,161, 268,158, 271,153',	
	'171,135, 179,138, 185,133, 190,132, 195,138, 207,133, 213,132, 223,137, 239,140, 247,130, 255,126, 261,127, 267,131, 272,125, 278,119, 283,120, 287,128, 292,132, 297,128, 299,123, 298,122, 293,122, 290,118, 286,112, 286,107, 294,107, 294,102, 297,96, 296,89, 297,83, 300,81, 299,79, 291,76, 286,79, 282,79, 275,72, 255,74, 242,75, 231,67, 221,67, 205,76, 204,80, 198,84, 196,84, 194,82, 191,90, 192,98, 192,102, 196,104, 199,107, 198,112, 190,117, 185,117, 184,121, 184,124, 179,124, 172,122, 171,122',
	'140,59, 141,59, 147,59, 160,67, 170,69, 184,75, 189,77, 201,77, 191,80, 188,86, 185,89, 188,93, 189,106, 195,107, 195,110, 192,112, 185,112, 181,115, 181,120, 178,120, 172,118, 169,119, 168,120, 167,138, 170,140, 174,140, 174,155, 172,155, 169,153, 167,153, 168,167, 166,168, 161,165, 156,163, 152,163, 148,160, 143,164, 139,167, 137,165, 134,161, 131,163, 128,171, 126,170, 126,165, 120,159, 118,156, 120,151, 120,147, 118,146, 113,144, 113,142, 117,140, 119,138, 117,133, 111,131, 106,130, 106,128, 116,115, 115,109, 115,105, 118,102, 121,104, 124,105, 129,106, 131,102, 134,102, 136,97, 134,95, 128,89, 131,84, 132,79, 136,73, 137,67, 136,63, 137,60',
	'70,62, 76,62, 80,58, 85,56, 104,52, 118,53, 132,61, 134,68, 124,89, 133,98, 128,99, 127,102, 123,102, 120,99, 115,100, 112,106, 111,116, 102,128, 102,131, 116,137, 110,141, 109,146, 104,144, 97,150, 86,153, 80,146, 78,140, 71,137, 68,140, 63,139, 56,130, 56,127, 46,114, 53,108, 53,103, 55,100, 59,100, 68,81, 66,76, 69,76, 74,74, 78,73, 78,69',
	'42,1, 61,15, 76,18, 78,23, 70,29, 61,35, 55,45, 61,54, 76,58, 65,60, 74,70, 63,75, 64,81, 57,96, 49,101, 50,107, 42,112, 38,111, 36,106, 32,107, 29,102, 25,102, 22,95, 21,86, 21,78, 17,72, 14,69, 12,60, 11,57, 9,53, 10,50, 12,46, 13,41, 14,36, 15,29, 17,27, 28,26, 28,22, 33,21, 36,14, 36,7, 38,3'
	]
	
}


var VillaMap = {
	
	map: null,
	
	show: function(){
		var div = $('gmap');
		if($('map_canvas')){
			div.innerHTML = '';
			return;
		}
		
		div.innerHTML = '<br /><div id="map_canvas"></div>';
		LoadDialog.show(div);
		
		setTimeout(function(){
			LoadDialog.hide();
			if(typeof(villa.lat)!='undefined'&&typeof(villa.lng)!='undefined'&&villa.lat!=''&&villa.lng!=''){
				var myLatlng = new google.maps.LatLng(villa.lat, villa.lng);
				var myOptions = {
				  zoom: 11,
				  center: myLatlng,
				  mapTypeId: google.maps.MapTypeId.ROADMAP
				};
				VillaMap.map = new google.maps.Map(document.getElementById('map_canvas'), myOptions);
				VillaMap.setMarker({lat:villa.lat, lng: villa.lng}, false);
			}
		},1000);
		
		//setTimeout(function(){LoadDialog.show($('map_canvas'));}, 500);
		
		
	},
	
	init: function(coords, scrollwheel, map_canvas){
		
		var myLatlng = new google.maps.LatLng(coords.lat, coords.lng);
		var myOptions = {
		  zoom: 11,
		  center: myLatlng,
		  mapTypeId: google.maps.MapTypeId.ROADMAP
		};
		
		if(typeof(scrollwheel)!='undefined'){
			myOptions.scrollwheel= scrollwheel;
		}
		if(typeof(map_canvas)=='undefined'){
			map_canvas = 'map_canvas';
		}
		
		VillaMarker.setContainer('coords_lat','coords_lng');
		VillaMap.map = new google.maps.Map(document.getElementById(map_canvas), myOptions);

	},
	
	setMarker: function(m, dragable){
		if(typeof(dragable)=='undefined'){dragable=true;}
		var myLatlng = new google.maps.LatLng(m.lat, m.lng);
		VillaMarker.marker = new google.maps.Marker({
		     position: myLatlng,
		     draggable:dragable,
		     animation: google.maps.Animation.DROP,
		     title: m.title,
		     position_changed: VillaMarker.updateContainer
		 });
		 
		 VillaMarker.marker.setMap(VillaMap.map);
		 google.maps.event.addListener(VillaMarker.marker, 'dragend', VillaMarker.onDragEnd);

	},
	
	moveByAddress: function(address){
		var G = new google.maps.Geocoder();
		var req = {address: address, region: 'bg'}

		G.geocode(req, function(res, status){
			VillaMap.moveWhenReady(res[0], status);
		});
		
	},
	
	moveByCoords: function(coords){
		var myLatlng = new google.maps.LatLng(coords.lat, coords.lng);
		VillaMarker.marker.setPosition(myLatlng);
		VillaMarker.marker.setMap(VillaMap.map);
		VillaMap.map.panTo(myLatlng);
	},
	
	moveWhenReady: function(res, status){
		// res:type GeocoderResult

		if(status=='OK'){
			VillaMarker.marker.setPosition(res.geometry.location);
			VillaMarker.marker.setMap(VillaMap.map);
			VillaMap.map.panTo(res.geometry.location);
		}

	}
	
}

/* BULGARIA
MIN
	lat:	44.218260330744215
	lng:	22.357006164062568
MAX
	lat:	41.24128543343357
	lng:	28.619213195312568
*/
var VillaMarker = {
	
	marker: {lat: 0, lng: 0},
	
	container: {
		lat: null,
		lng: null
	},
	
	setContainer: function(lat, lng){
		VillaMarker.container.lat = $(lat);
		VillaMarker.container.lng = $(lng);
	},
	
	onDragEnd: function(e){
		VillaMarker.container.lat.value = e.latLng.lat();
		VillaMarker.container.lng.value = e.latLng.lng();
	},
	
	updateContainer: function(){
		var pos = VillaMarker.marker.getPosition();
		VillaMarker.container.lat.value = pos.lat();
		VillaMarker.container.lng.value = pos.lng();
	},
	
	getUserData: function(){
		var lat = parseFloat(VillaMarker.container.lat.value);
		var lng = parseFloat(VillaMarker.container.lng.value);
		
		if(VillaMarker.container.lat.value!='' && isNaN(lat)){
			alert('Не сте въвели валидна стойност за GPS Lat');
			VillaMarker.container.lat.focus();
			return;
		}
		if(VillaMarker.container.lng.value!='' && isNaN(lng)){
			alert('Не сте въвели валидна стойност за GPS Lng');
			VillaMarker.container.lng.focus();
			return;
		}
		
		if(VillaMarker.container.lat.value=='' && VillaMarker.container.lng.value==''){
			return;
		}
				
		var coords = {lat: VillaMarker.container.lat.value, lng:VillaMarker.container.lng.value}
		VillaMap.moveByCoords(coords);
		
	}
}
