/* drop down menu script */

var droplinemenu = {

	arrowimage: {
		classname: 'downarrowclass', 
		src: 'down.gif', 
		leftpadding: 5
	}, //customize down arrow image
	animateduration: {
		over: 200, 
		out: 0
	}, //duration of slide in/ out animation, in milliseconds

	buildmenu:function(menuid){
		jQuery(document).ready(function($){
			var $mainmenu=$("#"+menuid+">ul")
			var $headers=$mainmenu.find("ul").parent()
			$headers.each(function(i){
				var $curobj=$(this)
				var $subul=$(this).find('ul:eq(0)')
				this._dimensions={
					h:$curobj.find('a:eq(0)').outerHeight()
				}
				this.istopheader=$curobj.parents("ul").length==1? true : false
				if (!this.istopheader)
					$subul.css({
						left:0, 
						top:this._dimensions.h
					})
				var $innerheader=$curobj.children('a').eq(0)
				$innerheader=($innerheader.children().eq(0).is('span'))? $innerheader.children().eq(0) : $innerheader //if header contains inner SPAN, use that
				$innerheader.append(
					/*'<img src="'+ droplinemenu.arrowimage.src
				+'" class="' + droplinemenu.arrowimage.classname
				+ '" style="border:0; padding-left: '+droplinemenu.arrowimage.leftpadding+'px" />'*/
					)
				$curobj.hover(
					function(e){
						var $targetul=$(this).children("ul:eq(0)")
						if ($targetul.queue().length<=1) //if 1 or less queued animations
							if (this.istopheader)
								$targetul.css({
									left: $mainmenu.offset().left, 
									top: $mainmenu.offset().top+this._dimensions.h-3
								})
						if (document.all && !window.XMLHttpRequest) //detect IE6 or less, fix issue with overflow
							$mainmenu.find('ul').css({
								overflow: (this.istopheader)? 'hidden' : 'visible'
							})
						$targetul.fadeIn(droplinemenu.animateduration.over)
					},
					function(e){
						var $targetul=$(this).children("ul:eq(0)")
						$targetul.slideUp(droplinemenu.animateduration.out)
					}
					) //end hover
			}) //end $headers.each()
			$mainmenu.find("ul").css({
				display:'none', 
				visibility:'visible', 
				width:$(".mainBar").width()
			})
			
		}) //end document.ready
	}
};

// плагин для инпутов
(function($) {
	$.fn.inputDefualts = function(options) {
		// дефолтные значения
		var defaults = {
			cl: 'inactiveSiver',
			text: this.val()
		}, 	opts = $.extend(defaults, options);
  		
		this.addClass(opts['cl']); 	// добавляем класс к инпуту
		this.val(opts['text']);			// ставим значение по умолчанию
  		
		// обрабатываем события фокуса на поле
		this.focus(function() {
			if($(this).val() == opts['text']) $(this).val(''); // обнуляем его, если надо
			$(this).removeClass(opts['cl']); // убираем класс
		});
  		
		// теперь очередь блюра
		this.blur(function() {
			if($(this).val() == '') {
				$(this).val(opts['text']); 			// возвращаем значение
				$(this).addClass(opts['cl']); 	// и класс, если надо
			}
		});
	};
	
})(jQuery);

$(document).ready(function() {
	
	// для инпута в поиске
	$('.input').inputDefualts({
		cl: 'inactiveSiver',
		text: 'Ключевое слово'
	});
	
//	$('.customsearch').inputDefualts({
//		cl: 'inactiveSiver',
//		text: 'Поиск события'
//	});	
	
	$('.subscribin').inputDefualts({
		cl: 'inactiveSiver',
		text: 'e-mail'
	});		
	
});


$(window).resize(function() {
			$("#mydroplinemenu>ul").find("ul").css({
				width:$(".mainBar").width()
			})
});


// end плагин для инпутов



