$(document).ready(function(){
    $('#h_flow li.h_this').hover(
        function() {
            $(this).addClass("selected");
            $(this).find('ul').stop(true, true);
            $(this).find('ul').slideDown('fast');
        },
        function() {
            $(this).find('ul').slideUp('fast');
            $(this).removeClass("selected");
        }
    );
    $(".ctable").claba();
});
$(function() {
	$(".fade").css("opacity", "1");
	$(".fade").hover(function () {
		$(this).stop().fadeTo(300, 0.65);
	},
	function () {
		$(this).stop().fadeTo(300, 1);
	});
});
WebFontConfig = {
    google: { families: [ 'Ubuntu+Condensed::latin,cyrillic' ] }
};
(function() {
    var wf = document.createElement('script');
    wf.src = ('https:' == document.location.protocol ? 'https' : 'http') +
        '://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js';
    wf.type = 'text/javascript';
    wf.async = 'true';
    var s = document.getElementsByTagName('script')[0];
    s.parentNode.insertBefore(wf, s);
})();
(function ($) {

	$(document).ready(function() {
        $("a").easyTooltip();
        $("img").easyTooltip();
    });

	$.fn.easyTooltip = function (b) {
		var c = {
			xOffset: 12,
			yOffset: 20,
			tooltipId: "easyTooltip",
			clickRemove: false,
			content: "",
			useElement: ""
		};
		var b = $.extend(c, b);
		var d;
		this.each(function () {
			var a = $(this).attr("title");
			$(this).hover(function (e) {
				d = (b.content != "") ? b.content : a;
				d = (b.useElement != "") ? $("#" + b.useElement).html() : d;
				$(this).attr("title", "");
				if (d != "" && d != undefined) {
					$("body").append("<div id='" + b.tooltipId + "'><div class='easyTooltip'>" + d + "</div></div>");
					$("#" + b.tooltipId).css("position", "absolute").css("top", (e.pageY - b.yOffset) + "px").css("left", (e.pageX + b.xOffset) + "px").css("display", "none").fadeIn("fast")
				}
			}, function () {
				$("#" + b.tooltipId).remove();
				$(this).attr("title", a)
			});
			$(this).mousemove(function (e) {
				$("#" + b.tooltipId).css("top", (e.pageY - b.yOffset) + "px").css("left", (e.pageX + b.xOffset) + "px")
			});
			if (b.clickRemove) {
				$(this).mousedown(function (e) {
					$("#" + b.tooltipId).remove();
					$(this).attr("title", a)
				})
			}
		})
	}
})(jQuery);
var logopened=false;
$(document).ready(function(){
    $('#logbtn').click(function(){
        if(logopened)
        {
            $('#logform').hide('fast');
            $('#logbtn').removeClass('selected');
        }
        else
        {
            $('#logform').show('fast');
            $('#logbtn').addClass('selected');
        }
        logopened=!logopened;
        return false;
    });
}).click(function(e){
        if(!logopened)
            return;
        e=e||window.event;
        var target=e.target||e.srcElement;
        while(target)
        {
            if(target==$('#logform').get(0))
                return;
            target=target.parentNode;
        }
        $('#logform').hide('fast');
        $('#logbtn').removeClass('selected');
        logopened=false;
    });
ddaccordion.init({
    headerclass: "sublink",
    contentclass: "submenu",
    revealtype: "click",
    mouseoverdelay: 200,
    collapseprev: false,
    defaultexpanded: [],
    onemustopen: false,
    animatedefault: false,
    persiststate: false,
    toggleclass: ["closed", "opened"],
    togglehtml: ["none", "", ""],
    animatespeed: "fast",
    oninit:function(expandedindices){ //custom code to run when headers have initalized
        //do nothing
    },
    onopenclose:function(header, index, state, isuseractivated){ //custom code to run whenever a header is opened or closed
        //do nothing
    }
});

