function callback(fun,argum){
	fun(argum);
}

// 删除类型框
function delTypeBox(){
	$('input[name="publish_type"]').val( 0 );
	$('.talkPop').remove();
}

$(document).ready(function(){
	  // 评论切换
	  $("a[rel='comment']").live('click',function(){
	      var id = $(this).attr('minid');
	      var $comment_list = $("#comment_list_"+id);
		  if( $comment_list.html() == '' ){
			  $comment_list.html('<div class="feed_quote feed_wb" style="text-align:center"><img src="'+ _THEME_+'/images/icon_waiting.gif" width="15"></div>');
			$.post( U("weibo/Index/loadcomment"),{id:id},function(txt){
				$comment_list.html( txt ) ;
			});
		  }else{
			  $comment_list.html('');
		  }
	  });
	  
	

	// 发布评论
	$("form[rel='miniblog_comment']").live("submit", function(){
		var _this = $(this);
		var callbackfun = _this.attr('callback');
		var _comment_content = _this.find("textarea[name='comment_content']");
		if( _comment_content.val()=='' ){
			ui.error('内容不能为空');
			return false;
		}
		_this.find("input[type='submit']").val( '评论中...').attr('disabled','true') ;
		var options = {
		    success: function(txt) {
				txt = eval('('+txt+')');
				_this.find("input[type='submit']").val( '确定');
			       _this.find("input[type='submit']").removeAttr('disabled') ;
				   _comment_content.val('');
				if(callbackfun){
					callback(eval(callbackfun),txt);
				}else{
					_comment_content.css('height','');
			       $("#comment_list_before_"+txt.data['weibo_id']).after( txt.html );
				   

				   $("#replyid_" + txt.data['weibo_id'] ).val('');
				   //更新评论数
				   $("a[rel='comment'][minid='"+txt.data['weibo_id']+"']").html("评论("+txt.data['comment']+")");
				 //  _this.find("textarea[name='comment_content']").focus();
				   
				}
		    }
		};
		_this.ajaxSubmit( options );
	    return false;
	});
});

weibo = function(){
	
}

