﻿/// удвлить после очистки кеша
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>'));
    }
}
/* /удвлить после очистки кеша */


var _s = {
	go : function(){
		var text = escape($('#text').val())
		if(text=='')return;
		var url = "http://obozrevatel.com/search_result.htm?cx=000234703784691205514:fw-ak-gykzm&ie=utf-8&cof=FORID:11&q=" + encodeURI(text);
		window.open(url);
	}
}

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);
    }
}

var _mi =
{
	over:function(e,i){
		if(eval($('.main-item .main-item-body li:first').attr('pos'))==i)
			return;

		$('.main-item .main-item-choose a').attr('class','');
		$(e).attr('class','cur');
		$('.main-item .main-item-body li:first').before($('.main-item .main-item-body li[pos="'+i+'"]')); 
	},
	init:function(){
		if(location.hash!=null){
			if(location.hash.indexOf('#')==0){
				var key = location.hash.substr(1);
				if(key.match( /^\d+$/ )){
					var item = $('.main-item .main-item-choose a[key="'+key+'"]');
					var pos = item.index('.main-item .main-item-choose a');
					if(pos!=-1){
						_mi.over(item, pos)
					}
				}
			}
		}
	}
}

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){
		$('.'+c+' .'+c+'-item:first').before($('.'+c+' .'+c+'-item:last'));
		var pos = $('.'+c+' .'+c+'-item:first').attr('pos')
		$('.'+c+'-scroller .cur-item').attr('class','item');
		$('.'+c+'-scroller .item:eq('+pos+')').attr('class','cur-item');
	},
	right : function(c){
		$('.'+c+' .'+c+'-item:last').after($('.'+c+' .'+c+'-item:first'));
		var pos = $('.'+c+' .'+c+'-item:first').attr('pos')
		$('.'+c+'-scroller .cur-item').attr('class','item');
		$('.'+c+'-scroller .item:eq('+pos+')').attr('class','cur-item');
	}
}

/* News scroll
*/
var topArticle, bottom, heightScroll, bottomTop;
function FixBlockHeight(){
	var scroll = $(document).scrollTop();

//		$('#info').html(
//			"topArticle="+topArticle+"<br/>"+
//			"bottom="+bottom+"<br/>"+
//			"heightScroll="+heightScroll+"<br/>"+
//			"bottomTop="+bottomTop+"<br/>"+
//			"scroll="+scroll
//		);

	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);

