// Добавить в Избранное 
function bookmark(a) { 
  title=document.title; 
  url=document.location; 
  try { 
    // Internet Explorer 
    window.external.AddFavorite(url, title); 
  } 
  catch (e) { 
    try { 
      // Mozilla 
      window.sidebar.addPanel(title, url, ""); 
    } 
    catch (e) { 
      // Opera 
      if (typeof(opera)=="object") { 
        a.rel="sidebar"; 
        a.title=title; 
        a.url=url; 
        return true; 
      } 
      else { 
        // Unknown 
        alert('Нажмите Ctrl-D чтобы добавить страницу в закладки'); 
      } 
    } 
  } 
  return false; 
}

images = new Array();
var option_view = '';
var left_map;
var top_map;
var current_step;
$(document).ready(function(){

	left_map = $('.google_map').position().left+238;
	top_map = $('.google_map').position().top+30;

	for(var i = 1; i < 6; i++){
	 	imageObj = new Image();
		imageObj.src="/design/img/map/step-"+i+".jpg";
		images[i]=imageObj;
	 }
	
	//Слайдер зума
	var count_steps = 5;
	current_step = 4;
	if ($('#zooming_shkala').size()>0)
		var current_position = $('#zooming_shkala').children().css('top').replace('px', '');
	
	$('#zooming_in').click(function(){
		if(current_step < count_steps){
			$('#zooming_shkala').children().css('top', (parseInt(current_position) - 26)+'px');
			current_position = $('#zooming_shkala').children().css('top').replace('px', '');
			current_step++;
			$('.google_map').children('#world_map:not(:animated)').fadeOut('fast',function(){mapstep(current_step);});
			$('.google_map').children('#world_map').fadeIn('fast');
		}
	});
	
	$('#zooming_out').click(function(){		
		if(current_step > 1){
			$('#zooming_shkala').children().css('top', (parseInt(current_position) + 26)+'px');
			current_position = $('#zooming_shkala').children().css('top').replace('px', '');
			current_step--;
			$('.google_map').children('#world_map:not(:animated)').fadeOut('fast',function(){mapstep(current_step);});
			$('.google_map').children('#world_map').fadeIn('fast');
		}
	});
	
	$('#zooming_shkala').children().draggable({
					containment:'parent',
					cursor: 'n-resize',
					grid:[0, 26],
					drag: function(){
								current_step = ((108 - $('#zooming_shkala').children().css('top').replace('px', '')) / 26)+1;
								current_position = $('#zooming_shkala').children().css('top').replace('px', '');
								$('.google_map').children('#world_map:not(:animated)').fadeOut('fast',function(){mapstep(current_step);});
								$('.google_map').children('#world_map').fadeIn('fast');

							}
	});

	$('#world_map').draggable({
		cursor: 'move',
		containment : [left_map, top_map, left_map, top_map]
	});
	
	$('#show_weather').click(function(){
		$('.mesta_block').fadeOut('slow');
		$('.weather_block').fadeIn("slow");
		$(this).addClass('active');
		$('#show_mesto').removeClass('active');
		option_view = '';
		mapstep(current_step);
	});
	
	$('#show_mesto').click(function(){
		$('.weather_block').fadeOut('slow');
		$('.mesta_block').fadeIn("slow");
		$(this).addClass('active');
		$('#show_weather').removeClass('active');
		option_view = 'mesto_';
		mapstep(current_step);
	});
	
	mapstep(current_step);
	//$('#smallsearch').css('display', 'none');
	//$('.weather_block').draggable();
	
	$(window).resize(function(){
		left_map = $('.google_map').position().left+238;
		top_map = $('.google_map').position().top+30;
		mapstep(current_step);
	});

	//Динамическое верхнее меню
	$(".directs li")		
		.mouseenter(function(){
			if($(this).parent().hasClass("city_columns")) return;	
			$(this).children(".city_list:not(:animated)").show(250, function(){
				$(this).addClass("cur_fix");
				$('.city_list').each(function(){ 
					if(!$(this).hasClass("cur_fix")) $(this).hide();
				});
				$(this).removeClass("cur_fix");
				//var height = $(this).height();
				//if(height<70) height=70;
				//$(".fix_block").animate({"height": height+"px"}, 'fast');
			});
		})
		.mouseleave(function(){	
			if($(this).parent().hasClass("city_columns")) return;			
			$(this).children(".city_list:not(:animated)").hide();									
		});
	$(".directs").mouseenter(function(){
		$('#tours').hide();		
	})	
	.mouseleave(function(){
		$('#tours').show();
		$('.city_list').hide();
	});

	$('.mesta_block').click(function(){
		$('#show_info').append($(this).children('.hide_info').html());
		$('#show_info').fadeIn(300);
	});
	
	$('#show_info').click(function(){
		$('#show_info').empty();
		$('#show_info').fadeOut(200);
	});
	
	//Плавающий онлайн консультант
	var offset = $("#fixed").offset();
		var topPadding = 15;
		$(window).scroll(function() {
			if ($(window).scrollTop() > offset.top) $("#fixed").stop().animate({marginTop: $(window).scrollTop() - offset.top + topPadding});
				else {$("#fixed").stop().animate({marginTop: 0});};});
		
	$("#feedback").fancybox({
		'width'				: 590,
		'height'			: 480,
		'padding'			: 30,
        'autoScale'     	: false,
		'autoDimensions'	: false,
        'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'overlayColor'		: '#000',
		'type'				: 'iframe'
	});
	
	//слайдшоу
	//$("#slideshow").cycle('scrollDown');
	$(".small_img").click(function(){ 
		slide_img($(this));
	});
	$(".small_img:first").click();

	if(!($.browser.msie && $.browser.version=="6.0"))
		setInterval("slide_img(next_img())", 5000);
});

