﻿/// удвлить после очистки кеша
if (!("isLoadObozrevatelCommonJS" in window) || typeof (window.isLoadObozrevatelCommonJS) == "undefined") {
    document.write('<script src="http://obozrevatel.com/js/common.js"></script>');
}

if (!("_Is" in window && typeof (window._Is) != "undefined")) {
    var _Is = new function () {
        var gBool = function (v) { return (v || false) && true; }
        var _isMob = gBool(
                ((navigator.userAgent.match(/iPhone/i))
                || (navigator.userAgent.match(/iPod/i))));
        var _isFlash = gBool(
                (navigator.plugins && navigator.plugins.length && navigator.plugins["Shockwave Flash"])
               || (navigator.mimeTypes && navigator.mimeTypes.length && navigator.mimeTypes['application/x-shockwave-flash'] && navigator.mimeTypes['application/x-shockwave-flash'].enabledPlugin));
        this.Mob = function () { return _isMob; }
        this.Flash = function () { return _isFlash; }
    }
}

if (!("EmbedSWF" in window && typeof (window.EmbedSWF) != "undefined")) {
    function EmbedSWF(swf, width, height, flashvars) {
        return document.write('<embed type="application/x-shockwave-flash" width="' + width + '" height="' + height + '" quality="best" wmode="opaque" play="true" loop="true" menu="false" allowscriptaccess="always" src="' + swf + '" flashvars="' + flashvars + '" />');
    };
}

if (!("BannerFooter" in window && typeof (window.BannerFooter) != "undefined")) {
    function BannerFooter() {
        var loc = window.location.href;
        var CompanyBans = [
		{ name: "veneto", Bans: [{ swf: '300x250_footer_veneto1', url: 'http://veneto.ua/' }, { swf: '300x250_footer_veneto2', url: 'http://veneto.ua/'}] },
		{ name: "tompo", Bans: [{ swf: '300x250_footer_tompo', url: 'http://tompo.com.ua/'}] },
		{ name: "kalina", Bans: [{ swf: '300x250_footer_kalina', url: 'http://kalina.ua/'}] },
		{ name: "marelli", Bans: [{ swf: '300x250_footer_marelli', url: 'http://www.marelli.com.ua/'}] },
		{ name: "temp", Bans: [{ swf: '300x250_footer_temp', url: 'http://temp.com.ua/'}] },
        { name: "Polyana", Bans: [{ swf: '300x250', url: 'http://obozrevatel.com/polyanovedenie/'}] },
		{ name: "deksim", Bans: [{ swf: '300x250_footer_deksim', url: 'http://deksim.com.ua/inside.aspx?sID=2'}] }
	];
        var nCB = Math.floor(Math.random() * 100 % CompanyBans.length); //(loc.indexOf('.htm')<0 || loc.indexOf('/main.htm')>0) ? 0 :
        var nB = Math.floor(Math.random() * 100 % CompanyBans[nCB].Bans.length);
        var bf = CompanyBans[nCB].Bans[nB]; //banner from footer
        return ((bf.swf != null) ? ('<embed type="application/x-shockwave-flash" width="300" height="250" quality="best" wmode="opaque" play="true" loop="true" menu="false" allowscriptaccess="always" src="http://obozrevatel.com/css/banners/' + bf.swf + '.swf"  flashvars="link1=' + escape(bf.url) + '&">') : ('<a target="_blank" href="' + bf.url + '" title="" rel="nofollow"><img src="http://obozrevatel.com/css/banners/' + bf.gif + '"/></a>'));
    }
}
/* /удвлить после очистки кеша */

$.fn.disableSelection = function () {
    $(this).attr('unselectable', 'on')
           .css('-moz-user-select', 'none')
           .each(function () {
               this.onselectstart = function () { return false; };
           });
};

var _s = {
    go: function() {
        var text = $('#text').val()
        if (text == '') return;
        var url = "/search_result.htm?cx=000234703784691205514:fw-ak-gykzm&ie=utf-8&cof=FORID:11&q=" + encodeURI(text);
        window.open(url);
    }
};

var Week = new function () {
    var _date = new Date(); var _today = (new Date(_date.getFullYear(), _date.getMonth(), 0)).getTime(); var _week = Math.round((_date.getTime() - _today) / (1000 * 60 * 60 * 24 * 7));
    this.Get = function () { return _week; }
};

