// Paedia
jQuery(function paedia_slider() {
	var time, image_width = jQuery("#paedia_list").width();
	jQuery("#paedia_left").bind('mouseover', function(event) {
		time = setInterval(function (){
			var pos = jQuery("#paedia_list").css("left");
			pos = parseInt(pos);
			var width = jQuery("#paedia_container").width();
			if (pos < 0 ) {
				jQuery("#paedia_list").css({ left: pos + 5 + "px" });
			}
		}, 40)
	});
	
	
	jQuery("#paedia_right, #paedia_right_arrow").bind('mouseover', function(event) {
		time = setInterval(function (){
			var pos = jQuery("#paedia_list").css("left");
			pos = parseInt(pos);
			var width = jQuery("#paedia_container").width();
			if (pos > (width - image_width) ) {
				jQuery("#paedia_list").css({ left: pos - 5 + "px" });
			}
		}, 40)
	});
	
	
	var clear_time = function () {
		clearInterval(time);
	}
	jQuery("#paedia_left").bind('mouseout', clear_time);
	jQuery("#paedia_right, #paedia_right_arrow").bind('mouseout', clear_time);
});

// Search
jQuery(function search() {
	jQuery("#search_field").bind('focus', function(event) {
		if ( jQuery(this).attr("value") == "Поиск по сайту" ) {
			jQuery(this).attr("value","");
		}
	});
	jQuery("#search_field").bind('blur', function(event) {
		if ( jQuery(this).attr("value") == "" ) {
			jQuery(this).attr("value","Поиск по сайту");
		}
	});
});

/* Top Nav Animation */
(function($) {
	$.fn.lavaLamp = function(o) {
	    o = $.extend({ fx: "backout", speed: 500, click: function(){} }, o || {});
	    return this.each(function() {
	        var me = $(this), noop = function(){},
	            $back = $('<li class="back"><div class="left"></div></li>').appendTo(me),
	            $li = $("li", this),curr = $("li.current", this)[0] || $($li[0]).addClass("current")[0];
	            $li.not(".back").hover(function() {
	            move(this)
	        }, noop);
	
	        $(this).hover(noop, function() {
	            move(curr);
	        });
	        $li.click(function(e) {
	            setCurr(this);
	            return o.click.apply(this, [e, this]);
	        });
	        setCurr(curr);
	        function setCurr(el) {
	            $back.css({ "left": el.offsetLeft + 5 +"px", "width": el.offsetWidth -10 +"px" });
	            curr = el;
	        };
	
	        function move(el) {
	            $back.each(function() {
	                $(this).stop(this, "fx"); }
	            ).animate({
	                width: el.offsetWidth - 10,
	                left: el.offsetLeft + 5
	            }, o.speed, o.fx);
	        };
	
	    });
	
	};
	$(function() {
		$(".col-menu,").lavaLamp({
		fx: "backout", 
		speed: 700,
		click: function(event, menuItem) {
			return true;
			}
		});
	});
	
	
	/* Hover Buttons */
	$(function rss() {
		$(".col-rss img").bind('mouseenter', function () {
			$(this).attr({src: "/@/fit/rss-hover.gif"});
		});
		$(".col-rss img").bind('mouseleave', function () {
			$(this).attr({src: "/@/fit/rss.gif"});
		});
	});
	
	$(function submit() {
		$(".col-submit-button img").bind('mouseenter', function () {
			$(this).attr({src: "/@/fit/submitad-hover.png"});
		});
		$(".col-submit-button img").bind('mouseleave', function () {
			$(this).attr({src: "/@/fit/submitad.png"});
		});
	});
	
	
	/* Email Block */
	$(function email_block() {
		$(".col-email").bind('click', function () {
			$("#email_block").slideToggle();
			return false;
		});
		
		$(".col-email-dismiss").bind('click',  function () {
	      $("#email_block").slideToggle();
	      return false;
	   }); 
	})
	
	
	/* Sign Popup */
	$(function sign() {
		$("#sign-button").bind('mouseenter', function () {
			$(this).attr({src: "/@/fit/login-hover.png"});
		});
		$("#sign-button").bind('mouseleave', function () {
			$(this).attr({src: "/@/fit/login.png"});
		});
		
		$("#signin").bind('click', function () {
	
				$("#bg").show();
				$("#signup").show();
	
			$("#login").focus();
			return false;
		});
		$("#bg").bind('click', function () {
			$("#bg").hide();
			$("#signup").hide();
		});
		$("#signup form div span a").bind('click', function () {
			$("#bg").hide();
			$("#signup").hide();
			return false;
		});
	});
})(jQuery);