$(document).ready(function(){
	
	$(".topContent").css({opacity:0});
	
	$("#accordion dd").hover(function() {
		$(".topContent").stop().animate({opacity:1}, 300);
	}, function() {
		$(".topContent").stop().animate({opacity:0}, 300);
	});		
	
	
	$(".lentaList .readMore").css({opacity:0});
	
	$(".lentaList li").hover(function() {
		$(this).children('a.readMore').stop().animate({opacity:1}, 300);
		$(this).addClass("hover");
	}, function() {
		$(this).children('a.readMore').stop().animate({opacity:0}, 300);
		$(this).removeClass("hover");
	});		


	
	
	
	// удерживать активное положение при наведении в горизонтальном меню
	$('.navigation li').hover(
		function() {
			$(this).addClass("keepHat");
		},
		function() {
			$(this).removeClass("keepHat");
		}
		);
		
		
	// при наведени премиум ховерится бэкграунд	
	$(".mapper .premiumList li").hover(function() { //Hover over event on list item
		$(this).addClass("hoverMover");
		$(this).addClass("chanImg");
	} , function() { //on hover out...

		$(this).removeClass("hoverMover");
		$(this).removeClass("chanImg");
	});
	  
	  
	// баннерные леталки  
	$('.bannerGrid.caption').hover(function(){
		var px = $(".cover", this).height();
		$(".cover", this).stop().animate({
			top:(160-px)+'px'
		},{
			queue:false,
			duration:300
		});
	}, function() {
		$(".cover", this).stop().animate({
			top:'145px'
		},{
			queue:false,
			duration:150
		});
	});
	
	$('.gallery.caption').hover(function(){
		var px = $(".cover", this).height();
		$(".cover", this).stop().animate({
			top:(116-px)+'px'
		},{
			queue:false,
			duration:50
		});
	}, function() {
		$(".cover", this).stop().animate({
			top:'145px'
		},{
			queue:false,
			duration:150
		});
	});
	
	
	// функция для показа фотографии в листинге
	$(".imgPrev").hover(function() {
		$(this).next("div.loadme").fadeIn(200);
	}, function() {
		$(this).next("div.loadme").fadeOut(0);
	});
	
	// ховерит бордюр у строк в таблце
	$(".switchSmall.big li, .objShortBox table tr").hover(function() {
		$(this).addClass("hover"); 
	} , function() {

		$(this).removeClass("hover");
	});
	  
	$("table.myObjTable tr").hover(function() {
		$(this).addClass("hover"); 
	} , function() {

		$(this).removeClass("hover");
	});
	  
	// ставит фэйдин-опасити у фотографий на странице просмотра объявления
	$(".objShortBox .photoBoxer ul.photoPreview li img").hover(function() {
		$(this).addClass("hover").animate({
			opacity: 1
		}); 
	} , function() {

		$(this).removeClass("hover").animate({
			opacity: 0.8
		});
	});
	  
	  
	$("#videoScroller .overview li img").hover(function() {
		$(this).addClass("hover").animate({
			opacity: 1
		}); 
	} , function() {

		$(this).removeClass("hover").animate({
			opacity: 0.8
		});
	});  
	  
	  
	$('#accordion dd').hide();
	$('#accordion dd').first().show();
	$('#accordion dt a').click(function(){
		$('#accordion dd').slideUp();
		$(this).parent().next().slideDown();
		return false;
	});
	
	// функция табов на странице просмотра объявления
	$.fn.extend({  
		tabify: function() {
			function getHref(el){
				hash = $(el).find('a').attr('href');
				if(hash)
					return hash.substring(0,hash.length-0);
				else
					return false;
			}
			function setActive(el){
				$(el).addClass('active');
				if(getHref(el))
					$(getHref(el)).fadeIn('fast');
				else
					return false;
				
				$(el).siblings('li').each(function(){
					$(this).removeClass('active');
					$(getHref(this)).hide();
				}
				);
			}
			return this.each(function() {
				var self = this;
				
				$(this).find('li>a').each(function(){
					$(this).attr('href',$(this).attr('href') + '');
				});
				
				function handleHash(){
					if(location.hash)
						setActive($(self).find('a[href=' + location.hash + ']').parent());
				}
				if(location.hash)
					handleHash();
				setInterval(handleHash,100);
				$(this).find('li').each(function(){
					if($(this).hasClass('active'))
						$(getHref(this)).show();
					else
						$(getHref(this)).hide();
				});
			});
		}
	});
	
	// вызов плагина
	$('.find').inputDefualts({
		cl: 'inactiveSiver',
		text: 'Поиск недвижимости'
	});	
	
	$('.ot').inputDefualts({
		cl: 'inactiveSiver',
		text: 'от'
	});		
	
	$('.do').inputDefualts({
		cl: 'inactiveSiver',
		text: 'до'
	});


	// pop-up show
	$('.popUper').click(function(){
		$('.popup').fadeIn();
		$('.positionBlackWood').show();
		$(this).parent().addClass('active');
		return false;
	});
	
	//popup hide
	$('.positionBlackWood, .closePopUp').click(function(){
		$('.popup').fadeOut();
		$('.positionBlackWood').hide();
		$('#cities').hide();
		$('.popUper').parent().removeClass('active');
		return false;
	});

	
   

	

	// скрыть, закрыть, плюс, минус
    $('.addAdvertFields li ul li ul li ul').first().show();
	$('.addAdvertFields li ul li ul li a.trigger.opened').first().removeClass("opened");

    $('.menu li ul li ul li ul').first().show();
	$('.menu li ul li ul li a.trigger.opened').first().removeClass("opened");

    $('.expert li ul li ul li ul').first().show();
	$('.expert li ul li ul li a.trigger.opened').first().removeClass("opened");
	$("a.trigger").click(function () {
		$(this).next().animate({
			height: 'toggle',
			opacity: 'toggle'
		}, 0);
		$(this).toggleClass("opened");
	});

	// для формы подчаи, показ полей
	$("input[name='offerType']").change(function() {
		if ($("input[name='offerType']:checked").val() == 'rent') {
			$(".rentShower").show("");
		}

		else if ($("input[name='offerType']:checked").val() == 'sale') {
			$(".rentShower").hide("");
		}

	});
	if ($("input[name='offerType']:checked").val() == 'rent') {
		$(".rentShower").show("");
	}
});
