/*加入本机书签*/
function add_bookmark(title,url) {
	if (window.sidebar) {
		window.sidebar.addPanel(title, url,"");
	} else if( document.all ) {
		window.external.AddFavorite( url, title);
	} else if( window.opera && window.print ) {
		return true;
	}
}
/*设置为首页*/
function set_homepage(url){
	if (document.all)
	{
		document.body.style.behavior='url(#default#homepage)';
		document.body.setHomePage(url);
	}else{
		if (window.sidebar)
		{
			try {
				netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
			}
			catch (e)
			{
				alert("此操作被浏览器拒绝！\n请在浏览器地址栏输入“about:config”并回车\n然后将[signed.applets.codebase_principal_support]设置为'true'");
				return false;
			}
			var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
			prefs.setCharPref('browser.startup.homepage',url);

		}
	}
}


function preview_icon(){

	var _file = document.getElementById("file");

	if(!_file.value){

		return false;

	}

	var path = /\.jpg$|\.jpeg$|\.gif$/i;

	if(path.test(_file.value)){

		var _icon = document.getElementById("icon");


		if(_icon){

			_icon.src = 'file://localhost/' + _file.value;

		}

	}else{

		alert('您上传的不是图像文件或不支持该文件类型！');

	}

}

//模仿trim()函数
String.prototype.trim = function(){

	return this.replace(/^\s+|\s+$/g,'');

}

function check_search(){
	
	var _wd = document.getElementById('wd');
	
	if(_wd.value.trim() == ""){
		
		_wd.focus();
		
		alert("请您输入搜索关键字！");
		
		return false;
	}
	
	if(_wd.value.trim().length < 2){
		
		_wd.focus();
		
		alert("很抱歉，搜索关键字长度不能少于2个字符！");
		
		return false;
	}
	
	return true;
	
}

/*复制到剪贴板*/

function copy(txt,dir) 
{
	if (window.clipboardData) 
	{
		window.clipboardData.setData("Text",txt);
	} 
	else 
	{
		var flashcopier = 'flashcopier';
		if(!document.getElementById(flashcopier)) 
		{
			var divholder = document.createElement('div');
			divholder.id = flashcopier;
			document.body.appendChild(divholder);
		}
		document.getElementById(flashcopier).innerHTML = '';
		var divinfo = '<embed src="'+dir+'/_clipboard.swf" FlashVars="clipboard='+escape(txt)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';
		document.getElementById(flashcopier).innerHTML = divinfo;
	}

	alert("网址已经复制成功，你可以利用快捷键Ctrl+V粘贴到QQ或MSN里！")
}


/*我的收藏全部展开/收起*/
var classname;
var show;
function show_list(){
	if($.cookie('myshow')!=null){
		show=$.cookie('myshow');
	}
	obj=document.getElementsByTagName('div');
	if(show==1)
	{
		classname="listitem listitemclose";
		document.getElementById('showimg').src=document.getElementById('showimg').src.replace('closeall','openall');
		show=0;
	}else{
		classname="listitem";
		document.getElementById('showimg').src=document.getElementById('showimg').src.replace('openall','closeall');
		show=1;
	}
	$.cookie('myshow',show,{expires:7});
	for(i=0;i<obj.length;i++){
		if (obj[i].className == 'listitem' || obj[i].className == 'listitem listitemclose'){
			obj[i].className=classname;
		}
	}
}
/*我的收藏 单个展开/收起*/
function showlistone(obj){
	if (obj.parentNode.parentNode.parentNode.className=='listitem')
	{
		obj.parentNode.parentNode.parentNode.className='listitem listitemclose'
	}else{
		obj.parentNode.parentNode.parentNode.className='listitem'
	}
}
/*反选功能*/
function choose_other(object){
	for (var i = 0 ; i < object.form.elements.length ; i++) {
		var e = object.form.elements[i];
		if(e.name != object.name && e.type == 'checkbox'){
			if(e.checked){
				e.checked =  false
			}else{
				e.checked =  true;
			}
		}
	}
}
/*全选*/
function choose_all(object) {
	for (var i = 0 ; i < object.form.elements.length ; i++) {
		var e = object.form.elements[i];
		if(e.name != object.name && e.type == 'checkbox'){
			e.checked = object.checked;
		}
	}
}