weibo.prototype = {
	//初始化分享发布
	init:function(option){
		var __THEME__ = "http://old.tiaojie.com/public/themes/jumin";
		var Interval;
		$("#publish_type_content_before").html("<span>添加：</span><a href=\"javascript:void(0)\" target_set=\"content_publish\" onclick=\"ui.emotions(this)\" class=\"a52\"><img class=\"icon_add_face_d\" src=\""+__THEME__+"/images/zw_img.gif\" />表情</a> <a href=\"javascript:void(0)\" onclick=\"addtheme()\" class=\"a52\"><img class=\"icon_add_topic_d\" src=\""+__THEME__+"/images/zw_img.gif\" />话题</a><a href=\"javascript:void(0)\" onclick=\"weibo.plugin.goods.click(150)\" class=\"a52\" id=\"shoplogo\">宝贝</a> <a href=\"javascript:void(0)\" onclick=\"weibo.plugin.image.click(200)\" class=\"a52\"><img class=\"icon_add_img_d\" src=\""+__THEME__+"/images/zw_img.gif\" />图片</a> <a href=\"javascript:void(0)\" onclick=\"weibo.plugin.dapei.click(250)\" class=\"a52\"><img class=\"icon_add_img_d2\" src=\""+__THEME__+"/images/zw_img.gif\" />搭配</a> <a href=\"javascript:void(0)\" onclick=\"weibo.plugin.shaihuo.click(310)\" class=\"a52\"><img class=\"icon_add_img_d3\" src=\""+__THEME__+"/images/zw_img.gif\" />晒货</a><a href=\"javascript:void(0)\" onclick=\"weibo.plugin.video.click(360)\" class=\"a52\"><img class=\"icon_add_video_d\" src=\""+__THEME__+"/images/zw_img.gif\" />视频</a> <a href=\"javascript:void(0)\" onclick=\"weibo.plugin.music.click(405)\" class=\"a52\"><img class=\"icon_add_music_d\" src=\""+__THEME__+"/images/zw_img.gif\" />音乐</a>");

		$("#content_publish").keypress(function(event){
			var key = event.keyCode?event.keyCode:event.which?event.which:event.charCode;
	        if (key == 27) {
	        	clearInterval(Interval);
	        }
			weibo.checkInputLength(this,140);
		}).blur(function(){
			clearInterval(Interval);
			weibo.checkInputLength(this,140);
		}).focus(function(){
			//分享字数监控
			clearInterval(Interval);
		    Interval = setInterval(function(){
		    	weibo.checkInputLength('#content_publish',140);
			},300);
		});
		weibo.checkInputLength('#content_publish',140);
		shortcut('ctrl+return',	function(){weibo.do_publish();clearInterval(Interval);},{'target':'miniblog_publish'});
	},
	//发布前的检测
	before_publish:function(){
		
		if( $.trim( $('#content_publish').val() ) == '' ){
            ui.error('内容不能为空');		
			return false;
		}
		return true;
	},
	//发布操作
	do_publish:function(){
		if( weibo.before_publish() ){
			weibo.textareaStatus('sending');
			var options = {
			    success: function(txt) {
			      if(txt){
			    	   weibo.after_publish(txt);
			      }else{
	                  alert( '发布失败' );
			      }
				}
			};		
			$('#miniblog_publish').ajaxSubmit( options );
		    return false;
		}
	},
	//分享专题发布操作
	do_publish_zhuanti:function(){
		if( weibo.before_publish() ){
			weibo.textareaStatus('sending');
			var options = {
			    success: function(txt) {
			      if(txt){
			    	   weibo.after_publish_zhuanti(txt);
			      }else{
	                  alert( '发布失败' );
			      }
				}
			};		
			$('#miniblog_publish').ajaxSubmit( options );
		    return false;
		}
	},
	//发布后的处理
	after_publish:function(txt){
		if(txt==0) {
			ui.success('您发布的分享含有敏感词，请等待审核！');
		}else {
			delTypeBox();
		    $("#feed_list").prepend( txt ).slideDown('slow');
		    var sina_sync = $('#sina_sync').attr('checked');
		    $('#miniblog_publish').clearForm();
		    if (sina_sync) {
		    	$('#sina_sync').attr('checked', true);
		    }
		    weibo.upCount('weibo');
		    ui.success('分享发布成功');
			$("#taobao").hide();
		    weibo.checkInputLength('#content_publish',140);
		}
	},
	//分享专题发布后的处理
	after_publish_zhuanti:function(txt){
		if(txt==0) {
			ui.success('您发布的分享含有敏感词，请等待审核！');
		}else {
			delTypeBox();
		    $("#feed_list").prepend( txt ).slideDown('slow');
		    var sina_sync = $('#sina_sync').attr('checked');
		    $('#miniblog_publish').clearForm();
		    if (sina_sync) {
		    	$('#sina_sync').attr('checked', true);
		    }
		    weibo.upCount('weibo');
			location.reload();
			$("#taobao").hide();
		    weibo.checkInputLength('#content_publish',140);
		}
	},
	
	//发布按钮状态
	textareaStatus:function(type){
		var obj = $('#publish_handle');
		if(type=='on'){
			obj.removeAttr('disabled').attr('class','btn_big hand');
		//}else if( type=='sending'){
		//	obj.attr('disabled','true').attr('class','btn_big_disable hand');
		}else{
			obj.attr('disabled','true').attr('class','btn_big_disable hand');
		}
	},
	
	//----------------------------仿知美二次开发 ---------------------//
	//删除一条分享
	deleted:function(weibo_id){
		$.post(U("weibo/Operate/delete"),{id:weibo_id},function(txt){
			if( txt ){
				$("#list_li_"+weibo_id).slideUp('fast');
				weibo.downCount('weibo');
				location.reload();

			}else{
				alert('删除失败');
			}
		});
	},
	
	
	//仿知美二次开发 
	deleted2:function(weibo_id){
		$.post(U("weibo/Operate/delete"),{id:weibo_id},function(txt){
			if( txt ){
				$("#list_li_"+weibo_id).slideUp('fast');
				weibo.downCount('weibo');
				//location.reload();
				var url= U('home/User/index');
				window.location = url; 

			}else{
				alert('删除失败');
			}
		});
	},
	
	
	//删除喜欢
	deletfav:function(weibo_id,type){
		//alert("asdf");
		$.post(U("weibo/Operate/delfav"),{id:weibo_id},function(txt){
			if( txt ){
				if(type=='mylove'){
					$("#list_li_"+weibo_id).slideUp('fast');
					   weibo.upfavCount('del');
					}else{
				var text='<span class="love">已取消</span>';
			   $("#favicon_"+weibo_id).html(text);
			   $("#favloe_"+weibo_id).slideUp('fast');
			      weibo.upfavCount('del');
					}
			}else{
				alert('取消喜欢失败，请检查网络或联系管理员');
			}
		});
	},
	
	
	//删除喜欢
	deletfav2:function(weibo_id,type){
		//alert("asdf");
		$.post(U("weibo/Operate/delfav"),{id:weibo_id},function(txt){
			if( txt ){
				if(type=='mylove'){
					$("#list_li_"+weibo_id).slideUp('fast');
					   weibo.upfavCount('del');
					}else{
				var text='<a href="javascript:;" class="hb favourite-btn">喜欢</a>';
			   $("#favicon_"+weibo_id).html(text);
			   $("#favloe_"+weibo_id).slideUp('fast');
			      weibo.upfavCount('del');
					}
			}else{
				alert('取消喜欢失败，请检查网络或联系管理员');
			}
		});
	},
	
	
	//删除推荐
	delettuijian:function(weibo_id,type){
		//alert("asdf");
		$.post(U("weibo/Operate/deltuijian"),{id55:weibo_id},function(txt){
			if( txt ){
				if(type=='mytuijian'){
					$("#list_li_"+weibo_id).slideUp('fast');
					   weibo.uprjcount('del');
					}else{
				var text='<span class="love">已取消</span>';
			   $("#tuijianicon_"+weibo_id).html(text);
			   $("#tuijianloe_"+weibo_id).slideUp('fast');
			      weibo.uprjcount('del');
					}
			}else{
				alert('取消推荐失败，请检查网络或联系管理员');
			}
		});
	},
	
	//删除推荐达人
	deletdaren:function(weibo_id,type){
		//alert("asdf");
		$.post(U("weibo/Operate/deldaren"),{id:weibo_id},function(txt){
			if( txt ){
				if(type=='mydaren'){
					$("#list_li_"+weibo_id).slideUp('fast');
					   weibo.updrcount('del');
					}else{
				var text='<span class="love">已取消</span>';
			   $("#darenicon_"+weibo_id).html(text);
			   $("#darenloe_"+weibo_id).slideUp('fast');
			      weibo.updrcount('del');
					}
			}else{
				alert('取消推荐失败，请检查网络或联系管理员');
			}
		});
	},
	
	//删除关注
	deletfengmian:function(bc_id,type){
		//alert("asdf");
		$.post(U("weibo/Operate/delfengmian"),{id:bc_id},function(txt){
			if( txt ){
				if(type=='myfengmian'){
					$("#list_li_"+bc_id).slideUp('fast');
					   weibo.upfmcount('del');
					}else{
				var text='<a href="javascript:;" class="longbutton unconcern">已取消</a>';
			   $("#fengmianicon_"+bc_id).html(text);
			   $("#fengmianloe_"+bc_id).slideUp('fast');
			      weibo.upfmcount('del');
					}
			}else{
				alert('取消失败，请检查网络或联系管理员');
			}
		});
	},
	
	//删除关注 图格详细页
	delettuijiantuge:function(bc_id,type){
		//alert("asdf");
		$.post(U("weibo/Operate/delfengmian"),{id:bc_id},function(txt){
			if( txt ){
				if(type=='myfengmian'){
					$("#list_li_"+bc_id).slideUp('fast');
					   weibo.upfmcount('del');
					}else{
				var text='<a href="javascript:;" class="winbtn unaddin">已取消</a>';
			   $("#fengmianicon_"+bc_id).html(text);
			   $("#fengmianloe_"+bc_id).slideUp('fast');
			      weibo.upfmcount('del');
					}
			}else{
				alert('取消失败，请检查网络或联系管理员');
			}
		});
	},
	
	//----------------------------仿知美二次开发  end ---------------------//
	
	//收藏
	favorite:function(id,o){
		$.post( U("weibo/Operate/stow") ,{id:id},function(txt){
			if( txt ){
				$(o).wrap('<span class=nwl_share id=content_'+id+'></span>');
				$('#content_'+id).html('已收藏');
			}else{
				alert('收藏失败！已收藏过？');
			}
		});
	},
	//取消收藏
	unFavorite:function(id,o){
		$.post( U("weibo/Operate/unstow") ,{id:id},function(txt){
			if( txt ){
				$('#list_li_'+id).slideUp('slow');
			}else{
				alert('取消失败');
			}
		});
	},
	//仿知美二次开发
	//发表评论
	pinglun:function(id){
		ui.box.load( U("weibo/index/publishcomment",["id="+id] ),{title:'发表评论',closeable:true});
	},
	
	//转发
	transpond:function(id,upcontent){
		upcontent = ( upcontent == undefined ) ? 1 : 0;
		ui.box.load( U("weibo/operate/transpond",["id="+id,"upcontent="+upcontent] ),{title:'转发',closeable:true});
	},
	
	//仿知美二次开发 编辑功能
	myedit:function(id,bc_id,upcontent){
		upcontent = ( upcontent == undefined ) ? 1 : 0;
		ui.box.load( U("weibo/operate/myedit",["id="+id,"bc_id="+bc_id,"upcontent="+upcontent] ),{title:'编辑',closeable:true});
	},
	
	//关注话题
	followTopic:function(name){
		$.post(U('weibo/operate/followtopic'),{name:name},function(txt){
			txt = eval( '(' + txt + ')' );
			if(txt.code==12){
				$('#followTopic').html('<a href="javascript:void(0)" onclick="weibo.unfollowTopic(\''+txt.topicId+'\',\''+name+'\')">取消该话题</a>');
			}
		});
	},
	unfollowTopic:function(id,name){
		$.post(U('weibo/operate/unfollowtopic'),{topicId:id},function(txt){
			if(txt=='01'){
				$('#followTopic').html('<a href="javascript:void(0)" onclick="weibo.followTopic(\''+name+'\')">关注该话题</a>');
			}
		});	
	},
	quickpublish:function(text){
		$.post(U('weibo/operate/quickpublish'),{text:text},function(txt){
			ui.box.show(txt,{title:'添加分享',closeable:true});
		});
	},
	//更新计数器
	upCount:function(type){
		if(type=='weibo'){
			$("#miniblog_count").html( parseInt($('#miniblog_count').html())+1 );
		}
	},
	//----------------仿知美二次开发--------------------
	
	//更新喜欢
	upfavCount:function(type){
		if(type=='weibo'){
			$("#fav_count").html( parseInt($('#fav_count').html())+1 );
		}else{
			$("#fav_count").html( parseInt($('#fav_count').html())-1 );
			}
	},
	
	//更新推荐
	updrcount:function(type){
		if(type=='weibo'){
			$("#daren_count").html( parseInt($('#daren_count').html())+1 );
		}else{
			$("#daren_count").html( parseInt($('#daren_count').html())-1 );
			}
	},
	
	//更新推荐
	uprjcount:function(type){
		if(type=='weibo'){
			$("#tuijian_count").html( parseInt($('#tuijian_count').html())+1 );
		}else{
			$("#tuijian_count").html( parseInt($('#tuijian_count').html())-1 );
			}
	},
	//更新关注
	upfmcount:function(type){
		if(type=='weibo'){
			$("#fengmian_count").html( parseInt($('#fengmian_count').html())+1 );
		}else{
			$("#fengmian_count").html( parseInt($('#fengmian_count').html())-1 );
			}
	},
	
	
	//----------------仿知美二次开发 end--------------------
	
	
	downCount:function(type){
		if(type=='weibo'){
			$("#miniblog_count").html( parseInt($('#miniblog_count').html())-1 );
		}
	},
	//检查字数输入
	checkInputLength:function(obj,num){
		var len = getLength($(obj).val(), true);
		var wordNumObj = $('.wordNum');
		
		if(len==0){
			wordNumObj.css('color','').html('你还可以输入<strong id="strconunt">'+ (num-len) + '</strong>字');
			weibo.textareaStatus('off');
		}else if( len > num ){
			wordNumObj.css('color','red').html('已超出<strong id="strconunt">'+ (len-num) +'</strong>字');
			weibo.textareaStatus('off');
		}else if( len <= num ){
			wordNumObj.css('color','').html('你还可以输入<strong id="strconunt">'+ (num-len) + '</strong>字');
			weibo.textareaStatus('on');
		}
	},
	publish_type_box:function(type_num,content,mg_left){
		var __THEME__ = "http://old.tiaojie.com/public/themes/jumin";
		var html = '<div class="talkPop"><div  style="position: relative; height: 7px; line-height: 3px;">'
		     + '<img class="talkPop_arrow" style="margin-left:'+ mg_left +'px;position:absolute;" src="'+__THEME__+'/images/zw_img.gif" /></div>'
             + '<div class="talkPop_box">'
			 + '<div class="close" id="weibo_close_handle"><a href="javascript:void(0)" class="del" onclick=" delTypeBox()" > </a></div>'
			 + '<div id="publish_type_content">'+content+'</div>'
			 + '</div></div>';
		$('input[name="publish_type"]').val( type_num );
		$('div.talkPop').remove();
		$("#publish_type_content_before").after( html );
	}
}


