// действие необходимо переопределять для каждого сайта в отдельности, т.к. зависит от верски
$(document).ready(function(){
	//режим отладки
   	lps.showConsole();
	lps.setConsoleReportingLevel("warning");

	// Устанавливаем обработчик на смену состояния: авторизован / не авторизован.
	lps.onChangeLogin(function(){
		$('#page_header').load('/?login #page_header');
		//$('#page_left_menu').load('/?login #page_left_menu');
	});

	//меняем назначение ссылки
	$('#registration_link').click(function(){
		lps.auth(function(){
			lps.console('login: ok', "debug");
		});
		return false;
	});
	
	$('.top_login_form .enter').click(function(event) {
  		var $form = $(event.target).closest('FORM');
		$form.submit();
		return true;
	});
	
	$('.top_login_form .enter').mouseenter(function(){
		$(this).addClass("mouseover");
	}).mouseleave(function(){
		$(this).removeClass("mouseover");
	});
	
	$('#page_header .label').mouseenter(function(){
		var label_for=$(this).attr('class').replace('label ','');
		$('#page_header .icon_' + label_for).addClass('mouseover');
	}).mouseleave(function(){
		var label_for=$(this).attr('class').replace('label ','');
		$('#page_header .icon_' + label_for).removeClass('mouseover');
	});
	
	$('#not_main_page.module_portfolio #page_main .text_content .studio .one_project').mouseenter(function(){
		$('.relation',this).addClass('mouseover');
		$('.hint', this).slideDown('fast');
	}).mouseleave(function(){
		$('.relation', this).removeClass('mouseover');
		$('.hint', this).slideUp('fast');
	});

	$('#not_main_page.module_portfolio #page_main .text_content .studio .one_project').click(function(){
		location.href=$('.link A', this).attr('href');
	});
	
	$('.stand .left_arrow').mouseenter(function(){
		$(this).addClass('mouseover');
	}).mouseleave(function(){
		$(this).removeClass('mouseover');
	});
	
	$('.stand .right_arrow').mouseenter(function(){
		$(this).addClass('mouseover');
	}).mouseleave(function(){
		$(this).removeClass('mouseover');
	});
	
	$('.stand .left_arrow').click(function(){
		var center=$('.project .wrap_center');
		$('A',center).animate({
			left: "294px"
		}, 500, "linear", function(){
			center.removeClass('wrap_center').addClass('wrap_right');
		});
		var prev=$('.project .wrap_center').prev();
		$('A', prev).css('left', '-882px').animate({
			left: "-50%"
		}, 500, "linear", function(){
			prev.removeClass('wrap_left').addClass('wrap_center');
		});
		$('.project .wrap_right:last').clone().insertBefore('.project span:first').removeClass('wrap_right').addClass('wrap_left');
		$('.project .wrap_right:last').remove();
	});
	
	$('.stand .right_arrow').click(function(){
		var center=$('.project .wrap_center');
		$('A',center).animate({
			left: "-882px"
		}, 500, "linear", function(){
			center.removeClass('wrap_center').addClass('wrap_left');
		});
		var next=$('.project .wrap_center').next();
		$('A', next).css('left', '294px').animate({
			left: "-50%"
		}, 500, "linear", function(){
			next.removeClass('wrap_right').addClass('wrap_center');
		});
		$('.project .wrap_left:first').clone().appendTo('.project').removeClass('wrap_left').addClass('wrap_right');
		$('.project .wrap_left:first').remove();
	});

    //модальные окна
    $('A.modal_window').fancybox({
      'zoomSpeedIn': 0,
      'zoomSpeedOut':0,
      'autoDimensions': false,
      'hideOnContentClick': false,
      'padding': 0,
      'margin': 0,
      'scrolling' : 'no',
      'autoScale' : false
    });
    $('A.modal_window_iframe').fancybox({
      'zoomSpeedIn': 0,
      'zoomSpeedOut':0,
      'autoDimensions': false,
      'hideOnContentClick': false,
      'padding': 0,
      'margin': 0,
      'scrolling' : 'no',
      'autoScale' : false,
      'type'      : 'iframe',
      'width'     : 800,
      'height'    : 450
    });
});

function checkData(input_element, result_element, module, method, field){
	$("#"+result_element).html("<img src='/img/load.gif' width=16 height=16>");
	$.post("/"+module+"/"+method,{
        field_name: $("[name='"+input_element+"']").attr("value"),
        field: field
    },
    function(data){
        $("#"+result_element).html(data);
    });
}
