function animateFeedBack(){
    $('.feedback_box').parent().css("z-index","1025");
    $('.feedback_box').css({
        height:'77px', 
        width: '167px',
        opacity:1, 
        top: $("#leave_comment").offset().top +"px",
        left: $("#leave_comment").offset().left +"px"
    });
    $('.feedback_past_msg').hide();
	
    //	$('.feedback_box').css({height:'0', width:'0'},200);
    $('.feedback_box .ib_wrap').css("height", 477);
    $('body').append('<div class="popup_overlay"></div>')

    $('.popup_overlay').css({
        opacity:0
    });
    $('.popup_overlay').animate({
        opacity:1
    },300);
    $('.popup_overlay').show();


    // Скролл на форму 
        
    $('.feedback_box').show();
    var winLeft = (windowWidth() - 560)/2;
    var winTop = (windowHeight() - 442)/2 ;
         
    $('.feedback_box').animate({
        height:'442px', 
        width:'560px', 
        opacity:1, 
        left: winLeft+"px", 
        top: (winTop + $(window).scrollTop())+"px"
    }, 300,'linear',
    function(){
        $.scrollTo('.feedback_box', 0, {
            offset:-100
        });
        $('.feedback_form').show();
        $(this).css({
            position: "fixed",
            left: winLeft+"px", 
            top: winTop+"px"
        });
    }
                                       
    );

       
    
	
};

function copleateFeedBack(){
    $('.feedback_form').hide();
    $('.feedback_box').animate({
        height:'77px', 
        width: '167px', 
        opacity:1, 
        top: $("#leave_comment").offset().top +"px",
        left: $("#leave_comment").offset().left +"px"
    },
    300,
    'linear',
    function(){
        $('.feedback_box').hide();
    } 
    );
    $('.feedback_box .ib_wrap').css("height", 186);
    $('.feedback_past_msg').show();
};
function closeFeedBack(){

         
    var winTop = (windowHeight() - 442)/2 ;
    $('.feedback_box').css({
        position: "absolute",
        top: (winTop + $(window).scrollTop()) +"px"
    });
    $('.popup_overlay').animate({
        opacity:0
    },300);
    $('.feedback_box').animate({
        height:'77px', 
        width: '167px', 
        opacity:1,
        top: $("#leave_comment").offset().top +"px",
        left: $("#leave_comment").offset().left +"px"
    },
    300,'linear',function(){
        $('.feedback_box').hide();

        $('.popup_overlay').remove();
        $('.feedback_box').parent().css("z-index","4"); //fu..ng IE7
    } );
	
	
	

};

function hideHover(tClass){
    $(tClass).find(".sel_link").addClass("sel_link_activated");
    $(tClass).click(							  
        function() {
            var scroll =$(".main").height() - $(this).offset().top - $(this).parent().find(".sel_sity").height()-20;
            if (scroll < 0) $(this).parent().find(".sel_sity").css("margin-top",scroll);
                        
            $(this).find('.sel_sity').slideDown(180);
        })
    .mouseleave(
        function() {
            $(this).find('.sel_sity').hide();

        }
        );

};
function openpopup(tPopup){
    $('body').append('<div class="popup_overlay"></div>')
    $('.popup_overlay').show();
    $(tPopup).show();
};
function closedpopup(tPopup){
    $('.popup_overlay').remove();
    $(tPopup).hide();
};

function hidenLine6(){
    var hideLine6 = $(".calendar .datepickerDays .line_6");
    if (hideLine6.children("td.datepickerNotInMonth").length == 7){
        hideLine6.hide()
    }
    else {
        hideLine6.show()
    };
};

var d=new Date();
var day=d.getDate();
var month=d.getMonth() + 1;
var year=d.getFullYear();
tDay = year+"-"+month+"-"+day;