weibo = new weibo();

weibo.plugin = {};

function addtheme(){
	var text = '#请在这里输入自定义话题#';
	var   patt   =   new   RegExp(text,"g");  
	var content_publish = $('#content_publish');
	var result;
				
	if( content_publish.val().search(patt) == '-1' ){
		content_publish.val( content_publish.val() + text);
	}
	
	var textArea = document.getElementById('content_publish');
	
	result = patt.exec( content_publish.val() );
	
	var end = patt.lastIndex-1 ;
	var start = patt.lastIndex - text.length +1;
	
	if (document.selection) { //IE
		 var rng = textArea.createTextRange();
		 rng.collapse(true);
		 rng.moveEnd("character",end)
		 rng.moveStart("character",start)
		 rng.select();
	}else if (textArea.selectionStart || (textArea.selectionStart == '0')) { // Mozilla/Netscape…
        textArea.selectionStart = start;
        textArea.selectionEnd = end;
    }
    textArea.focus();
	weibo.checkInputLength('#content_publish',140);
	return ;
}jQuery.extend(weibo.plugin, {
	video:function(element, options){
	   
	    
	}
});


jQuery.extend(weibo.plugin.video, {
	html:'<div id="video_input">请输入新浪播客、优酷网等视频网站的视频播放页链接： <div><input name="publish_type_data" type="text" style="width: 235px" class="text mr5" value="" /><input type="button" id="shangchuan" class="btn_b" onclick="weibo.plugin.video.add_video()" value="添加"></div>&nbsp;&nbsp;<span style="color:red;"  id="video_add_complete">添加完成！</span></div>',
	click:function(options){
	   weibo.publish_type_box(3,this.html,options)
	},
	add_video:function(){
		$("#shangchuan").val('添加中...');
		var video_url = $("input[name='publish_type_data']").val();
		$.post( U('weibo/plugins/before_publish'),{url:video_url,plugin_id:3},function(txt){
			txt = eval('('+txt+')');
			if(txt.boolen){
				html  = '<div class="indeximg"><div class="mytips">请输入新浪播客,优酷网等的视频播放页链接： </div></div><input name="publish_type_data" type="text" style="width: 255px" class="text mr5" value="" /><input id="shangchuan" type="button" class="btn_b" onclick="weibo.plugin.video.add_video()" value="添加">&nbsp;&nbsp;<span style="color:red"    id="video_add_complete">添加完成</span><input id="pickpic" name="publish_type_data" type="hidden" style="width:86%" value='+video_url+' />';
				$("#publish_type_content").html( html);	
				
				$("#shangchuan").val('添加');
				$('#video_input').show();
				$('#video_add_complete').show();
				$("#content_publish").val( $("#content_publish").val( ) + ' ' + txt.data + ' ');
				weibo.checkInputLength('#content_publish',140);
				$('div .talkPop').show();
			}else{
				alert(txt.message);
				$("#shangchuan").val('重新添加');
			}
		})
	}
});

