// JavaScript Document

$(function(){	
	 $('a,input[type="button"]').bind('focus',function(){ 
	  if(this.blur){ 
			//如果支持 this.blur
			this.blur(); 
		} 
	}); 
	
	$(document.body).click(function(){ 
	$(".my_homepage,.my_notice_info,#ul_sort").hide();
	});
	
	/*
	$('.mine').click(function(){	
		if($('.my_homepage').css('display')=='none') {
			$('.my_homepage').show();
		}else{
			$('.my_homepage').hide();			
			}						  
		$('.my_notice_info').hide();		
	})
	$('.mynotice').click(function(){
		if($('.my_notice_info').css('display')=='none') {
			$('.my_notice_info').show();
		}else{
			$('.my_notice_info').hide();			
			}					  
		$('.my_homepage').hide();						  
	})
	
	$(".mine,.mynotice").click(function(e) {
		e.stopPropagation();
   	});
	*/
	
	$(".sort").click(function(e) {
		e.stopPropagation();
   	});
	$(".text").focus(function(){
		$(this).css("background-color","#FFFCEA");	
	}).blur(function(){
		$(this).css("background-color","#fff");	
	});
/*
function tips(o){     
  o=  (typeof(o)=="undefined")?"c":o ;
   var _st = { 
	//base 
	c: ['嘿，哥们儿，嘛呢？', '既来之，则说之……', '什么叫热闹？大吼小叫！', '“得瑟得瑟”也不犯法！'],
	//6:00 - 9:00 
	m: ['路上堵车吗？', '地铁上遇到帅哥了吗？', '今天没迟到吧？', '今天小报上有什么趣闻？', '繁忙的一天开始，你要说的第一句是什么？'],
	//9:00 - 12:00 
	a: ['你准备买房了吗？', '你是否仍深爱酒井法子？', '贾君鹏回家吃饭了吗？', '今天任务多吗？', '今天中午吃点啥？'],
	//12:00 - 14:00 
	n: ['吃完饭后困了？', '今天中午吃的啥？', '附近新开了家饭馆？', '今天中午有什么八卦吗？', '今天中午和谁吃的饭？'],
	//14:00 - 17:00 
	p: ['今天大猫在公司吗？', '还有几个小时你就下班了？','向好友大声喊两句发泄发泄……', '说的不是一句话，是寂寞……', '工作完成了？'],
	//17:00 - 19:00 
	d: ['今天下班后什么安排？', '今天有人加班吗？', '还不下班？','你妈妈喊你回家吃饭', '有人请客吃饭吗？'],
	//19:00 - 21:00 
	e: ['这一天累吗？跟大家汇报汇报……', '晚上有什么好事儿发生？'],
	//21:00 - 24:00 
	l: ['周围安静吗？聊两句冒个泡', '还没睡？那喊两句吵醒别人！', '你正在干嘛？', '还在工作么？休息一下聊两句……'],
	//0:00 - 6:00 
	w: ['发现什么好玩的了吗？', '我要在这深夜对你们说些心里话……', '夜生活才刚刚开始？'],
	//weekend 
	k: ['周末玩得开心吗？', '周末有人加班吗？', '大周末的，跟朋友扯两句吧', '此刻你在哪呢？', '生活才刚刚开始？']
	};  
	  return _st[o];     
}
function maketips(){
	var hours, xfile; 
	var today;
	today = new Date(); 
	intHours = today.getHours(); 
	 if (intHours <6) {        
		xfile = 'w';
	} else if (intHours < 9) {   
		 xfile = 'm';        
	} else if (intHours < 12) {  
		 xfile = 'a';        
	} else if (intHours < 14) {  
		 xfile = 'n';        
	} else if (intHours < 17) {  
		 xfile = 'p';        
	} else if (intHours < 19) {  
		 xfile = 'd';        
	} else if (intHours < 21) {  
		 xfile = 'e';        
	} else if (intHours < 24) {  
		 xfile = 'l';        
	} else {
	 	xfile = 'c';        
	}       
	
	var Arr = tips(xfile);       
	
   var n = Math.floor(Math.random() * Arr.length + 1)-1;       
   //document.getElementById('tips').innerHTML = Arr[n];    
	  document.title=Arr[n];   
	
	}

	
 
  window.onload = maketips;     
*/
	
	/*
	$(document).click(function(){ 
	$(".my_homepage,.my_notice_info,#ul_sort").hide();
	});

	 $('.nav .current').hover(function(){
		$subNav = $(this).children('.menu');
		$subNav.stop().show();
		 }, function(){
		 $subNav = $(this).children('.menu');
		$subNav.stop().hide();
		 }); 
		  
		function update()
{ 
    $.post("server.jsp", {}, function(data){
        $("#screen").val(data);
        textareaHeight();
    }); 
    setTimeout('update()', 1000);
}
$(document).ready(function(){
    update();
    $("#button").click(function(){            
         $.post("server.jsp", {
                             message: $("#message").val(),
                             username: $("#username").val()
                     },function(data){   
                         $("#screen").val(data);
                         $("#message").val("");
                         textareaHeight();
         });
    });
   
    //回车自动提交内容
    $(document).keypress(function(e){
        if(e.keyCode == 13){
            $("#button").trigger("click");
        }
    })

});


*/  
		  
		  
	$('.up').click(function(){
		$('.first').toggle();
		$('.last').toggle();
	})

	$('.i-add').live("click", function(){
			var ID=$(this).attr('id');	
			var mark=$(this).attr('mark');
			$.post('?m=friend&a=request',
				{ 
				id: ID
				}
				);
			var content ='<p>请求已发送，等待对方确认</p>';																					
			$(content).replaceAll(this);
	})
	
	$('.i-ignore').live("click", function(){

		var ID=$(this).attr('id');	
			$.post('?m=message&a=del',
				{ 
				id: ID
				}
				);
				var ignore=$(this).parent().parent().parent().attr('id');
				$('#'+ignore).hide("slow",function(){
				 $(this).children().remove();
				 }); 
				var content ='<div class="friendAvatar"><a href="/profile.do?u=3707813" title="在你附近上网的人"><img class="avatar-48" src="http://s2.bai.itc.cn/r/i/avatars/48.gif" alt="在你附近上网的人"/></a></div><div class="friendInfo"><h4><a href="/profile.do?u=3707813" title="哆啦小梦">646464</a></h4><p><a id="recommend_3707813" class="icon i-add" href="javascript:void(0)" title="加为好友">加为好友</a><a class="icon i-ignore" href="javascript:void(0)" title="不要再把他推荐给我">不要再把他推荐给我</a></p></div>';
			//	$(this).parent().parent().parent().children().hide('slow', function(){ })
				$('#'+ignore).show("slow",function(){
				 $('#'+ignore).html(content);
					$('.i-ignore').bind
				 }); 
				
; 
	})
/*
	var $content = $('#content');
	var $str  =  $('#str');
	var time;
	var limit_str = 140;
	$content.focus(function(){
		time = window.setInterval( substring,100 );
	});	
	$content.blur(function(){
		window.clearInterval(time);
		substring();
	});
	function substring() {
		var val = $content.val();
		var length = val.length;
		if(length > limit_str){
			$content.val( $content.val().substring(0 , limit_str) );
		}
		if( $str.html() != (limit_str-length ) ){ //跳出循环
			$str.html( (limit_str-length<=0)?'0':limit_str-length );
		}
	}

	// ctrl+enter提交表单
	var $loading = $(".loading");
	var i=0;
	$content.keydown(function(e){
		if(e.ctrlKey&&e.keyCode=="13"){
			$loading.show();
			i++;
			var html ="<p>"+i+"，"+$content.val()+"</p>";
			setTimeout(function(){
				$(html).appendTo("#update");
				$loading.hide();
			},1000);
		}
	});

	
	$('#reply').keydown(function(e){
		if(e.keyCode=="13"){
			var html ="<p>"+$('#reply').val()+"</p>";
			setTimeout(function(){
				$(html).appendTo("#update");
				$loading.hide();
			},1000);
		}
	});
		*/
	$('.selectAll').click(function(){

   if(document.getElementById('selectAll').checked==true)
   {
    $('input[name="checkboxlist[]"]').attr("checked",true);  
   }
   else
   {
    $('input[name="checkboxlist[]"]').attr("checked",false);
   }
   });
	
	
	
	/*$(".del").bind('click',function(){
			var ID=$(this).attr('id');	
			$.post('?m=message&a=del',
				{ 
				id: ID
				}
				);
			$(this).parent().parent().hide('slow', function(){ $(this).remove(); }); 
			
		});*/
	
			   var getQuery = function(separator) {
	if (!separator) separator = ',';
	var query = $('[name="checkboxlist[]"]:checked').map(function(){
			return this.value;
		}).get().join(separator);
	query = encodeURI(query);
	return query;
};
	$(".delete").bind('click',function(){
						var query = getQuery(',');
	if (!query) {
		$.alert(NO_ITEM_SELECTED);
		return false;
	}
	var url = ROOT_URL + 'admin/users-delete/?user=' + query;
	$.confirm(ENSURE_DELETE, function(){
		$.redirect(url, true);
	});	
									   })
	
	
	$('.ignore').click(function(){
								$(this).hide();
								
	/*							})
	 $("input").bind("keyup",function() {
       var str=this.value;
        while (str.replace(/[^\x00-\xFF]/g,"aa").length>8) {
          str=str.substr(0,str.length-1);
        }
        this.value=str;
		*/
  });
	 
	$('.box li,.game').hover(function () {
		$(this).css('background-color',"#F7F7F7");
	  },
	  function(){
		$(this).css('background-color',"#FEFEFE");
	  })
	
	$(".progress small em").each(function(){
		var val=$(this).text();
	$(this).parent().animate({width:val},500);
	});
	

	/*
	
	$('.previewtoggle').click(function(){
	  	 var id=$(this).attr('title'); 	
		 if( id == '热点预览')
		 	{
				$(this).html('关闭预览').attr('title','关闭预览').addClass("preview_off");	
				$(this).parent().parent().next().children('.expand_on').hide();			
				$(this).parent().parent().next().children('.expand_off').slideDown("slow"); 				
			}else{
				$(this).html('热点预览').attr('title','热点预览').removeClass('preview_off');	
				$(this).parent().parent().next().children('.expand_off').hide();			
				$(this).parent().parent().next().children('.expand_on').slideDown("slow"); 
				}
		
	})
	*/
	
	$('.special_game_about li,.records dl,.records_summary li,.covers_summary li,.pop_summary li,.feeds dd,.announcement li').hover(function () {
		$(this).css('background-color',"#F7F7F7");
	  },
	  function(){
		$(this).css('background-color',"#fff");
	  })
	
	$('.covers li').hover(function () {
		$(this).addClass("current_hover");
		$(this).find(".act").show();
	  },
	  function(){
		$(this).removeClass("current_hover");
		$(this).find(".act").hide();
	  })
	
	  
	/*
	 //Default Action
	 $(".tab_content").hide(); //Hide all content
	 $("ul.show_tab li:first a").addClass("choose").show(); //Activate first tab
	 $(".tab_content:first").show(); //Show first tab content

	On Click Event
	 $("ul.show_tab li a").click(function() 	{
	  $("ul.show_tab li a").removeClass("choose"); //Remove any "active" class
	  $(this).addClass("choose"); //Add "active" class to selected tab
	  $(".tab_content").hide();
	  var activeTab = $(this).attr("href"); //Find the href attribute value to identify the active tab + content
  		$(activeTab).fadeIn();  //Fade in the active ID content
		return false; 
	})
	 
	 
	 	 //Default Action
	 $(".tab_content").hide(); //Hide all content
	 $("ul.tabs li:first").addClass("current").show(); //Activate first tab
	 $(".tab_content:first").show(); //Show first tab content

	//On Click Event
	 $("ul.tabs li a").click(function() 	{
	  $("ul.tabs li").removeClass("current"); //Remove any "active" class
	  $(this).parent().addClass("current"); //Add "active" class to selected tab
	  $(".tab_content").hide();
	  var activeTab = $(this).attr("href"); //Find the href attribute value to identify the active tab + content
  		$(activeTab).fadeIn();  //Fade in the active ID content
		//return false; 
	})
	  $('.server_bg').click(function(){
		$(this).find('.server_list').toggle();
									
	})
	 
	 */
	
	  	 
	 $("#thumbnails ul").jcarousel();


	var links = $('#previewbox a')
	links.click(function(){
		$(this).parent().siblings('li').removeClass('current').end().addClass('current');
		$('#preview').attr('src', this.href);
		$('#a_old_img').attr('href', $(this).parent().find("input:hidden").attr("value"));
		$('#information').children().empty().text(this.title);
		return false;
	});

 // back links
	$('a.top').click(function(){
		$(this).parents().scrollTo( 0, 800, { queue:true } );
		return false;
	});
	/* 
$(function(){$(".txt img[src*='510769.com']").replaceWith("<img src='http://www.misuisui.com/images/noimg.png' alt='' />");});
$(function(){$(".txt img[src*='www.510769.com']").replaceWith("<img src='http://www.misuisui.com/images/noimg.png' alt='' />");});
*/ 
});

function setRows( id, row) {	
	var textarea = document.getElementById(id);
	var cols = textarea.cols;
	var str = textarea.value;
	// windows - replace \r\n
	// mac - replace just \r
	// linux - is just \n
	str = str.replace(/\r\n?/, "\n");
	var lines = row;
	var chars = 0;
	for (i = 0; i < str.length; i++) {
		var c = str.charAt(i);
		chars++;
		if (c == "\n" || chars == cols) {
			lines ++;
			chars = 0;
		}
	}
	textarea.setAttribute("rows", lines);
	textarea.style.height = lines*12 + "px";
}