var i_url = 'http://yar-life.ru/i/';
$(document).ready(function(){
 $("html#nojs").attr("id", "js");

$('dl.tabs dt').click(function(){$(this).siblings().removeClass('selected').end().next('dd').andSelf().addClass('selected');});
$("#add_favorite_link").click(function (){addBookmark();return false;});
$("#message").click(function(){$(this).empty();});
$("#alert").click(function(){$(this).empty();});

$(".i_search_tab").live("click", function(){
where = $(this).attr("id").replace(/\i_search_(\w+)/, "$1");
$(".i_search_seltab").addClass("i_search_tab").removeClass("i_search_seltab");
$(this).addClass("i_search_seltab").removeClass("i_search_tab");
$("#search_where").attr("value", where);
});

$(".menu_item").hover(function(){
menu_id = $(this).attr("id");
$(this).css("background","url("+i_url+"new/menu_bg_act.png) repeat-x");
var timer_id = setTimeout(function(){$('#'+menu_id+' .i_submenu').slideDown('fast');},200);
$(this).mouseleave(function(){if (('#'+menu_id+' .i_submenu:hidden')){clearTimeout(timer_id);}})
}, function(){menu_id = $(this).attr("id");$('#'+menu_id+' .i_submenu').slideUp('fast');$(this).css("background","none");});

$("#logo_text").mouseover(function(){var timer_id = setTimeout(function(){$('#logo_inform').slideDown('fast');},1500);$("#logo_text").mouseleave(function(){if ($("#logo_inform:hidden")){clearTimeout(timer_id);}});});
$("#logo_inform").mouseleave(function(){$(this).slideUp('fast');});

    $('.subm').hover(function(){
        $(this).css("background", "#80a0ae");
    }, function(){
        $(this).css("background", "#c4d3da");
    });

    if ($.browser.msie && $.browser.version <= 6) {
    //код только для ИЕ шестой версии!
       $("#i_top").before('<div id="updateBrowser" align="left"><a href="http://li.ru/go?www.microsoft.com/downloads/details.aspx?FamilyID=9ae91ebe-3385-447c-8a30-081805b2f90b&amp;displaylang=ru"  style="font-family: Arial; font-size: 12px; text-decoration: none; display: block; line-height: 18px; height: 20px; color: Black;">&nbsp;Ваш браузер устарел и имеет <b>критические уязвимости</b>. Нажмите здесь, чтобы установить новую версию.</a> Либо, рекомендуем загрузить один из <b>более безопасных и удобных</b> браузеров: <a href="http://li.ru/go?fx.yandex.ru/" target="_blank">Firefox</a>, <a href="http://li.ru/go?ru.opera.com/" target="_blank">Opera</a> или  <a href="http://li.ru/go?www.google.com/chrome" target="_blank">Google Chrome</a></div>');
       $("#updateBrowser").slideDown("slow");
    }

    $(".rarrow_active").live("click", function()
    {
        var jq_module_id = "#"+$(this).parent().attr("id");
        var module_id = jq_module_id.replace(/#manage_(\w+)/, "$1");
        var slide_width = parseInt($(jq_module_id + " .i_slide_cont").width());
        var slide_from = parseInt($(jq_module_id + " #"+module_id+"_slide_from").val());
        var slides_count = parseInt($("#"+module_id+"_slide_count").val()) - 1;

        $(jq_module_id + " #"+module_id+"_slide_from").val(slide_from+1);

        if (slide_from > slides_count)
        {
            return false;
        }

        var next_slide = $(jq_module_id + " #"+module_id+"_slide_"+slide_from).next(".i_slide");

        if (next_slide.size() == '0')
        {
            $.ajax({
            dataType: "html",
            url: "/js/ajax/slides.php?dir=next&module="+module_id+"&from="+slide_from,
            cache: true,
            beforeSend: function ()
                {
                    img_load = '<img src="'+i_url+'loader.gif" alt="Загрузка..." class="slide_img_load" />'
                    $(jq_module_id + " .i_slide_cont").addClass("slide_load").append(img_load);
                },
            success: function(slide)
                {
                    $(jq_module_id + " .i_slide_cont").removeClass("slide_load");
                    $(jq_module_id + " .slide_img_load").remove();
                    w = parseInt($(jq_module_id + " .i_slide_move").width())+slide_width;
                    $(jq_module_id + " .i_slide_move").css("width", w+"px").append(slide);
                },
            complete: function(slide)
                {
                    $(jq_module_id + " .i_slide_move").animate({left: "-="+slide_width+"px"}, "slow");
                    l_active("manage_"+module_id);r_active("manage_"+module_id);
                }
            });
        }
        else
        {
            $(jq_module_id + " .i_slide_move").animate({left: "-="+slide_width+"px"}, "slow");
            l_active("manage_"+module_id);r_active("manage_"+module_id);
        }
        return false;
    });

    $(".larrow_active").live("click", function()
    {
        var jq_module_id = "#"+$(this).parent().attr("id");
        var module_id = $(this).parent().attr("id").replace(/manage_(\w+)/, "$1");
        var slide_width = parseInt($(jq_module_id + " .i_slide_cont").width());

        var slide_from = parseInt($(jq_module_id + " #"+module_id+"_slide_from").val());

        $(jq_module_id + " #"+module_id+"_slide_from").val(slide_from-1);

        if (slide_from < 0)
        {
            return false;
        }

        var prev_div = $(jq_module_id + " #"+module_id+"_slide_"+slide_from).prev(".i_slide");

        if (prev_div.size() == '0')
        {
            $.ajax({
            dataType: "html",
            url: "/js/ajax/slides.php?dir=prev&module="+module_id+"&from="+slide_from,
            cache: true,
            beforeSend: function ()
                {
                    img_load = '<img src="'+i_url+'loader.gif" alt="Загрузка..." class="slide_img_load" />'
                    $(jq_module_id + " .i_slide_cont").addClass("slide_load").append(img_load);
                },
            success: function(slide)
                {
                    $(jq_module_id + " .i_slide_cont").removeClass("slide_load");
                    $(jq_module_id + " .slide_img_load").remove();
                    $(jq_module_id + " .i_slide_move").css("width", parseInt($(this).width())+slide_width+"px").prepend(slide);
                },
            complete: function()
                {
                    $(jq_module_id + " .i_slide_move").animate({left: "+="+slide_width+"px"}, "slow");
                    l_active("manage_"+module_id);r_active("manage_"+module_id);
                }
            });
        }
        else
        {
            $(jq_module_id + " .i_slide_move").animate({left: "+="+slide_width+"px"}, "slow");

            l_active("manage_"+module_id);r_active("manage_"+module_id);
        }
        return false;
    });


    $("#ban_728x90").show();
    $("#ban_240x400").show();
    $("#ban240x400").show();
    $(".ban_240x400").show();
    $("#full_banner").show();
    $(".ban_468x60").show();
    $("#full_banner_2").show();
});

function byId(obj_id)
{
    return document.getElementById(obj_id);
}

function r_active (module)
{

    var module_id = module.replace(/manage_(\w+)/, "$1");
    jq_module_id = '#' + module;
    slides_count = parseInt($("#"+module_id+"_slide_count").val()) - 1;
    if ($(jq_module_id + " #"+module_id+"_slide_from").val() >= slides_count)
    {
        $(jq_module_id + " .i_slide_next").removeClass("rarrow_active").addClass("rarrow_inactive");
    }
    else
    {
        $(jq_module_id + " .i_slide_next").removeClass("rarrow_inactive").addClass("rarrow_active");
    }
}

function l_active (module)
{
    var module_id = module.replace(/manage_(\w+)/, "$1");
    jq_module_id = '#' + module;
    if ($(jq_module_id + " #"+module_id+"_slide_from").val() <= '0')
    {
        $(jq_module_id + " .i_slide_prev").removeClass("larrow_active").addClass("larrow_inactive");
    }
    else
    {
        $(jq_module_id + " .i_slide_prev").removeClass("larrow_inactive").addClass("larrow_active");
    }
}

document.onkeydown = NavigateThrough;
function NavigateThrough (event)
{
	if (!document.getElementById) return;
	if (window.event) event = window.event;
	if (event.ctrlKey)
	{
		var link = null;
		var href = null;
		switch (event.keyCode ? event.keyCode : event.which ? event.which : null)
		{
			case 0x25:
				link = document.getElementById ('prev_link');
				break;
			case 0x27:
				link = document.getElementById ('next_link');
				break;
			case 0x24:
				href = '/';
				break;
            case 0x23:
				href = '/about/contacts.html';
				break;
		}
		if (link && link.href) document.location = link.href;
		if (href) document.location = href;
	}
}

function mousePageXY(e)
{
    var x = 0, y = 0;
    var coord=new Array();
    if (!e) e = window.event;
    if (e.pageX || e.pageY)
    {
        x = e.pageX;
        y = e.pageY;
    }
    else if (e.clientX || e.clientY)
    {
        x = e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft) - document.documentElement.clientLeft;
        y = e.clientY + (document.documentElement.scrollTop || document.body.scrollTop) - document.documentElement.clientTop;
    }
    coord[0]=x;coord[1]=y;
    return coord;
}