/*-- stickyTooltip --*/
$(function () {
    function b(a, b, c) {
        a.find(".stick_tooltip").each(function () {
            if (!$(this).hasClass("spinned")) {
                $(this).fadeOut()
            }
        });
        if (b.animation) {
            $("#sticky_tooltip").stop().animate({
                path: new $.path.move(parseInt(c.left), b.sinOut, "out", parseInt(c.top), b.sinYRange),
                opacity: "0"
            }, b.speedOut, function () {
                $(this).remove()
            })
        } else {
            $("#sticky_tooltip").stop().remove()
        }
    }
    function a(a, b, c) {
        $("#sticky_tooltip").remove();
        var d = a.find(".laba_tip").html();
        var e = $("<div>", {
            id: "sticky_tooltip",
            "class": "sticky_tooltip",
            html: "<p>" + d + '</p><span class="sticky_tooltip_arrow"></span>'
        }).css({
                display: "none",
                "background-color": b.bgcolor,
                color: b.color
            });
        var f = b.position;
        $("body").prepend(e);
        var g = a.outerWidth();
        var h = a.outerHeight();
        var i = a.offset().left;
        var j = a.offset().top;
        var k = 7;
        switch (f) {
            case "TL":
                c = {
                    left: i,
                    top: j + h + k + "px"
                };
                class_arrows = "sticky_tooltip_arrow_TL";
                break;
            case "TR":
                c = {
                    left: i + g - e.width() + "px",
                    top: j + h + k + "px"
                };
                class_arrows = "sticky_tooltip_arrow_TR";
                break;
            case "BL":
                c = {
                    left: i + "px",
                    top: j - k - e.height() + "px"
                };
                class_arrows = "sticky_tooltip_arrow_BL";
                break;
            case "BR":
                c = {
                    left: i + g - e.width() + "px",
                    top: j - k - e.height() + "px"
                };
                class_arrows = "sticky_tooltip_arrow_BR";
                break;
            case "LT":
                c = {
                    left: k + i + g + "px",
                    top: j + "px"
                };
                class_arrows = "sticky_tooltip_arrow_LT";
                break;
            case "LB":
                c = {
                    left: k + i + g + "px",
                    top: j + h - e.height() + "px"
                };
                class_arrows = "sticky_tooltip_arrow_LB";
                break;
            case "RT":
                c = {
                    left: i - e.width() - k - 15 + "px",
                    top: j + "px"
                };
                class_arrows = "sticky_tooltip_arrow_RT";
                break;
            case "RB":
                c = {
                    left: i - e.width() - k + "px",
                    top: j + h - e.height() + "px"
                };
                class_arrows = "sticky_tooltip_arrow_RB";
                break;
            case "T":
                c = {
                    left: i + g / 2 - e.width() / 2 + "px",
                    top: j + h - k + "px"
                };
                class_arrows = "sticky_tooltip_arrow_T";
                break;
            case "R":
                c = {
                    left: i - e.width() - k + "px",
                    top: j + h / 2 - e.height() / 2 + "px"
                };
                class_arrows = "sticky_tooltip_arrow_R";
                break;
            case "B":
                c = {
                    left: i + g / 2 - e.width() / 2 + "px",
                    top: j - e.height() + k + "px"
                };
                class_arrows = "sticky_tooltip_arrow_B";
                break;
            case "L":
                c = {
                    left: i + g + k + "px",
                    top: j + h / 2 - e.height() / 2 + "px"
                };
                class_arrows = "sticky_tooltip_arrow_L";
                break
        }
        e.find("span.sticky_tooltip_arrow").addClass(class_arrows);
        a.find(".stick_tooltip").fadeIn();
        if (b.animation) {
            e.stop().show().animate({
                path: new $.path.move(parseInt(c.left), b.sinEnter, "enter", parseInt(c.top), b.sinYRange),
                opacity: "1"
            }, b.speedEnter, function () {
                $(this).css("zIndex", "100")
            })
        } else {
            e.stop().css(c).css("zIndex", "100").show()
        }
        return c
    }
    $.path = {};
    $.path.move = function (a, b, c, d, e) {
        this.css = function (f) {
            var g = 0;
            if (b) g = Math.sin(5 * f);
            var h = a - f * a;
            if (c == "out") h = (a - $(window).width()) * f + $(window).width();
            var i = g * e + d;
            return {
                top: i + "px",
                left: h + "px"
            }
        }
    };
    $.fx.step.path = function (a) {
        var b = a.end.css(1 - a.pos);
        for (var c in b) a.elem.style[c] = b[c]
    };
    $.fn.stickyTooltip = function (c) {
        var d = {
            bgcolor: "#fff",
            color: "#727272",
            sinEnter: true,
            sinOut: true,
            sinYRange: 100,
            speedOut: 1500,
            speedEnter: 2e3,
            position: "RT",
            animation: true
        };
        var e = 0;
        var c = $.extend(d, c);
        this.each(function (d) {
            var e = c.animation;
            var f = $(this);
            f.addClass("indexed");
            var g = f.index(".indexed");
            var h = {};
            var i = "";
            var j = c.bgcolor;
            var k = c.color;
            f.hover(function () {
                h = a(f, c, h)
            }, function () {
                b(f, c, h)
            });
        })
    }
});
$(function() {
    $('.lastcomm').stickyTooltip({position:'RT',animation : false});
});
/*--tabs--*/