var _community = {
    interval: 4000,
    hover: false,
    next: function () {
        if (!_community.hover) {
            var pos = $(".tabs .cur").index();
            pos = pos == 1 ? 0 : pos + 1;
            _community.show($(".tabs a").eq(pos));
        }
        setTimeout(_community.next, _community.interval);
    },
    show: function (item) {
        var index = item.index();
        $(".tabs .cur").removeClass("cur");
        item.addClass("cur");
        $(".tabs-content > div").hide().eq(index).show();
    },
    init: function () {
        $(".tabs a").hover(
			function () {
			    if ($(this).hasClass("cur")) return;
			    var item = $(this);
			    _community.show(item);
			    _community.hover = true;
			},
			function () {
			    _community.hover = false;
			}
		);
        setTimeout(_community.next, _community.interval);
    }
}

function InitRadioDropDown() {
    $('.radio-dropdown').hover(
        function () { $(this).css({ backgroundPosition: "0 -22px" }) },
        function () { $(this).css({ backgroundPosition: "0 0" }) }
    );
    $('.radio-dropdown').click(function (e) {
        if ($(e.target).is(".radio-dropdown,.current")) {
            if (!$(".dropdown-options", this).is(":hidden")) {
                $(".dropdown-options", this).hide();
            } else {
                $(".dropdown-options").hide();
                $(".dropdown-options", this).slideDown(200);
            }
            e.stopPropagation();
        }
    });

    $(document).click(function (e) {
        if ($(".dropdown-options:not(:hidden)").length) {
            if ($(e.target).is(":not(.dropdown-options,.dropdown-options *)")) {
                $(".dropdown-options").hide();
            }
        }
    });

    $(".dropdown-options a").click(function () {
        $(".current", $(this).parent().parent().parent()).text($(this).text());
        $(".dropdown-options").hide();
    });
}

var _mi =
{
    pos: 0,
    posOld: 0,
    interval: 4000,
    hover: false,
    next: function () {
        if (!_mi.hover) {
            var pos = _mi.posOld;
            pos = pos == 2 ? 0 : pos + 1;
            _mi.show(pos);
        }
        setTimeout(_mi.next, _mi.interval);
    },
    over: function (e, i) {
        if (eval($('.main-item .main-item-body li:first').attr('pos')) == i) {
            return;
        }
        _mi.hover = true;
        _mi.show(i);
    },
    show: function (i) {
        if (i <= 2) {
            _mi.posOld = i;
        }
        _mi.pos = i;
        var cur = $('.main-item .cur');
        cur.removeClass('cur');
        cur.find("img").css("opacity", 0.5);
        $('.main-item .mainItem' + i).addClass('cur').find("img").css("opacity", 1);
        $('.main-item .main-item-body li:first').before($('.main-item .main-item-body li[pos="' + i + '"]'));
    },
    init: function () {
        setTimeout(_mi.next, _mi.interval);
    },
    out: function () {
        _mi.hover = false;
        if (_mi.pos > 2) {
            _mi.show(_mi.posOld);
        }
    }
}

var _pub =
{
    pos: 0,
    interval: 4000,
    initialInit: 8000,
    hover: false,
    next: function () {
        if (!_pub.hover) {
            var pos = _pub.pos;
            pos = pos == 2 ? 0 : pos + 1;
            _pub.show(pos);
        }
        setTimeout(_pub.next, _pub.interval);
    },
    over: function () {
        _pub.hover = true;
        _pub.show($(this).index());
    },
    show: function (i) {
        _pub.pos = i;
        $(".current-publication-item").hide().eq(i).show();
        $(".show-publication-item img").css("opacity", 0.5).eq(i).css("opacity", 1);
    },
    init: function () {
        $(".show-publication-item").hover(
			_pub.over,
			_pub.out
		);
        setTimeout(_pub.next, _pub.initialInit);
    },
    out: function () { _pub.hover = false; }
}

var _mi2 =
{
    over: function (e, i) {
        if (eval($('.main-item .main-item-body li:first').attr('pos')) == i)
            return;

        $('.main-item .main-item-body li:first').before($('.main-item .main-item-body li[pos="' + i + '"]'));
    }
}

