﻿/*任意位置浮动固定层
修改by虫虫3000 20091104
*/

/*调用：
1 无参数调用：默认浮动在右下角
$('#id').floatdiv();

2 内置固定位置浮动
//右下角
$('#id').floatdiv('rightbottom');
//右上角
$('#id').floatdiv('righttop');
//左下角
$('#id').floatdiv('leftbottom');
//左上角
$('#id').floatdiv('lefttop');
//居中
$('#id').floatdiv('middle');
//居中置顶
$('#id').floatdiv('middletop');
//居中置底
$('#id').floatdiv('middlebottom');
//靠左水平居中
$('#id').floatdiv('leftmiddle');
//靠右水平居中
$('#id').floatdiv('rightmiddle');

3 自定义位置浮动
$('#id').floatdiv({left:'10px',top:'10px'});
以上参数，设置浮动层在left 10个像素,top 10个像素的位置
*/

jQuery.fn.floatdiv=function(location){
	//判断浏览器版本
	var isIE6=false;
	if (($.browser.msie) && ($.browser.version.indexOf('6.0')>=0))
	isIE6 = true;
	
	var windowWidth,windowHeight;//窗口的高和宽
	//取得窗口的高和宽
	if (self.innerHeight) {
		windowWidth=self.innerWidth;
		windowHeight=self.innerHeight;
	}else if (document.documentElement&&document.documentElement.clientHeight) {
		windowWidth=document.documentElement.clientWidth;
		windowHeight=document.documentElement.clientHeight;
	} else if (document.body) {
		windowWidth=document.body.clientWidth;
		windowHeight=document.body.clientHeight;
	}
	return this.each(function(){
		var loc;//层的绝对定位位置
		var WrapfloatMenuBar =$('<div style="position:absolute;z-index:9999;"></div>');
		var WrapfloatMenu=$('<div id="FloatMenu" style="height:32px;background:url(/themes/style1/img/fnavibg.gif) repeat-x;"></div>');
		var top=-1;
		if(location==undefined || location.constructor == String){
			switch(location){
				case('rightbottom')://右下角
					loc={right:'0px',bottom:'0px'};
					break;
				case('leftbottom')://左下角
					loc={left:'0px',bottom:'0px'};
					break;	
				case('lefttop')://左上角
					loc={left:'0px',top:'0px'};
					top=0;
					break;
				case('righttop')://右上角
					loc={right:'0px',top:'0px'};
					top=0;
					break;
				case('middletop')://居中置顶
					loc={left:windowWidth/2-$(this).width()/2+'px',top:'0px'};
					top=0;
					break;
				case('middlebottom')://居中置低
					loc={left:windowWidth/2-$(this).width()/2+'px',bottom:'0px'};
					break;
				case('leftmiddle')://左边居中
					loc={left:'0px',top:windowHeight/2-$(this).height()/2+'px'};
					top=windowHeight/2-$(this).height()/2;
					break;
				case('rightmiddle')://右边居中
					loc={right:'0px',top:windowHeight/2-$(this).height()/2+'px'};
					top=windowHeight/2-$(this).height()/2;
					break;
				case('middle')://居中
					var l=0;//居左
					var t=0;//居上
					l=windowWidth/2-$(this).width()/2;
					t=windowHeight/2-$(this).height()/2;
					top=t;
					loc={left:l+'px',top:t+'px'};
					break;
				default://默认为右下角
					location='rightbottom';
					loc={right:'0px',bottom:'0px'};
					break;
			}
		}else{
			loc=location;
			var str=loc.top;
			str=str.replace('px','');
			top=str;
		}
		/*fied ie6 css hack*/
		if(isIE6){
			if (top>=0)
			{
				WrapfloatMenuBar=$('<div id="WrapfloatMenuBar" style="position:absolute;top:expression(documentElement.scrollTop+'+top+');height:30px;line-height:30px;z-index:9999;"></div>');
			}else{
				WrapfloatMenuBar=$('<div id="WrapfloatMenuBar" style="position:absolute;top:expression(documentElement.scrollTop+documentElement.clientHeight-this.offsetHeight);height:30px;line-height:30px;z-index:9999;"></div>');
			}
		}
		
		WrapfloatMenuBar.append('<div id="closeMenu" onclick="jQuery(\'#FloatMenu\').hide();jQuery(\'#openMenu\').show();jQuery(\'#closeMenu\').hide();" style="position:absolute;right:28px;top:10px;z-index:10000;cursor:pointer;"><img src="/Themes/style1/img/pub/closeBar.gif" alt="关闭功能条" title="关闭功能条"  />')
	    WrapfloatMenuBar.append('<div id="openMenu" onclick="jQuery(\'#FloatMenu\').show();jQuery(\'#openMenu\').hide();jQuery(\'#closeMenu\').show();" style="position:absolute;right:28px;top:10px;z-index:10000;display:none;cursor:pointer;"><img src="/Themes/style1/img/pub/openBar.gif" alt="展开功能条" title="展开功能条"  />')	
		$('body').append(WrapfloatMenuBar);
		WrapfloatMenuBar.css(loc).css({position:'fixed',width:'100%'});
		if (isIE6)
		{
			
			WrapfloatMenuBar.css({'position':'absolute',width:'100%'});
			//防止ie6跳动
			$('body').css('background-attachment','fixed').css('background-image','url(/nothing.txt)');
		}
		WrapfloatMenuBar.append(WrapfloatMenu);
		//将要固定的层添加到固定层里
		$(this).appendTo(WrapfloatMenu);
	});
};