$(document).ready(function(){
    
    $("a.historyback").click(function() {
        history.back(1);
        return false;
    }); 
    $('.top_menu ul li').hover(							  
        function() {
            //$(this).addClass("active");
            $(this).find('ul').stop(true, true);
            $(this).find('ul').slideDown(200);
        },
        function() {
            $(this).find('ul').stop(true, true);
            $(this).find('ul').hide();
        //$(this).removeClass("active");

        }
        );
    $('.top_menu ul ul li a').css( {
        backgroundPosition: "-12px 50%"
    } )
    .mouseover(function(){
        $(this).stop().animate({
            backgroundPosition:"(0px 50%)"
        }, {
            duration:200
        })
    })
    .mouseout(function(){
        $(this).stop().animate({
            backgroundPosition:"(-12px 50%)"
        }, {
            duration:200, 
            complete:function(){
                $(this).css({
                    backgroundPosition: "-12px 50%"
                })
            }
        })
    })

    hideHover('#select_sity');
    hideHover('#ofices_selector');
    hideHover('#popup_ofices_selector');
	
    $("#offices_map .ib_wrap strong:first, #offices_map .ib_wrap .ib_links:first, #support .sity_phones:first, #courses .table_box table:first").show();
	
    $(".index_carusel").jCarouselLite({
        btnNext: ".ic_right",
        btnPrev: ".ic_left",
        speed: 500,
        circular: true,
        scroll: 1
    });

       


	
    $('.vis_links_box').css({
        opacity: 1
    });
	
    $('.lic_sub_menu li').click(
        function() {
            if ($(this).hasClass('active')){
                return;
            }
            else{
                $(this).siblings('li').removeClass('active')
                $(this).addClass('active');
                viz_linksID = $(this).children('a').attr('rel');
    			
                $(".vis_links_box")
                       
                $(this).parents(".li_cont_wrap").find('.vis_links_box').hide();
                        
                $("#"+viz_linksID).show();
                           
                            
            //                            animate({opacity: 0}, 200, function() {
            //    				$(this).hide();
            //    				if($(this).attr("id") == viz_linksID)
            //    				    $('.lic_right #'+viz_linksID).css({display: "table-cell"}).show().animate({opacity: 1}, 100);
            //    			});
            //$('.lic_right #'+viz_linksID).stop().css({display: "table-cell"}).animate({opacity: 1}, 500, function() {});
            }
        }
        );
                    
    $('.lic_right').find(".vis_links_box:first").show();            
                    
    $('.faq_question').live("click",
        function() {
            $(this).toggleClass('opened');
            $(this).next('div').slideToggle(200);
        });
    /*$('.popup_overlay').click(function() {$(this).hide();});*/
    /*$('.slide_link[rel]').click(
        function() {
			$(this).next(".li_cont").slideToggle(259).siblings("div:visible").slideUp(250);
			$(this).toggleClass('active');
			$(this).siblings('a').removeClass("active");
        });*/
    /*$(".listing div:first").delay(1000).slideDown(150, function(){
		$(this).prev('a[rel]').addClass("active");
	});*/

    $(".btn_print").click(function(){
        PrintPage();
        return false;
    } );


 
    //Ширина ячек для разных таблиц
    setWidthToTd();
  
    //попап окно
    $(".contentshowlink").click( function(){
        showPopupContent(this);
        return false;
    } );
  
    //для табов выравнивание тдшек
    if ($(".tabs td").length ) 
    {
        var widthTabs = 100 / $(".tabs td").length;
        $(".tabs td").css({
            width: widthTabs + "%"
        });
    }
       
    $(".left_menu li a.active").click(function (){
        return false;
    }); 
    
    
});



function setWidthToTd()
{
    $(".li_cont[rel=result_block] th").wrapInner("<div class='paddingdiv'></div>");
  
    $(".li_cont[rel=result_block] th").each( function(i) {
                                                 
        $(this).addClass("th"+i);
    } );
  
    $(".li_cont[rel=result_block] th").css({
        padding: 0
    }); 
    $(".service_type tr td").wrapInner("<div class='paddingdiv'></div>");
    $(".service_type tr td").css({
        padding: 0
    }); 
  
    $(".li_cont[rel=result_block] th:eq(1)").addClass("tdwidth1");
    $(".li_cont[rel=result_block] th:eq(2)").addClass("tdwidth2");
    $(".li_cont[rel=result_block] th:eq(3)").addClass("tdwidth3");  
  
    var main_width1 = $(".li_cont[rel=result_block] th:eq(1)").width();
    var centerTd =  $(".li_cont[rel=result_block] th:eq(2)").width();
    var main_width2 = $(".li_cont[rel=result_block] th:eq(3)").width();
 
 
    $(".service_type tr").each(
                           
        function()
        {
            $(this).find("td").each(function(i) {
                i++ ;
                $(this).addClass("tdwidth"+i);
            } );
            if ($(this).find("td").length !=3 ) return;
                                                  
                                                 
                                               
            $(this).find("td:eq(0)").width(main_width1);
            $(this).find("td:eq(1)").width(centerTd);
            $(this).find("td:eq(2)").width(main_width2);  
                                                   
        }
        );
                                
    $(".tdwidth1").width(findmax(".tdwidth1"));
    $(".tdwidth2").width(findmax(".tdwidth2"));
    $(".tdwidth3").width(findmax(".tdwidth3"));
  
    $(".service_type table").css({
        "table-layout":"auto"
    });   
}

