jQuery(function(){

	//小广播
	jQuery("#broard_show textarea").click(function(e){
		if(jQuery(this).val() == "小心思、得意事、不爽ing……想说就说"){
			jQuery(this).val("");
			jQuery(this).animate({height:"50px"},200,function(){
				jQuery("#broard_show .icon_face, #broard_show cite, #broard_show .broard_btn").show();
				jQuery("#broard_show .lastbroard_post").hide();
			})
		};
		e.stopPropagation();
	});

	jQuery("#show_intimity_self a").click(function(){
		jQuery("#show_intimity_self").hide();
		jQuery("#intimity_self_more").slideDown(500);
		return false;
	})

	jQuery("#welcome .closed").click(function(){
		jQuery("#welcome").slideUp(500);
	})
	jQuery(".subnav_config a").click(function(e){
		e.stopPropagation();
		jQuery(".subnav_config_list").toggle();
		return false;
	});
	jQuery(".subnav_config_list").click(function(e){
		e.stopPropagation();
	})
	
	jQuery(".view_home a").hover(
		function(){
			jQuery(".view_home span").show();
		},
		function(){
			jQuery(".view_home span").hide();
		}
	)
	jQuery(".invite .closed a").click(function(){
		jQuery(this).parents(".invite").hide();
		return false;
	})
	jQuery(".win_pop .btn_option").click(function(){jQuery("#win_pop_mask").hide();jQuery(".win_pop").hide();})

	jQuery("#tab_showmore a").click(function(){jQuery("#tab_more").toggle();return false;})
	jQuery("#abinfo_tab").click(function(){jQuery("#abinfo_more").toggle();return false;})
	jQuery("#showip span").click(function(){jQuery("#showip ul").toggle();return false;})

	jQuery(".gold_log tbody tr:odd").addClass("cam_blue");
	jQuery(".gold_manage .datasheet tbody tr:odd").addClass("cam_blue");
	jQuery(".intimity_overlook tbody tr:odd").addClass("cam_blue");
	
	//回车提交表单
	jQuery("form[rel='keysubmit']").keypress(function(event){
		if(getkeycode(event) == "13"){
			jquery(this).submit();
		}
	})
	//limit input
	jQuery("textarea").each(function(){
		if(jQuery(this).attr("maxlength")){
			limitinput(jQuery(this));
		}
	})
	
	jQuery("#keywords").click(function(){if(jQuery("#keywords").val() == "请输入搜索关键词..."){jQuery("#keywords").val("")}})
	
	if(jQuery("#container .right").is("div")){
		jQuery(".subnav .content").height(jQuery(".right").height()*0.8+"px");
	}

	//if(jQuery("#container .main").height() > jQuery("#container .subnav").height() ) jQuery("#leftcontent").height(jQuery("#container .main").height());


	if(jQuery.browser.msie && jQuery.browser.version == "6.0"){
		jQuery(".main label").click(function(){
			jQuery(this).find("input[type='radio']").attr("checked","checked");
			if(!jQuery(this).find("input[type='checkbox']").attr("checked")){jQuery(this).find("input[type='checkbox']").attr("checked",true);}
			else{jQuery(this).find("input[type='checkbox']").attr("checked",false);}
		});
		jQuery(".main input[type='checkbox']").click(function(){
			if(!jQuery(this).attr("checked")){jQuery(this).attr("checked",true);}
			else{jQuery(this).attr("checked",false);}
		});
	}

	jQuery(".box > h4 + cite").click(function(){
		jQuery(this).parents(".box").find(".content").toggle();
		jQuery(this).toggleClass("fold");
		jQuery("#leftcontent").height(jQuery("#container .main").height());
	})
	
	function changenews_tab(obj){
		jQuery("#tab_myfriend").next().hide();
		if(obj == "tabnews_all"){
			jQuery("#tab_myfriend > div").show();
		}else{
			jQuery("#tab_myfriend > div").hide();
			jQuery("#"+ obj).show();
		}
		jQuery("#leftcontent").height(jQuery("#container .main").height());	
	}

	//if(jQuery("dl.record p").width() > 372) jQuery("dl.record p").width("372");
	
	jQuery(".news_msg .options span:first-child a").focus(function(){
		var obj = jQuery(this).parent().parent().next();
		obj.show();
		jQuery(obj).find("textarea").focus();
	}).click(function(){return false;})
	
	//jQuery(".news_msg .replaybox textarea").blur(function(){if(jQuery(this).val() == ""){jQuery(this).parent().parent().hide()}})
	
	jQuery("#file_upload_face").css({opacity:0});
	
	jQuery("#upload_face form").submit(function(){
		if(jQuery("#input_upload_face").val() == "") return;
		jQuery("#cp_face h4").html("头像预览");
		jQuery("#upload_face h4").html("重新上传");
		jQuery("#editface").show();
		return false;
	})

	jQuery("#sms_main dl").live("mouseover",function(){
		if(jQuery(this).is(".sms_selected")){return false;}
		jQuery(this).addClass("sms_over")
	})
	jQuery("#sms_main dl").live("mouseout",function(){
		if(jQuery(this).is(".sms_selected")){return false;}
		jQuery(this).removeClass("sms_over")
	});
	
	jQuery("#sms_main dl").live("click",function(){
		var limit = parseInt(jQuery("#sms_cuser_cont").attr("limit"));
		jQuery("button").removeAttr("disabled");
		if(jQuery("#sms_choosed li").eq(1).is(".cms_choosed_this")){
			if(jQuery(this).attr("class") == "sms_selected"){
				jQuery(this).hide();
			}
		}
		jQuery(this).removeClass("sms_over");
		var otar = jQuery("#sms_cuser_cont").attr("output").split("&");
		if(jQuery(this).attr("class") == ""){
			if(limit >=0){
				var nowNo = jQuery("#sms_main .sms_selected").size();
				if(nowNo >= limit){
					return false;
				}
			}
			jQuery(this).addClass("sms_selected");
			if(otar[1] == "uname"){
				jQuery("#"+otar[0]).val(getsms_user_info()['name']);
			}
			if(otar[1] == "uid"){
				jQuery("#"+otar[0]).val(getsms_user_info()['id']);
			}
		}else{
			jQuery(this).removeClass("sms_selected");
			if(otar[1] == "uname"){
				jQuery("#"+otar[0]).val(getsms_user_info()['name']);
			}
			if(otar[1] == "uid"){
				jQuery("#"+otar[0]).val(getsms_user_info()['id']);
			}
		}
		jQuery("#sms_choosed em").html(jQuery("#sms_main dl.sms_selected").size());
	});
	jQuery("#sms_cuser_cont .btn_option").live("click",function(){
			hide_u_group();
	})
	
	jQuery(".msg_cont_main .msg_u_name").click(function(){
		jQuery(this).parent().next().toggle();
		jQuery(this).find("em").toggleClass("u_info_show");
		return false;
	})

	jQuery(".friendgroup li").live("mouseover",function(){jQuery(this).find("span").show();});
	jQuery(".friendgroup li").live("mouseout",function(){if(jQuery(this).is(".current")) return;jQuery(this).find("span").hide();});
	
	jQuery(".friendlist dl").click(function(){show_fullinfo(jQuery(this))});
	jQuery(".friendlist dl a").click(function(e){
		if(jQuery(this).is(".friend_viewall")){
			return;
		}
		e.stopPropagation();
	});
	jQuery(".setnikename input").click(function(e){
		e.stopPropagation();
	});
	jQuery(".friend_options .friend_viewall").click(function(){show_fullinfo(jQuery(this));e.stopPropagation();return false;});

	jQuery(".friendlist .show_option").hover(
		function(){
			jQuery(this).find(".sendmail").css({"visibility":"visible"});
		},
		function(){
			jQuery(this).find(".sendmail").css({"visibility":"hidden"});
		}
	);
	jQuery(".setnikename a").click(function(){showeditbox(jQuery(this),0);return false;});
	jQuery(".setnikename input").blur(function(){showeditbox(jQuery(this),1);return false;});
	
	jQuery(".friend_find dl").hover(function(){jQuery(this).addClass("current")},function(){jQuery(this).removeClass("current")})

	jQuery(".dy_ulist").live("mouseover",function(){
		jQuery(this).children(".msg_option").show();
	});
	jQuery(".dy_ulist").live("mouseout",function(){
		jQuery(this).children(".msg_option").hide();
	});
	


	jQuery(".dylist").hover(function(){
			if(!jQuery(this).find(".dynamic_conf").html()) return;
			jQuery(this).css({"z-index":1}).find(".dynamic_conf").show();
			jQuery(this).find(".updata_time").hide();
		},
		function(){
			if(!jQuery(this).find(".dynamic_conf").html()) return;
			jQuery(this).css({"z-index":0}).find(".dynamic_conf").hide().find("div").hide();
			jQuery(this).find(".updata_time").show();
		}
	)
	jQuery(".dynamic_conf em").click(function(){jQuery(this).next("div").toggle();return false;})
	
	jQuery(".show_log_raply").live("click",function(){
		var c_display = jQuery(this).parent().parent().find(".msg_list");
		if(c_display.css("display") == "block"){
			display_msg_list(jQuery(this),"hide");
			return false;
		}else{
			display_msg_list(jQuery(this),"show");
			return false;
		}
	})
	
	jQuery(".msg_list dl").live("mouseover",function(){
		jQuery(this).children(".msg_option").show();
	});
	jQuery(".msg_list dl").live("mouseout",function(){
		jQuery(this).children(".msg_option").hide();
	});
	jQuery(".show_send_mail").live("mouseover",function(){
		jQuery(this).find("span").css({"visibility":"visible"});
	});
	jQuery(".show_send_mail").live("mouseout",function(){
		jQuery(this).find("span").css({"visibility":"hidden"})
	});

	
	jQuery(".msg_allwaystips .msg_allclosed").click(function(){jQuery(this).parent().slideUp("slow",function(){jQuery(".msg_allwaystips").remove()});})

	jQuery("#reply_face a").live("mouseover",function(){
			if(jQuery(this).next().is("span")){$(this).parent().addClass("triger")}
	}),
	jQuery("#reply_face a").live("mouseout",function(){
			if(jQuery(this).next().is("span")){$(this).parent().removeClass("triger")}
		}
	)

	
	jQuery(".photo_list_simple dl").live("mouseover",function(){
		jQuery(this).addClass("current");
		if(jQuery(this).find(".manage_photolist_option").css("display") == "block"){
			return;
		}else{
			jQuery(this).find(".author").show();
		}
	})
	jQuery(".photo_list_simple dl").live("mouseout",function(){
		if(jQuery(this).find("input").is("input:checked")){
			return false;
		}
		if(jQuery(this).find(".manage_photolist_option").is("div:visible")){
			return false;
		}
		jQuery(this).find(".author").hide();
		jQuery(this).removeClass("current");
	})
	
	jQuery(".manage_photolist .btn_option").click(function(){hidepoption(jQuery(this),0)});
	//jQuery(".manage_photolist .sumbit").click(function(){hidepoption(jQuery(this),1)})

	jQuery(".manage_photolist .author a").click(function(){
		jQuery(this).parent().next().show();
		var tspan = jQuery(this).parent().prev().find("span");
		var tinput = jQuery(this).parent().prev().find("input");
		tspan.hide();
		tinput.show();
		var v = tspan.text(); 
		tinput.val(tspan.text());
		jQuery(this).parent().hide();
		return false;
	})
	jQuery(".manage_photolist input[type='text']").keypress(function(event){
		if(getkeycode(event) == 13){
			jQuery(this).parent().parent().next().next().find(".sumbit").click();
		}
	});

	//照片最终页编辑照片说明
	jQuery(".view_photo_intro dt a").click(function(){
		jQuery(this).prev().andSelf().hide();
		jQuery(this).next().css({"display":"block"});
		return false;
	})
	jQuery(".view_photo_intro .btn_option").click(function(){
		jQuery(this).parent().hide().prev().show().prev().show();
	})
	
	//重置表情列表位置
	jQuery(window).resize(function(){
		if(jQuery("#reply_face").css("display") == "block"){reset_replybox();}
		if(jQuery("#gift_ulist").css("display") == "block"){reserGulist();}
	})

	jQuery("body").click(function(){
		if(jQuery("#reply_face").css("display") == "block"){
			jQuery("#reply_face").hide().find("ul").hide().eq(0).show();
		}
		jQuery(".subnav_config_list").hide();
		jQuery(".replybox .atxt textarea").each(function(){
			if(jQuery(this).attr("rel") == "unfold"){
				return;
			}else if(jQuery(this).val() == ""){
				show_inputbox(jQuery(this),0)
			}
		})

		var index_broad = jQuery("#broard_show textarea");
		if(index_broad.val() == ""){
			index_broad.val("小心思、得意事、不爽ing……想说就说");
			index_broad.animate({height:"23px"},200,function(){
				jQuery("#broard_show .icon_face, #broard_show cite, #broard_show .broard_btn").hide();
				jQuery("#broard_show .lastbroard_post").show();
			})
		}
		

	})
	


	
})