function switchVideo(id,type,host,flashvar){
	if( type == 'close' ){
		$("#video_mini_show_"+id).show();
		$("#video_content_"+id).html( '' );
		$("#video_show_"+id).hide();
	}else{
		$("#video_mini_show_"+id).hide();
		$("#video_content_"+id).html( showFlash(host,flashvar) );
		$("#video_show_"+id).show();
		
	}
}

//显示视频
function showFlash( host, flashvar) {
	var flashAddr = {
		'youku.com' : 'http://player.youku.com/player.php/sid/FLASHVAR/v.swf',
		'ku6.com' : 'http://player.ku6.com/refer/FLASHVAR/v.swf',
		//'sina.com.cn' : 'http://vhead.blog.sina.com.cn/player/outer_player.swf?vid=FLASHVAR',
		'sina.com.cn' : 'http://you.video.sina.com.cn/api/sinawebApi/outplayrefer.php/vid=FLASHVAR/s.swf',
		//'tudou.com' : 'http://www.tudou.com/v/FLASHVAR',
		'tudou.com' : 'http://www.tudou.com/v/FLASHVAR/&autoPlay=true/v.swf',
		'youtube.com' : 'http://www.youtube.com/v/FLASHVAR',
		'5show.com' : 'http://www.5show.com/swf/5show_player.swf?flv_id=FLASHVAR',
		//'sohu.com' : 'http://v.blog.sohu.com/fo/v4/FLASHVAR',
		'sohu.com' : 'http://share.vrs.sohu.com/FLASHVAR/v.swf',
		'mofile.com' : 'http://tv.mofile.com/cn/xplayer.swf?v=FLASHVAR',
		'music' : 'FLASHVAR',
		'flash' : 'FLASHVAR'
	};
	var videoFlash = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="430" height="400">'
        + '<param value="transparent" name="wmode"/>'
		+ '<param value="FLASHADDR" name="movie" />'
		+ '<embed src="FLASHADDR" wmode="transparent" allowfullscreen="true" type="application/x-shockwave-flash" width="430" height="400"></embed>'
		+ '</object>';
	var flashHtml = videoFlash;

	flashvar = encodeURI(flashvar);
	if(flashAddr[host]) {
		var flash = flashAddr[host].replace('FLASHVAR', flashvar);
		flashHtml = flashHtml.replace(/FLASHADDR/g, flash);
	}

	return flashHtml;
}jQuery.extend(weibo.plugin, {
	music:function(element, options){
	}
});