//		$('#info').show().css({position:'fixed',left:0,top:0});
		
		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;
		if(loc.indexOf('/css/')<0 ){
			if(loc.indexOf('/money.htm')>0 || loc.indexOf('/money/')>0 || loc.indexOf('/life.htm')>0 || loc.indexOf('/life/')>0 ){
				$('.news-view-right-scroll style').after(
'<div class="clr6"></div><strong style="font:italic 11px georgia,\'times new roman\',times,serif;color:#D62728">Партнер раздела:</strong>'+
'<div class="clr6"></div><div id="b195x100_adr" class="adriverBanner" style="display:block;width:195px;height:100px;">'+
'<embed type="application/x-shockwave-flash" width="100%" height="100%" quality="best" wmode="opaque" play="true" loop="true" menu="false" allowscriptaccess="always" src="/css/coffee_totti/new1/TOTTI_195x100.swf" flashvars="link1='+escape('http://services.obozrevatel.ua/reference.ashx?id=e52cb906-c351-4184-a583-25589c1667f9')+'&">'+
'</div><div class="clr6"></div>' 
				);
				$('body header, body nav, body section, body footer').css('background-color','#fff').css('padding-left','10px').css('padding-right','10px').css('cursor','default');
				$('body footer').css('padding-bottom','10px');
				$('body').css('cursor','pointer').css('background','').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;
							case 'img':
									switch(target[0].className){
										case 'lavazza_BLUE_1': window.open('http://services.obozrevatel.ua/reference.ashx?id=e3ed1933-e997-456b-adca-f7e96ee57f31');
											return;
										case 'lavazza_BLUE_2': window.open('http://services.obozrevatel.ua/reference.ashx?id=cd3e426b-f1bf-4407-98c0-040af8b353d4');
											return;
									}
								break;
						}
						target = target.parent();
					}
					if (event.pageX < ($(document).width()/2) ){
						window.open('http://services.obozrevatel.ua/reference.ashx?id=c9862562-18d7-4e8d-a86b-db4a11e71957','_blank');//L
					} else { 
						window.open('http://services.obozrevatel.ua/reference.ashx?id=2c3df894-de74-429c-9c66-ccd171fd9a40','_blank');//R
					}
				});
				var dW = $(document).width();
				var dH = $(document).height();			
				var wW = $(window).width();
				var wH = $(window).height();
				var RimgW = 295; var RimgD = 75;
				var LimgW = 296; var LimgD = 50;
				if (wW - 1010 - RimgW - LimgW + RimgD + LimgD > 0 ) { RimgD = 0; LimgD = 0; }
				$('body').append(
	'<div id="_content_brend" style="margin: 0; padding: 0; width:0px; height:0px; position:relativ; float:left;">'+
		'<div style="position:fixed; width:0px; height:0px; z-index:-23; top:0px; left:0px; float:left;"><div style="float:left; background: #E9EEF4 url(/css/coffee_totti/2/bg.gif) repeat-x fixed; width:'+((wW)/2)+'px;height:'+dH+'px;"></div></div>'+
		'<div style="position:fixed; width:0px; height:0px; z-index:-22; top:0px; left:0px; float:left;"><div style="float:left; background: transparent url(/css/coffee_totti/2/bg_t.png) repeat fixed; width:'+((wW)/2)+'px;height:'+dH+'px;"></div></div>'+
		'<div style="position:fixed; width:0px; height:0px; z-index:2; top:0px; left:0px; float:left;"><div style="float:left; margin-left:-'+(LimgD)+'px; background: none; height:'+(159)+'px;">'+
				'<img class="lavazza_BLUE_1" src="/css/coffee_totti/2/left_top.png" alt="" style="border:none; float:left;">'+
		'</div></div>'+
		'<div style="position:fixed; width:0px; height:0px; z-index:-20; top:0px; left:0px; float:left;"><div style="float:left; background: none; height:'+(681)+'px;">'+
				'<img src="/css/coffee_totti/2/left_caps.png" alt="" style="margin-top:'+(159+50)+'px; border:none; float:left;">'+
		'</div></div>'+
		'<div style="position:fixed; width:0px; height:0px; z-index:-33; top:0px; right:0; float:left;"><div style="float:left; margin-left:-'+((wW)/2)+'px; background: #E9EEF4 url(/css/coffee_totti/2/bg.gif) repeat-x fixed; width:'+((wW)/2)+'px;height:'+dH+'px;"></div></div>'+
		'<div style="position:fixed; width:0px; height:0px; z-index:-32; top:0px; right:0; float:left;"><div style="float:leftt; margin-left:-'+((wW)/2)+'px; background: transparent url(/css/coffee_totti/2/bg_t.png) repeat fixed; width:'+((wW)/2)+'px;height:'+dH+'px;"></div></div>'+
		'<div style="position:fixed; width:0px; height:0px; z-index:-30; bottom:0px; right:0; float:left;"><div style="float:left; margin-left:-'+(267)+'px; margin-top:-'+(582+159+50)+'px; background: none; width:'+(267)+'px; height:'+(582)+'px;">'+
				'<img src="/css/coffee_totti/2/right_cofevarki.png" alt="" style="border:none; float:left;">'+
		'</div></div>'+
		'<div style="position:fixed; width:0px; height:0px;  z-index:2; bottom:0px; right:0; float:left;"><div style="float:left; margin-left:-'+(RimgW - RimgD)+'px; margin-top:-'+(159)+'px; background: none; width:'+(RimgW)+'px; height:'+(159)+'px;">'+
				'<img class="lavazza_BLUE_2" src="/css/coffee_totti/2/right_bottom.png" alt="" style="border:none; float:left;">'+
	'</div></div></div>'
				);
				
			} else {
                    $('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>');
           } 
		}
	})
}
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()
			}
		);
		$('.scroll-button-left').click(
			function(){
				interesting.changed = true;
				interesting.left();
			}
		);
		setTimeout(interesting.slide, interesting.slideInterval);
	}
}

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 + " > *");
		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.css({'margin-left':bn.ml+'px','margin-right':'auto'});//

            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();


$(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() });
            });

        });
    });