//向导
function showShade()
{
	var shade=$("#shade")
	shade.show();	
	shade.width($(window).width());
	//if(shade.width()<980)shade.width(980);
	shade.height($(document).height());
}
function openw(obj){
	showShade();
	var obj=$("#"+obj)
	$(obj).show()
	var windowHeight = ($(window).height() - obj.height())/2 ;
	var windowWidth = ($(window).width() - obj.width())/2 ;
	obj.css({"top":(windowHeight + $(document).scrollTop())+"px","left":(windowWidth + $(document).scrollLeft())+"px"})
}
function clswin(obj){
	$("#shade").hide();
	$("#"+obj).hide();
	$(document).scrollTop(0);
	$(document).scrollLeft(0);
}
function skip_To(n){
	obj=$("#step_"+n);	
	obj_next=$("#step_"+(n+1));		
	obj_next.css({"left":obj.offset().left,"top":obj.offset().top})
	if(n==1)obj_t=$("div.dropbar").eq(1).find("a")
	if(n==2)obj_t=$("dl.minfo")
	if(n==3)obj_t=$("label.atxt")
	if(n==4)obj_t=$("dl.minfo").find("li").eq(1)
	if(n==5)obj_t=$("div.per_house")
	if(n==6)obj_t=$("div.invite").find("a")
	if(n==7)obj_t=$("div.slide_find_friend").find("li").eq(2)
	if(n==8)obj_t=$("ul.view_stati").find("li").eq(1)
	l_0=obj_t.offset().left
	l=l_0-206
	t_0=obj_t.offset().top
	t=t_0+20
	if(n==2){l=l_0-20;t=t_0-60}
	if(n==5){l=l_0+36;t=t_0+120}
	obj.hide();
	obj_next.show();
	obj_next.animate({left:l,top:t},300);
	wW=$(window).width()
	wH=$(window).height()
	w=obj_next.width()
	h=obj_next.height()
	if(wW<l+w){$(document).scrollLeft(l+w)}else{$(document).scrollLeft(0)}
	if(wH<t+h){$(document).scrollTop(t-50)}else{$(document).scrollTop(0)}		
}
function over_to(obj,url){
	clswin(obj);
	location.href=url
}
//over