jQuery.extend(weibo.plugin.music, {
	html:'<div class="indexmusic" id="end"><div class="mytips">虾米音乐提供技术支持，请输入歌曲名称： </div></div><div id="music_input"><input name="publish_type_data" id="music_url" type="text" style="width: 235px" class="text mr5" value="" /><input type="button" class="btn_b" onclick="weibo.plugin.music.add_music(\'1\')" value="搜索"></div><div id="music_ok" style="display:none; z-index:999">loading</div><div id="page" style="display:none">1</div>',
	click:function(options){
	   weibo.publish_type_box(4,this.html,options)
	},
	add_music:function(page){
		$("#shangchuan").val('搜索中...');
		var music_url = $("input[name='publish_type_data']").val();
		$.post( U('weibo/plugins/before_publish'),{s:music_url,page:page,plugin_id:'4'},function(txt){
			  $('#music_ok').html('<img src="img/loading.gif" align="center" style="text-align:center" />');							 
			txt= eval('('+txt+')');
			var json=eval(txt.results);
		
			if(json){
				
				 $('#load').hide();
				$('#music_more').hide('');
				$('#music_ok').show();
				$('#music_ok').html('');
				$('#end').show('');
				if(eval(txt.total)=='0'){
					$('#end').html('共找'+eval(txt.total)+'首相应歌曲，请重试！');
					$("#shangchuan").val('搜索');
				}else{
					
					var pages=parseInt($('#page').html())+1;
					
					$('#end').html('共找'+eval(txt.total)+'首相应歌曲,<a href="javascript:;" onclick="nextpage('+pages+',\'next\')"">【下一页】</a>,<a href="javascript:;" onclick="nextpage('+(parseInt($('#page').html())-1)+',\'star\')"">【上一页】</a');
					}
				
				 for(var i=0; i<8; i++)  {
var html='<li class="musiclist"><a href="javascript:;" onclick="add('+json[i].song_id+',\''+decodeURI(json[i].album_logo)+'\',\''+decodeURI(json[i].artist_name)+'\',\''+decodeURI(json[i].song_name)+'\');">'+decodeURI(json[i].song_name)+' —— '+decodeURI(json[i].artist_name)+'</a></li>';
				  $('#music_ok').append(html);
			      }
				  $("#shangchuan").val('搜索');
				  weibo.checkInputLength('#content_publish',140);
				  
			
				
			}else{
			
			   $("#content_publish").val('Sorry!可能是我们现在的歌曲还不够?你可以将歌曲'+ music_url+'提交给管理员,谢谢！');
			  weibo.checkInputLength('#content_publish',140);
			 $('div .talkPop').show();
			 $("#shangchuan").val('重新搜索');
			}
		})
	}
});
function add(id,logo,uname,name){
  
	var h1='<input style="display:none" id="pickpic" name="publish_type_data[mp3id]"  value="'+id+'" />';
	var h2='<input style="display:none" name="publish_type_data[logo]"  value="'+logo+'" />';
	$('#test_input').html(h1+h2);
	
	var v1='<div class="pt10"><object width="257" height="33" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"><param value="http://www.xiami.com/widget/0_'+id+'/singlePlayer.swf" name="movie"><param value="transparent" name="wmode"><param value="high" name="quality"><embed width="257" height="33" type="application/x-shockwave-flash" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" quality="high" wmode="transparent" menu="false" src="http://www.xiami.com/widget/0_'+id+'/singlePlayer.swf"></object></div>';
	$('#test_music').html(v1);
    $('#content_publish').val('#分享歌曲#'+name+' —— '+uname+'');
	$('div .talkPop').show();
	  weibo.checkInputLength('#content_publish',140);
	}
function nextpage(id,type){
     $('#music_ok').html('<img src="img/loading.gif" align="center" style="text-align:center" />');
	weibo.plugin.music.add_music(id);
	if(type=='next'){
	$('#page').html(id);
	}else if(type=='star'){
	$('#page').html(id);
	 }
	}	jQuery.extend(weibo.plugin, {
	image:function(element, options){
	   
	    
	}
});