/*验证码更新*/
function change_imgcode(){
	var nowtime	 = new Date().getTime();
	$('#imgcodeshow').attr('src','/code.php?nowtime=' + nowtime);
}
/*显示上传头像*/
function diplay_icon(){
	document.getElementById('filebox').style.display='block';
}

function change_defualt_icon(value){

	var dir = $('#icon').attr('alt');

	var tmp = $('#icon').attr("src").replace(dir,'');

	if(tmp == '0.gif' || tmp == '1.gif'){

		$('#icon').attr("src",dir+value+'.gif');

	}

}


/*评论*/
function check_comment(){
	
	/*
	 是否在线判断
     if(document.getElementById('is_online')){
     	
	    if(document.getElementById('is_online').value == 'no'){

	    	alert("请您先登陆，再进行评论！");

	    	return false;
	    
	    }
	    
     }
     */
	
	if($('#content').val().length<10){
		alert('评论不能少于10个字符!');
		$('#content')[0].focus();
		return false;
	}
	if($('#imgcode').val()==''){
		$('#imgcodeerror').html('请您输入验证码!');
		$('#imgcodeerror').show();
		$('#imgcode')[0].focus();
		return false;
	}
	return true;
}


function change_icon(imgvalue,dir){

	document.getElementById('icon').src = dir+imgvalue+'.gif';

	document.getElementById('iconvalue').value = imgvalue+'.gif';

}

// 分类切换
function selectTag(showContent,selfObj,num){
	var tag = document.getElementById(showContent).getElementsByTagName("li");
	var taglength = tag.length;
	for(i=0; i<taglength; i++){
		tag[i].className = "";
	}
	selfObj.className = "focu";
	for(i=0;i<3; i++){
		if(document.getElementById(showContent+"_"+i)){
			j=document.getElementById(showContent+"_"+i)
			if (i==num)
			{
				j.style.display = "block";
			}else{
				j.style.display = "none";
			}
		}
	}
}
// 分类选择
function seletcclass(p,c){
	$('#a_'+c).attr("class","bold");
	$('#li_'+p).trigger("onmouseover");
}

//首页搜索
function search(type){
	if (type=='baidu')
	{
		url='http://www.baidu.com/s';
		target='_blank';
	}else{
		url='/index.php';
		target='_self';
	}
	document.searchform.action=url;
	document.searchform.target=target;
}

function delthis(lid){
  if(confirm("确定要删除这个收藏吗？")){
		 $(':checkbox').attr('checked','');
		 $('#lid_'+lid).attr("checked",true);
		 $('#action').attr("value",'del');
		 document.getElementById('myfav').submit();
		 return true;
   } 
}
function ck(){
   var ischoose=false;
   for (var i = 0 ; i <$("input[name='lid[]']").length ; i++) {
		if($("input[name='lid[]']").get(i).checked){
			 ischoose=true;
			 break;
		}
	}
	return ischoose;
}
function movetag(){
    type=$("input[@type=radio][@checked]").val();
    if (type=='old')
    {
		if ($('#taglist').val()=='')
		{
			alert('请选择要移动到的标签');
		}
    }else{
	   if ($('#newtag').val()=='')
	   {
		    alert('请输入新的标签');
	   }
	}
	document.getElementById('myfav').submit();
}
function selaction(action){
   $('#action').attr("value",action);
   $('#actionsel').hide();
   ischoose=ck();
   if (action=='move')
   { 
	   if (ischoose){
	      $('#movewin').show();
		  $('#tagload').show();
          $.post('/index.php?q=my_collection', {
		    action:'alltag'
	      }, function(HTML){
		     $('#taglist').html(HTML);
	       }); 
          $('#tagload').hide();
          
   
	   }else{
		   alert('请选择要移动的收藏');
	   }           
   }else{
        if (ischoose)
        {
          if(confirm("确定要删除选择的收藏吗？")){
              document.getElementById('myfav').submit();
          }          
        }else{
		   alert('请选择要删除的收藏');
		}
   }
     
}
// tag
function showtag(uid,offset,type){
	    if(type=='owen'){
			posturl='my_collection';
		}else{
		    posturl='user';
		}
        $.post('/index.php?q='+posturl, {
		action:'showtag',
		uid: uid,
		offset: offset,
		type: type
	}, function(HTML){
		$('#usercate').html(HTML);
	}
	);  
}
// 搜索
function gosearch(){
	keyword=$('#wd').val();
	if (keyword=='')
	{
		showsearcherror('搜索关键词不能为空');
		return false;
	}
	if (keyword.length<2)
	{
		showsearcherror('搜索关键词长度不能少于2个字节!');
		return false;
	}
	getsearch(keyword,0,'');
	return false;
}