//重置礼物用户列表位置
function reserGulist(obj){
	var _x = ($(window).width() - 490)/2;
	var _y = ($(window).height())/2 + $(window).scrollTop();
	$("#gift_ulist").show().css({top:_y,left:_x,width:"380px"});
}

//
function displayLoading(type){
	if(type){
		var tmp;
		if(jQuery("#loading").css("display") == "none"){
			tmp = "#loading";
		}else if(jQuery("#loading").css("display") == "block"){
			return false;	
		}else{
			var tmp = document.createElement("div");
			jQuery(tmp).attr("id","loading").html("loading");
			jQuery("body").append(jQuery(tmp));
			resetLoading();
		}
		jQuery(tmp).slideDown(300);
	}else{
		tmp = "#loading";
		jQuery(tmp).fadeOut(500);
	}
}

function resetLoading() {
	if(jQuery.browser.msie&&(jQuery.browser.version == "6.0")&&!jQuery.support.style){
			jQuery("#loading").css("top",jQuery(window).scrollTop())
	}
}

//展开收起回复
function display_msg_list(obj,type) {
	var c_display = obj.parent().parent().find(".msg_list");
	if(type == "hide"){
		c_display.hide();
		obj.find("a").html(obj.find("em").text()+"条回复");
		if(jQuery("msg_msgboard_tother")){
			var right_height = obj.parent().parent().parent().height();
			var left_height = obj.parent().parent().parent().prev().height();
			if(left_height > right_height){
				obj.parent().parent().parent().parent().height(left_height + 10)
			}
		}
	}
	if(type == "show"){
		c_display.show();
		obj.find("em").hide();
		obj.find("a").html("收起回复");
		if(jQuery("msg_msgboard_tother")){
			obj.parent().parent().parent().parent().height("auto");
		}
	}
}

