$.fn.extend({
	//自动消失
	autoHide : function(timeout){
		var obj = this;
		setTimeout(function(){obj.remove();}, timeout);
	},
	
	//平滑滚动
	smoothScrolling : function(feedback){
		var obj = this;
		var i = 1;
		//处于兼容浏览器考虑，"html"和"body"各执行1次，为保证highlight仅执行1次，所以设置了变量 i
		if($.browser.opera){
			$animate_operatoer = $("html");
		}else{
			$animate_operatoer = $("html, body");
		}
		$animate_operatoer.animate({
			scrollTop: obj.offset().top
		}, 200,'linear',
		function(){
			if(feedback == 'highlight'){
				if(i==1){
					obj.beautyHighLight();
					i++;
				}
			}
		});
	},
	
	//高亮显示
	beautyHighLight : function(){
		this.effect("highlight", {mode: 'show'}, 1500);
	},
	
	//快捷键
	navHotkey: function(){
		$(document).keydown(function(event){
			if(document.body.scrollTop){
				var screenOffsetTop = document.body.scrollTop;
			}else{
				var screenOffsetTop = document.documentElement.scrollTop;
			}
	
			//向下滚动
			if(event.keyCode == 74  && (!event.ctrlKey)){
				var i = 1;
				$('.hotkey').each(function(){
					if((i == 1) && ($(this).offset().top > (screenOffsetTop + 3))){
						$(this).smoothScrolling('');
						i++;
					}
	
				});
				return false;
			}
			//向上滚动
			if(event.keyCode == 75  && (!event.ctrlKey)){
				var i = 1;
				$('.hotkey').each(function(){
						if((i == 1) && ($(this).offset().top > (screenOffsetTop - 3))){
							$(this).prev().smoothScrolling('');
							i++;
						}
				});
				return false;
			}
			//滚动到顶部
			if(event.keyCode == 84  && (!event.ctrlKey)){
				$('.leader').smoothScrolling('');
				return false;
			}
			//向下滚动
			if(event.keyCode == 66 && (!event.ctrlKey)){
				$('.footer').smoothScrolling('');
				return false;
			}
		});
	},
	//反馈
	feedBack: function(){
		$('#post_feedback').click(function(){
		
			$('#feedback_say').html('反馈发送中...');
			$('#post_feedback').hide();
			$('#feedback_say').addClass('pt_5');
			
			$.post('/ajax/feedback',{
				feedback_content: $('#feedback_content').val()
			 },
			 function(i){
				$('#post_feedback').show();
				$('#feedback_say').html('反馈成功，谢谢您的支持！');
			});
			
			return false;
		});
		
	}
	
});


$(document).ready(function() {
	
	//绑定键盘操作
	$().navHotkey();
	
	//反馈
	$().feedBack();

	//当进入文本框，接触键盘绑定
	$('textarea, input').focus(function(){
		$(document).unbind('keydown', $().navHotkey());
		//postHotkey();
	});
	//当焦点移出文本框，重新绑定键盘操作
	$('textarea, input').blur(function(){
			$().navHotkey();
	});
	//自动消失的提示
	$('.greenTip').autoHide(4500);

});