var _scroll =
{
    left: function (c, pc) {
        var prefix = (pc != null ? ('.' + pc + ' ') : '');
        $(prefix + '.' + c + ' .' + c + '-item:first').before($(prefix + '.' + c + ' .' + c + '-item:last'));
        var pos = $(prefix + '.' + c + ' .' + c + '-item:first').attr('pos')
        $(prefix + '.' + c + '-scroller .cur-item').attr('class', 'item');
        $(prefix + '.' + c + '-scroller .item:eq(' + pos + ')').attr('class', 'cur-item');
    },
    right: function (c, pc) {
        var prefix = (pc != null ? ('.' + pc + ' ') : '');
        $(prefix + '.' + c + ' .' + c + '-item:last').after($(prefix + '.' + c + ' .' + c + '-item:first'));
        var pos = $(prefix + '.' + c + ' .' + c + '-item:first').attr('pos')
        $(prefix + '.' + c + '-scroller .cur-item').attr('class', 'item');
        $(prefix + '.' + c + '-scroller .item:eq(' + pos + ')').attr('class', 'cur-item');
    }
}

var _accordion = {
    init: function () {
        $(".accordion .accordion-head").click(
			function () {
			    if ($(this).hasClass('up'))
			        return;

			    var posOld = $('.accordion .up').removeClass('up').addClass('dn').attr('pos');
			    var posNew = $(this).removeClass('dn').addClass('up').attr('pos');
			    $('.accordion' + posOld).slideUp();
			    $('.accordion' + posNew).slideDown();
			}
		);
    }
}



$(document).ready(function () {

    //move he last list item before the first item. The purpose of this is if the user clicks to slide left he will be able to see the last item.
    $('.video-scroll-window').each(function () {
        $(this).find('li:first').before($(this).find('li:last'));
        $(this).find('ul').css({ 'left': -$(this).find('li').outerWidth() });
    });

    $('.video-scroll-surface li').hover(function () {
        var pos = $(this).attr('pos');
        var scroll = $(this).parent().parent().parent().parent().parent().find(".video-body-scroll");
        var first = scroll.find('li:first');
        if (first.attr('pos') != pos) {
            first.before(scroll.find('li[pos="' + pos + '"]'));
        }
    });

    $('.video-scroll-window .right').click(function () {
        var scrollWindow = $(this).parent();
        var item_width = scrollWindow.find("li").outerWidth();
        var left_indent = parseInt(scrollWindow.find('ul').css('left')) - item_width;

        scrollWindow.find('ul:not(:animated)').animate({ 'left': left_indent }, 500, function () {
            scrollWindow.find('li:last').after(scrollWindow.find('li:first'));
            scrollWindow.find('ul').css({ 'left': -scrollWindow.find('li').outerWidth() });
        });
    });

    $('.video-scroll-window .left').click(function () {
        var scrollWindow = $(this).parent();
        var item_width = scrollWindow.find('li').outerWidth();
        var left_indent = parseInt(scrollWindow.find('ul').css('left')) + item_width;

        scrollWindow.find('ul:not(:animated)').animate({ 'left': left_indent }, 500, function () {
            scrollWindow.find('li:first').before(scrollWindow.find('li:last'));
            scrollWindow.find('ul').css({ 'left': -scrollWindow.find('li').outerWidth() });
        });

    });
});

var _op = {
    click: function () {
        if ($(".our-projects .dn").length == 1) {
            $(".our-projects .our-projects-body").hide();
            $(".our-projects .dn").removeClass('dn').addClass('up');
        } else {
            $(".our-projects .our-projects-body").show();
            $(".our-projects .up").removeClass('up').addClass('dn');
        }
    }
}

var _photoMain =
{
    over: function (e, i) {
        $(".show-inner-main .item-current").attr('class', '');
        $(e).attr('class', 'item-current');
        $('.show-inner-main .main-item-inner').hide();
        $('.show-inner-main .main-item-inner:eq(' + i + ')').show()
    }
}

/* News scroll
*/
var topArticle, bottom, heightScroll, bottomTop;
function FixBlockHeight() {
    var scroll = $(document).scrollTop();

    if (topArticle - scroll <= 0 && scroll + heightScroll < bottom) {
        $(".news-view-right-scroll").css({
            position: 'fixed',
            left: $(".news-view-right-scroll").offset().left,
            right: 'auto',
            top: 0
        });
    } else if (scroll + heightScroll >= bottom) {
        $(".news-view-right-scroll").css({
            position: 'absolute',
            left: 'auto',
            right: 0,
            top: bottomTop
        });
    } else {
        $(".news-view-right-scroll").css({
            position: 'relative',
            left: 'auto',
            right: 'auto',
            top: 'auto'
        });
    }
    return true;
}