//好友分组
	//显示
	function show_u_group(obj,type,limit){
		var $obj = jQuery("#sms_cuser_cont");
		var wheight = $(window).height();
		var scrolltop = ($(window).scrollTop() + (wheight - $obj.height())/2) + "px";
		if(limit >=0){
			$obj.attr("limit",limit);
		}
		if($.browser.msie && $.browser.version < 7){
			$obj.css("top",($(window).scrollTop() + (wheight - $obj.height())/2) + "px");
			$(window).scroll(function(){
				var  tmptop = ($(window).scrollTop() + (wheight - $obj.height())/2) + "px";
				$obj.css("top",tmptop);
			})
		}else{
			$obj.css({position:"fixed",top:((wheight - $obj.height())/2)+"px"});
		}
		$obj.show().attr("output",obj+"&"+type).jqDrag("h5");
	}
	//隐藏
	function hide_u_group(){
		var $obj = jQuery("#sms_cuser_cont");
		var otar = $obj.attr("output").split("&");
		$obj.removeAttr("output").removeAttr("limit").hide();
		jQuery("#"+otar[0]).val("");
	}

//礼物包装
function getflashstr(str){
	return '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="220" height="100" id="giftpacking"><param name="allowScriptAccess" value="sameDomain" /><param name="movie" value="http://i3.dukuai.com/ui/sns/user/images/giftpack.swf" /><param name="quality" value="high" /><param name="wmode" value="transparent" /><param name="menu" value="false" /><param name="FlashVars" value="'+ str +'" /><embed src="http://i3.dukuai.com/ui/sns/user/images/giftpack.swf" quality="high" wmode="transparent" menu="false" width="220" height="100" flashvars="'+ str +'" allowscriptaccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"  name="giftpacking" swliveconnect="true" /></object>';
}

//显示输入框
function show_inputbox(obj,i){
	if(obj.attr("rel") == "unfold"){
			return false;
	}
	if(i == 0){
		obj.animate({height:"19px"},200);
		obj.parent().parent().next().slideUp(200);
	}
	if(i==1){
		obj.parent().parent().next().slideDown(200);
		obj.animate({height:"55px"},200,function(){
			jQuery(this).css({"overflow":"auto"})
		});
		if(obj.val() == "我也要回复") obj.val("");
	}
}

function reset_replybox(str) {
	if(jQuery("#reply_face").attr("edit") == str && jQuery("#reply_face").css("display") == "block"){
		jQuery("#reply_face").find("ul").hide().end().hide();
	}else{
		str = !str ? jQuery("#reply_face").attr("edit") : str;
		if(!str) {return false;}
		var _x = jQuery("#"+str).offset().left + "px"
		var _y;
		if(jQuery("#"+str).attr("rel") == "unfold"){
			var tmpObj = jQuery(".icon_face[rel='"+str+"']");
			_y = parseInt(tmpObj.offset().top - 170)+ "px";
		}else{
			_y = parseInt(jQuery("#"+str).offset().top - 170)+ "px";
		}
		jQuery("#reply_face ul").eq(0).show();
		jQuery("#reply_face").css({top:_y,left:_x}).attr("edit",str).show();
		jQuery("#reply_face_page span").html(1)
		show_inputbox(jQuery("#"+str),1);
	}
}

function getkeycode(e){
	var keycode = window.event ? e.keyCode:e.which;
	return keycode;
}

function hidepoption(obj,type){
	obj.parent().hide();
	obj.parent().prev().show();
	var hspan = obj.parent().prev().prev().find("span");
	var hinput = obj.parent().prev().prev().find("input");
	hinput.hide();
	hspan.show();
	if(type){
		var v = hinput.val();
		hspan.text(v);
	}	
}

function getsms_user_info(){
	var sms_user_str = new Array();
	sms_user_str['name'] = sms_user_str['id'] = "";
	jQuery("#sms_main .sms_selected").each(function(){
		sms_user_str['name'] = (sms_user_str['name'] == "")? jQuery.trim(jQuery(this).find("dt").html()):sms_user_str['name']+","+jQuery.trim(jQuery(this).find("dt").html());
		sms_user_str['id'] = (sms_user_str['id'] == "")? jQuery(this).find("input").val():sms_user_str['id']+","+jQuery(this).find("input").val();	
	})
	return sms_user_str;	
}

