$(document).ready(function(){
	
	// Бегущая строка
	if(!$.browser.msie || ($.browser.msie && $.browser.version!=8)){
		$(".myScroll").hScroller("15",true);
	}
	
	$(".userPanel").insertBefore(".NameAndText");
	
	$(".NameAndText .Text *").css("font-size", "12px");
	
	$("a[href='#mail']").attr("title","Отправить ссылку другу").attr("href","mailto:?Subject="+document.domain+"&Body="+document.location);
	
	$("a[href='#print']").attr("title","Распечатать страницу").click(function(){window.print(); return false;});
	
	$("a[href='#pluse']").attr("title","Увеличить шрифт").click(function(){
		var e = $(".NameAndText .Text");
		var size = parseInt( $(e).css("font-size"), 10) + 3;
		$("*",e).css("font-size", size+"px");
		$(e).css("font-size", size+"px");
		SetCookie("Text-font-size", size);
		return false;
	});
	
	$("a[href='#minus']").attr("title","Уменьшить шрифт").click(function(){
		var e = $(".NameAndText .Text");
		var size = parseInt( $(e).css("font-size"), 10) - 3;
		$("*",e).css("font-size", size+"px");
		$(e).css("font-size", size+"px");
		SetCookie("Text-font-size", size);
		return false;
	});
	
	var size = GetCookie("Text-font-size"); if(size!=""){ $(".NameAndText .Text, .NameAndText .Text *").css("font-size", size+"px"); }
	
	// Нижние баннеры
	$("#bannersBottom A").addClass("Banner");
	var l = $('<A href="#L" class="inline-block L Stop"></A>').click(function(){
		var a = $("#bannersBottom A.Banner");
		var i_showed = 0;
		var checked = false;
		$(a).each(function(i){
			if(this.style.display!="none" && !checked){// находим первый показываемый элемент
				i_showed = i;
				checked = true;
			}
		});
		if(i_showed>0){
			var back = i_showed - 1;
			a[ back+2 ].style.display = "none";
			a[ back ].style.display = "";
			$(this).removeClass("Stop");
			$("#bannersBottom A.R").removeClass("Stop");
		}
		if(typeof(a[ back-1 ])!="object"){ $(this).addClass("Stop"); }
	});
	var r = $('<A href="#R" class="inline-block R"></A>').click(function(){
		var a = $("#bannersBottom A.Banner");
		var i_visible = 0;
		$(a).each(function(i){
			if(this.style.display!="none"){
				i_visible = i;// находим последний показываемый элемент
			}
		});
		var next = i_visible + 1;
		if(next!=a.length){
			a[ next-2 ].style.display = "none";
			a[ next ].style.display = "";
			$("#bannersBottom A.L").removeClass("Stop");
		}
		if(typeof(a[ next+1 ])!="object"){ $(this).addClass("Stop");  }
	});
	$("<td></td>").prepend(l).insertBefore("#bannersBottom TD");
	$("<td></td>").append(r).insertAfter("#bannersBottom TD:eq(1)");
	
	// Видео баннеры
	$("#Video .MoreLinks A").addClass("Banner");
	var l = $('<A href="#L" class="inline-block L Stop"></A>').click(function(){
		var a = $("#Video .MoreLinks A.Banner");
		var i_showed = 0;
		var checked = false;
		$(a).each(function(i){
			if(this.style.display!="none" && !checked){// находим первый показываемый элемент
				i_showed = i;
				checked = true;
			}
		});
		if(i_showed>0){
			var back = i_showed - 1;
			a[ back+3 ].style.display = "none";
			a[ back ].style.display = "";
			$(this).removeClass("Stop");
			$("#Video A.R").removeClass("Stop");
		}
		if(typeof(a[ back-1 ])!="object"){ $(this).addClass("Stop"); }
	});
	var r = $('<A href="#R" class="inline-block R"></A>').click(function(){
		var a = $("#Video .MoreLinks A.Banner");
		var i_visible = 0;
		$(a).each(function(i){
			if(this.style.display!="none"){
				i_visible = i;// находим последний показываемый элемент
			}
		});
		var next = i_visible + 1;
		if(next!=a.length){
			a[ next-3 ].style.display = "none";
			a[ next ].style.display = "";
			$("#Video A.L").removeClass("Stop");
		}
		if(typeof(a[ next+1 ])!="object"){ $(this).addClass("Stop");  }
	});
	$("<td></td>").prepend(l).insertBefore("#Video .MoreLinks TD");
	$("<td></td>").append(r).insertAfter("#Video .MoreLinks TD:eq(1)");
	
	// пролистывание длинной новости
	var longHTML = longTime = innerWidth = null;
	$(".MoreLinks DIV DIV A").mouseover(function(){
		var inner = $(this).parent();
		var outer = $(inner).parent()[0].clientWidth;
		longHTML = $(this).text();
		var a = this;
		var t = longHTML;
		longTime = setInterval(function(){
			if(t){
				var w = a.offsetWidth + a.offsetLeft;
				if(w >= outer){
					t = t.substr(1);
					$(a).text( t );
				}
			}
		},100);
	}).mouseout(function(){
		clearInterval(longTime);
		$(this).text(longHTML);
	}).mousedown(function(){
		clearInterval(longTime);
	});
	
	// закладки
	$("#SwitchTab TD").mouseover(function(){
		var i = $("#SwitchTab TD").removeClass("TabSelected").index(this);
		$(this).addClass("TabSelected");
		$("#SwitchBox > DIV").hide().eq(i).show();
		
	});
	
	// Авторская колонка - подразделы
	var authorsColumnTimer = null;
	$(".Menu2 TD:eq(2)").mouseover(function(){
		clearInterval(authorsColumnTimer);// говорим: не скрывать подменю
		var xy = pos(this);// определяем координаты
		$("#authorsColumn").css("left", xy.Left + "px").css("top", xy.Bottom + "px");
	}).mouseout(function(){
		authorsColumnTimer = setTimeout(function(){
			$("#authorsColumn").css("left","-12345px").css("top","-12345px");
		}, 100);
	});
	$("#authorsColumn A").mouseover(function(){
		clearInterval(authorsColumnTimer);// говорим: не скрывать подменю
	}).mouseout(function(){
		authorsColumnTimer = setTimeout(function(){
			$("#authorsColumn").css("left","-12345px").css("top","-12345px");
		}, 100);
	});
});