
$(function () {

/*Красивый вывод новостей*/

	var nNews = $("div[id*=new-id-]")
	nNews.each(function (nid) {
	$(this).replaceWith("<div id='n-id-"+nid+"' class='modnews'><div class='image load'></div>" + $(this).text() + "</div>");
	$(this).find("img").filter("img:first").unwrap().removeAttr("align").fadeIn(2000).prependTo("div[id='n-id-"+nid+"'] div[class*=image]");
	$("div[class*=image]:empty").hide(2000);
	});//конец красивого вывода новостей

$(function newsHilite () {
/*Подсветка новостей и коментов*/
	$(".news:odd, .comments:odd").addClass("even");
	$(".comments").hover(
		function() { $(this).addClass("hover"); },
		function() { $(this).removeClass("hover"); }
	);
	});//конец подсветки новостей и комментариев

/*Блок-кнопка для перехода к верху страницы*/

	var m1 = 310; // расстояние от начала страницы до плавающей панели 
	var m2 = 300; //расстояние от верха видимой области страницы до плавающей панели (должно быть меньше чем m1)

	$("#wrapper").append('<div id="gotop"><a href="#"/></a></div>');
	var s = $('#gotop');
	s.css({top: m1}).hide();
	function margin() {
		var top = $(window).scrollTop();
		if (top+m2 < m1) {
			s.css({top: m1-top}).fadeOut(400);
		} else {
			s.css({top: m2}).fadeIn(400);
			s.find('a').css({opacity: 0.8});
		}
	}
	$(window).scroll(function() { margin(); })

	s.hover(
		function() { $(this).find('a').css({opacity: 1}); },
		function() { $(this).find('a').css({opacity: 0.8}); }
	);//конец блока перехода к началу страницы
	
});//конец Ready 
  
function simple_tooltip(target_items, name){
 $(target_items).each(function(i){
		$("body").append("<div class='"+name+"' id='"+name+i+"'><p>"+$(this).attr('title')+"</p></div>");
		var tooltip = $("#"+name+i);
		if($(this).attr("title") != "" && $(this).attr("title") != "undefined" ){
		$(this).removeAttr("title").mouseover(function(){
				tooltip.css({opacity:0.9, display:"none"}).fadeIn(30);
		}).mousemove(function(kmouse){
				tooltip.css({left:kmouse.pageX+15, top:kmouse.pageY+15});
		}).mouseout(function(){
				tooltip.fadeOut(10);
		});
		}
	});
}
$(function () {
simple_tooltip(".ttp_lnk a","tooltip");
});//конец Ready 

$(function forlinks () {
var flnk = $(".menunews");
	flnk.hover(
  		function () {
    		$(this).addClass("hover");
  		}, 
  		function () {
    		$(this).removeClass("hover");
  		});
flnk.click(function(){window.location=$(this).find("a").attr("href"); return false;});
});//конец Ready 

$(function inputs_style () {
	$('input:text:not(#story), input:password, input:file, select, textarea')
		 .addClass('inputs')
	.focus(function(){
		$(this).addClass("focus");
		$(this).parents('label').addClass("over");
	})
	.blur(function(){
		$(this).removeClass("focus");
		$(this).parents('label').removeClass("over");
	})
});


$(function() {

	function createCookie(name,value,days) {
		if (days) {
			var date = new Date();
			date.setTime(date.getTime()+(days*24*60*60*1000));
			var expires = "; expires="+date.toGMTString();
		}
		else var expires = "";
		document.cookie = name+"="+value+expires+"; path=/";
	}
	function readCookie(name) {
		var nameEQ = name + "=";
		var ca = document.cookie.split(';');
		for(var i=0;i < ca.length;i++) {
			var c = ca[i];
			while (c.charAt(0)==' ') c = c.substring(1,c.length);
			if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
		}
		return null;
	}
	function eraseCookie(name) {
		createCookie(name,"",-1);
	}

	$('ul.tabs').each(function(i) {
		var cookie = readCookie('tabCookie'+i);
		if (cookie) $(this).find('li').eq(cookie).addClass('current').siblings().removeClass('current')
			.parents('div.tabsblock').find('div.box').hide().eq(cookie).show();
	})

	$('ul.tabs').delegate('li:not(.current)', 'click', function() {
		$(this).addClass('current').siblings().removeClass('current')
			.parents('div.tabsblock').find('div.box').hide().eq($(this).index()).show();
		var ulIndex = $('ul.tabs').index($(this).parents('ul.tabs'));
		eraseCookie('tabCookie'+ulIndex);
		createCookie('tabCookie'+ulIndex, $(this).index(), 365);
	})

});