var stopUploadPic = 0;
jQuery.extend(weibo.plugin.image, {
	html:'<input type="text" style="width:230px;height:20px;" id="online_img" value="" name="online_img">'+
	'<input type="button" style="width:130px;" value="采集" id="shangchuan" onclick="weibo.plugin.image.upload1()">'+
	'<div id="upload_selectpic"><div class="btn_green2">'+
	'<form action="'+U("weibo/plugins/before_publish")+'" enctype="multipart/form-data" method="post" id="uploadpic">'+
	'<input type="hidden" name="plugin_id" value="1"><a class="gp_btn_c"><input type="file" hidefoucs="true" name="pic" onchange="weibo.plugin.image.upload(this)"></a>'+
	'</form></div></div><div class="alC pt10 pb10 f14px" id="upload_loading" style="display:none"><img src="'+ _THEME_+'/images/icon_waiting.gif" width="20" class="alM"> 正在上传中...<br /><a class="btn_w mt10" href="javascript:void(0)" onclick="$(\'div .talkPop\').remove();weibo.plugin.image.stopAjax();">取消上传</a></div>',
	click:function(options){
		if (1 != $('div.talkPop').data('type')) {
			weibo.publish_type_box(1,this.html,options);
		}
	},
	upload1:function(){
		$("#shangchuan").val('获取中...');
               
                
		var img_url=$("#online_img").val();
		$.post( U("weibo/plugins/before_publish_input") ,{imgurl:img_url,plugin_id:1},function(txt){
			 txt = eval( '(' + txt + ')' );
			      if(txt.boolen==1){
						var img = new Image;
						img.src = txt.picurl;
						img.onload = function(){
							if( this.width>190 || this.height>190 ){
								var style;
								if( this.height >  this.width ){
									style = "height:190px;width:"+this.width*(190/this.height)+"px";
								}else{
									style = "width:190px;height:"+this.height*(190/this.width)+"px";
								}
								
								var html = '<div class="indeximg"><img src="'+txt.picurl+'" style="'+style+'"><input id="pickpic" name="publish_type_data" type="hidden" style="width:86%" value='+txt.type_data+' /></div>'+
								'<div class="mymargin"><input type="text" style="width:230px;height:20px;" id="online_img" value="http://" name="online_img">&nbsp;&nbsp;'+
	'<input type="button" class="btn_b" value="采集" id="shangchuan" onclick="weibo.plugin.image.upload1()"></div>';
								 
							}else{
								var html = '<div class="indeximg"><img src="'+txt.picurl+'"><input id="pickpic" name="publish_type_data" type="hidden" style="width:86%" value='+txt.type_data+' /></div>'+
								'<div class="mymargin"><input type="text" style="width:230px;height:20px;" id="online_img" value="http://" name="online_img">&nbsp;&nbsp;'+
	'<input type="button" class="btn_b" value="采集" id="shangchuan" onclick="weibo.plugin.image.upload1()"></div>';
								}
							if($('#content_publish').val()==''){
								$('#content_publish').val('');
							}
							$("#publish_type_content").html( html );
							$('div.talkPop').data('type', 1);
							$('#upload_loading').hide();
							$("#shangchuan").val('采集');
							$("#online_img").val('http://');
                                                        $('#online_img').show();
                                                        $('#shangchuan').show();
							$('#upload_selectpic').hide();
							weibo.checkInputLength('#content_publish',140);
						};
								
				  }else{
					alert( txt.message );
						$("#shangchuan").val('重新采集');
			      }
		});
	},
	upload:function(o){
		var allowext = ['jpg','jpeg','gif','png'];
		var ext = /\.[^\.]+$/.exec( $(o).val() );
		ext = ext.toString().replace('.','');
		if( jQuery.inArray( ext.toLowerCase() , allowext )==-1 ){
			alert('只允许上传jpg、jpeg、gif、png格式的图片');
			return false;
		}
		weibo.textareaStatus('off');
		$('#upload_selectpic').hide();
		$('#upload_loading').show();
		$('#weibo_close_handle').hide();
		var options = {
			    success: function(txt) {
				if(stopUploadPic==1){
					return false;
				}
			      txt = eval( '(' + txt + ')' );
			      if(txt.boolen==1){
						var img = new Image;
						img.src = txt.picurl;
						img.onload = function(){
							if( this.width>190 || this.height>190 ){
								var style;
								if( this.height >  this.width ){
									style = "height:190px;width:"+this.width*(190/this.height)+"px";
								}else{
									style = "width:190px;height:"+this.height*(190/this.width)+"px";
								}
								
							var html = '<div class="indeximg"><img src="'+txt.picurl+'" style="'+style+'"><input id="pickpic" name="publish_type_data" type="hidden" style="width:86%" value='+txt.type_data+' /></div>'+
								'<div id="upload_selectpic"><div class="btn_green2" >'+
	'<form action="'+U("weibo/plugins/before_publish")+'" enctype="multipart/form-data" method="post" id="uploadpic">'+
	'<input type="hidden" name="plugin_id" value="1"><a class="gp_btn_c"><input type="file" hidefoucs="true" name="pic" onchange="weibo.plugin.image.upload(this)"></a>'+
	'</form></div></div><div class="alC pt10 pb10 f14px" id="upload_loading" style="display:none"><img src="'+ _THEME_+'/images/icon_waiting.gif" width="20" class="alM"> 正在上传中...<br /><a class="btn_w mt10" href="javascript:void(0)" onclick="$(\'div .talkPop\').remove();weibo.plugin.image.stopAjax();">取消上传</a></div>';
								 
							}else{
								var html = '<div class="indeximg"><img src="'+txt.picurl+'"><input id="pickpic" name="publish_type_data" type="hidden" style="width:86%" value='+txt.type_data+' /></div>'+
								'<div id="upload_selectpic"><div class="btn_green2" href="javascript:void(0);" >'+
	'<form action="'+U("weibo/plugins/before_publish")+'" enctype="multipart/form-data" method="post" id="uploadpic">'+
	'<input type="hidden" name="plugin_id" value="1"><a class="gp_btn_c"><input type="file" hidefoucs="true" name="pic" onchange="weibo.plugin.image.upload(this)"></a>'+
	'</form></div><div class="alC pt10 pb10 f14px" id="upload_loading" style="display:none"><img src="'+ _THEME_+'/images/icon_waiting.gif" width="20" class="alM"> 正在上传中...<br /><a class="btn_w mt10" href="javascript:void(0)" onclick="$(\'div .talkPop\').remove();weibo.plugin.image.stopAjax();">取消上传</a></div>';			
								
								}
							if($('#content_publish').val()==''){
								$('#content_publish').val('');
							}
							$("#publish_type_content").html(html );
							$('#upload_loading').hide();
							$('#upload_selectpic').show();
						
							weibo.checkInputLength('#content_publish',140);
						};
								
				  }else{
					alert( txt.message );
                                        
                                        $('#upload_selectpic').show();
                                        
                                         
			      }
			    } 
			};
//			$('#publish_type_content').html('<div style="width:400px;text-align:center;height:150px;"><img src="__THEME__/images/icon_waiting.gif" width="30"></div>');
			var httpRespondHandle = $('#uploadpic').ajaxSubmit( options );
		    return false;
	},
	stopAjax:function(){
		stopUploadPic=1;
	}

});