function showeditbox(obj,n) {
	var f_parent;
	if(obj.parent().is(".setnikename")){
		f_parent = obj.parent();
	}else{
		f_parent = obj.parent().parent();
	}
	if(n == 0){
		jQuery(f_parent).children("a").hide();
		jQuery(f_parent).find("input").show().focus();
	}else{
		jQuery(f_parent).children("a").show();
		obj.val("").hide();
	}
}

function upload_face_change(){
	jQuery("#input_upload_face").val(jQuery("#file_upload_face input").val());
}

function getTipId(){
	return "tip_"+new Date().getTime();
}

function msg_closed(obj){
	if(typeof(obj) == "string"){
		window.setTimeout(function(){
			jQuery("#"+obj).animate({opacity:"0",height:"0",marginTop:"0"},500,function(){jQuery(this).hide()})	
		},6000);
	}else if(typeof(obj) == "object"){
		jQuery(obj).animate({opacity:"0",height:"0",marginTop:"0"},500,function(){jQuery(this).hide()});
	}
}

function show_fullinfo(obj){
	if(jQuery(obj).attr("rel") == "noevent") return false;
	if(jQuery(obj).find(".uface_full").css("display") == "none"){
		hide_info_full();
		jQuery(obj).find(".friend_viewall").addClass("friend_viewall_unfold");
		jQuery(obj).find(".friend_viewall").attr("title","收起");
		jQuery(obj).find(".uface_small").hide();
		jQuery(obj).find(".uface_full").show();
		jQuery(obj).find(".friend_full_info").show();
	}else{
		hide_info_full(obj);
	}
	return false;
}

function hide_info_full(obj){
	jQuery(obj).find(".friend_viewall").removeClass("friend_viewall_unfold");
	jQuery(obj).find(".friend_viewall").attr("title","展开");
	jQuery(obj).find(".uface_small").show();
	jQuery(obj).find(".uface_full").hide();
	jQuery(obj).find(".friend_full_info").hide();
}

/* textarea maxlength */
function limitinput(obj){
	var max_length = obj.attr("maxlength");
	if(!max_length){return false;}
	obj.bind("keyup",function(){
		obj.parent().find("em").html(jQuery(this).val().length)
		if(jQuery(this).val().length > max_length){
			obj.next().find("em").html(max_length)
			jQuery(this).val(jQuery(this).val().substring(0, max_length));
		}
	})
	if(obj.attr("entermethod")){
		obj.unbind("keypress").bind("keypress",function(e){
			if(e.shiftKey && getkeycode(e) == 13){
				return true;
			}else if(getkeycode(e) == 13){
				eval($(this).attr("entermethod")+"()");
				return false;
			}
		})
	}
	/*obj.bind("focus",function(){
		document.oncontextmenu = function(){return false;}
	})
	obj.bind("blur",function(){
			document.oncontextmenu = function(){return true;}
	})*/
}


function insertcharacter(textObj,textFeildValue){
	if(document.all&&textObj.createTextRange&&textObj.caretPos){
		var caretPos=textObj.caretPos;
		caretPos.text=caretPos.text.charAt(caretPos.text.length-1)==''?textFeildValue+'':textFeildValue;
	}else if(textObj.setSelectionRange){
		var rangeStart=textObj.selectionStart;
		var rangeEnd=textObj.selectionEnd;
		var tempStr1=textObj.value.substring(0,rangeStart);
		var tempStr2=textObj.value.substring(rangeEnd);
		textObj.value=tempStr1+textFeildValue+tempStr2;
		textObj.focus();
		var len=textFeildValue.length;
		textObj.setSelectionRange(rangeStart+len,rangeStart+len);
		textObj.blur();
	}else {
	textObj.value+=textFeildValue;
	}
}


