jQuery.noConflict();
jQuery(document).ready(function($){
	function initFeedBackFormEvents()
	{
		var obFldFeedBackContainer = $(".feedback input");
		
		if(obFldFeedBackContainer != null)
		{
			for(var i=0; i < obFldFeedBackContainer.length; i++)
			{
				/**
				 * Скрытие лэйблов для FeedBack - input
				 */
				$($(".feedback input").get(i)).bind('focus', function(){
					var obFldLabel = null;
					var sFldType = $(this).attr('type');
					if(sFldType != null && sFldType !== 'submit' && sFldType !== 'image' && sFldType !== 'hidden')
					{
						obFldLabel = $("label[for=" + $(this).attr("id") + "]", $(this).parent());
						if(obFldLabel != null)
						{
							obFldLabel.hide();
						}
					}
				});
				
				/**
				 * Показ лэйблов для FeedBack - input
				 */
				$($(".feedback input").get(i)).bind('blur', function(){
					var obFldLabel = null;
					var sFldType = $(this).attr('type');
					if(sFldType != null && sFldType !== 'submit' && sFldType !== 'image' && sFldType !== 'hidden')
					{
						obFldLabel = $("label[for=" + $(this).attr("id") + "]", $(this).parent());
						if(obFldLabel != null && !$(this).val().length)
						{
							obFldLabel.show();
						}
					}
				});
			}
		}
		
		var obFldFeedBackContainer = $(".feedback textarea");
		
		if(obFldFeedBackContainer != null)
		{
			for(var i=0; i < obFldFeedBackContainer.length; i++)
			{
				/**
				 * Скрытие лэйблов для FeedBack - textarea
				 */
				$($(".feedback textarea").get(i)).bind('focus', function(){
					var obFldLabel = null;
					obFldLabel = $("label[for=" + $(this).attr("id") + "]", $(this).parent());
					if(obFldLabel != null)
					{
						obFldLabel.hide();
					}
				});
				
				/**
				 * Показ лэйблов для FeedBack - textarea
				 */
				$($(".feedback textarea").get(i)).bind('blur', function(){
					var obFldLabel = null;
					obFldLabel = $("label[for=" + $(this).attr("id") + "]", $(this).parent());
					if(obFldLabel != null && !$(this).val().length)
					{
						obFldLabel.show();
					}
				});
			}
		}
		
		$(".feedback input[type=submit]").bind("click", function(){
			var arData = new Object();
			var sFldType = null;
			var sFldName;
			
			var obFldContainer = $(".feedback input");
			var obItem = null;
			if(obFldContainer != null)
			{
				for(i=0; i<obFldContainer.length; i++)
				{
					obItem = obFldContainer.get(i);
					sFldType = $(obItem).attr('type');
					if(sFldType != null)// && sFldType !== 'submit' && sFldType !== 'image' && sFldType !== 'hidden')
					{
						sFldName = $(obItem).attr("name");
						arData[sFldName] = $(obItem).val();
					}
				}
			}
			
			obFldContainer = $(".feedback textarea");
			obItem = null;
			if(obFldContainer != null)
			{
				for(i=0; i<obFldContainer.length; i++)
				{
					obItem = obFldContainer.get(i);
					sFldName = $(obItem).attr("name");
					arData[sFldName] = $(obItem).val();
				}
			}
			
			$.post(
				"/feedback.php?ajax=1",
				arData,
				function(data){ onLoadFeedBack(data) },
				"html"
			);
			
			return false;
		});
	}
	
	function initFormLabelsShow()
	{
		/**
		 * Скрытие лэйблов для search
		 */
		$(".search input").bind('focus', function(){
			var obFldLabel = null;
			var sFldType = $(this).attr('type');
			if(sFldType != null && sFldType !== 'submit' && sFldType !== 'image' && sFldType !== 'hidden')
			{
				obFldLabel = $("label[for=" + $(this).attr("id") + "]", $(this).parent());
				if(obFldLabel != null)
				{
					obFldLabel.hide();
				}
			}
		});
		
		/**
		 * Показ лэйблов для search
		 */
		$(".search input").bind('blur', function(){
			var obFldLabel = null;
			var sFldType = $(this).attr('type');
			if(sFldType != null && sFldType !== 'submit' && sFldType !== 'image' && sFldType !== 'hidden')
			{
				obFldLabel = $("label[for=" + $(this).attr("id") + "]", $(this).parent());
				if(obFldLabel != null && !$(this).val().length)
				{
					obFldLabel.show();
				}
			}
		});
	}
	
	function onLoadFeedBack(data)
	{
		$(".feedback").html(data);
		//alert(data);
		initFeedBackFormEvents();
	}
	
	function initFeedBackPopupEvents()
	{
		/**
		 * Показ-скрытие формы обратной связи
		 */
		$(".addquestion span").click(function(){
			var obFeedBack = $(".feedback");
			if(obFeedBack != null)
			{
				if(obFeedBack.css("display") == "none") obFeedBack.slideDown(500);
				else obFeedBack.slideUp(500);
			}
		});

		$(".feedback .close").click(function(){
			var obFeedBack = $(".feedback");
			obFeedBack.slideUp(500);
		});
	}

	
	
	/*---------------------------------------------------*/
	initFeedBackFormEvents();
	
	initFormLabelsShow();
	
	initFeedBackPopupEvents();
	
	
	setInterval(function() { 
		var $MainLenta = $('.slider');
		var $MainLentaItems = $MainLenta.find('> a');
		var itemWidth = 160;	
		$MainLenta.animate({ left:-170 }, 400, function(){
			$MainLenta.append($MainLentaItems.eq(0)).css({ left:0 });
				});},3000);
	
	
});