//切换图片
function switchPic(id,type,picurl){
	if( type=='close' ){
		$("#pic_show_"+id).hide();
		$("#pic_mini_show_"+id).show();
	}else{
		
		if( $("#pic_show_"+id).find('.imgSmall').attr('src')==''){
			$("#pic_mini_show_"+id).find('.loadimg').show();
			var img = new Image;
			img.src = picurl+'?time='+new Date();
			img.onload = function(){
				if( this.width>460 ){
					$("#pic_show_"+id).find('.imgSmall').css('width','460px');
				}
				$("#pic_show_"+id).find('.imgSmall').attr('src',this.src);
				$("#pic_mini_show_"+id).find('.loadimg').hide();
				$("#pic_show_"+id).show();
				$("#pic_mini_show_"+id).hide();	
			};
		}else{
			$("#pic_show_"+id).show();
			$("#pic_mini_show_"+id).hide();	
		}
	}
}

//旋转图片
function revolving(id,type){
	var img = $("#pic_show_"+id).find('.imgSmall');
	img.rotate(type);
}


$.fn.rotate = function(p){

	var img = $(this)[0],
		n = img.getAttribute('step');
	// 保存图片大小数据
	if (!this.data('width') && !$(this).data('height')) {
		this.data('width', img.width);
		this.data('height', img.height);
	};
	this.data('maxWidth',img.getAttribute('maxWidth'))

	if(n == null) n = 0;
	if(p == 'left'){
		(n == 0)? n = 3 : n--;
	}else if(p == 'right'){
		(n == 3) ? n = 0 : n++;
	};
	img.setAttribute('step', n);

	// IE浏览器使用滤镜旋转
	if(document.all) {
		if(this.data('height')>this.data('maxWidth') && (n==1 || n==3) ){
			if(!this.data('zoomheight')){
				this.data('zoomwidth',this.data('maxWidth'));
				this.data('zoomheight',(this.data('maxWidth')/this.data('height'))*this.data('width'));
			}
			img.height = this.data('zoomwidth');
			img.width  = this.data('zoomheight');
			
		}else{
			img.height = this.data('height');
			img.width  = this.data('width');
		}
		
		img.style.filter = 'progid:DXImageTransform.Microsoft.BasicImage(rotation='+ n +')';
		// IE8高度设置
		if ($.browser.version == 8) {
			switch(n){
				case 0:
					this.parent().height('');
					//this.height(this.data('height'));
					break;
				case 1:
					this.parent().height(this.data('width') + 10);
					//this.height(this.data('width'));
					break;
				case 2:
					this.parent().height('');
					//this.height(this.data('height'));
					break;
				case 3:
					this.parent().height(this.data('width') + 10);
					//this.height(this.data('width'));
					break;
			};
		};
	// 对现代浏览器写入HTML5的元素进行旋转： canvas
	}else{
		var c = this.next('canvas')[0];
		if(this.next('canvas').length == 0){
			this.css({'visibility': 'hidden', 'position': 'absolute'});
			c = document.createElement('canvas');
			c.setAttribute('class', 'maxImg canvas');
			img.parentNode.appendChild(c);
		}
		var canvasContext = c.getContext('2d');
		switch(n) {
			default :
			case 0 :
				img.setAttribute('height',this.data('height'));
				img.setAttribute('width',this.data('width'));
				c.setAttribute('width', img.width);
				c.setAttribute('height', img.height);
				canvasContext.rotate(0 * Math.PI / 180);
				canvasContext.drawImage(img, 0, 0);
				break;
			case 1 :
				if(img.height>this.data('maxWidth') ){
					h = this.data('maxWidth');
					w = (this.data('maxWidth')/img.height)*img.width;
				}else{
					h = this.data('height');
					w = this.data('width');
				}
				c.setAttribute('width', h);
				c.setAttribute('height', w);
				canvasContext.rotate(90 * Math.PI / 180);
				canvasContext.drawImage(img, 0, -h, w ,h );
				break;
			case 2 :
				img.setAttribute('height',this.data('height'));
				img.setAttribute('width',this.data('width'));
				c.setAttribute('width', img.width);
				c.setAttribute('height', img.height);
				canvasContext.rotate(180 * Math.PI / 180);
				canvasContext.drawImage(img, -img.width, -img.height);
				break;
			case 3 :
				if(img.height>this.data('maxWidth') ){
					h = this.data('maxWidth');
					w = (this.data('maxWidth')/img.height)*img.width;
				}else{
					h = this.data('height');
					w = this.data('width');
				}
				c.setAttribute('width', h);
				c.setAttribute('height', w);
				canvasContext.rotate(270 * Math.PI / 180);
				canvasContext.drawImage(img, -w, 0,w,h);
				break;
		};
	};
};jQuery.extend(weibo.plugin, {
    goods:function(element, options){
	   
	    
    }
});


