anchor = {
	init : function()  {
		elementClick = $('div.b-feedback1');
		destination = $(elementClick).offset().top - 150;
		$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination}, 1100 );
	}
}

function fadeSlogan(){
	jQuery("div.b-slogan img.slogan1").fadeOut(4000, function(){
		jQuery("div.b-slogan img.slogan2").fadeIn(4000, function(){
			jQuery("div.b-slogan img.slogan2").fadeOut(4000, function(){
				jQuery("div.b-slogan img.slogan1").fadeIn(4000, function(){
					fadeSlogan()
				})
			})
		});
	})
}

jQuery(function() {
	
	fadeSlogan();
	
	$('div.b-rcol blockquote').append('<i></i>');
	
	/* позиционирование формы на главной */
	topOffset = ($('.b-hotspot-list').height() - $('div.b-feedback form').height())/2 -5;
	jQuery('div.b-feedback_outer').css('top', topOffset);
	
	/* позиционирование подписей к полям в форме на главной */
	var ua = navigator.userAgent.toLowerCase();
	isSafari = (ua.indexOf("safari") != -1);
	
	//jQuery('div.b-feedback .row i').css('position', 'absolute');
	//jQuery('div.b-feedback1 .row i').css('position', 'absolute');
	
	if( isSafari )
	{
		//jQuery('div.b-feedback .row-file i').hide();
		//jQuery('div.b-feedback1 .row-file i').hide();
	}	
	
	/* убираем подписи и ставим фокус по клику для форм на главной и внутренних */
	
	/*jQuery('div.b-feedback .row i').click(function(){
		$(this).hide();
		$(this).siblings('input').focus()
	});
	jQuery('div.b-feedback .row-file i').click(function(){
		$(this).hide();
		$(this).siblings('input').focus()
	});	
	jQuery('div.b-feedback1 .row i').click(function(){
		$(this).hide();
		$(this).siblings('input').focus()
	});
	jQuery('div.b-feedback .input-file').focus(function(){
		$(this).siblings('i').hide()		
	});
	jQuery('div.b-feedback .input-text').focus(function(){
		$(this).siblings('i').hide();
	});
	jQuery('div.b-feedback1 .input-file').focus(function(){
		$(this).siblings('i').hide()		
	});
	jQuery('div.b-feedback1 .input-text').focus(function(){
		$(this).siblings('i').hide();
	});
	jQuery('div.b-feedback .input-textarea').focus(function(){
		$(this).siblings('i').hide()		
	});
	jQuery('div.b-feedback1 .input-textarea').focus(function(){
		$(this).siblings('i').hide()		
	});
	*/
	/* если есть ошибки в формах, то не сворачиваем их */
	
	if($('div.b-feedback p.err').length == 0 ){
		jQuery('div.b-feedback').animate({width: "29px"}, {queue:true,duration: 1000});
		jQuery('div.b-feedback').queue(function(){
			jQuery(this).removeClass('b-feedback_act');
			jQuery('div.b-feedback_outer').removeClass('b-feedback_outer_act');
		});
	}
	if($('div.b-feedback1 p.err').length == 0 ){
		jQuery('div.b-feedback1 form').slideToggle("slow", function () {
			jQuery('div.b-feedback1').removeClass('b-feedback1_act');
		})
	}
	else{
		anchor.init()
	}
	
	/* сворачивание / разворачивание по клику */
	
	jQuery('div.b-feedback .ititle').click(function(){
		
		feedback = jQuery('div.b-feedback');
		feedbackOuter = jQuery('div.b-feedback_outer');
		
		feedback.stop();
		if( feedback.hasClass('b-feedback_act') ){
			
			feedback.animate({width: "29px"}, {queue:true,duration: 1000});
			feedback.queue(function(){
				feedback.removeClass('b-feedback_act');
				feedbackOuter.removeClass('b-feedback_outer_act');				
			});
		}
		else
		{
			feedback.addClass('b-feedback_act');
			feedbackOuter.addClass('b-feedback_outer_act');
			feedback.animate({width: "340px"}, {queue:true,duration: 1000});
		}
		
	});
		
	jQuery('div.b-feedback1 .title').click(function () {
		jQuery('div.b-feedback1 form').slideToggle("slow");
		anchor.init();
		if( jQuery('div.b-feedback1').hasClass('b-feedback1_act') )
			jQuery('div.b-feedback1').removeClass('b-feedback1_act');
		else{
			jQuery('div.b-feedback1').addClass('b-feedback1_act');
		}
    });
	
	/* для шаблона "письменный перевод": заменяем картинки меню на другие, заменяем телефон в шапке на картинку */
	
	jQuery('body.l-page3 div.b-nav img').each(function (i){
		
		path = $(this).attr('src').split('/');
		path = path[path.length-1];
		path_new = 'pismenno_' + path;
		path_new = $(this).attr('src').replace(path, path_new);
		$(this).attr('src', path_new)
	})
	
	jQuery('body.l-page3 div.b-phone').html('<img src="/images/style/page3phone.jpg" alt="' + jQuery('body.l-page3 div.b-phone').text() + '"/>');
	
	/* в подменю закрашиваем пунктиры */
	
	jQuery('div.b-submenu li li').each(function (i){
		s = jQuery(this).text();
        s = s.split(' ');
        g = '';
        for(i=0; i < s.length; i++){
            g = g + ' ' +  '<span>' + s[i] + '</span>'
        }
        my_p = jQuery('<p></p>');
        my_p.appendTo(jQuery(this));
        my_p.append(g);
		my_p.append('<br/><em></em>');
   
        my_height = 0;
        my_string = '';
        
		jQuery(this).find('span').each(function (i){
			if( jQuery(this).position().top > my_height ){
				my_string = jQuery(this).text();
				my_height = jQuery(this).position().top;
			}
            else if( jQuery(this).position().top == my_height ){
                my_string = my_string + ' ' + jQuery(this).text();
                my_height = jQuery(this).position().top;
            }
		//	alert(jQuery(this).position().top)
        })
		
		//alert(my_string);
		$(this).find('em').html(my_string);
        
        $(this).append('<b></b>');
        $(this).find('b').css('width', $(this).find('em').width() + 5)
        
    })

})