(function($) {
	$.dk_confim = function(message, options) {
		options = $.extend({},$.dk_confim.defaults,options);
		$.dk_confim.currentPrefix = options.prefix;
		options.currentclass = (options.myclass) ? "dk_confirm "+ options.myclass:"dk_confirm";
		var ie6		= ($.browser.msie && $.browser.version < 7);
		var $body	= $(document.body);
		var $window	= $(window);

		//build the box and fade
		var msgbox = '<div class="'+ options.prefix +'box" id="'+ options.prefix +'box">';
		if(ie6) {
				$('select').css('visibility','hidden');
			}
		msgbox +='<div class="'+ options.prefix +'fade" id="'+ options.prefix +'fade"></div>';
		msgbox += '<div class="'+ options.currentclass +'" id="'+ options.prefix +'"><div class="'+options.prefix+'background"></div><div class="'+ options.prefix +'container"><div class="imskin ';
		msgbox += options.prefix +'close" title="关闭">关闭</div><div id="'+ options.prefix +'states"></div>';
		msgbox += '</div></div></div>';

		if($("#dk_confirmbox")){
			$("#dk_confirmbox").remove();
		}
		var $jqib	= $(msgbox).appendTo($body);
		var $jqi	= $jqib.children('#'+ options.prefix);
		var $jqif	= $jqib.children('#'+ options.prefix +'fade');

		//if a string was passed, convert to a single state
		if(message.constructor == String){
			message = {
				state0: {
					html: message,
				 	buttons: options.buttons,
				 	focus: options.focus,
				 	submit: options.submit
			 	}
		 	};
		}

		//build the states
		var states = "";

		$.each(message,function(statename,stateobj){
			stateobj = $.extend({},$.dk_confim.defaults.state,stateobj);
			message[statename] = stateobj;
			states += '<div id="'+ options.prefix +'_state_'+ statename +'" class="'+ options.prefix + '_state" style="display:none;"><div class="'+ options.prefix +'message">' + stateobj.html +'</div><div class="'+ options.prefix +'buttons"><span class="sumbit"><span><button id="' + options.prefix +	'_confim_button" value="'+ options.button +'">'+ options.button +'</button></span></span><span class="btn_option"><span><button id="' + options.prefix +	'_cancel_button" class="btn_option" value="取消">'+ options.cancel +'</button></span></span></div></div>';
		});

		//insert the states...
		$jqi.find('#'+ options.prefix +'states').html(states).children('.'+ options.prefix +'_state:first').css('display','block');
		$jqi.find('.'+ options.prefix +'buttons:empty').css('display','none');
		
		//Events
		$.each(message,function(statename,stateobj){
			var $state = $jqi.find('#'+ options.prefix +'_state_'+ statename);
		});

		var ie6scroll = function(){
			$jqib.css({ top: $window.scrollTop() });
		};

		var getKeyCode = function(e){
			var key = (window.event) ? event.keyCode : e.which;
			return key;
		};

		var positionPrompt = function(){
			$jqib.css({
				position: (ie6) ? "absolute" : "fixed",
				height: $window.height(),
				width: "100%",
				top: (ie6)? $window.scrollTop() : 0,
				left: 0,
				right: 0,
				bottom: 0
			});
			$jqif.css({
				position: "absolute",
				height: $window.height(),
				width: "100%",
				background:"#000000",
				opacity:"0.4",
				top: 0,
				left: 0,
				right: 0,
				bottom: 0
			});
			$jqi.css({
				position: "absolute",
				top: options.top,
				left: "50%",
				marginLeft: (($jqi.outerWidth()/2)*-1),
				marginTop: (($jqi.outerHeight()/2)*-1)
			});
		};

		var stylePrompt = function(){
			$jqif.css({
				zIndex: options.zIndex,
				display: "none",
				opacity: options.opacity
			});
			$jqi.css({
				zIndex: options.zIndex+1,
				display: "none"
			});
			$jqib.css({
				zIndex: options.zIndex
			});
		};

		var removePrompt = function(callCallback){
			if(callCallback && options.callback() == false){
					return false;
			}else{
				jQuery("button").removeAttr("disabled");//取消button的disable
				$jqib.hide();
				//ie6, remove the scroll event
				if(ie6) {
					$body.unbind('scroll',ie6scroll);
				}
				$window.unbind('resize',positionPrompt);
				$jqif.fadeOut('fast',function(){
					$jqif.unbind();
					//$jqif.remove();
					
					//$jqib.remove();
					if(ie6 && !options.useiframe) {
						$('select').css('visibility','visible');
					}
				});
			}
		};

		positionPrompt();
		stylePrompt();
		
		//ie6, add a scroll event to fix position:fixed
		if(ie6) {
			$window.scroll(ie6scroll);
		}
		$window.resize(positionPrompt);
		$jqi.find('.'+ options.prefix +'close').click(function(){removePrompt(0)});
		$jqi.find('#'+ options.prefix +'_confim_button').click(function(){removePrompt(1)});
		$jqi.find('#'+ options.prefix +'_cancel_button').click(function(){removePrompt(0)});
		$(document).keydown(function(event) {
			if(getKeyCode(event) == 27){removeConfim()};
		});

		//Show it
		$jqif.show();
		$jqi.show();
	};
	
	$.dk_confim.defaults = {
		prefix:'dk_confirm',	
		callback: function(){},
		myclass:'dk_confirm',
		opacity: 0.4,
	 	zIndex: 999,
		overlayspeed: 'fast',
		promptspeed: 'fast',
		focus: 0,
		useiframe: false,
	 	top: "50%",
		button:"确定",
		cancel:"取消"
	};
	
	$.dk_confim.close = function() {
		$('#'+ $.dk_confim.currentPrefix +'box').fadeOut('fast',function(){
        		$(this).remove();
		});
	};
	
})(jQuery);

(function($) {
	$.fn.dk_openwin = function(options) {
		var options = $.extend({},$.fn.dk_openwin.defaults,options);
		var $this = $(this);
		var ie6		= ($.browser.msie && $.browser.version < 7);
		var $body	= $(document.body);
		var $window	= $(window);

		if(ie6) {
			$('select').css('visibility','hidden');
		}

		if($("#openwin_fade")){
			$("#openwin_fade").remove();
		}
		
		if($this.length == 0){return false;}

		html ='<div class="openwin_fade" id="openwin_fade"></div>';
		
		$winfade = $(html).appendTo($body);

		var ie6scroll = function(){
			$winfade.css({top: $window.scrollTop()});
			$this.css({top: ($window.height() - $this.height())/2 + $window.scrollTop() + "px" });
		};

		var getKeyCode = function(e){
			var key = (window.event) ? event.keyCode : e.which;
			return key;
		};

		var positionWin = function(){
			$winfade.css({
				position: (ie6) ? "absolute" : "fixed",
				zIndex: 1000,
				height: $window.height(),
				width: "100%",
				top: (ie6)? $window.scrollTop() : 0,
				left: 0,
				right: 0,
				bottom: 0,
				background: options.background,
				opacity:options.opacity
			});
			$this.css({
				position: (ie6) ? "absolute" : "fixed",
				zIndex: 3180,
				top: (ie6) ? (($window.height() - $this.height())/2 + $window.scrollTop()) + "px" : ($window.height() - $this.height())/2 + "px",
				left:($window.width() - $this.width())/2 + "px"
			});
		};

		removeWin = function(callCallback){
			if(callCallback && options.callback() == false){
					return false;
			}else{
				$winfade.unbind().remove();
				if(ie6) {
					$body.unbind('scroll',ie6scroll);
				}
				$window.unbind('resize',positionWin);
				$this.hide();
				if(ie6){
					$('select').css('visibility','visible');
				}
			}
		};

		positionWin();
		$this.fadeIn(10,function(){
			options.callin && eval(options.callin)
		});

		
		//ie6, add a scroll event to fix position:fixed
		if(ie6) {$window.scroll(ie6scroll);}
		$window.resize(positionWin);
		$this.find(options.closeobj).click(function(){removeWin();return false;})
		$(document).keydown(function(event) {if(getKeyCode(event) == 27){removeWin()};});
	};
	
	$.fn.dk_openwin.defaults = {
		callback: function(){},
		callin: function(){},
		opacity: 0.5,
		background: "#000",
	 	zIndex: 999
	};
	
	$.fn.dk_openwin.close = function(){removeWin()};
})(jQuery);