jQuery.extend(weibo.plugin.goods, {
    html:'<div id="goods_input">请输入商品网址（暂支持淘宝和拍拍）： <div><input name="publish_type_data" type="text" style="width: 235px" class="text mr5" value="" /><input type="button" class="btn_b" onclick="weibo.plugin.goods.add_goods()" value="添加"></div> </div>  ',
    click:function(options){
        weibo.publish_type_box(5,this.html,options)
    },
    add_goods:function(){
        var goods_url = $("input[name='publish_type_data']").val();
		goods_url=goods_url.replace(/beta./ig,'');//仿知美二次开发，过滤掉目前淘宝的http://item.beta.taobao.com
		$('#goods_input').html('正在分享宝贝,请稍后....');
		$('#content_publish').append('');
		deleteTag('alltag');
        if(goods_url=="")
        {
            alert("请正确输入网址");
			//delTypeBox();
            return false;
        }
        
        var yz=yz_url(goods_url);
        if(!yz)
        {
           alert("请正确输入网址");
			//delTypeBox();
            return false;
        }
        function GetUrlParam(url, paramName )
        {
            var oRegex = new RegExp( '[\?&]' + paramName + '=([^&]+)', 'i' ) ;
            var oMatch = oRegex.exec( url ) ;
            if ( oMatch && oMatch.length > 1 )
                return oMatch[1] ;  //返回值
            else
                return '' ;
        }
        
            
        gid=GetUrlParam(goods_url,"id");
        if(yz=="paipai.com"){
            gid=GetpaiID(goods_url);
        }

        if(gid==""){
            alert("请正确输入网址");
			//delTypeBox();
            return false;
        }
        $.post( U('weibo/plugins/before_publish'),{
            url:goods_url,
            plugin_id:5,
            id: gid,
            fenlei: yz
        },function(txt){
            txt = eval('('+txt+')');
            if(txt.taoke==1){
                ///前处理
                $('#goods_input').show();
				$('#goods_input2').hide();
				$("input[name='publish_type_data']").val('');
				$('#publish_type_content').hide();
				$('#selectfl').show();
				$('#selectfl2').show();
                $("#taobao_goods_images").show();
                $('#taoke').show();
                $("#shop").hide('slow');
                $("#post").show('slow');
				$("#fenlei").html(txt.data.fenlei);
				$("#fenlei_input").val(txt.data.fenlei);
                $('#goods_img').attr("src",txt.data.pic_url+"_160x160.jpg");
                $('#click_url').attr("href",txt.data.click_url);
                $('#click_url_img').attr("href",txt.data.click_url);
                $('#click_url').text(txt.data.title);
                $('#click_url').attr("title",txt.data.title);
                $('#price').text(txt.data.price);
                $('.commission').text(txt.data.commission);
                $('.commission_rate').text(txt.data.commission_rate+"%");
                //后负值处理
                html1 = "<input id='pickpic' name='publish_type_data' type='hidden' style='width:86%' value='"+txt.data.pic_url+"' />";					
                goods_url="<input name='goods_url' type='hidden' value='"+txt.data.click_url+"' />";
                g_url="<input name='g_url' type='hidden' value='"+txt.rand_url+"' />";
                cid="<input name='cid' type='hidden' value='"+txt.data.cid+"' />"; 
                seller_cids="<input name='seller_cids' type='hidden' value='"+txt.data.seller_cids+"' />"; 
                num_iid="<input name='num_iid' type='hidden' value='"+txt.data.num_iid+"' />";
                g_title="<input name='g_title' type='hidden' value='"+escape(txt.data.title)+"' />";
                g_host="<input type='hidden' name='g_host' value='"+txt.host+"' />";
               price_d="<input name='price' type='hidden' value='"+txt.data.price+"' />";
                commission="<input name='commission' type='hidden' value='"+txt.data.commission+"' />";
                commission_rate="<input name='commission_rate' type='hidden' value='"+txt.data.commission_rate+"' />";
                taoke_1="<input name='taoke' type='hidden' value='"+txt.taoke+"' />";
                $("#publish_type_content").html( html1+goods_url+g_url+g_title+price_d+commission+commission_rate+taoke_1+g_host+cid+seller_cids +num_iid);
                $(".talkPop").show();

				
                weibo.textareaStatus('on');
            }else if(txt.taoke==0){
                                        
                $('#goods_input').show();
				$('#publish_type_content').hide();
				$('#selectfl').show();
				$('#selectfl2').show();
                $("#taobao_goods_images").show();
                if(txt.host=="taobao"){
                    $('#goods_img').attr("src",txt.data.pic_url+"_160x160.jpg");
                }else{
                    len=txt.data.pic_url.length;
                    pic=txt.data.pic_url.substring(0,len-3);
                    $('#goods_img').attr("src",pic+"160x160.jpg");
                }
                
                $("#fenlei").html(txt.data.fenlei);
				$("#fenlei_input").val(txt.data.fenlei);
                $('#click_url').attr("href",txt.data.click_url);
                $('#click_url_img').attr("href",txt.data.click_url);
                $('#click_url').text(txt.data.title);
                $('#click_url').attr("title",txt.data.title);
                $('#price').text(txt.data.price);
                $('#taoke').hide();


				g_host="<input type='text' name='g_host' value="+txt.host+" />";
                html  = '<input id="pickpic" name="publish_type_data" type="hidden" style="width:86%" value='+txt.data.pic_url+' />';
                goods_url="<input name='goods_url' type='hidden' value="+txt.data.click_url+" />";
                cid="<input name='cid' type='hidden' value="+txt.data.cid+" />"; 
				num_iid="<input name='num_iid' type='hidden' value="+txt.data.num_iid+" />";
                seller_cids="<input name='seller_cids' type='hidden' value="+txt.data.seller_cids+" />"; 
                g_url="<input name='g_url' type='hidden' value="+txt.rand_url+" />";
                g_title="<input name='g_title' type='hidden' value="+escape(txt.data.title)+" />";
                price_d="<input name='price' type='hidden' value="+txt.data.price+" />";
                taoke_1="<input name='taoke' type='hidden' value="+txt.taoke+" />";
                $("#publish_type_content").html( html+goods_url+g_url+g_title+price_d+taoke_1+g_host+cid+seller_cids +num_iid);	
                $(".talkPop").hide();
                                              
                weibo.textareaStatus('on');
            }
                                        
                                        
           
        })
        
        
        
        
    }
});


//获得拍拍商品ID值
function GetpaiID(url)
{
    var string=url;
    var startIndex=string.lastIndexOf("/")+1;   
    var SubString=string.substr(startIndex,32);
    return SubString;
}
//验证URL
function yz_url(url)
{
    var re=/(^|:\/\/)(\w+\.)?(\w+\.\w+)(?=(\/|$))/;
    var m=url.match(re);
    if(m)
    {
        if(m[3]=="taobao.com" || m[3]=="tmall.com" || m[3]=="paipai.com"){
            return m[3];
        }else{
            return false;
        }
    }else{
        return false;
    }
}