function findmax(ob)
{
    var widtd=0;
    $(ob).each(function() {
        if($(this).width() > widtd ) widtd = $(this).width();
    });
    return widtd;
}

function PrintPage()
{
    $(".content").addClass("printPage");  
    $("body").addClass("printPage");  
    $(".main").addClass("printPage");
       
    $(".header").fadeTo(500, 0, function(){
        $(this).hide(); 
        $(".content_center").prepend('<table class="printHeader" width="100%"  style="border-bottom: 1px dotted #D5D5D5;">\n\
                                                                                  <tr>\n\
                                                                                        <td><img alt="" title="" src="/images/belroslogo.png"></td>\n\
                                                                                        <td align="right" style="text-align:right;"><div class="top_info"><img class="promo_text" alt="По всей Республике. Для Вас." src="/images/promo_text.png"></div>\n\
                                                                                    <br/><br/><span style="font-size:11px;">(017) <b>229-73-29</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Белтелеком, VELCOM, MTC: <b>198</b> (по тарифам  оператора)</span><br/><br/>\n\
                                                                                    </td>\n\
                                                                                  </tr>\n\
                                                                            </table>');
    }
    );
    $(".left_sidebar").fadeTo(500, 0, function(){
        $(this).hide()
    });
    $(".right_sidebar").fadeTo(500, 0, function(){
        $(this).hide()
    });
    $(".bread_crumbs").fadeTo(500, 0, function(){
        $(this).hide()
    });
    $(".footer").fadeTo(500, 0, function(){
        $(this).hide();
    });
    //alert("dfsgdsf");
    setTimeout(function(){
        window.print();
        ShowPageAfterPrint();
    }, 2000 );
    
      
      
     
}
    
function ShowPageAfterPrint()
{
 
      
    $(".content_center .printHeader").remove();
       
    $(".header").show( function() {
        $(this).fadeTo(500,1);
    });
    $(".left_sidebar").show( function() {
        $(this).fadeTo(500,1);
    });
    $(".right_sidebar").show( function() {
        $(this).fadeTo(500,1);
    });
    $(".bread_crumbs").show( function() {
        $(this).fadeTo(500,1);
    });
    $(".bread_crumbs").show( function() {
        $(this).fadeTo(500,1);
    });
    $(".footer").show( function() {
        $(this).fadeTo(500,1);
          
        $(".content").removeClass("printPage");  
        $("body").removeClass("printPage");  
        $(".main").removeClass("printPage");     
    });
  
}
 
//*Не станадартный ajax*//

if (window.jsAjaxUtil)
{


    jsAjaxUtil._ShowLocalWaitWindow = jsAjaxUtil.ShowLocalWaitWindow;
    jsAjaxUtil.ShowLocalWaitWindow = function (TID, cont, bShadow)
    {
    
        //тень отображается всегда
        if (null == bShadow) 
            bShadow = true;
        jsAjaxUtil._ShowLocalWaitWindow(TID, cont, bShadow);

        loader_custom_ajax(cont);
        return;
    /*
И затем производим любые манипуляции с уже созданными объектами
*/
    }
}

/*
 *для jquery ajaxa тень и окно подождите удаление
*/
function  loader_sustom_ajax_remove()
{
    $(".waitwindowlocalshadow").remove();
    $(".waitwindowlocal").remove();
}
/*
 *для jquery ajaxa тень и окно подождите
*/
function loader_сustom_ajax_shadow(cont)
{
    $("body").append('<div class="waitwindowlocalshadow"></div>'); 
    $("body").append('<div class="waitwindowlocal"></div>'); 

    var waitwindowlocalshadowWidth = $(cont).width(); 
    var waitwindowlocalshadowHeight = $(cont).height(); 
    var offsetObj = $(cont).offset();
    
       
       
    $(".waitwindowlocalshadow").css({
        width: waitwindowlocalshadowWidth +"px",
        height: waitwindowlocalshadowHeight +"px",
        left: offsetObj.left + "px", 
        top: offsetObj.top + "px"
    });
    loader_custom_ajax(cont);
}