(function($) {
	$.fn.dk_circle = function(options) {
		var option = $.extend({},$.fn.dk_circle.defaults,options);
		var $obj = this;
		var $obj_cld = $obj.find("li");
		var $slidepage;
		var $slidepage_cld;
		var current = 0;
		var pause = false;
		var timeout;


		var init = function(){
			var txt = "";
			for(var i=0;i < $obj_cld.size();i++){
				if(i==0){
					txt += '<span class="current">'+ (i+1) +'</span>';
				}else{
					txt += '<span>'+ (i+1) +'</span>';
				}
			}

			$obj.after('<div class="slidepage" id="slideplay-page">'+ txt +'</div>');
			current = 0;//初始化当前位置

			$obj_cld.each(function(i){
				$(this).css({position:"absolute",zIndex:(3-i)});
			});
			
			$slidepage = $("#slideplay-page");
			$slidepage_cld = $slidepage.find("span");

			$slidepage_cld.each(function(i){
				$(this).bind("click",function(){
					clearInterval(timeout);
					if(i == current || pause) return false
					pause = true;
					dkslide(i);
				})
			});

			if(option.auto){
				timeout = setInterval(autoplay,option.time);
			}
		}

		var autoplay = function(){
			if(current == 2){
				dkslide(0);
			}else{
				dkslide(current+1);
			}
		}
		
		var dkslide = function(i){
			$slidepage_cld.removeClass("current");
			$slidepage_cld.eq(i).addClass("current");
			var now_zindex = $obj_cld.eq(i).css("z-index");
			$obj_cld.eq(i).css({zIndex:3}).end().eq(current).css("z-index",4).animate({opacity:0},500,function(){
				$(this).css({zIndex:now_zindex,opacity:100});
				pause = false;
				if(option.auto){
					clearInterval(timeout);
					timeout = setInterval(autoplay,option.time);
				}
			}).end();
			current = i;
		}

		

		$.fn.dk_circle.defaults = {
			time:3000,
			auto:false
		};

		init();
		
	}
	
})(jQuery);