function InitNewsScroll() {
    $(document).ready(function () {
        if (!$("article .news-view-right-scroll").length)
            return;

        topArticle = $("article .news-view-right-scroll").offset().top;
        bottom = $("article .text").offset().top + $("article .text").height();
        heightScroll = $(".news-view-right-scroll").height();
        bottomTop = (bottom - heightScroll - topArticle);

        if (bottom - topArticle > heightScroll) {
            $(".news-view-right").height(heightScroll + bottomTop).css({ position: "relative" });
            $(window).scroll(function () {
                FixBlockHeight();
                setTimeout(FixBlockHeight, 0);
            });
        }
    });
}

function InitBrend() {
    $(document).ready(function () {
        var loc = window.location.href;

        //Banner 300x75 -- begin
        //if( $('.banner300x75').length == 0 && ( loc.indexOf('main.htm')>0 || loc.indexOf('.htm')<0 )){
        //	$('.show-block.small-informer > .zodiak').before('<div class="banner300x75" ><a href="http://from-ua.com/eco/04c0930b2cd2e.html&msgid=" target="_blank" rel="nofollow"><img src="/css/banners/vertolet_300x65.gif" ></a></div><div class="clr20" style="float:none"></div>');
        //	$('.show-block.small-informer>.zodiak').css('display','none'); $($('.show-block.small-informer>.currency').get(1)).css('display','none');
        //}//Banner 300x75 -- end

        //Banner OBOZ + YA.RU -- begin
        var CompanyBans = [
		    { name: "610x40", Bans: [{ img: '/css/banners/oboz_yandex_663x40.gif', url: 'http://www.yandex.ua/?add=54933&from=shared' }, { img: '/css/banners/oboz_yandex_663x40_2.gif', url: 'http://www.yandex.ua/?add=54933&from=shared'}] }
	    ];
        var nCB = 0;
        var nB = Math.floor(Math.random() * 100 % CompanyBans[nCB].Bans.length);
        var bf = CompanyBans[nCB].Bans[nB]; //banner from footer

        /*
        var content1 = '<div class="banner610x40"><a href="http://www.yandex.ua/?add=54933&from=shared" target="_blank" rel="nofollow"><img src="'+bf.img+'"></a></div>';
        if( !(loc.indexOf('main.htm')>0 || loc.indexOf('.htm')<0) ){
        $('article > .interesting').before(content1);
        } else {
        //$($('section > .main > div').get(0)).append(content1);
        }
        */
        //Banner OBOZ + YA.RU -- end

        if (loc.indexOf('/css/') < 0) {
            if (loc.indexOf('/health/') > 0) {
                //<!--  VETO -->
                $('body header, body nav, body section, body footer').css('background-color', '#fff').css('padding-left', '10px').css('padding-right', '10px').css('cursor', 'default');
                $('body').css({ 'cursor': 'pointer', 'background': 'url(/css/veneto/bg5.png) fixed', 'background-color': '#fff', 'background-position': '0% 0%', 'background-repeat': 'repeat-x' }).bind('click', function (event) {
                    var target = $(event.target);
                    while (target[0].nodeName.toLowerCase() != 'body') {
                        switch (target[0].nodeName.toLowerCase()) {
                            case 'header':
                            case 'nav':
                            case 'section':
                            case 'footer':
                                return;
                            case 'div': if (target[0].className.toLowerCase().indexOf('ui-dialog') >= 0) return;
                        }
                        target = target.parent();
                    }
                    window.open('http://www.veneto.ua/', '_blank');
                });
                //<!-- /VETO -->
            } else if (loc.indexOf('/politics/') > 0) {
            // Veneto Hotel
            $('body header, body nav, body section, body footer').css('background-color', '#fff').css('padding-left', '10px').css('padding-right', '10px').css('cursor', 'default');
            $('body').css({ 'cursor': 'pointer', 'background': 'fixed', 'background-color': '#2d1b0f', 'background-position': '0% 0%', 'background-repeat': 'repeat-x' }).bind('click', function (event) {
                var target = $(event.target);
                while (target[0].nodeName.toLowerCase() != 'body') {
                    switch (target[0].nodeName.toLowerCase()) {
                        case 'header':
                        case 'nav':
                        case 'section':
                        case 'footer':
                            return;
                        case 'div': if (target[0].className.toLowerCase().indexOf('ui-dialog') >= 0) return;
                    }
                    target = target.parent();
                }
                window.open('http://services.obozrevatel.ua/reference.ashx?id=A75BF552-03F8-4968-9A2E-F1CD12A461BD', '_blank');
            });
            $($('body footer').get(0)).prepend(
'<div id="goodyear_bg_r" style="margin: 0; padding: 0; width:0px; height:0px; position:relativ; float:right;">' +
	'<div style="position:fixed; height:0px; z-index:-3; top:0px; right:0px; float:left; ">' +
        '<div style="float:left; margin-left: 10px; background: transparent; ">' +
		'<img src="/css/veneto/bgr.jpg" alt="" style=" border:none; float:left;">' +
	'</div></div>' +
	'<div style="position:fixed; height:0px; z-index:-1; top:0px; float:left; width:0px;">' +
        '<div style="float:left; margin-left: 10px; background: transparent; margin-top:0px;">' +
		'<img src="/css/veneto/text.png" alt="" style=" border:none; float:left;">' +
	'</div></div>' +
'</div>' +
'<div id="goodyear_bg_l" style="margin: 0; padding: 0; width:0px; height:0px; position:relativ; float:left;">' +
	'<div style="position:fixed; height:0px; z-index:-2; top:0px; left:0px; float:left; ">' +
        '<div style="float:left; margin-right: 10px; background: transparent; ">' + /// <reference path="../css/veneto/2/" />

        '<img src="/css/veneto/bgl.jpg" alt="" style=" border:none; float:left;">' +
	'</div></div>' +
	'<div style="position:fixed; height:0px; z-index:-1; top:0px; float:left; ">' +
        '<div style="float:left; margin-right: 10px; background: transparent; margin-left:-190px;">' +
        '<img src="/css/veneto/text.png" alt="" style=" border:none; float:left;">' +
'</div>');
            ///Veteno Hotel
        } else if (loc.indexOf('/culture/') > 0 || loc.indexOf('/persons/') > 0 ) {
                    $('body header, body nav, body section, body footer').css({ 'background-color': '#fff', 'padding-left': '10px', 'padding-right': '10px', 'cursor': 'default' });
                    $('body footer').css('padding-bottom', '10px');
                    $('body').css('cursor', 'pointer').css('background', 'url(/css/marelli/bgl.jpg) 0% 0% fixed no-repeat').bind('click', function (event) {
                        var target = $(event.target);
                        var loc = window.location.href;
                        while (target[0].nodeName.toLowerCase() != 'body') {
                            switch (target[0].nodeName.toLowerCase()) {
                                case 'header':
                                case 'nav':
                                case 'section':
                                case 'footer':
                                    return;
                                case 'div': if (target[0].className.toLowerCase().indexOf('ui-dialog') >= 0) return;
                            }
                            target = target.parent();
                        }
                        window.open('http://services.obozrevatel.ua/reference.ashx?id=C487C2FB-5C07-463D-9187-AC3F81AF4E65', '_blank');
                    });
                    $($('body footer').get(0)).prepend(
'<div style="margin: 0; padding: 0; width:0px; height:0px; position:relativ; float:right;">' +
	'<div style="position:fixed; height:0px; z-index:-1; top:0px; right:0px; float:right; ">' +
        '<div style="float:right; background: transparent; ">' +
		'<img src="/css/marelli/bg.jpg" alt="" style=" border:none;">' +
'</div></div></div>');
           } 
        }
    });
}
var _1242143542;
function fl_Command_(s, f) {
    if (s == "play") {
        var hd = 108; var w = 512; var h = 444; var h_2 = ($(window).height() - h) / 2; if (hd > h_2) h_2 = hd; var w_2 = ($(window).width() - w) / 2;
        if ($('#goto_button_veneta').length < 1) {
            $("body").prepend(
'<header id="goto_button_veneta" style="margin: 0; padding: 0; position: fixed; top: ' + h_2 + 'px; left: ' + w_2 + 'px; z-index: 10000;"><div style="float: left;"><a style="display:block;width:512px;height:384px;" target="_blank" title="" rel="nofollow">' +
	'<embed type="application/x-shockwave-flash" width="100%" height="100%" quality="best" wmode="opaque" play="true" loop="true" menu="false" allowscriptaccess="always" src="http://obozrevatel.ua/css/veneto/video/veneto_video3.swf" flashvars="link1=http://veneto.ua/">' +
'</a></div></header>'
			);
            _1242143542 = setTimeout(function () { fl_Command("kill", 0); }, 20000);
        } else { fl_Command("kill", 0); }
    }
}
function fl_Command(s, f) { if (s == "kill") { $("#goto_button_veneta").remove(); clearTimeout(_1242143542); } }
InitBrend();

