var elem = new Array();
var lines = new Array();
var build = new Array();
var canvas;
var canvas_line;
var build_show = false;
var last_click = 0;
var build_data = new Array();
var preload = new Array();

$(function () {
	if ($.browser.opera) $("#buildings-vect, #buildings-rastr").css('margin-left', '-1540px');

	timer = setInterval(blinking, 2000);

	if (lang == "rus") {
	    var t = new Array();
	    t['capt'] = 'Конюшня №3';
	    t['param'] = '24 денника&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Постройка 1811 г.';
	    t['txt'] = 'Являясь одним из&nbsp;старейших зданий конезавода, оно одновременно остается и&nbsp;самым удобным. В&nbsp;2006&nbsp;г. здесь был проведен капитальный ремонт, и&nbsp;в&nbsp;настоящий момент здание используется как маточная конюшня. Благодаря толстым <nobr>(70&ndash;90 см)</nobr> стенам летом в&nbsp;помещении сохраняется прохлада, а&nbsp;зимой&nbsp;&mdash; тепло. Пол&nbsp;&mdash; глинобитный, подбивается ежегодно. К&nbsp;основному корпусу прилегает удобный варок для выгула жеребят и&nbsp;проблемных лошадей.';
	    t['img'] = '/img/buildings/konyushnya_03.jpg';
	    build_data[1] = t;

	    var t = new Array();
	    t['capt'] = 'Конюшня №2';
	    t['param'] = '48 денников&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Постройка 1956 г.';
	    t['txt'] = 'Здание не&nbsp;эксплуатируется.';
	    t['img'] = '';
	    build_data[2] = t;

	    var t = new Array();
	    t['capt'] = 'Конюшня №6';
	    t['param'] = '48 денников&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Постройка 1964 г.';
	    t['txt'] = 'Здание не&nbsp;эксплуатируется с&nbsp;1997&nbsp;года.';
	    t['img'] = '';
	    build_data[3] = t;

	    var t = new Array();
	    t['capt'] = 'Конюшня №7';
	    t['param'] = '40 денников&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Постройка 1983 г.';
	    t['txt'] = 'Это тренерская конюшня, она имеет удобный выход на&nbsp;ипподром. Здесь содержатся жеребята в&nbsp;возрасте от&nbsp;6&nbsp;месяцев до&nbsp;2&nbsp;лет, которые проходят подготовку перед отправкой на&nbsp;центральные ипподромы. В&nbsp;2008&nbsp;г. в&nbsp;здании был осуществлен капитальный ремонт.';
	    t['img'] = '/img/buildings/konyushnya_07.jpg';
	    build_data[4] = t;

	    var t = new Array();
	    t['capt'] = 'Ветеринарный<br/>лазарет';
	    t['param'] = '';
	    t['txt'] = 'Здание оборудовано станком для исследования лошадей, искусственной кобылой для взятия спермы, лабораторией для осеменения, случным манежем и&nbsp;ветеринарной аптекой. Здесь&nbsp;же в&nbsp;специальных емкостях, охлаждаемых жидким азотом, хранится сперма жеребцов-производителей.';
	    t['img'] = '/img/buildings/lazaret.jpg';
	    build_data[5] = t;

	    var t = new Array();
	    t['capt'] = 'Конюшня №1';
	    t['param'] = '24 денника&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Постройка 1811 г.';
	    t['txt'] = 'Это старейшее здание конезавода является памятником архитектуры. В&nbsp;настоящее время не&nbsp;используется&nbsp;&mdash; законсервировано и&nbsp;ожидает реставрации.';
	    t['img'] = '/img/buildings/konyushnya_01.jpg';
	    build_data[6] = t;

	    var t = new Array();
	    t['capt'] = 'Конюшня №5';
	    t['param'] = '40 денников&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Постройка 1965 г.';
	    t['txt'] = 'Здание используется как маточная конюшня. В&nbsp;2007&nbsp;г. проведен капитальный ремонт. Пол&nbsp;&mdash; глинобитный, подбивается ежегодно. Рядом со&nbsp;зданием находится небольшая левада площадью 0.8&nbsp;Га, предназначенная для индивидуальных прогулок лошадей. В&nbsp;этом&nbsp;же здании находится офис управления Злынского конезавода.';
	    t['img'] = '/img/buildings/konyushnya_05.jpg';
	    build_data[7] = t;

	    var t = new Array();
	    t['capt'] = 'Конюшня №4';
	    t['param'] = '4 больших денника&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Постройка 1965 г.';
	    t['txt'] = 'Конюшня предназначена для содержания жеребцов-производителей. Два денника имеют размеры 14&times;6&nbsp;м; другие два&nbsp;&mdash; 8&times;8&nbsp;м. Здесь&nbsp;же находится большой случной манеж. Конюшня имеет прямой выход на&nbsp;крытую беговую дорожку.';
	    t['img'] = '';
	    build_data[8] = t;

	    var t = new Array();
	    t['capt'] = 'Крытая беговая дорожка';
	    t['param'] = 'Протяженность дорожки: 145 м';
	    t['txt'] = 'Здание служит местом тренировки лошадей при любых погодных условиях и&nbsp;в&nbsp;любое время суток. Покрытие состоит из&nbsp;намывного песка. Имеется освещение и&nbsp;система искусственной вентиляции. Здание было реконструировано в&nbsp;2010&nbsp;г.';
	    t['img'] = '/img/buildings/krytaya_begovaya_dorozhka.jpg';
	    build_data[9] = t;

	    var t = new Array();
	    t['capt'] = 'Конкурное<br/>поле';
	    t['param'] = '15 барьеров&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;4150 м&sup2;';
	    t['txt'] = 'Площадка предназначена для проведения тренировок и&nbsp;соревнований по&nbsp;преодолению препятствий. Она оборудована дренажной системой и&nbsp;имеет специально разработанное покрытие, состоящее из&nbsp;3&nbsp;слоев. Для судей и&nbsp;зрителей предусмотрена трибуна с&nbsp;навесом.';
	    t['img'] = '/img/buildings/konkurnoe_pole.jpg';
	    build_data[10] = t;

	    var t = new Array();
	    t['capt'] = 'Ипподром';
	    t['param'] = 'Внутренний диаметр: 845 м<br/>Ширина беговой дорожки: 10 м';
	    t['txt'] = 'Ипподром служит местом тренировки лошадей. По&nbsp;внешней стороне виражи защищены лесопосадкой. Грунт&nbsp;&mdash; чернозем; периодически обрабатывается дискатором, культиватором, бороной и&nbsp;катком. Внутри находятся 2&nbsp;левады с&nbsp;деревянной оградой для прогулки тренерских лошадей.';
	    t['img'] = '/img/buildings/ippodrom.jpg';
	    build_data[11] = t;

	    var t = new Array();
	    t['capt'] = 'Большая маточная левада';
	    t['param'] = 'Площадь: 76 Га';
	    t['txt'] = 'Левада предназначена для выпаса конематок с&nbsp;жеребятами. Она делится на&nbsp;2&nbsp;части, используемые поочередно по&nbsp;2&nbsp;месяца в&nbsp;период с&nbsp;весны до&nbsp;осени. Одна из&nbsp;частей имеет выход к&nbsp;пруду. В&nbsp;центральной части левада оборудована водопоем. На&nbsp;80% состоит из&nbsp;тимофеевки (семейство злаковых); на&nbsp;20%&nbsp;&mdash; из&nbsp;белого клевера (семейство бобовых). Весной проводятся агрообработки, растения подкармливаются минеральными удобрениями. Левада служит для конезавода источником запасов сена.';
	    t['img'] = '/img/buildings/bolshaya_levada.jpg';
	    build_data[12] = t;


	    //нет на рендере еще
	    var t = new Array();
	    t['capt'] = 'Левада';
	    t['param'] = 'Площадь: 2 Га';
	    t['txt'] = 'Левада предназначена для выпаса отъемного молодняка. На&nbsp;80% состоит из&nbsp;тимофеевки (семейство злаковых); на&nbsp;20%&nbsp;&mdash; из&nbsp;белого клевера (семейство бобовых). Весной проводятся агрообработки, растения подкармливаются минеральными удобрениями.';
	    t['img'] = '/img/buildings/build_1.jpg';
	    build_data[13] = t;

	    var t = new Array();
	    t['capt'] = 'Сенной сарай';
	    t['param'] = 'Постройка 2008 г.';
	    t['txt'] = 'Здесь хранятся основные запасы сена для всего конезавода. Сарай оборудован специальными сетками, позволяющими осуществлять хранение при естественной вентиляции воздуха.';
	    t['img'] = '/img/buildings/build_1.jpg';
	    build_data[14] = t;
	}
















	if (lang == "eng") {
	    var t = new Array();
	    t['capt'] = 'Stable No.&nbsp;3';
	    t['param'] = '24 stalls&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Constructed in 1811.';
	    t['txt'] = 'This stable is one of the oldest and still the most comfortable buildings in the stud. In 2006 major repairs were carried out here and now the building is used as a dam stable. Thanks to thick (70–90 cm) walls it remains cool inside during the summer and warm in winter. The floor is wattle and daub and is lined annually. There is a special yard near the stable for walking of foals and problem horses.';
	    t['img'] = '/img/buildings/konyushnya_03.jpg';
	    build_data[1] = t;

	    var t = new Array();
	    t['capt'] = 'Stable No.&nbsp;2';
	    t['param'] = '48 stalls&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Constructed in 1956.';
	    t['txt'] = 'The building is not maintained.';
	    t['img'] = '';
	    build_data[2] = t;

	    var t = new Array();
	    t['capt'] = 'Stable No.&nbsp;6';
	    t['param'] = '48 stalls&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Constructed in 1964.';
	    t['txt'] = 'The building has not been maintained since 1997.';
	    t['img'] = '';
	    build_data[3] = t;

	    var t = new Array();
	    t['capt'] = 'Stable No.&nbsp;7';
	    t['param'] = '40 stalls&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Constructed in 1983.';
	    t['txt'] = 'This is a trainer\'s stable and it has a convenient access to the hippodrome.  The foals (6 months &mdash; 2 years old) that have training before sending to the central hippodromes are kept here. In 2008 major repairs were carried out in this stable.';
	    t['img'] = '/img/buildings/konyushnya_07.jpg';
	    build_data[4] = t;

	    var t = new Array();
	    t['capt'] = 'Veterinary<br/>Infirmary';
	    t['param'] = '';
	    t['txt'] = 'The building is equipped with machine for scrutiny of horses, artificial mare for sperm sampling, laboratory for insemination, arena for pairing and veterinary drugstore. Also stallion\'s semen is saved here in a special containers, cooled by liquid nitrogen.';
	    t['img'] = '/img/buildings/lazaret.jpg';
	    build_data[5] = t;

	    var t = new Array();
	    t['capt'] = 'Stable No.&nbsp;1';
	    t['param'] = '24 stalls&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Constructed in 1811.';
	    t['txt'] = 'This is the oldest building on the territory of the stud and it is an architectural monument. Nowadays it is not used and is waiting for restoration.';
	    t['img'] = '/img/buildings/konyushnya_01.jpg';
	    build_data[6] = t;

	    var t = new Array();
	    t['capt'] = 'Stable No.&nbsp;5';
	    t['param'] = '40 stalls&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Constructed in 1965.';
	    t['txt'] = 'The building is used as a dam stable. In 2007 major repairs were carried out here. The floor is wattle and daub and is lined annually. Near the building there is a small pasture (0.8 ha) that is used for individual walks with horses. In the same building there is the office of Zlynski Stud management.';
	    t['img'] = '/img/buildings/konyushnya_05.jpg';
	    build_data[7] = t;

	    var t = new Array();
	    t['capt'] = 'Stable No.&nbsp;4';
	    t['param'] = '4 big stalls&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Constructed in 1965.';
	    t['txt'] = 'The stable is intended for the maintenance of stallions. Two stalls are 14 х 6 m, and the other two — 8 х 8 m. There is also a large arena for pairing. The stable has a direct access to the covered racetrack.';
	    t['img'] = '';
	    build_data[8] = t;

	    var t = new Array();
	    t['capt'] = 'Covered<br/>Racetrack';
	    t['param'] = 'Length of track: 145 m';
	    t['txt'] = 'The building is used as a place for horse training in all weather conditions and at any time. The covering consists of alluvial sand. There is lightning and ventilation system. Racetrack was reconstructed in 2010.';
	    t['img'] = '/img/buildings/krytaya_begovaya_dorozhka.jpg';
	    build_data[9] = t;

	    var t = new Array();
	    t['capt'] = 'Jumping<br/>Field';
	    t['param'] = '15 barriers&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;4150 m&sup2;';
	    t['txt'] = 'This ground is intended for trainings and competitions on clearing of obstacles. It is equipped with drainage system and has specially developed covering which consists of 3 layers. There is a tribune with a shed for umpires and audience.';
	    t['img'] = '/img/buildings/konkurnoe_pole.jpg';
	    build_data[10] = t;

	    var t = new Array();
	    t['capt'] = 'Hippodrome';
	    t['param'] = 'Inner diameter: 845 m<br/>Width of a racetrack: 10 m';
	    t['txt'] = 'Hippodrome is used as a place for horse training. Bends are protected by tree-planting on an outer side. The ground consists of chernozem; it is periodically processed with discator, cultivator, harrow and roller. Inside of hippodrome there are 2 pastures with a wooden fence that are used for a walk of trainer\'s horses.';
	    t['img'] = '/img/buildings/ippodrom.jpg';
	    build_data[11] = t;

	    var t = new Array();
	    t['capt'] = 'Large<br/>Dam Pasture';
	    t['param'] = 'Area: 76 ha';
	    t['txt'] = 'This area is used for the pasture of mares and foals. It is divided into 2 parts that are used by turns for 2 months from spring to autumn. One of the parts has an access to the pond. There is a watering place in the central part. About 80% of the pasture consists of timothy (grass family) and 20% consists of white clover (legume). During the spring plants are fed up by mineral fertilizers and agroprocessings are carried out. This pasture is a source of stocks of hay for the stud.';
	    t['img'] = '/img/buildings/bolshaya_levada.jpg';
	    build_data[12] = t;


	    //нет на рендере еще
	    var t = new Array();
	    t['capt'] = 'Pasture';
	    t['param'] = 'Area: 2 ha';
	    t['txt'] = 'This area is used for the pasture of cubs. About 80% of the pasture consists of timothy (grass family) and 20% consists of white clover (legume). During the spring plants are fed up by mineral fertilizers and agroprocessings are carried out.';
	    t['img'] = '/img/buildings/build_1.jpg';
	    build_data[13] = t;

	    var t = new Array();
	    t['capt'] = 'Barn';
	    t['param'] = 'Constructed in 2008';
	    t['txt'] = 'The main stocks of hay for the whole stud are stored here. The barn is equipped with special nets which allow storing hay under condition of natural ventilation of air.';
	    t['img'] = '/img/buildings/build_1.jpg';
	    build_data[14] = t;
	}

	canvas = Raphael($("#buildings-vect")[0], 2000, 535);
	canvas.clear();
	elem[0] = canvas.path("M0,0 L2000,0 L2000,535 L0,535 z");
	elem[0].attr({"fill": "red", "fill-opacity":"0", "opacity":"0"});
	elem[0].node.onclick = clickAnywhere;
	elem[1] = canvas.path("M1590,208 L1593,200 L1655,190 L1664,195 L1669,193 L1683,201 L1705,192 L1719,207 L1717,215 L1635,240 z");
	elem[2] = canvas.path("M1512,234 L1502,227 L1504,218 L1512,210 L1591,199 L1597,207 L1599,221 L1574,228 L1571,232 L1554,234 L1547,231 z");
	elem[3] = canvas.path("M1392,247 L1498,239 L1504,243 L1510,245 L1514,255 L1512,259 L1504,265 L1463,269 L1462,274 L1443,276 L1436,272 L1394,273 L1388,269 L1378,269 L1377,256 L1380,253 L1388,252 z");
	elem[4] = canvas.path("M1571,326 L1507,271 L1506,264 L1516,254 L1533,255 L1600,307 L1600,320 z");
	elem[5] = canvas.path("M1559,262 L1554,257 L1554,248 L1557,242 L1562,238 L1592,231 L1595,235 L1598,242 L1599,256 z");
	elem[6] = canvas.path("M1720,331 L1696,320 L1698,302 L1712,295 L1719,281 L1726,277 L1741,283 L1765,270 L1789,283 L1789,292 z");
	elem[7] = canvas.path("M1792,226 L1773,218 L1773,206 L1785,195 L1796,198 L1896,240 L1907,248 L1906,263 L1891,272 z");
	elem[8] = canvas.path("M1870,290 L1850,284 L1850,269 L1857,260 L1927,244 L1939,257 L1939,270 z");
	elem[9] = canvas.path("M1872,378 L1868,278 L1885,267 L1906,278 L1912,365 L1910,381 z");
	elem[10] = canvas.path("M1867,361 L1762,320 L1829,299 L1833,290 L1844,291 L1866,299 L1868,306 z");
	elem[11] = canvas.path("M1442,423 L1237,369 L1202,360 L1175,346 L1166,336 L1158,320 L1156,305 L1165,290 L1178,286 L1195,276 L1215,269 L1243,266 L1271,267 L1299,268 L1322,274 L1341,279 L1405,292 L1475,307 L1605,335 L1708,356 L1777,378 L1824,393 L1850,410 L1860,429 L1856,455 L1845,475 L1825,486 L1791,491 L1770,490 L1740,487 L1702,481 z");
	elem[12] = canvas.path("M0,412 L864,279 L950,317 L991,331 L1035,355 L1064,371 L1103,396 L1113,407 L1199,448 L1201,454 L1039,535 L0,534 z");

	for (var i = 1; i <= 12; i++) {
		elem[i].attr({"fill": "red", "fill-opacity":"0", "opacity":"0", "cursor":"pointer"});
		var f1 = function() {var funcObj = arguments.callee;  clickBuilding(funcObj.ind);}; 	f1.ind = i;		elem[i].node.onclick = f1;
		var f2 = function() {var funcObj = arguments.callee;  overBuilding(funcObj.ind);}; 		f2.ind = i;		elem[i].node.onmouseover = f2;
		var f3 = function() {var funcObj = arguments.callee;  outBuilding(funcObj.ind);}; 		f3.ind = i; 	elem[i].node.onmouseout = f3;
	}

	build[1] = '<img class="building-class" id="build_1" style="position:absolute;left:1590px;top:190px" src="/img/buildings/1.jpg" width="130" height="51"/>';
	build[2] = '<img class="building-class" id="build_2" style="position:absolute;left:1502px;top:199px" src="/img/buildings/2.jpg" width="98" height="36"/>';
	build[3] = '<img class="building-class" id="build_3" style="position:absolute;left:1377px;top:239px" src="/img/buildings/3.jpg" width="138" height="38"/>';
	build[4] = '<img class="building-class" id="build_4" style="position:absolute;left:1506px;top:254px" src="/img/buildings/4.jpg" width="95" height="73"/>';
	build[5] = '<img class="building-class" id="build_5" style="position:absolute;left:1554px;top:231px" src="/img/buildings/5.jpg" width="46" height="32"/>';
	build[6] = '<img class="building-class" id="build_6" style="position:absolute;left:1696px;top:270px" src="/img/buildings/6.jpg" width="94" height="62"/>';
	build[7] = '<img class="building-class" id="build_7" style="position:absolute;left:1773px;top:195px" src="/img/buildings/7.jpg" width="135" height="78"/>';
	build[8] = '<img class="building-class" id="build_8" style="position:absolute;left:1850px;top:244px" src="/img/buildings/8.jpg" width="90" height="47"/>';
	build[9] = '<img class="building-class" id="build_9" style="position:absolute;left:1868px;top:267px" src="/img/buildings/9.jpg" width="45" height="115"/>';
	build[10] = '<img class="building-class" id="build_10" style="position:absolute;left:1762px;top:290px" src="/img/buildings/10.jpg" width="107" height="72"/>';
	build[11] = '<img class="building-class" id="build_11" style="position:absolute;left:1156px;top:266px" src="/img/buildings/11.jpg" width="705" height="226"/>';
	build[12] = '<img class="building-class" id="build_12" style="position:absolute;left:0px;top:279px" src="/img/buildings/12.jpg" width="1202" height="257"/>';

	canvas_line = Raphael($("#building-line")[0], 3082, 1500);
	canvas_line.clear();
	lines[1] = canvas_line.path("M1651,232 C1677,280 1668,414 1493,385");
	lines[2] = canvas_line.path("M1514,215 C1456,202 1275,227 1397,392");
	lines[3] = canvas_line.path("M1424,249 C1377,210 1254,227 1384,399");
	lines[4] = canvas_line.path("M1537,293 C1484,273 1430,276 1402,388");
	lines[5] = canvas_line.path("M1585,256 C1639,284 1772,375 1398,393");
	lines[6] = canvas_line.path("M1740,313 C1767,367 1654,441 1401,391");
	lines[7] = canvas_line.path("M1839,245 C1636,262 1600,397 1392,393");
	lines[8] = canvas_line.path("M1854,276 C1656,209 1581,470 1390,394");
	lines[9] = canvas_line.path("M1880,377 C1807,433 1614,340 1401,392");
	lines[10] = canvas_line.path("M1793,330 C1786,383 1614,443 1397,393");
	lines[11] = canvas_line.path("M1528,327 C1500,285 1415,282 1391,399");
	lines[12] = canvas_line.path("M973,333 C1038,223 1240,198 1399,387");
	for (var i = 1; i <= 12; i++) lines[i].attr({"stroke": "#ffff21", "stroke-width":"2", "opacity":"0"});

	for (i = 1; i <= 12; i++) $(build[i]).appendTo("#buildings-rastr").hide();



	preload[0] = new Image();
	preload[0].src = '/img/buildings/foto-ramka.png';

	preload[1] = new Image();
	preload[1].src = '/img/buildings/build_top.png';

	preload[2] = new Image();
	preload[2].src = '/img/buildings/build_middle.png';

	preload[3] = new Image();
	preload[3].src = '/img/buildings/build_bottom.png';

	for (var i = 1; i <= 12; i++) {
		preload[i + 3] = new Image();
		preload[i + 3].src = '/img/buildings/'+i+'.jpg';
		if (build_data[i]['img'] != "") {
			preload[i + 30] = new Image();
			preload[i + 30].src = build_data[i]['img'];
		}
	}


})