function keywordlight(keyword){
   var reg=new RegExp("("+keyword+")","g");
   $("a.title").each(function(){
	     newtitle=$(this).text().replace(reg,"<font color=red>$1</font>");
	     $(this).html(newtitle);
   });
}
function showsearcherror(msg){
	$('#list').html('<div class="err" style="margin-bottom:10px;"><div class="errormsg">'+msg+'</div></div>');
}
function getsearch(keyword,offset,type){
	$('#list').html('<div class="tab2"><em class="loading">正在搜索中...</em></div>');
	$.post('index.php?q=search', {
		wd: keyword,
		offset: offset,
		type: type
	}, function(HTML){
		$('#main').html(HTML);
		if(type=='img' || type=='')FAV114LA.initimg();
	}
	);
}
// 首页ajax却换
function showlist(type,selfobj){
	for(i=1;i<=3;i++){
		document.getElementById('site'+i).className='';
	}
	GetLink(type,0);
	selfobj.className='focu';
}
function GetLink(type,offset){
	$('#ajaxloading').show();
	//$('#ajaxlink').html('');
	$.post('index.php?q=ajax', {
		type: type,
		offset: offset
	}, function(HTML) {
		$('#ajaxlink').html(HTML);
		FAV114LA.initimg();
	}
	);
}
//cookie
$.cookie = function(name, value, options) {
	if (typeof value != 'undefined') { // name and value given, set cookie
		options = options || {};
		if (value === null) {
			value = '';
			options.expires = -1;
		}
		var expires = '';
		if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
			var date;
			if (typeof options.expires == 'number') {
				date = new Date();
				date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
			} else {
				date = options.expires;
			}
			expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
		}
		var path = options.path ? '; path=' + options.path : '';
		var domain = options.domain ? '; domain=' + options.domain : '';
		var secure = options.secure ? '; secure' : '';
		document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
	} else { // only name given, get cookie
		var cookieValue = null;
		if (document.cookie && document.cookie != '') {
			var cookies = document.cookie.split(';');
			for (var i = 0; i < cookies.length; i++) {
				var cookie = $.trim(cookies[i]);
				// Does this cookie string begin with the name we want?
				if (cookie.substring(0, name.length + 1) == (name + '=')) {
					cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
					break;
				}
			}
		}
		return cookieValue;
	}
};
// 预览图
$.fn._height=$.fn.height;
$.fn._width=$.fn.width;
$.fn.height=function(){
	if(this[0]==window)
	return self.innerHeight||$.boxModel&&document.documentElement.clientHeight||document.body.clientHeight;
	if(this[0]==document)
	return Math.max(document.body.scrollHeight,document.body.offsetHeight);
	return this._height(arguments[0]);
} ;
$.fn.width=function(){
	if(this[0]==window)
	return self.innerWidth||$.boxModel&&document.documentElement.clientWidth||document.body.clientWidth;
	if(this[0]==document)
	return Math.max(document.body.scrollWidth,document.body.offsetWidth);
	return this._width(arguments[0]);
} ;
$.fn.innerHeight=function(){
	return this[0]==window||this[0]==document?this.height():this.css('display')!='none'?this[0].offsetHeight-(parseInt(this.css("borderTopWidth"))||0)-(parseInt(this.css("borderBottomWidth"))||0):this.height()+(parseInt(this.css("paddingTop"))||0)+(parseInt(this.css("paddingBottom"))||0);
} ;

