$(document).ready(function(){
	// Подгружаем виджет группы ВКонтакте
	VK.Widgets.Group("vk_groups", {mode: 0, width: "270", height: "290"}, 21716141);
});

// Подгружаем картинки с логотипами тематических сайтов
var pics = new Array();	
function js_load(id, img1, img2){  
	pics[id] = new Array(3);
	pics[id][0] = new Image();
	pics[id][0].src = img1;
	pics[id][1] = new Image();
	pics[id][1].src = img2;
}
js_load(1, "/IMGS/logo_auto.png", "/IMGS/logo.png");
js_load(2, "/IMGS/logo_reality.png", "/IMGS/logo.png");
js_load(3, "/IMGS/logo_build.png", "/IMGS/logo.png");
js_load(4, "/IMGS/logo_learn.png", "/IMGS/logo.png");
js_load(5, "/IMGS/logo_travel.png", "/IMGS/logo.png");
js_load(6, "/IMGS/logo_beauty.png", "/IMGS/logo.png");
js_load(7, "/IMGS/logo_food.png", "/IMGS/logo.png");
js_load(8, "/IMGS/logo_health.png", "/IMGS/logo.png");


// Массив с краткими описаниями основных поддоменов
var mainsites_descs = new Array();
mainsites_descs[1] = 'Сайт об автомобилях. Купля-продажа новых и подержанных авто, каталог авто, отзывы, тест-драйвы. Автосалоны, автосервисы, автомагазины.';
mainsites_descs[2] = 'Сайт о недвижимости. Бесплатная доска объявлений с фото: квартиры, дома, гаражи, земля, коммерческая недвижимость. Агентства недвижимости, компании-застройщики.';
mainsites_descs[3] = 'Все что Вас интересует о стройке и ремонте; магазин товаров для стройки и ремонта.';
mainsites_descs[4] = 'Тут Вы найдете множество познавательных статей для учебы. Огромный выбор книг, журналов, логических игр.';
mainsites_descs[5] = 'Тысячи статей о всех странах, онлайн бронирование отелей, ж\д и авиабилетов; онлайн магазин путевок.';
mainsites_descs[6] = 'Сайт о красоте. Последние тенденции моды, советы по уходу за телом, лицом и ногтями. Всё о парфюмерии и косметике, стиле и имидже. Салоны красоты и модный шоппинг.';
mainsites_descs[7] = 'Сайт о еде и кулинарии. Тысячи рецептов, советы по сервировке, правила питания и кулинарные советы. Бары, кафе, пицерии, рестораны.';
mainsites_descs[8] = 'Энциклопедии болезней, лекарств и активных веществ; советы специалистов и народной медицины.';

// Ф-ции показа всплывающиъ подсказок (и изменения лого) для тематических сайтов из шапки
function showHint(id, message){
	$("#cloud_text").html(message);
	var offset = $("#LOGO").offset();
	var logo_width = $("#LOGO").width();
	
	$("#cloud").css({
		"display" : "block",
		"position" : "absolute",
		"left" : (offset.left + parseInt(logo_width / 1.4))+"px",
		"top" : "1px",
		"z-index" : "10",
		"overflow" : "hidden",
		"width" : "400px",
		"height" : "50px"
		});
	document.getElementById("LOGO").src = pics[id][0].src;
}

function hideHint(id){
	$("#cloud_text").html("");
	$("#cloud").hide();
	document.getElementById("LOGO").src = pics[id][1].src;
}

// Функции выделения/сброса выделения блока под логотипом с датой и погодой
function highlight_headinfo(){
	$("#head_info").css({"background":"url(http://mir46.ru/IMGS/tpl/line_hover.png) no-repeat","background-position":"center bottom"});
}

function delight_headinfo(){
	$("#head_info").css({"background":"url(http://mir46.ru/IMGS/tpl/line.png) no-repeat","background-position":"center bottom"});
}

// Функции выделения/снятия выделения с тумб сайтов представленных в шапке
function hightlight_sitetd(sitetd){
	sitetd.css({"background":"url(/IMGS/icons/main/hover_bg.png) no-repeat","background-position":"center center"});
}

function delight_sitetd(sitetd){
	sitetd.css("background","none");
}