var interesting = {
    right: function () {
        var item_width = 126;
        var left_indent = parseInt($('.scroll-interesting').css('margin-left')) - item_width;
        $('.scroll-interesting:not(:animated)').animate({ 'margin-left': left_indent }, 500, function () {
            $('.scroll-interesting div:last').after($('.scroll-interesting div:first'));
            $('.scroll-interesting').css({ 'margin-left': -126 });
        });
    },
    left: function () {
        var item_width = 126;
        var left_indent = parseInt($('.scroll-interesting').css('margin-left')) + item_width;
        $('.scroll-interesting:not(:animated)').animate({ 'margin-left': left_indent }, 500, function () {
            $('.scroll-interesting div:first').before($('.scroll-interesting div:last'));
            $('.scroll-interesting').css({ 'margin-left': -126 });
        });
    },
    slideInterval: 4000,
    changed: false,
    slide: function () {
        if (!interesting.changed) {
            interesting.right();
        }
        interesting.changed = false;
        setTimeout(interesting.slide, interesting.slideInterval);
    },
    init: function () {
        $('.scroll-interesting div:first').before($('.scroll-interesting div:last'));
        $('.scroll-button-right').click(
			function () {
			    interesting.changed = true;
			    interesting.right()
			}
		)
		.disableSelection();
        $('.scroll-button-left').click(
			function () {
			    interesting.changed = true;
			    interesting.left();
			}
		)
		.disableSelection();
        setTimeout(interesting.slide, interesting.slideInterval);
    }
}

