//--ljf
//自动添加展开/收缩、关闭按钮，悬浮
$(document).ready(function(){
	init_();
})
function init_(){
	
	//template: <div class="float_div"><div class="float_content none/displayed">1111111</div></div>
	
	$("[class*='float_content'][class*='none']").hide();
	//if ($.browser.msie && ($.browser.version == "6.0" || $.browser.version == "8.0")){
	if (true){
		do_float();
			/*
			$(".float_div").css({position:"absolute"});
			$("body").css({margin:"0px",height:"100%",overflow:"auto"}).css("overflow_y","auto");
			//$("html").css({overflow:"hidden"}).css("overflow_x","auto").css("overflow_y","hidden");
			$("html").css({overflow:"auto"});
			$(".float_div").css({position:"absolute"});
			_right = parseInt($(".float_div").css("right")) + 17;
			$(".float_div").css({right:_right});
			*/
	}else{
		do_float_fixed();
	}
	if($('.float_content').html()!=""){
		$(".float_div").css({display:"block"});
	}
	//add button begin
	collapse_button = "[-]";
	collapse_button_move = "<font style='color:red'>[-]</font>";
	expand_button = "[+]";
	expand_button_move = "<font style='color:red'>[+]</font>";
	close_button = "[X]";
	close_button_move = "<font style='color:red'>[X]</font>";
	//button_with_collapse = $('<div class="float_menu"><span title="关闭" style="float:right; padding-right:3px;" class="float_close">'+close_button+'</span><span title="收缩" style="float:right;padding-right:3px;" class="float_switch float_collapse">'+collapse_button+'</span></div>');
	button_with_collapse = $('<div class="float_menu"><div style="float:right;"><span title="收缩" style="padding-right:3px;" class="float_switch float_collapse">'+collapse_button+'</span><span title="关闭" style="padding-right:3px;" class="float_close">'+close_button+'</span></div></div>');
	//button_with_expand = $('<div class="float_menu"><span title="关闭" style="float:right; padding-right:3px;" class="float_close">'+close_button+'</span><span title="展开" style="float:right;padding-right:3px;" class="float_switch float_expand">'+expand_button+'</span></div>');
	button_with_expand = $('<div class="float_menu"><div style="float:right;"><span title="展开" style="padding-right:3px;" class="float_switch float_expand">'+expand_button+'</span><span title="关闭" style="padding-right:3px;" class="float_close">'+close_button+'</span></div></div>');
	$("[class*='float_content'][class*='displayed']").before(button_with_collapse);
	$("[class*='float_content'][class*='none']").before(button_with_expand);
	//add button end
	//close begin
	$(".float_close").click(function(){close_(this);});
	//$(".float_close").mousemove(function(){$(this).html(close_button_move);});
	
	//close end
	//switch begin
	$(".float_switch").click(function(){switch_(this);});
	var mouse_over_effect = false;
	if (mouse_over_effect){
		$(".float_close").mouseover(function(){$(this).html(close_button_move);});
		$(".float_close").mouseout(function(){$(this).html(close_button);});
		$(".float_switch").mouseover(function(){
			if ($(this).hasClass('float_collapse')){
				$(this).html(collapse_button_move);
				return;
			}
			if ($(this).hasClass('float_expand')){
				$(this).html(expand_button_move);
				return;
			}
		});
		$(".float_switch").mouseout(function(){
			if ($(this).hasClass('float_collapse')){
				$(this).html(collapse_button);
				return;
			}
			if ($(this).hasClass('float_expand')){
				$(this).html(expand_button);
				return;
			}
		});
	}
	/*
	$(".float_switch").mousemove(function(){
		if ($(this).hasClass('float_collapse')){
			$(this).html(collapse_button_move);
			return;
		}
		if ($(this).hasClass('float_expand')){
			$(this).html(expand_button_move);
			return;
		}
	});
	*/
	//switch end
}
function do_float(){
	var _top = new Array();
	var _right = new Array();
	var _left = new Array();
	$(".float_div").each(function(index,node){
		$(node).css({position:"absolute"});
		_top[index] = isNaN(parseInt($(node).attr("top")))?"200":parseInt($(node).attr("top"));
		if (!isNaN(parseInt($(node).attr("right")))){
			_right[index] = parseInt($(node).attr("right"));
			$(node).css({right:_right[index]+"px"});
		}else if (!isNaN(parseInt($(node).attr("left")))){
			_left[index] = parseInt($(node).attr("left"));
			$(node).css({left:_left[index]+"px"});
		}else{
			_right[index] = 1;
			$(node).css({right:_right[index]+"px"});
		}
		if (_top[index]){
			timer = window.setInterval(function(){
				$(node).css({top:(parseInt($(document).scrollTop())+parseInt(_top[index]))+"px"});
			},500);
		}
	})
}
function do_float_fixed(){
	var _top = new Array();
	$(".float_div").each(function(index,node){
		$(node).css({position:"fixed"});
		$(node).css({top:($(node).attr("top"))?$(node).attr("top"):"200px"});
		if (!isNaN(parseInt($(node).attr("right")))){
			$(node).css({right:$(node).attr("right")});
		}else if (!isNaN(parseInt($(node).attr("left")))){
			$(node).css({left:$(node).attr("left")});
		}else{
			$(node).css({right:"1px"});
		}
	});
}
function close_(obj){
	_p = $(obj).parents(".float_div");//parent
	_c = $(_p).children(".float_content");//content
	_p.animate({height:"0px"},500,"swing",function(){$(_p).hide()});
}
function switch_(obj){
	_p = $(obj).parents(".float_div");//parent
	_c = $(_p).children(".float_content");//content
	if ($(_c).hasClass("displayed")){
		$(_c).removeClass("displayed");
		$(_c).slideUp(500,function(){$(_c).addClass("none");$(obj).text(expand_button);$(obj).removeClass('float_collapse');$(obj).addClass('float_expand');$(obj).attr("title","展开");});
		return false;
	}
	if ($(_c).hasClass("none")){
		$(_c).removeClass("none");
		$(_c).slideDown(500,function(){$(_c).addClass("displayed");$(obj).text(collapse_button);$(obj).removeClass('float_expand');$(obj).addClass('float_collapse');$(obj).attr("title","收缩");});
		return false;
	}
}