

// фото
$(document).ready(function() {
  $("a[rel=grouped_photos]").fancybox(
  {
    'showCloseButton'   : false,
    'transitionIn'		: 'none',
    'transitionOut'		: 'none',
    'titlePosition' 	: 'inside',

    'onComplete'	:	function()
    {
      $("#fancybox-wrap").hover(function() {
        $("#fancybox-title").show();
      }, function() {
        $("#fancybox-title").hide();
      });
    },
    'titleFormat'		: function(title, currentArray, currentIndex, currentOpts)
    {
      return '<div id="tip7-title"><span><a href="javascript:;" onclick="$.fancybox.close();"><img src="/shared/fancybox/closelabel.gif" /></a></span>' + (title && title.length ? '<b>' + title + '</b>' : '' ) + 'Изображение ' + (currentIndex + 1) + ' из ' + currentArray.length + '</div>';
    }
  });
  
  // close popup
	$('.popupLayer, .popupClose a').click(function() {
		$('.popupLayer, .popupBox').fadeOut();
		return false;
	});
	
	// popup popupContact
	$('.popupContactOpen a').click(function() {
		if ($(this.parentNode).hasClass('map_pos1')) {
			$('.popupBox').css('top','92px').css('left','50%');
		} else if ($(this.parentNode).hasClass('map_pos2')) {
			$('.popupBox').css('top','610px').css('left','51%');
		}
		
		$('.popupLayer, .popupContact').fadeIn('fast');
		$.map_up_redraw();
		return false;
	});
	
	//color tr for table
	$('.priceSlide').find('tr:odd').addClass('colorBG01');
	
	//slider in prices
	$('.priceLink a').click(function() {
		$(this).parent().toggleClass('priceLinkOpen').next().slideToggle();
		return false;
	});
  
});

//разъезжайка seo текста
$(document).ready(function() {
	$('.seo_text')
		.css('display', 'none')
		.after('<a href="#" class="show_seo seo_adown">Читатать текст целиком</a>');
	$('.show_seo').click(
		function() {
			if (this.action == 'expand') {
				$(this).removeClass('seo_adown').text('Скрыть текст').prev().slideDown('fast');
				this.action = 'hide';
			} else if (this.action == 'hide') {
				$(this).addClass('seo_adown').text('Читатать текст целиком').prev().slideUp('fast');
				this.action = 'expand'
			}
			
			return false;
		}
		)
		.each(
		function() {
			this.action = 'expand';
		});
});

//верхнее меню
$(document).ready(function() {
	$('.headerMenuItem').removeClass('headerMenuItem');
	
	var in_animate = false;
	$('.headerMenuIn > span').hover(
		function() {
			if (in_animate) return;
			
			var subMenu = $(this).find('.subMenu');
			
			if (subMenu.length > 0) {
				in_animate = true;
				
				subMenu.fadeIn('fast', function(){in_animate = false});
				$(this).addClass('active');
				$(this).find('> a')
					.css('position','relative')
					.css('z-index', '9999');
			}
		},
		function() {
			var subMenu = $(this).find('.subMenu');

			if (subMenu.length > 0) {
				subMenu.fadeOut('fast');
				$(this).removeClass('active');
				$(this).find('> a')
					.css('position','static')
					.css('z-index', '0');
			}
		}
	);
});

$(document).ready(function() {
	$("a:has(img.ico)").hover(function() {
		var name = $(this).attr("id");
		$("a#"+name+">img").attr("src", "img/"+name+"32.png");
	}, function() {
		var name = $(this).attr("id");
		$("a#"+name+">img").attr("src", "img/"+name+"32bw.png");
	});
	$("input#search").focus(function() {
		$(this).val("");
	});
	$("input#search").blur(function() {
		if($(this).val()=="") { $(this).val("Поиск по сайту"); }
	});

	$("input:text[name=contact_email]").blur(function() {
		var email = $(this).val();
		size = email.length;
		if (size>5) {
			if(!isValidEmail(email)) {
				alert("Проверьте правильность ввода вашего почтового адреса.");
				$(this).val("");
			}
		}
	});

});

function isValidEmail (email)
{
 return (/^([a-z0-9_\-]+\.)*[a-z0-9_\-]+@([a-z0-9][a-z0-9\-]*[a-z0-9]\.)+[a-z]{2,4}$/i).test(email);
}