jQuery(function($){

    tabs = function(options) {

        var defaults = {
            selector: '.tabs',
            targetClass: '.tab',
            selectedClass: 'selected'
        };

        if(typeof options == 'string') defaults.selector = options;
        var options = $.extend(defaults, options);

        return $(options.selector).each(function(){

            var obj = this;
            var targets = Array();

            function show(i){
                $.each(targets,function(index,value){
                    $(value).hide();
                })
                $(targets[i]).fadeIn('fast');
                $(obj).children().removeClass(options.selectedClass);
                selected = $(obj).children().get(i);
                $(selected).addClass(options.selectedClass);
            };

            $('a',this).each(function(i){
                targets.push($(this).attr('href'));
                $(this).click(function(e){
                    e.preventDefault();
                    show(i);
                });
            });

            show(0);

        });
    }

    tabs('nav ul');

});
/*---carousel---*/
$(document).ready(function() {

    $('.carousel').elegantcarousel({
        delay:150,
        fade:300,
        slide:500,
        effect:'fade',		  			//  fade, slide
        orientation:'horizontal',		//	horizontal, vertical
        captionFade: 150,
        loop: true,					//	false, true
        autoplay: true,					// 	false, true
        time: 4000
    });


    // horizontal center of the main
    function center_main() {
        var window_height = $(window).height();
        var main_height = parseInt($('.popular_c_c').css('height'));
        var main_height_margin = (window_height - main_height) / 2;
        $('.popular_c_c').css('top',Math.floor(main_height_margin));
    }
    center_main();

});
/*---table---*/
jQuery.fn.claba = function(options){
    // настройки по умолчанию
    var options = jQuery.extend({
        bgEven: '', // бэкграунд для четных строк
        bgOdd: '#ecebeb', // бэкграунд для нечетных строк
    },options);

    return this.each(function() {
        // четные строки
        jQuery(this).find('div.ctable_tr:even')
            .css('background-color', options.bgEven)
        // нечетные строки
        jQuery(this).find('div.ctable_tr:odd')
            .css('background-color', options.bgOdd)
            .css('color', options.fontOdd)
    });
}
/*---sharelinks---*/
$(function(){
    $("#sharelink").click(function () {
        $("#sharelinks").toggle("blind", { direction: "vertical" }, 500);
    });
});

/*---CLEditor---*/
function CLEditor(opts)
{
    opts=$.extend({id:""},opts);
    var th=this,
        textarea=$("#cl_"+opts.id).find("a").each(function(){
            var m=this.className.match(/cle_([a-z0-9\-]+)/),
                f;
            if(!m)
                return;
            switch(m[1])
            {
                case "splus":
                    f=function(){th.Plus();return false}
                    break;
                case "sminus":
                    f=function(){th.Minus();return false}
                    break;
            }
            if(f)
                $(this).click(f);
        }).end().find('select').each(function(){
                var m=this.className.match(/cle_([a-z0-9\-]+)/),
                    f;
                if(!m)
                    return;
            }).end().find('textarea:first');


    this.Plus=function()
    {
        textarea.stop(true,true).animate({
            height:"+=75"
        });
    }

    this.Minus=function()
    {
        var h=textarea.height();
        if(h-109>120)
            h=109;
        else if(h>120)
            h-=109;
        else
            return;
        textarea.stop(true,true).animate({
            height:"-="+h
        });
    }
}