var show = {
    right: function (count) {
        var item_width = Math.min(165 * count, 984);
        var left_indent = parseInt($('.scroll-afisha-center-item').css('margin-left')) - item_width;
        $('.scroll-afisha-center-item:not(:animated)').animate({ 'margin-left': left_indent }, 1000, function () {
            $('.scroll-afisha-center-item > ul > li:last').after($('.scroll-afisha-center-item > ul > li').slice(0, count));
            $('.scroll-afisha-center-item').css({ 'margin-left': -984 });
        });
    },
    left: function (count) {
        var item_width = Math.min(165 * count, 984);
        var left_indent = parseInt($('.scroll-afisha-center-item').css('margin-left')) + item_width;
        $('.scroll-afisha-center-item:not(:animated)').animate({ 'margin-left': left_indent }, 1000, function () {
            var items = $('.scroll-afisha-center-item > ul > li');
            $('.scroll-afisha-center-item > ul > li:first').before(items.slice(items.length - count));
            $('.scroll-afisha-center-item').css({ 'margin-left': -984 });
        });
    },
    slideInterval: 6000,
    changed: false,
    slide: function () {
        if (!show.changed) {
            show.right(1);
        }
        show.changed = false;
        setTimeout(show.slide, show.slideInterval);
    },
    init: function () {
        $('.scroll-afisha-center-item > ul > li:first').before($('.scroll-afisha-center-item > ul > li:last'));
        $('.scroll-button-right').click(
			function () {
			    show.changed = true;
			    show.right(6)
			}
		)
		.disableSelection();
        $('.scroll-button-left').click(
			function () {
			    show.changed = true;
			    show.left(6);
			}
		)
		.disableSelection();
        setTimeout(show.slide, show.slideInterval);
    }
}

var projects = {
    left: function () {
        var items = $(".projects-body tr:first td");
        $(".projects-body tr:first td:first").before(items.slice(items.length - 6));

        var items2 = $(".projects-body tr:last td");
        $(".projects-body tr:last td:first").before(items2.slice(items2.length - 6));
    },
    right: function () {
        $(".projects-body tr:first td:last").after($(".projects-body tr:first td").slice(0, 6));
        $(".projects-body tr:last td:last").after($(".projects-body tr:last td").slice(0, 6));
    },
    Init: function () {
        $(".projects-body .button-left").click(projects.left);
        $(".projects-body .button-right").click(projects.right);
    }
}