function clearAllBuildings() {
	build_show = false;
	$(".building-class").css("opacity", "1");
	$(".building-class").hide();
	$("#buildings-popup,#buildings-lines").hide();
	for (var i = 1; i <= 12; i++) lines[i].attr({"opacity":"0"});
}

function showBuilding(i) {
	clearInterval(timer);
	isblinking = false;
	clearAllBuildings();
	$("#build_"+i).show();

	$("#building-small-image").attr('src', build_data[i]['img']);
	if (build_data[i]['img'] == "") $("#building-small-image-block").hide(); else $("#building-small-image-block").show();
	$("#building-capt").html(build_data[i]['capt']);
	if (build_data[i]['param'] != "") {
		$("#building-param").html('<em>'+build_data[i]['param']+'</em>');
		$("#building-param").show();
	} else {
		$("#building-param").html("");
		$("#building-param").hide();
	}
	$("#building-txt").html(build_data[i]['txt']);
	$("#buildings-popup,#buildings-lines").show();
	lines[i].attr({"opacity":"1"});

    var h = $("#building-txt").position().top - $("#building-capt").position().top + $("#building-txt").height() + 24 + 52 - 135 - 41;
    if (h < 0) h = 0;
    $("#building-stub").height(h);

	build_show = true;
	last_click = +new Date();
}