function addBookmark(url, title)
{
if (!url) url = location.href;
if (!title) title = document.title;
//Gecko
if ((typeof window.sidebar == "object") && (typeof window.sidebar.addPanel == "function")) window.sidebar.addPanel (title, url, "");
//IE4+
else if (typeof window.external == "object") window.external.AddFavorite(url, title);
//Opera7+
else if (window.opera && document.createElement)
{
var a = document.createElement('A');
if (!a) return false; //IF Opera 6
a.setAttribute('rel','sidebar');
a.setAttribute('href',url);
a.setAttribute('title',title);
a.click();
}
else return false;
return true;
}


/* читаем куку */
function getCookie(sName)
{
    var tmp='';
    var aCookie = document.cookie.split("; ");
    for (var i=0; i < aCookie.length; i++)
    {
        var aCrumb = aCookie[i].split("=");
        if (sName == aCrumb[0])
        {
            tmp=unescape(aCrumb[1]);
        }
    }
    return tmp;
}
/* пишем куку */
//TODO: домен куки!
function setCookie(name, value)
{
    var curCookie = name + "=" + escape(value) +
        "; expires=Wed, 28 May 2012 17:45:38 +0400" +
        "; path=/" +
        "; domain=.yarland.ru";
    document.cookie = curCookie;
}