var ads300x250 = {
    filters: { bnOut: ".ads300x250", bnIner: '.ads300x250 > div, #banner300, #Banner_320x250' },
    top: 0,
    bottom: 0,
    height: 0,
    bottomTop: 0,
    show: true,
    debug: false,
    OnScroll: function () {

        if (!ads300x250.show)
            return;

        var scroll = $(document).scrollTop();

        if (ads300x250.debug) {

            if (!$('#info').length) {
                $(document.body).prepend(
                    $("<div>").attr("id", "info").css({
                        position: "fixed",
                        left: 0,
                        top: 0
                    }).text("asdasd")
						);
            }

            $('#info').html(
                "top=" + ads300x250.top + "<br/>" +
                    "bottom=" + ads300x250.bottom + "<br/>" +
                        "height=" + ads300x250.height + "<br/>" +
                            "bottomTop=" + ads300x250.bottomTop + "<br/>" +
                                "scroll=" + scroll
					);
        }

        if (ads300x250.top - scroll <= 0 && scroll + ads300x250.height < ads300x250.bottom) {
            $(ads300x250.filters.bnOut).css({
                position: "fixed",
                left: $(ads300x250.filters.bnOut).offset().left,
                right: "auto",
                top: 0
            }).find(".close").show();
        } else if (scroll + ads300x250.height >= ads300x250.bottom) {
            $(ads300x250.filters.bnOut).css({
                position: "absolute",
                left: "auto",
                right: 0,
                top: ads300x250.bottomTop
            }).find(".close").show();
        } else {
            $(ads300x250.filters.bnOut).css({
                position: "relative",
                left: "auto",
                right: "auto",
                top: "auto"
            }).find(".close").hide();
        }
        return true;
    },
    Wait: function () {
        var t = this;
        if (t['tl']) clearTimeout(t.tl);
        var bn = $(this.filters.bnIner);
        if (bn.length > 0 && bn[0].childElementCount > 0) {
            this.Init(true);
        } else {
            t.tl = window.setTimeout(function () { t.Wait() }, 1000);
        }
    },
    Init: function (f) {
        if (f) {
            var adr_bn_iframe = $(this.filters.bnIner).children('*');
            var bn = (adr_bn_iframe.length > 0) ? { w: adr_bn_iframe.width(), h: adr_bn_iframe.height(), dw: 6, dh: 6} : { w: 300, h: 250, dw: 6, dh: 6 };
            var MH = 350, mH = 250, W = 300;
            var H = (bn.h > MH) ? MH : ((bn.h < mH) ? mH : bn.h);
            bn.ml = (W - bn.w) / 2;

            //adr_bn_iframe.parent().css('padding-left: ' + bn.ml.toString() + 'px;');
            //adr_bn_iframe.css('margin-left: ' + bn.ml.toString() + 'px;');

            var wrap = $("<div>").css({
                margin: "0 0 16px",
                height: H + 6,
                width: W + 6,
                position: "relative"
            });

            var close = $("<div>").addClass("close").click(ads300x250.close);

            $(this.filters.bnOut).css({ margin: 0, zIndex: 500, height: H + 'px' }).append(close).wrap(wrap);

            ads300x250.top = $(this.filters.bnOut).offset().top;
            ads300x250.bottom = ($(".main-right").length > 0) ? $(".main-right").offset().top + Math.max($(".main-right").height(), ($(".main-left").length > 0) ? $(".main-left").height() : 0) : 0;
            ads300x250.height = $(this.filters.bnOut).height();
            ads300x250.bottomTop = (ads300x250.bottom - ads300x250.top) - ads300x250.height;

            if (ads300x250.bottom - ads300x250.top > ads300x250.height) {
                $(window).scroll(function () {
                    setTimeout(ads300x250.OnScroll, 0);
                });
                ads300x250.OnScroll();
            }
        } else {
            $(document).ready(function () {
                ads300x250.Wait();
            });
        }
    },
    close: function () {
        ads300x250.show = false;
        $(ads300x250.filters.bnOut).css({
            position: "relative",
            left: "auto",
            right: "auto",
            top: "auto"
        }).find(".close").hide();
    }
};
ads300x250.Init();
var _announces =
            {
                interval: 5500,
                speed: 450,
                next:
                    function () {
                        $('.freshNews p').first().animate({ marginTop: -32 }, _announces.speed, function () {
                            $('.freshNews p').last().after($(this).css({ marginTop: 0 }));
                            setTimeout(_announces.next, _announces.interval);
                        });
                    }
            }