// Ф-ции отображения событий в центральном табе Афиша
function load_afisha(evtype_id){
	$("#afisha_data").html("<center><img style=\"width:16px;height:16px;margin-top:80px;margin-bottom:80px;\" src=http://mir46.ru/IMGS/system_loading.gif></center>").load("/ajax/?mod=afisha&act=actualpop3&evtype="+parseInt(evtype_id)+"&rand="+Math.random());
}

// Функции переключения вкладок в центральном блоке "мои любимые сайты"
function restorebgc(cursiteid){
	if(cursiteid == $("#siurls").val()){
		$("#"+cursiteid).css("background", "#ffffff");
	}else{
		$("#"+cursiteid).css("background", "#eaeaea");
	}
}
function selectsite(cursiteid){
	$("#"+$("#siurls").val()).css({
		"background" : "#eaeaea",
		"border-bottom" : "solid 1px",
		"border-color" : "#c0c0c0",
		"font-weight" : "100"
	});
	$("#"+cursiteid).css({
		"background" : "#ffffff",
		"border-bottom" : "solid 0px",
		"font-weight" : "800"
	});
	$("#siurls").val(cursiteid);
	$("#siteinfo").html("<img width=16 height=16 src=http://mir46.ru/IMGS/system_loading.gif>");
	$("#siteinfo").load("/ajax/?mod=siteinfo&site="+cursiteid+"&rand="+new Date().getTime());
}

function agile_load_site(t){
	var cursiteid = t.attr("id");
	
	$.each(["sitenews","sitekino","siteauto","sitemedicine","sitefood","siteformation"], function(){
		if(this == cursiteid){
			$("#"+this).css({
				"background" : "#ffffff url(http://mir46.ru/IMGS/icons/agile/"+this+".png) no-repeat",
				"background-position" : "left center",
				"border-bottom" : "0px solid #ffffff",
				"font-weight" : "800"
			});
		}else{
			$("#"+this).css({
				"background" : "#eaeaea url(http://mir46.ru/IMGS/icons/agile/"+this+".png) no-repeat",
				"background-position" : "left center",
				"border-bottom" : "1px solid #c0c0c0",
				"font-weight" : "100"
			});
		}
	});
	

	$("#flavor_2").remove();
	$("#ag_container").html("<div class=\"slideshow\" id=\"flavor_2\"></div>");
	
	$("#flavor_2").width(480).html("<center><img style='width:16px;height:16px;' src='http://mir46.ru/IMGS/system_loading.gif'></center>");
	$.getJSON("/agile/agile_data.php?site="+cursiteid+"&rand="+Math.random(), function(data) {
		$("#flavor_2").agile_carousel({
			carousel_data: data,
			carousel_outer_height: 360,
			carousel_height: 180,
			slide_height: 180,
			carousel_outer_width: 480,
			slide_width: 480,
			transition_type: "fade",
			transition_time: 400,
			timer: 7000,
			continuous_scrolling: true,
			control_set_1: "numbered_buttons,previous_button,pause_button,next_button",
			control_set_2: "content_buttons",
			change_on_hover: "content_buttons"
		});
	});
}

// Функция рекурсивной ротации таба мини-сервисов
function nr2(num_services){
	var stop_rotate = parseInt($("#mouseonservice").val());
	if(stop_rotate == 0){
		stop_rotate = parseInt($("#selectedservice").val());
	}
	if(stop_rotate == 0){
		var shown_id = $("#shownserviceid").val();
		shown_id = parseInt(shown_id);
		if(shown_id == num_services){
			var show_id = 1;
		}else{
			var show_id = shown_id + 1;
		}
		$("#shownserviceid").val(show_id);
		
		$("#shownservice").html($("#service"+show_id).html());
	}
	setTimeout("nr2("+num_services+")", 5000);
}

function switch_news_block(block_id){
	$.each([1,2,3], function(){
		if(this != block_id){
			$("#newslink"+this).css("color", "#000000");
			$("#newstheme"+this).css("display", "none");
		}
	});
	$("#newslink"+block_id).css("color", "#0884be");
	$("#newstheme"+block_id).css("display", "block");
}