//simplescroll
(function($){
	$.fn.dk_simplescroll = function(options){
		var opt = $.extend({},$.fn.dk_simplescroll.defaults,options);
		var $this = $(this);
		var scrollPause = false //是否暂停自动播放
		var scrollWrapId = "scrollWrap_"+$this.attr('id');//包裹对象id
		var $scrollWrap;//包裹对象
		var ChildSize = $this.children().size(); //获得子节点数量
		var singleSize = opt.type == "x" ? $this.children().outerWidth() : $this.children().outerHeight(); //获得单个子节点尺寸
		var overPlus = opt.type == "x" ? $this.width() - ChildSize* singleSize : $this.height() - ChildSize* singleSize;
		
		if(overPlus >= 0) {return false} //内容不够多时候自动退出

		if(opt.auto){
			opt.cycle = true;
			opt.action = "single";
		}
		
		//初始化
		var init = function(){
			$this.css({position:"relative",zIndex:0});
			
			if(opt.cycle){ //循环播放时将类容复制3份
				opt.action = "single";
				$this.html("<div id='"+scrollWrapId+"' style='position:absolute;z-index:0;'>"+$this.html() + $this.html() + $this.html()+"</div>");
			}else{
				$this.html("<div id='"+scrollWrapId+"' style='position:absolute;z-index:0;'>"+$this.html()+"</div>");
			}
			$scrollWrap = $this.find("#"+scrollWrapId);

			if(opt.type == "x"){
				$scrollWrap.width(singleSize*$scrollWrap.children().size()).css({left:0,top:0});
				if(opt.cycle){
					$scrollWrap.css("left",singleSize*ChildSize*(-1));
				}
			}else{
				$scrollWrap.height(singleSize*$scrollWrap.children().size()).css({top:0,left:0});
				if(opt.cycle){
					$scrollWrap.css("top",singleSize*ChildSize*(-1));
				}
			}
			
			//绑定事件
			if(opt.nextId){
				$("#" + opt.nextId).click(function(){
					if(opt.auto) {clearInterval(timeout);}
					if(opt.action == "single"){
						doanimate(-1);
					}else	if(opt.action == "group"){
						if(opt.type == "x"){
							doanimate(0-$this.width()/singleSize);
						}else{
							doanimate(0-$this.height()/singleSize);
						}
					}
					return false;
				});
			};
			if(opt.prevId){
				$("#" + opt.prevId).click(function(){
					if(opt.auto) {clearInterval(timeout);}
					if(opt.action == "single"){
						doanimate(1);
					}else	if(opt.action == "group"){
						if(opt.type == "x"){
							doanimate($this.width()/singleSize);
						}else{
							doanimate($this.height()/singleSize);
						}
					}
					return false;
				});
			}
			if(opt.auto){
				$this.hover(function(){
						clearInterval(timeout);
						timeout = "mmover";
					},
					function(){
						timeout = window.setInterval(function(){
							doanimate(-1);
						},opt.autotime)
					}
				)
			}
		}

		//移动事件
		var doanimate = function(n){
			if(scrollPause){return false;}
			scrollPause = true;
			var tmpPosVal = opt.type == "x" ? parseInt($scrollWrap.css("left")) : parseInt($scrollWrap.css("top"));
			if(tmpPosVal == 0  && n >0){scrollPause = false;return false;}
			if(tmpPosVal <= overPlus && !opt.cycle && n<0){scrollPause = false;return false;}
			if(opt.type == "x"){
				$scrollWrap.animate({left:tmpPosVal + n*singleSize},opt.speed,function(){
					checkPosition(tmpPosVal + n*singleSize,"x");
				});
			}else{
				$scrollWrap.animate({top:tmpPosVal + n*singleSize},opt.speed,function(){
					checkPosition(tmpPosVal + n*singleSize,"y");
				});
			}
		}
		
		//检测
		var checkPosition = function(v,p){
			scrollPause = false;
			if(opt.cycle){
				if(v == 0){
					if(p == "x"){
						$scrollWrap.css("left",singleSize*ChildSize*(-1));
					}else{
						$scrollWrap.css("top",singleSize*ChildSize*(-1));
					}
				}
				if(v <= singleSize*ChildSize*(-2)){
					if(p == "x"){
						$scrollWrap.css({left:singleSize*ChildSize*(-1)});
					}else{
						$scrollWrap.css({top:singleSize*ChildSize*(-1)});
					}
				}
			}
			if(opt.auto && timeout != "mmover"){
				clearInterval(timeout);
				timeout = window.setInterval(function(){
					doanimate(-1);
				},opt.autotime)
			}
		}

		if(opt.auto){
			var timeout = window.setInterval(function(){
				doanimate(-1);
			},opt.autotime)
		}
		
		init();

	}

	$.fn.dk_simplescroll.defaults = {
		type:   "x",         //滚动方向{x|y} 横向、纵向 默认x
		action: "single",    //滚动方式{single|group}单张、组 默认single
		cycle:  false,       //是否循环 默认false
		auto:  false,        //是否自动播放，自动播放时cycle默认为true 默认false
		autotime: 3000,      //自动播放间隔时间 默认为3000毫秒(3秒)
		speed: 500           //速度 300 默认500毫秒(5秒)
	}

	
})(jQuery);

//drag
(function($){
$.fn.jqDrag=function(h){return i(this,h,'d');};
$.fn.jqResize=function(h){return i(this,h,'r');};
$.jqDnR={dnr:{},e:0,
drag:function(v){
 if(M.k == 'd'){
	if(E.attr("class") == "scrollbar"){
		var cleft = 0;
		if(M.X+v.pageX-M.pX < 0){cleft = 0;}else if(M.X+v.pageX-M.pX > 950){cleft = 950;}else{cleft = M.X+v.pageX-M.pX}
		E.css({left: cleft,top:M.Y});
		var mleft = ($(".tab_content:visible li").size() - 6) * 0.175 * cleft;
		$(".tab_content:visible ul").css({"margin-left":-(mleft.toFixed(2))+"px"});
	}else{
		E.css({left:M.X+v.pageX-M.pX,top:M.Y+v.pageY-M.pY});
	}
 }else{
 	E.css({left:M.X+v.pageX-M.pX,top:M.Y+v.pageY-M.pY});
	E.css({width:Math.max(v.pageX-M.pX+M.W,0),height:Math.max(v.pageY-M.pY+M.H,0)});
 }
},
stop:function(){E.css({opacity:1}).find("cite").css({opacity:1,"z-index":0});$().unbind('mousemove',J.drag).unbind('mouseup',J.stop);}
};
var J=$.jqDnR,M=J.dnr,E=J.e,
i=function(e,h,k){return e.each(function(){h=(h)?$(h,e):e;
 h.bind('mousedown',{e:e,k:k},function(v){var d=v.data,p={};E=d.e;
 // attempt utilization of dimensions plugin to fix IE issues
 if(E.css('position') != 'relative'){try{E.position(p);}catch(e){}}
 M={X:p.left||f('left')||0,Y:p.top||f('top')||0,W:f('width')||E[0].scrollWidth||0,H:f('height')||E[0].scrollHeight||0,pX:v.pageX,pY:v.pageY,k:d.k,o:E.css('opacity')};
 E.css({opacity:0.8});$().mousemove($.jqDnR.drag).mouseup($.jqDnR.stop);
 return false;
 });
});},
f=function(k){return parseInt(E.css(k))||false;};
})(jQuery);
