$(window).load(function() {

	function initializeMap(){
		$('#searchlocations').hide();
		$('#map').fadeOut(500, function(){
			$('#map').empty().css({
				width: '890px',
				height: '641px',
				backgroundImage: 'url(http://www.megaline.kg/images/map/full.jpg)',
				position: 'relative'
			});
			$('#map').fadeIn();
			loadBullets('coast', false);
		});
//	$('.zoomable').hover(function() {
//	$(this).css({border: '10px solid black'});
//});
	}

	function addZoomable(id, width, height, top, left, newheight){
		$('<img class="zoomable" src="http://www.megaline.kg/images/map/zoom.png" id="' + id + '" />').css({
			border: 'none',
			position: 'absolute',
			width: width + 'px',
			height: height + 'px',
			top: top + 'px',
			left: left + 'px',
			cursor: 'pointer'
		}).appendTo('#map').click(function() {
			$(this).siblings().fadeOut();
			$(this).hide()
				   .attr('src', 'http://www.megaline.kg/images/map/' + id + '_base.jpg')
				   .fadeIn('slow')
				   .animate({
						width: '890px',
						height: newheight + 'px',
						top: '0px',
						left: '0px'
					}, 500, '', function(){
						$('#map').css({backgroundImage: 'url(http://www.megaline.kg/images/map/' + id + '_base.jpg)', height: newheight + 'px'}).empty();
						loadBullets(id, true);
					});
		}).mouseover(function() {
			$(this).attr( 'src' , "http://www.megaline.kg/images/map/zoom-hover.png"  )
		}).mouseout(function() {
			$(this).attr( 'src' , "http://www.megaline.kg/images/map/zoom.png"  )
});
	}
	
	function loadBullets(id, back){
			//add back button
			if(back){
				$('<a id="mapback" href="javascript:void(0)"><span>Вернуться на полную карту &gt;</span></a>')
					.appendTo('#map')
					.click(function(){initializeMap()});
			}
			else{
				addZoomable('mkr12', 25, 25, 536, 528, 863);
				addZoomable('mkr11', 25, 25, 520, 497, 1037);
				addZoomable('mkr10', 25, 25, 415, 355, 819);
				addZoomable('mkr9', 25, 25, 378, 355, 745);
				addZoomable('mkr8', 25, 25, 396, 392, 1762);
				addZoomable('mkr7', 25, 25, 413, 431, 1805);
				addZoomable('mkr6', 25, 25, 483, 470, 997);
				addZoomable('mkr5', 25, 25, 404, 475, 1099);
				addZoomable('mkr4', 25, 25, 353, 477, 1006);
				addZoomable('mkr3', 25, 25, 333, 435, 1387);
				addZoomable('akun', 25, 25, 400, 233, 1030);
				addZoomable('archa-beshik', 25, 25, 455, 185, 787);
				addZoomable('mkr-djal15', 25, 25, 310, 141, 865);
				addZoomable('mkr-djal23', 25, 25, 342, 141, 1248);
				addZoomable('mkr-djal29', 25, 25, 400, 146, 924);
				addZoomable('sovmin', 25, 25, 602, 258, 963);
				addZoomable('mkr-kokjar', 25, 25, 297, 511, 1705);
				addZoomable('jantosheva', 25, 25, 297, 479, 1400);
				addZoomable('mkr-tunguch', 25, 25, 246, 817, 758);
				addZoomable('mkr-alamedin', 25, 25, 48, 790, 1365);
				addZoomable('gor-stroitelei', 25, 25, 83, 850, 1023);
				addZoomable('mkr-uchkun', 25, 25, 120, 848, 909);
				addZoomable('pishpek', 25, 25, 163, 55, 409);
				addZoomable('politeh-zapad-2', 25, 25, 310, 180, 665);
				addZoomable('politeh-zapad', 25, 25, 303, 230, 1793);
				addZoomable('politeh-vostok', 25, 25, 303, 288, 1224);
				addZoomable('park-ataturk', 25, 25, 363, 323, 1035);
				addZoomable('botanika', 25, 25, 211, 295, 1088);
				addZoomable('fizprib-zapad', 25, 25, 290, 352, 851);
				addZoomable('fizprib-vostok', 25, 25, 290, 402, 1539);
				addZoomable('kgma', 25, 25, 346, 354, 709);
				addZoomable('yug2-zapad', 25, 25, 215, 360, 1136);
				addZoomable('yug2-vostok', 25, 25, 220, 406, 1787);
				addZoomable('gorgai', 25, 25, 230, 456, 719);
				addZoomable('almaatinka-gorkogo', 25, 25, 200, 526, 620);
				addZoomable('mgvard-yug', 25, 25, 105, 205, 1249);
				addZoomable('mgvard-sever', 25, 25, 45, 210, 930);
				addZoomable('manasa-yug', 25, 25, 108, 255, 1338);
				addZoomable('manasa-sever', 25, 25, 45, 260, 867);
				addZoomable('tmoldo-yug', 25, 25, 115, 310, 1455);
				addZoomable('tmoldo-sever', 25, 25, 45, 315, 984);
				addZoomable('dzerj-yug', 25, 25, 120, 365, 1316);
				addZoomable('dzerj-sever', 25, 25, 45, 367, 1070);
				addZoomable('pravda-yug', 25, 25, 125, 420, 1470);
				addZoomable('pravda-sever', 25, 25, 45, 420, 1446);
				addZoomable('karp-yug', 25, 25, 115, 460, 1790);
				addZoomable('karp-sever', 25, 25, 30, 462, 1466);
				addZoomable('mkr-vostok5', 25, 25, 110, 505, 1178);
				addZoomable('vostok-4', 25, 25, 35, 560, 1685);
				addZoomable('vostok-3', 25, 25, 35, 615, 1413);
				addZoomable('vostok-2', 25, 25, 35, 670, 1558);
				addZoomable('vostok-1', 25, 25, 35, 730, 1425);
			}
	}
	
	
	//initialize map
	initializeMap();
	

});
