$(document).ready(function(){
	/*
    $("#newreg").mouseover(function(){
		$("#newreg").hide();
		$("#newreg2").show();
    });
	$("#leaves").mouseleave(function(){
		$("#newreg2").hide();
		$("#newreg").show();
    });
	*/
	$("#UF_FAKAD2").click(function(){
	if(this.checked==true)
		$("#UF_FAKAD").text("Такой же.").attr("readonly",true);
	else
		$("#UF_FAKAD").text("").attr("readonly",false);
	});
	//$(".latest").corners("18px");
	
	$(function() { $("#main_info").lavaLamp({ fx: "linear", speed: "fast"}) });
	/*
	$(".ma").click(function(){
		var img = $(this).attr("rel");
		var bg = "transparent url(/images/"+img+".jpg) no-repeat scroll center top";
		$(".block").css("background",bg);
		$('.ma').attr("href","#");
		$(this).removeAttr("href");
		return false;
	});
	*/
	$(function() { 
		var width = $(".mape").width(); 
		$(".back").css("width", width+20);
	});
	
	$("input.find, input.bgrey").hover(
		function () {
			$(this).css("background-position","bottom center");
		}, 
		function () {
			$(this).css("background-position","top center");
		}
    );
	$(".qq").hover(
		function () {
			$(this).css("background-position","bottom center");
		}, 
		function () {
			$(this).css("background-position","top center");
		}
    );
	$('.qq').tt({
		ttClass: 'customTip',
		align: 'flushRight',
		distanceY: -5,
		nudgeX: 100
	});

	/*
	$(".auth_input").hover(
		function () {
			var rel = $(this).attr("rel");
			if($(this).attr("value")=="")
				$(this).css("background", "transparent url("+rel+") no-repeat 10% center");
			else
				$(this).removeAttr("style");
		}, 
		function () {
			var rel = $(this).attr("rel");
			if($(this).attr("value")=="")
				$(this).css("background", "transparent url("+rel+") no-repeat 10% center");
		}
    ).keyup(function () {
		var rel = $(this).attr("rel");
		if($(this).attr("value")!=="")
			$(this).removeAttr("style");
		else 
			$(this).css("background", "transparent url("+rel+") no-repeat 10% center");
	}).change(function () {
		var rel = $(this).attr("rel");
		if($(this).attr("value")!=="")
			$(this).removeAttr("style");
		else 
			$(this).css("background", "transparent url("+rel+") no-repeat 10% center");
	});
	*/
	$(".auth_input").click(function(){
		$(this).removeAttr("style");
	});

	$("#mess_in").click(function(){
		var cc = $("#mess_in").attr("class");
		if((cc!="mess_button_on1")&&(cc!="mess_button_on2"))
		{
			$("#mess_in").attr("class","mess_button_on1");
			$("#mess_out").attr("class","mess_button_off1");
			$("#mess_in").css("width","110px");
			$(".mess_in").toggle();
			$(".mess_out").toggle();
		}
		return false;
	}); 
	$("#mess_out").click(function(){
		var cc = $("#mess_out").attr("class");
		if((cc!="mess_button_on1")&&(cc!="mess_button_on2"))
		{
			$("#mess_out").attr("class","mess_button_on2");
			$("#mess_in").attr("class","mess_button_off1");
			$("#mess_in").css("width","70px");
			$(".mess_out").toggle();
			$(".mess_in").toggle();
		}
		return false;
	});
	$(".mess_button_off1, .mess_button_off2, .mess_button_on1, .mess_button_on2").hover(function(){
		var cc = $(this).attr("class");
		if((cc!="mess_button_on1")&&(cc!="mess_button_on2"))
		{
			$(this).attr("class","mess_button_off2");
		}
	},
	function(){
		var cc = $(this).attr("class");
		if((cc!="mess_button_on1")&&(cc!="mess_button_on2"))
		{
			$(this).attr("class","mess_button_off1");
		}
	}).click(function(){});
	
	$(".photos_detail").click(function(){
		$("#bigfoto").attr("src",$(this).attr("title")).attr("width",$(this).attr("relW")).attr("height",$(this).attr("relH"));
		$("#bigfotourl").attr("href",$(this).attr("title"));
		$("img.selected").attr("class","photos_detail");
		$(this).attr("class","selected");
		$(".photos_detail").fadeTo("fast", 1);
		return false;
	}).hover(
		function () {
			$(this).fadeTo("slow", 0.5);
		}, 
		function () {
			var thisfade = $(this).attr("class");
			if(thisfade!="selected")
			{
				$(this).fadeTo("slow", 1);
			}
		}
    );
	$('.maf, .maof').click(function(){
		/*
		var rel = $(this).attr("rel");
		$(".maf[rel='"+rel+"']").attr("class","maof");
		$(".maof[rel='"+rel+"']").attr("class","maf");
		//$(".maof").attr("class","maf");
		//$(this).attr("class","maof");
		*/
	});
	$(".main_profile_hide, .main_profile").click(function(){
		if($(this).attr("class")=="main_profile")
			$(this).attr("class","main_profile_hide");
		else
			$(this).attr("class","main_profile");
		var url = $(this).attr("rel");
		var urlo = $("#"+url).attr("src");
		if(urlo == "/images/profile_hide.jpg")
			$("#"+url).attr("src","/images/profile_show.jpg");
		else
			$("#"+url).attr("src","/images/profile_hide.jpg");
	});
	
	$("#emk, #izd, .checkkod").keyup(function(){
		/*var val = parseInt($(this).attr("value"));
		if((val<0)||(isNaN(val)))
			$(this).attr("value","1");
			*/
		var reg = /^([0-9]{1,5})$/;
		var address = $(this).attr("value");
		if(address!="")
		{
			if(reg.test(address) == false) {
				alert('Допустимы только цифры!');
				$(this).attr("value","1");
			}
		}
	});
	
	$(".link, .link_hide").click(function(){
		$("#c"+$(this).attr("rel")+", #a"+$(this).attr("rel")).toggle(); 
		
		if($(this).attr("class")=="link")
			$(this).attr("class","link_hide");
		else
			$(this).attr("class","link");
		return false;
	});
	$(".delq").click(function(){
		var answer = confirm("Вы уверены что хотите удалить это объявление?");
		if (answer){
			return true;
		}
		else{
			return false;
		}
	});
	$("a[rel='check']").click(function(){
		var answer = confirm("Вы уверены что хотите удалить?");
		if (answer){
			return true;
		}
		else{
			return false;
		}
	});
	
	$("#logo_switch").click(function(){
		if(this.checked==true)
		{
			var val = $("#logouf").val();
			$("#logo_file").val("").attr("disabled","disabled");
			$("#logore").val(val);
		}
		else
		{
			$("#logo_file").attr("disabled",false);
			$("#logore").attr("value","");
		}
	});
	
	$(".toggleizdelia").click(function(){
		var id = $(this).attr("rel");
		$("#"+id).toggle();
	});

	$("select[name='arrFilter_pf[diff]'], select[name='arrFilter_pf[size]'], select[name='arrFilter_pf[format]']").change(function(){
		window.location = "/project/marker/templates/?"+$("#arrFilter_form").serialize();
	});
	
	$("a.marker").fancybox({ 'zoomSpeedIn': 300, 'zoomSpeedOut': 300, 'overlayShow': true, 'frameWidth':570, 'frameHeight':400, 'centerOnScroll':true, 'hideOnContentClick':false}); 
	
});