﻿jQuery.fn.floatdiv=function(location){
	
	var isIE6=false;
	if($.browser.msie && $.browser.version=="6.0"){
		$("body").css("overflow-y","hidden");
		isIE6=true;
	};
	
	$("body").css({margin:"0px",padding:"0 0px 0 0px",
		border:"0px"
	});
	return this.each(function(){
		var loc;
		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"};
					break;
				case("righttop"):
					loc={right:"0px",top:"0px"};
					break;
				case("middleleft"):
					var l=0;
					var t=0;
					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;
					}
					l=windowWidth/2-$(this).width()/2;
					t=windowHeight/2-$(this).height()/2;
					
					loc={left:0+"px",top:t+"px"};
					break;
					case("middleright"):
					var l=0;
					var t=0;
					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;
					}
					l=windowWidth/2-$(this).width()/2;
					t=windowHeight/2-$(this).height()/2;
					
					loc={right:0+"px",top:t+"px"};
					break;
				default:
					loc={right:"0px",bottom:"0px"};
					break;
			}
		}else{
			loc=location;
		}
		$(this).css("z-index","9999").css(loc).css("position","absolute");
		if(isIE6){
			if(loc.right!=undefined){
				
				if($(this).css("right")==null || $(this).css("right")==""){
					$(this).css("right","18px");
				}
			}
			
		}
	});
};

$(function(){
	
	
	var floatBoxId = 0;	   
	//var mxfloatbox = $(document.body).append('<div class="mxfloatbox"></div>')	;
	var floatBoxPath =wgScriptPath + "/extensions/Corpopedia/floatBox";
	
	$(".floatBox").each(function(){
	//get attr
	var attr = $(this).find(".floatBoxAttr");
	try {
		eval(attr.html());
	}catch(e)
	{
		;
		}
	//初始状态	
	var isHidden = "";
	if($(this).hasClass("hide")) isHidden = 'style="display:none"';
	if(this.className.replace("floatBox","").length==0)this.className="fb_rightbottom";
	$(document.body).append('<div class="floatBox_container '+this.className+'" id="floatBox'+floatBoxId+'"><div class="head"><div class="title"></div><a href="javascript:;"  class="floatBoxButton">&nbsp;</a></div><div class="content" '+isHidden+'></div></div>');
	
	this.className="";
	$(this).hide();
	var floatBox = $("#floatBox"+floatBoxId);
	//add title
	floatBox.find(".head .title").append($(this).attr("title"));
	//add concent
	floatBox.find(" .content").html($(this).html());
	//default win button
	if(floatBox.hasClass("hide"))
			floatBox.find(".head a").css({backgroundImage:"url("+floatBoxPath+"/image/max.gif)"});
			else
			floatBox.find(".head a").css({backgroundImage:"url("+floatBoxPath+"/image/min.gif)"});
	//set width
	$("#floatBox"+floatBoxId).width($(this).width());
	
	//$("#floatBox"+floatBoxId).height($(this).height());
	//add event
	floatBox.find(".head a").bind("click",function(){
			if(this.style.backgroundImage.indexOf("min.gif")!=-1){//min win
				
				floatBox.find(".head a").css({backgroundImage:"url("+floatBoxPath+"/image/max.gif)"});
				floatBox.find(".content").animate({height: 'toggle'},{ duration: 300 }); 
			}else{//max win
				floatBox.find(".content").animate({height: 'toggle'},{ duration: 300 }); 
				floatBox.find(".head a").css({backgroundImage:"url("+floatBoxPath+"/image/min.gif)"})
			}
		
		}) 
	    floatBoxId++;
		
		})
	
	    //fb_rightbottom
		
		if($(".floatBox_container,.fb_rightbottom").size()>0){
			var fc = document.createElement("div");
		    fc.className="mxfloatbox_br";
		    document.body.appendChild(fc);
		    $(".fb_rightbottom").wrapAll(fc);
		    $(".mxfloatbox_br").floatdiv("rightbottom");
			}
		
		// fb_leftbottom
		 
		if($(".floatBox_container,.fb_leftbottom").size()>0){
			var fc = document.createElement("div");
		    fc.className="mxfloatbox_bl";
		    document.body.appendChild(fc);
		    $(".fb_leftbottom").wrapAll(fc);
		    $(".mxfloatbox_bl").floatdiv("leftbottom");
			}
		// fb_lefttop 
		if($(".floatBox_container,.fb_lefttop").size()>0){
			var fc = document.createElement("div");
		    fc.className="mxfloatbox_tl";
		    document.body.appendChild(fc);
		    $(".fb_lefttop").wrapAll(fc);
		    $(".mxfloatbox_tl").floatdiv("lefttop");
			}
		//fb_righttop 
			if($(".floatBox_container,.fb_righttop").size()>0){
			var fc = document.createElement("div");
		    fc.className="mxfloatbox_tr";
		    document.body.appendChild(fc);
		    $(".fb_righttop").wrapAll(fc);
		    $(".mxfloatbox_tr").floatdiv("righttop");
			}
		//fb_middle 	
			if($(".floatBox_container,.fb_middleleft").size()>0){
			var fc = document.createElement("div");
		    fc.className="mxfloatbox_mdl";
		    document.body.appendChild(fc);
		    $(".fb_middleleft").wrapAll(fc);
		    $(".mxfloatbox_mdl").floatdiv("middleleft");
			}
			if($(".floatBox_container,.fb_middleright").size()>0){
			var fc = document.createElement("div");
		    fc.className="mxfloatbox_mdr";
		    document.body.appendChild(fc);
		    $(".fb_middleright").wrapAll(fc);
		    $(".mxfloatbox_mdr").floatdiv("middleright");
			}
			
		
		$(".floatBox_container").animate({height: 'toggle'},{ duration: 120 });  
		
    
		
});