$.fn.innerWidth=function(){
	return this[0]==window||this[0]==document?this.width():this.css('display')!='none'?this[0].offsetWidth-(parseInt(this.css("borderLeftWidth"))||0)-(parseInt(this.css("borderRightWidth"))||0):this.height()+(parseInt(this.css("paddingLeft"))||0)+(parseInt(this.css("paddingRight"))||0);
} ;

$.fn.outerHeight=function(){
	return this[0]==window||this[0]==document?this.height():this.css('display')!='none'?this[0].offsetHeight:this.height()+(parseInt(this.css("borderTopWidth"))||0)+(parseInt(this.css("borderBottomWidth"))||0)
	+(parseInt(this.css("paddingTop"))||0)+(parseInt(this.css("paddingBottom"))||0);
} ;

$.fn.outerWidth=function(){
	return this[0]==window||this[0]==document?this.width():this.css('display')!='none'?this[0].offsetWidth:this.height()+(parseInt(this.css("borderLeftWidth"))||0)+(parseInt(this.css("borderRightWidth"))||0)
	+(parseInt(this.css("paddingLeft"))||0)+(parseInt(this.css("paddingRight"))||0);
} ;

$.fn.scrollLeft=function(){
	if(this[0]==window||this[0]==document)
	return self.pageXOffset||$.boxModel&&document.documentElement.scrollLeft||document.body.scrollLeft;
	return this[0].scrollLeft;
} ;

$.fn.scrollTop=function(){
	if(this[0]==window||this[0]==document)
	return self.pageYOffset||$.boxModel&&document.documentElement.scrollTop||document.body.scrollTop;
	return this[0].scrollTop;
} ;

$.fn.offset=function(options,returnObject){

	var x=0,y=0,elem=this[0],parent=this[0],op,sl=0,st=0,options=$.extend({

		margin:true,border:true,padding:false,scroll:true

	} ,options||{


	} );

	do{

		x+=parent.offsetLeft||0;

		y+=parent.offsetTop||0;

		if($.browser.mozilla||$.browser.msie){

			var bt=parseInt($.css(parent,'borderTopWidth'))||0;

			var bl=parseInt($.css(parent,'borderLeftWidth'))||0;

			x+=bl;

			y+=bt;

			if($.browser.mozilla&&parent!=elem&&$.css(parent,'overflow')!='visible'){

				x+=bl;

				y+=bt;


			}

		}

		if(options.scroll){

			op=parent.offsetParent;

			do{

				sl+=parent.scrollLeft||0;

				st+=parent.scrollTop||0;

				parent=parent.parentNode;

				if($.browser.mozilla&&parent!=elem&&parent!=op&&$.css(parent,'overflow')!='visible'){

					y+=parseInt($.css(parent,'borderTopWidth'))||0;

					x+=parseInt($.css(parent,'borderLeftWidth'))||0;


				}

			} while(parent!=op);


		} else

		parent=parent.offsetParent;

		if(parent&&(parent.tagName.toLowerCase()=='body'||parent.tagName.toLowerCase()=='html')){

			if(($.browser.safari||($.browser.msie&&$.boxModel))&&$.css(parent,'position')!='absolute'){

				x+=parseInt($.css(op,'marginLeft'))||0;

				y+=parseInt($.css(op,'marginTop'))||0;


			}

			break;


		}

	} while(parent);

	if(!options.margin){

		x-=parseInt($.css(elem,'marginLeft'))||0;

		y-=parseInt($.css(elem,'marginTop'))||0;


	}

	if(options.border&&($.browser.safari||$.browser.opera)){

		x+=parseInt($.css(elem,'borderLeftWidth'))||0;

		y+=parseInt($.css(elem,'borderTopWidth'))||0;


	} else if(!options.border&&!($.browser.safari||$.browser.opera)){

		x-=parseInt($.css(elem,'borderLeftWidth'))||0;

		y-=parseInt($.css(elem,'borderTopWidth'))||0;


	}

	if(options.padding){

		x+=parseInt($.css(elem,'paddingLeft'))||0;

		y+=parseInt($.css(elem,'paddingTop'))||0;


	}

	if(options.scroll&&$.browser.opera&&$.css(elem,'display')=='inline'){

		sl-=elem.scrollLeft||0;

		st-=elem.scrollTop||0;


	}

	var returnValue=options.scroll?{

		top:y-st,left:x-sl,scrollTop:st,scrollLeft:sl

	} :{

		top:y,left:x

	} ;

	if(returnObject){

		$.extend(returnObject,returnValue);

		return this;


	}

	else{

		return returnValue;


	}

} ;
 var countimg=new Image(); 