function get_win_width() {
    var myWidth = 0;
    if( typeof( window.innerWidth ) == 'number' ) //Non-IE
        myWidth = window.innerWidth;
    else if( document.documentElement && document.documentElement.clientWidth ) //IE 6+ in 'standards compliant mode'
        myWidth = document.documentElement.clientWidth;
    else if( document.body && document.body.clientWidth) //IE 4 compatible
        myWidth = document.body.clientWidth;
    return myWidth;
}

function get_win_height() {
    var myHeight = 0;
    if( typeof( window.innerHeight ) == 'number' ) //Non-IE
        myHeight = window.innerHeight;
    else if( document.documentElement && document.documentElement.clientHeight ) //IE 6+ in 'standards compliant mode'
        myHeight = document.documentElement.clientHeight;
    else if( document.body && document.body.clientHeight) //IE 4 compatible
        myHeight = document.body.clientHeight;
    return myHeight;
}

function get_scroll() {
    var yPos = 0;
    if (self.pageYOffset) {
        yPos = self.pageYOffset;
    } else if (document.documentElement && document.documentElement.scrollTop){
        yPos = document.documentElement.scrollTop;
    } else if (document.body) {
        yPos = document.body.scrollTop;
    }
    return yPos;
}
/*
var tooltip = {options: {attr_name: "tooltip",blank_text: "(откроется в новом окне)",newline_entity: "  ",max_width: 0,delay: 100,skip_tags: ["link", "style"]},
	t: document.createElement("DIV"),
	c: null,
	g: false,
	canvas: null,

	m: function(e){
		if (tooltip.g){
			var x = window.event ? event.clientX + tooltip.canvas.scrollLeft : e.pageX;
			var y = window.event ? event.clientY + tooltip.canvas.scrollTop : e.pageY;
			tooltip.a(x, y);
		}
	},

	d: function(){
		tooltip.canvas = document.getElementsByTagName(document.compatMode && document.compatMode == "CSS1Compat" ? "HTML" : "BODY")[0];
		tooltip.t.setAttribute("id", "tooltip");
		document.body.appendChild(tooltip.t);
		if (tooltip.options.max_width) tooltip.t.style.maxWidth = tooltip.options.max_width + "px"; // all but ie
		var a = document.all && !window.opera ? document.all : document.getElementsByTagName("*"); // in opera 9 document.all produces type mismatch error
		var l = a.length;
		for (var i = 0; i < l; i++){

			if (!a[i] || tooltip.options.skip_tags.in_array(a[i].tagName.toLowerCase())) continue;

			var tooltip_title = a[i].getAttribute("title"); // returns form object if IE & name="title"; then IE crashes; so...
			if (tooltip_title && typeof tooltip_title != "string") tooltip_title = "";

			var tooltip_alt = a[i].getAttribute("alt");
			var tooltip_blank = a[i].getAttribute("target") && a[i].getAttribute("target") == "_blank" && tooltip.options.blank_text;
			if (tooltip_title || tooltip_blank){
				a[i].setAttribute(tooltip.options.attr_name, tooltip_blank ? (tooltip_title ? tooltip_title + " " + tooltip.options.blank_text : tooltip.options.blank_text) : tooltip_title);
				if (a[i].getAttribute(tooltip.options.attr_name)){
					a[i].removeAttribute("title");
					if (tooltip_alt && a[i].complete) a[i].removeAttribute("alt");
					tooltip.l(a[i], "mouseover", tooltip.s);
					tooltip.l(a[i], "mouseout", tooltip.h);
				}
			}else if (tooltip_alt && a[i].complete){
				a[i].setAttribute(tooltip.options.attr_name, tooltip_alt);
				if (a[i].getAttribute(tooltip.options.attr_name)){
					a[i].removeAttribute("alt");
					tooltip.l(a[i], "mouseover", tooltip.s);
					tooltip.l(a[i], "mouseout", tooltip.h);
				}
			}
			if (!a[i].getAttribute(tooltip.options.attr_name) && tooltip_blank){
				//
			}
		}
		document.onmousemove = tooltip.m;
		window.onscroll = tooltip.h;
		tooltip.a(-99, -99);
	},

	_: function(s){
		s = s.replace(/\&/g,"&amp;");
		s = s.replace(/\</g,"&lt;");
		s = s.replace(/\>/g,"&gt;");
		return s;
	},

	s: function(e){
		if (typeof tooltip == "undefined") return;
		var d = window.event ? window.event.srcElement : e.target;
		if (!d.getAttribute(tooltip.options.attr_name)) return;
		var s = d.getAttribute(tooltip.options.attr_name);
		if (tooltip.options.newline_entity){
			var s = tooltip._(s);
			s = s.replace(eval("/" + tooltip._(tooltip.options.newline_entity) + "/g"), "<br />");
			tooltip.t.innerHTML = s;
		}else{
			if (tooltip.t.firstChild) tooltip.t.removeChild(tooltip.t.firstChild);
			tooltip.t.appendChild(document.createTextNode(s));
		}
		tooltip.c = setTimeout(function(){
			tooltip.t.style.visibility = 'visible';
		}, tooltip.options.delay);
		tooltip.g = true;
	},

	h: function(e){
		if (typeof tooltip == "undefined") return;
		tooltip.t.style.visibility = "hidden";
		if (!tooltip.options.newline_entity && tooltip.t.firstChild) tooltip.t.removeChild(tooltip.t.firstChild);
		clearTimeout(tooltip.c);
		tooltip.g = false;
		tooltip.a(-99, -99);
	},

	l: function(o, e, a){
		if (o.addEventListener) o.addEventListener(e, a, false); // was true--Opera 7b workaround!
		else if (o.attachEvent) o.attachEvent("on" + e, a);
			else return null;
	},

	a: function(x, y){
		var w_width = tooltip.canvas.clientWidth ? tooltip.canvas.clientWidth + tooltip.canvas.scrollLeft : window.innerWidth + window.pageXOffset;
		var w_height = window.innerHeight ? window.innerHeight + window.pageYOffset : tooltip.canvas.clientHeight + tooltip.canvas.scrollTop; // should be vice verca since Opera 7 is crazy!

		if (document.all && document.all.item && !window.opera) tooltip.t.style.width = tooltip.options.max_width && tooltip.t.offsetWidth > tooltip.options.max_width ? tooltip.options.max_width + "px" : "auto";

		var t_width = tooltip.t.offsetWidth;
		var t_height = tooltip.t.offsetHeight;

		tooltip.t.style.left = x + 8 + "px";
		tooltip.t.style.top = y + 8 + "px";

		if (x + t_width > w_width) tooltip.t.style.left = w_width - t_width + "px";
		if (y + t_height > w_height) tooltip.t.style.top = w_height - t_height + "px";
	}
}

Array.prototype.in_array = function(value){
	var l = this.length;
	for (var i = 0; i < l; i++)
		if (this[i] === value) return true;
	return false;
};

var root = window.addEventListener || window.attachEvent ? window : document.addEventListener ? document : null;
if (root){
	if (root.addEventListener) root.addEventListener("load", tooltip.d, false);
	else if (root.attachEvent) root.attachEvent("onload", tooltip.d);
}
*/