function loader_custom_ajax(cont){
    $(".waitwindowlocal").html("Подождите...");
    
    var waitwidth = $(".waitwindowlocal").width(); //получение ширины
    var waitheight = $(".waitwindowlocal").height(); //получение ширины

    var waitwindowlocalshadowWidth = $(cont).width(); 
    var waitwindowlocalshadowHeight = $(cont).height(); 
    var offsetObj = $(cont).offset();
    var winHeihgt = windowHeight();
    var scrollTop = $(window).scrollTop();
    
    var laypot =0;
    var topLaypot = 0;
   
   
    //Граничные значания
    //если ниже всего блока и блок не  фокусе
    if  ((offsetObj.top + waitwindowlocalshadowHeight) < scrollTop)
    {
        scrollTop = offsetObj.top + waitwindowlocalshadowHeight - winHeihgt;
    }
    else if  ((scrollTop + winHeihgt) < offsetObj.top) //если выше всего блока и блок не  фокусе
    {
        scrollTop = offsetObj.top;
    }
    
    if (scrollTop < offsetObj.top)
    {
        laypot = -1;
    }
    else if ((scrollTop + winHeihgt) >( offsetObj.top + waitwindowlocalshadowHeight) )
    {
        laypot = 1;  
    }
    
    
    switch (laypot){
        //в объекте
        case 0:
            topLaypot = parseInt(scrollTop + winHeihgt/2);
            break;
        case 1:
            //ниже объекта
            topLaypot = parseInt( scrollTop  + (offsetObj.top + waitwindowlocalshadowHeight - scrollTop)/2);
            break;
        case -1:
            //выще объекта
            topLaypot = parseInt( offsetObj.top  + (scrollTop + winHeihgt - offsetObj.top )/2);    
            break;
    }
        
    if (parseInt(waitwindowlocalshadowWidth))
    {
        var setWidth = parseInt( (waitwindowlocalshadowWidth -  waitwidth ) /2);
      
        $(".waitwindowlocal").css({
            left: (offsetObj.left+setWidth) + "px", 
            top: topLaypot + "px"
        });
    }
}




/*
 * вывод popup окна
*/ 
function showPopupContent(obj)
{
    $(document).bind('keydown.fb', function(e) {
        if (e.keyCode == 27) {
            closePopupContent();
        }
    });
 
    $(".popup_content .popup_close, .popup_overlay").live("click", function(){
        closePopupContent();
    });
             
    $("body").append("<div class='popup_content' style='display:none;'><a class=\"popup_close\"></a></div>");
    $("body").append("<div class='popup_overlay'></div>");
            
    // Заголовок
    $(".popup_content").append(' <div class="contaner"> </div> ')
    $(".popup_overlay").show();
            
    $(".popup_content").fadeIn("quick", function(){
        $(".popup_content .contaner").load($(obj).attr("href"), {
            NOTSHOWHEADERFUTER: "Y"
        });  // загрузка данных об офисе
            
    });
            

}


/*
       * Закрывает всплывающее окно
       */
function closePopupContent()
{
    $(document).unbind('keydown.fb');

    $(".popup_overlay").fadeOut("quick", function(){
        $(this).remove();
    });
    $(".popup_content").hide().remove();
}
        
        
        
        

          
  
// Определение высоты видимой части страницы
function windowHeight() {
    var de = document.documentElement;

    return self.innerHeight || ( de && de.clientHeight ) || document.body.clientHeight;
}

// Определение ширины видимой части страницы
function windowWidth() {
    var de = document.documentElement;

    return self.innerWidth || ( de && de.clientWidth ) || document.body.clientWidth;
} 

/****************************
 *    Установка Cookie
 ****************************/
function SetCookie (name, value, expires, path, domain, secure)
{
    // set time, it's in milliseconds
    var today = new Date();
    today.setTime( today.getTime() );

    /*
    if the expires variable is set, make the correct
    expires time, the current script below will set
    it for x number of days, to make it for hours,
    delete * 24, for minutes, delete * 60 * 24
    */
    if (expires)
    {
        expires = expires * 1000 * 60 * 60 * 24;
    }
    var expires_date = new Date(today.getTime() + (expires));

    document.cookie = name + "=" +escape(value) +
    ((expires) ? ";expires=" + expires_date.toGMTString() : "") +
    ((path) ? ";path=" + path : "") +
    ((domain) ? ";domain=" + domain : "") +
    ((secure) ? ";secure" : "");
}