//щелкаем по маленькой картинке слайдера
function slide_img(img) { 
	if ($("#slideshow img.small_img").is(":animated")) return;
//	parent = img.parents("#slideshow");
	//parent.children(".small_img:hidden").show("slow");
	$(".small_img:hidden").show("slow");
	img.hide("slow");
	$("#slideshow #big_img img").fadeOut("fast", function(){
		$("#slideshow #big_img a").attr("href", img.attr("value"));
		$(this).attr("src", img.attr("src")).fadeIn("slow");
	});
}
//ф-ция находит следующий по порядку рисунок
function next_img() {
	img = $(".small_img:hidden").next(".small_img");
	if (img.size() == 0) img = $("#slideshow .small_img:first");
	return img;
}

function mapstep (step) {
	$('.google_map').children('#world_map').children('img').attr('src', images[step].src);
	switch(step){
		case 1:{
			$('.google_map').children('#world_map').draggable({containment : [left_map, top_map, left_map, top_map]});
			$('.google_map').children('#world_map').css('top', 0);
			$('.google_map').children('#world_map').css('left', 0);
			var citys = [	[27612,429,91], 	//Россия Москва
							[94767,665,303], 	//Австралия Сидней
							[83743,260,268], 	//Бразилия Рио-де-Жанейро
							[85577,205,298], 	//Чили Сантьяго
							[78486,205,192], 	//Доминикана Санто-Доминго
							[61991,471,272], 	//Маврикий Порт-луи
							[42182,514,170], 	//Индия Нью-Дейли
							[16235,377,133], 	//Италия  Рим
							[54511,593,140], 	//Китай Пекин
							[61641,316,203], 	//Сенегал Дакар
							[72403,188,139]		//США Вашингтон
						];
			viewcitys(citys);
			break;}
		case 2:{
			$('.google_map').children('#world_map').css('top', -113.5);
			$('.google_map').children('#world_map').css('left', -243.5);
			$('.google_map').children('#world_map').draggable({containment : [left_map-425, top_map-233.5, left_map, top_map]});
			var citys = [	[27612,637,245], 	//Россия Москва
							[94767,918,502], 	//Австралия Сидней
							[83743,442,462], 	//Бразилия Рио-де-Жанейро
							[85577,367,501], 	//Чили Сантьяго
							[78486,371,363], 	//Доминикана Санто-Доминго
							[61991,684,463], 	//Маврикий Порт-луи
							[42182,733,332], 	//Индия Нью-Дейли
							[16235,575,293], 	//Италия  Рим
							[54511,837,309], 	//Китай Пекин
							[61641,504,376], 	//Сенегал Дакар
							[72403,350,302],	//США Вашингтон
							[4030 ,489,203],	//Рекьявик Исландия
							[62468,628,340],	//Шарм-эль-Шейх Египет
							[48461,795,379]		//Паттайя Тайланд
						];
			viewcitys(citys);
			break;}
		case 3:{
			$('.google_map').children('#world_map').css('top', -177);
			$('.google_map').children('#world_map').css('left', -368.5);
			$('.google_map').children('#world_map').draggable({containment : [left_map-700, top_map-348.5, left_map, top_map]});
			var citys = [	[27612,765,297], 	//Россия Москва
							[94767,1106,608], 	//Австралия Сидней
							[83743,537,558], 	//Бразилия Рио-де-Жанейро
							[85577,445,606], 	//Чили Сантьяго
							[78486,446,444], 	//Доминикана Санто-Доминго
							[61991,821,566], 	//Маврикий Порт-луи
							[42182,880,406], 	//Индия Нью-Дейли
							[16235,692,359], 	//Италия  Рим
							[54511,1008,375], 	//Китай Пекин
							[61641,605,457], 	//Сенегал Дакар
							[72403,419,373],	//США Вашингтон
							[4030 ,590,250],	//Рекьявик Исландия
							[62468,757,415],	//Шарм-эль-Шейх Египет
							[48461,956,462],	//Паттайя Тайланд
							[63870,773,521],	//Занзибар Танзания
							[99125,694,251]		//Оре Швеция
							
						];
			viewcitys(citys);
			break;}
		case 4:{
			$('.google_map').children('#world_map').css('top', -431);
			$('.google_map').children('#world_map').css('left', -868.5);
			$('.google_map').children('#world_map').draggable({containment : [left_map-1250, top_map-868.5, left_map, top_map]});
			var citys = [	[27612,1290,528], 	//Россия Москва
							[94767,1861,1031], 	//Австралия Сидней
							[83743,907,955], 	//Бразилия Рио-де-Жанейро
							[85577,753,1028], 	//Чили Сантьяго
							[78486,752,764], 	//Доминикана Санто-Доминго
							[61991,1382,969], 	//Маврикий Порт-луи
							[42182,1489,701], 	//Индия Нью-Дейли
							[16235,1171,627], 	//Италия  Рим
							[54511,1697,647], 	//Китай Пекин
							[61641,1024,790], 	//Сенегал Дакар
							[72403,712,649],	//США Вашингтон
							[37177,1306,622],	//Абхазия Гагра
							[6180,1170,524],	//Дания Копенгаген
							[4030 ,996,445],	//Рекьявик Исландия
							[71628,739,603],	//Канада Оттава
							[41194,1382,730],	//Дубай ОАЭ
							[67774,1264,944],	//Зимбабве Хараре
							[62460,1275,713],	//Шарм-эль-Шейх Египет
							[48461,1604,794],	//Паттайя Тайланд
							[63870,1300,889],	//Занзибар Танзания
							[17300,1258,664],	//Турция Анталия
							[8535,1057,653],	//Лиссабон Португалия
							[99125,1169,447]	//Оре Швеция
						];
			viewcitys(citys);
			break;}
		case 5:{
			$('.google_map').children('#world_map').css('top', -1880);
			$('.google_map').children('#world_map').css('left', -3454.5);
			$('.google_map').children('#world_map').draggable({containment : [left_map-6536, top_map-3708, left_map, top_map]});
			var citys = [	[27612,4000,1310], 	//Россия Москва
							[94767,6323,3412], 	//Австралия Сидней
							[83743,2348,3153], 	//Бразилия Рио-де-Жанейро
							[85577,1815,3390], 	//Чили Сантьяго
							[78486,1816,2294], 	//Доминикана Санто-Доминго
							[61991,4420,3100], 	//Маврикий Порт-луи
							[42182,4825,2091], 	//Индия Нью-Дейли
							[16235,3487,1733], 	//Италия  Рим
							[54511,5614,1796], 	//Китай Пекин
							[61641,2887,2373], 	//Сенегал Дакар
							[72403,1675,1810],	//США Вашингтон
							[37177,4040,1698],	//Абхазия Гагра
							[6180,3486,1313],	//Дания Копенгаген
							[4030 ,2798,967],	//Рекьявик Исландия
							[71628,1698,1642],	//Канада Оттава
							[41194,4368,2146],	//Дубай ОАЭ
							[67774,3879,3046],	//Зимбабве Хараре
							[62460,3935,2091],	//Шарм-эль-Шейх Египет
							[48461,5297,2417],	//Паттайя Тайланд
							[63870,4045,2805],	//Занзибар Танзания
							[17300,3865,1869],	//Турция Анталия
							[8535,3057,1821],	//Лиссабон Португалия
							[99125,3483,1005],	//Оре Швеция
							
							[10381,3502,1421],	  	//Берлин - Германия
							[10702,3403,1539],	  	//Баден-Баден - Германия
							[40176,3948,1980],	  	//Тель-Авив - Израиль
							[96745,5418,2805],		//Джакарта - Индонезия
							[43555,4742,2573],	  	//Мале - Мальдивские острова
							[37004,4006,1671],	  	//Россия - Геленджик
							[16701,3724,1850],	  	//Греция - Афины
							[16066,3433,1647],	  	//Италия - Милан
							[16289,3531,1775],	  	//Италия - Неаполь
							[48564,5244,2522],  	//Таиланд - остров Пхукет
							[17059,3806,1754],	  	//Стамбул - Турция
							[33990,3922,1661],	  	//Украина - Ялта
							[7149,3281,1537],	  	//Франция - Париж
							[14472,3608,1723],	  	//Хорватия - Дубровник
							[78374,1567,2191],	  	//Куба - Гавана
							[8181,3279,1745],		//Испания - Барселона
							[33837,3857,1607]		//Украина - Одесса
						];
			viewcitys(citys);
			break;}
	}
	return false;
}

function viewcitys (coordinates) {
	
	$('.weather_block').css('display', 'none');
	$('.mesta_block').css('display', 'none');
	
	if(option_view == '') var shift_icon = 0;
		else var shift_icon = -26;
	for(var key in coordinates){
		$('#'+option_view+coordinates[key][0]).css({
				'display' 	: 'block',
				'left' 		: coordinates[key][1],
				'top' 		: coordinates[key][2]+shift_icon
			});

		if(shift_icon == 0 && current_step == 5){
			var name = $('#'+option_view+coordinates[key][0]).children('.city_name').text();
			$('#'+option_view+coordinates[key][0]).children('.city_name').empty();
			$('#'+option_view+coordinates[key][0]).children('.city_name').append($('#'+option_view+coordinates[key][0]).children('.city_name').attr('title'));
			$('#'+option_view+coordinates[key][0]).children('.city_name').attr('title', name);
		}
	}
	return false;
}