FAV114LA={
	initimg:function(){
		var timeOutID=null;
		var hideSnap=function(){
			$("#bigsnap").hide().css(
			{"top":"-400px","left":"-400px"}
			);
		};
		$('#bigsnap').mouseover(function(){window.clearTimeout(timeOutID);$(this).show();
		}).mouseout(function(){
			$(this).hide();
		});
		$("img.LA_snapview").each(function(){
			$(this).mouseover( function(){
				window.clearTimeout(timeOutID);
				//if($(this).attr("src").indexOf("/images/home/nopic_small.jpg")!='-1'){return;};
				var bigImgUrl=$(this).attr("src").replace("small","medium");
				var offset={};
				$(this).offset({},offset);
				var dir=$(this).attr("snapdir");
				var snapTop=offset.top-33;
				var snapLeft=-400;
				if(dir=="right"){
					snapLeft=offset.left+120;
					$("#bigsnap").attr("class","bigsnap1");
				}else{
					snapLeft=offset.left-330;
					$("#bigsnap").attr("class","bigsnap2");
				}
				$("#bigsnap").css({"top":snapTop,"left":snapLeft}).show();
				$("#LA_prewImgLink").html("<img id='LA_prewimg' src='"+bigImgUrl+"' class='snap' >");
				$("#LA_prewImgLink").attr("href",$(this).attr("aURL"));
				$("#LA_prewdetail").attr("href",$(this).attr("aURL"));
				$("#LA_addpost").attr("href","/index.php?q=add&t="+encodeURIComponent($(this).attr("aTitle"))+"&u="+encodeURIComponent($(this).attr("aLinkURL")));
				var strTitle=$(this).attr("aTitle");
				$("#LA_prewurl").text(strTitle).attr("href",$(this).attr("aLinkURL")).attr("title",$(this).attr("aTitle")).attr("class","mid").attr("mid",$(this).attr("amid"));}).mouseout(function(){timeOutID=window.setTimeout(hideSnap,250);
				$("#LA_prewurl").click(function(){
				     countimg.src ='/count.php?action=count&mid='+$(this).attr('mid');
					  
				});					    
				});
				});
				$("#bigsnap").mouseover(function(){
					window.clearTimeout(timeOutID);
					$(this).show();
				}).mouseout(function(){
					$(this).hide();
				});
				
				$("A.mid").each(function(){
		           var mid=$(this).attr('mid');
			       if(mid!='')
			       {
				      $(this).click(function() {
　　                    countimg.src ='/count.php?action=count&mid='+$(this).attr('mid');
                         
                        });
			       }
		        });

	}
};


