
function main(){
	(function($){
		// functions
		$(document).ready(function() {
		
			$('#uptrend_video').click( function() {
				var howWeWorksContent = '<div class="uptrend_video"><div class="wr"><iframe width="640" height="360" src="http://www.youtube.com/embed/xyqyjCCBPus" frameborder="0" allowfullscreen></iframe>'
				+ '<p><a href="/feedback/">Начните работу с Аптренд прямо сейчас</a></p></div></div>';
				$(this).fancybox( {
					padding: 0,
					content: howWeWorksContent
				} );
				return false;
			} );
			
			$('#uptrend_video').fancybox();
		
			var mouse_x = 0;
			var mouse_y = 0;
			var bell_down=0;
			soundManager.url = '/templates/swf/';
			soundManager.onload = function() { soundManager.createSound({ id: 'bellSound', url: '/templates/sound/zvonok.mp3', autoLoad: true });}

		// звонок
		$('#bell2').bind('click', function(event) {
		    $("#bell_hand").animate({  marginTop: "0" }, 300, "linear", function(){
		      bell_down=1;
		      soundManager.play('bellSound');
		      $("#bell_hand").delay(700).animate({  marginTop: "-5" }, 300, "linear", function(){ bell_down=0; });
		      });
		   });

		  // смена цвета при наведении в решениях на ссылку
		  $('.block a').hover(
		    function(){ $(this).parents(".block").children(".name").css("color", "#ffffff"); },
			function(){ $(this).parents(".block").children(".name").css("color", "#802222"); }
			);
		  // смена цвета при наведении в решениях на название
		  $('.block .name').hover(
		    function(){ $(this).css("color", "#FFFFFF"); $(this).parents(".block").children("a").addClass("hover1"); },
			function(){ $(this).css("color", "#802222"); $(this).parents(".block").children("a").removeClass("hover1"); }
			);

/*
		  $('.block').hover(
		    function(){ $(this).attr('src', $(this).attr('src_on'));},
			function(){ $(this).attr('src', $(this).attr('src_off'));}
			);

		  $('#right img').hover(
		    function(){ $(this).css(' background-position:', '0px -50px;');  },
			function(){ $(this).css(' background-position:', '0px 50px;'); }
			);
*/

    	// обновление отзывов - старый вариант
/*
       $('#comment_one .control').live('click', function(event){
         $('#comment_one').fadeOut(50).load('/ajax/control_update.php', function(){
           $(this).fadeIn(50);
           });
        });
*/

       // обновление отзывов новый вариант
       $('#comment_one .control').live('click', function(event){
        var str = $('#newcp').serialize();
	    $.post('/ajax/control_update2.php', str, function(data) {
	      $perem = $(data).find('div')
	      $("#comment_text").text( $perem.eq(0).text() );
	      $("#comment_fio").text( $perem.eq(1).text() );
	      $("#comment_dolzhost").html( $perem.eq(2).text()+'<div id="comment_link" class="link"><a href="'+$perem.eq(4).text()+'">'+$perem.eq(3).text()+'</a></div>' );
	  });
  });

    	// двигаем флажки языков
		  $('.rus, .eng').hover(
		    function(){$("." + $(this).attr('class')).css('background-position', 'left');},
				function(){$("." + $(this).attr('class')).css('background-position', 'right');}
			);

			// координаты мыши
			$(document).mousemove(function(e){
				mouse_x = e.pageX;
				mouse_y = e.pageY;
				x_max = $('#wrap').offset().left + 657;
				if(mouse_x > x_max) mouse_x = x_max; // чтобы меню не вылезало вправо
   		});

			// карта портфолио
			$('#map area').hover(
				function(){
					var cls = $(this).attr('class').replace('map_', '');
				  $('[class ^= sprite_]').hide();
				  $('[class ^= hint_]').fadeOut('slow');
					$('.sprite_' + cls).stop().fadeIn('slow').fadeTo(1,1);
					$('.hint_' + cls).stop().show().offset({top: mouse_y + 1, left: mouse_x - 5}).fadeTo(1,1);
				},
				function(){
          $('div.' + $(this).attr('class')).hide();
          $('ul.' + $(this).attr('class')).not(':hover').fadeOut('slow');
				});
      $('#map area').click(function(){
				if($('#long_text').size()){
				  $('#long_text').html($($(this).attr('class').replace('map_', '.text_')).html());
				  $('html, body').animate({ scrollTop: $("#long_text").offset().top }, 1000);
				}
				return false;
			});
			$('[class ^= hint_] .more').click(function(){
				$('#long_text').html($($(this).parent().attr('class').replace('hint_', '.text_')).html());
				$('html, body').animate({ scrollTop: $("#long_text").offset().top }, 1000);
				return false;
			});
			$('[class ^= hint_]').hover(
				function(){
					$(this).stop().show().fadeTo(1,1);
					$($(this).attr('class').replace('hint_', '.sprite_')).stop().show().fadeTo(1,1);
				},
				function(){
					$(this).fadeOut('slow');
					$($(this).attr('class').replace('hint_', '.sprite_')).hide();
				}
			);

			/*// развернуть комментарии
			$('.comment .more a').click(function(){
				$(this).parent('.more').hide();
				$('.comment:hidden').slideDown('slow');
				return false;
			});*/

			// решения
			// переключение освещения
			$('#solutions #controls a').click(function(){
			  var id = $(this).attr('href').split('#').join('');
			  if($('#' + id + ':hidden').size()){
					$('.solution:visible').fadeOut('slow');
					$('#' + id).fadeIn('slow');
					$('#solutions #controls a.active').removeClass('active');
					$(this).addClass('active');
				}
				return false;
			});
			// выбор картинки
			$('#solutions .solution li img').click(function(){
			  var cl = $(this).attr('class');
			  if($('div:visible.solution .bigpic img.' + cl + ':hidden').size()){
					// сначала для скрытых видов освещения чтобы потом соответствовало
					$('div:hidden.solution .bigpic img').hide();
					$('div:hidden.solution .bigpic img.' + cl).show();
					//
					$('div:visible.solution .bigpic img:visible').fadeOut('slow');
					$('div:visible.solution .bigpic img.' + cl).fadeIn('slow');
				}
			});
			// разворачивание ассортимента
			$('#right_col li span').click(function(){
			  var l_list = $(this).parent('li').children('ul:hidden');
				if(l_list.size()){
					$('#right_col li ul:visible').slideUp('fast');
					l_list.slideDown('fast');
				}
			});
			// отправка формы
			$('#feedback a.button').click(function(){
			  var text = $('#feedback .need input[type=text]').css('background', 'transparent').filter('input[value=""]').css('background-color', '#dc9a9a').parent('label').text();
				if(text){
					alert('Не заполнены обязатeльные поля: \n' + text.split(':').join('; '));
				}else{
          $('#feedback').submit();
				}
				return false;
			});
			// форма подписки
			$('#subscription a.button').click(function(){
				if($(this).parent().find('input').filter('[value=""]').focus().size()) alert('Пожалуйста, укажите имя и email');
				else $(this).parent().submit();
				return false;
			});
		});
	})(jQuery);
}

if (typeof jQuery == 'undefined'){ // если jquery не вытянулось с гугля, берём локальный
	document.write(unescape("%3Cscript src='/templates/js/jquery-1.6.2.min.js' type='text/javascript'%3E%3C/script%3E"));
 	window.onload = main;
} else main();

