$.fn.extend({  
	position:function( value ){  
		var elem = this[0];  
			if (elem&&(elem.tagName=="TEXTAREA"||elem.type.toLowerCase()=="text")) {  
			   if($.browser.msie){  
					   var rng;  
					   if(elem.tagName == "TEXTAREA"){   
							rng = event.srcElement.createTextRange();  
							rng.moveToPoint(event.x,event.y);  
					   }else{   
							rng = document.selection.createRange();  
					   }  
					   if( value === undefined ){  
						 rng.moveStart("character",-event.srcElement.value.length);  
						 return  rng.text.length;  
					   }else if(typeof value === "number" ){  
						 var index=this.position();  
						 index>value?( rng.moveEnd("character",value-index)):(rng.moveStart("character",value-index))  
						 rng.select();  
					   }  
				}else{  
					if( value === undefined ){  
						 return elem.selectionStart;  
					   }else if(typeof value === "number" ){  
						 elem.selectionEnd = value;  
						 elem.selectionStart = value;  
					   }  
				}  
			}else{  
				if( value === undefined )  
				   return undefined;  
			}  
	}  
})

// JavaScript Document
$(document).ready(function(){
	$('.menu li').hover(function(){
		$(this).find('span').stop(true).animate({'top':'42px'},200);
	},function(){
		$(this).find('span').stop(true).animate({'top':'20px'},200);
	});
	$('.hover').hover(function(){
		$(this).addClass('active');
	},function(){
		$(this).removeClass('active');
	});
	
	$('.archive .pictures li:not(:first)').hide();
	$('.archive .thumb li:first').addClass('active');
	var current=0;
	//改变图片
	function changePic(num){
		$('.archive .thumb li.active').removeClass('active');
		$('.archive .pictures li').slideUp();
		$('.archive .pictures li').eq(num).slideDown();
		$('.archive .thumb li').eq(num).addClass('active');
		current=num;
	}
	
	$('.archive .thumb li').click(function(){
		var num=$(this).index();
		if(current != num){
			changePic(num);
		}
	});
	//上一张
	$('.action .pre').click(function(){
		current--;
		if(current<0) current=$('.archive .thumb li').length-1;
		changePic(current);
		return false;
	});
	//下一张
	$('.action .next').click(function(){
		current++;
		if(current>$('.archive .thumb li').length-1) current=0;
		changePic(current);
		return false;

	});
	
	//emotions
	$('.emotions img').click(function(){
		//alert($('#body').position());
		var txt=$('#body').val();
		txt+=$(this).attr('alt')
		$('#body').val(txt);
	});
	
});