function overBuilding(i) {
	showBuilding(i)
}

function outBuilding(i) {
	clearAllBuildings();
}

function clickBuilding(i) {
	showBuilding(i);
}

var timer;
var isblinking = false;
var blinkDir;
var blinkCnt;
var blinkVal;
var blinkingTimer;


function blinkStep(i) {
	if (!isblinking)  {
		clearInterval(blinkingTimer);
		return;
	}
	blinkVal += 0.1 * blinkDir;
	if (blinkVal < 0.01) {
		blinkVal = 0;
		blinkDir *= -1;
		blinkCnt++;
	}
	if (blinkVal > 1) {
		blinkVal = 1;
		blinkDir *= -1;
		blinkCnt++;
	}
	$("#build_"+i).css("opacity", blinkVal);

	if (blinkCnt == 4) {
		$("#build_"+i).hide().css("opacity", "1");
		isblinking = false;
		clearInterval(blinkingTimer);
	}
}

function blinking() {
	if (isblinking) return;
	var i = Math.floor(Math.random() * 10) + 1;
	if (i > 10) i = 10;
	isblinking = true;
	blinkDir = 1;
	blinkVal = 0;
	blinkCnt = 0;
	$("#build_"+i).show().css("opacity", "0");
	blinkingTimer = setInterval(function(){blinkStep(i)}, 20);
}
