
var hansonmenu = {
  setdropdown:function(menuid){
    var $mainmenu = $("#"+menuid+">ul")
    var $headers = $mainmenu.find("ul").parent()
    $headers.each(function(i){
      var $curobj = $(this)
      var $subul = $(this).find('ul:eq(0)')
      this._arrows = {
        down:['downarrowclass', 'down.gif', 20],
        right:['rightarrowclass', 'right.gif']
      },
      this._dimensions = {
        w:this.offsetWidth,
        h:this.offsetHeight,
        subulw:$subul.outerWidth(),
        subulh:$subul.outerHeight()
      }
      this.istopheader = $curobj.parents("ul").length == 1 ? true : false
      $subul.css({top:this.istopheader ? this._dimensions.h + "px" : 0})
      $curobj.children("a:eq(0)").css(this.istopheader ? {paddingRight: this._arrows.down[2]} : {}).append(
        '<span class="' + (this.istopheader ? this._arrows.down[0] : this._arrows.right[0]) + '"></span>'
      )
      $curobj.hover(
        function(e){
          var $targetul = $(this).children("ul:eq(0)")
          this._offsets = { left:$(this).offset().left, top:$(this).offset().top }
          var menuleft = this.istopheader? 0 : this._dimensions.w
          menuleft = (this._offsets.left+menuleft+this._dimensions.subulw>$(window).width()) ? (this.istopheader? -this._dimensions.subulw+this._dimensions.w : -this._dimensions.w) : menuleft
          if ($targetul.queue().length<=1) $targetul.css({left:menuleft+"px", width:this._dimensions.subulw+'px'}).slideDown(200)
        },
        function(e){
          var $targetul=$(this).children("ul:eq(0)")
          $targetul.slideUp(50)
        }
      )
    })
    $mainmenu.find("ul").css({display:'none', visibility:'visible'})
  }
}


jQuery.fn.float= function(settings){
	if(typeof settings == "object"){
		settings = jQuery.extend({
			//延迟
			delay : 1000,
			//位置偏移
			offset : {
				left : 0,
				right : 0,
				top : 0,
				bottom : 0
			},
			style : null, //样式
			width:100,  //宽度
			height:200, //高度
			position:"rm" //位置
		}, settings || {});	
		var winW = $(window).width();
		var winH = $(window).height();
		
		 //根据参数获取位置数值
		function getPosition($applyTo,position){
			var _pos = null;
			switch(position){
				case "rm" : 
					$applyTo.data("offset","right");
					$applyTo.data("offsetPostion",settings.offset.right);
					_pos = {right:settings.offset.right,top:winH/2-$applyTo.innerHeight()/2};
				break;
				case "lm" :
					$applyTo.data("offset","left");
					$applyTo.data("offsetPostion",settings.offset.left);
					_pos = {left:settings.offset.left,top:winH/2-$applyTo.innerHeight()/2};
				break;
				case "rb" :
					_pos = {right:settings.offset.right,top:winH - $applyTo.innerHeight()};
				break;
				case "lb" :
					_pos = {left:settings.offset.left,top:winH - $applyTo.innerHeight()};
				break;
				case "l" : 
					_pos = {left:settings.offset.left,top:settings.offset.top};
				break;
				case "r" : 
					_pos = {right:settings.offset.right,top:settings.offset.top};
				break;				
				case "t" :
					$applyTo.data("offset","top");
					$applyTo.data("offsetPostion",settings.offset.top);					
					_pos = {left:settings.offset.left,top:settings.offset.top};
				break;
				case "b" :
					$applyTo.data("offset","bottom");
					$applyTo.data("offsetPostion",settings.offset.bottom);					
					_pos = {left:settings.offset.left,top:winH - $applyTo.innerHeight()};				
				break;
        case "7j" :					
					_pos = {left:settings.offset.left,top:360};				
				break;
			}
			return _pos;
		}
		//设置容器位置
		function setPosition($applyTo,position,isUseAnimate){
			var scrollTop = $(window).scrollTop();
			var scrollLeft = $(window).scrollLeft();
			var _pos = getPosition($applyTo,position);
			_pos.top += scrollTop;
			isUseAnimate && $applyTo.stop().animate(_pos,settings.delay) || $applyTo.css(_pos);
		} 
		return this.each(function(){
			var $this =  $(this);
			$this.css("position","absolute");
			settings.style && $this.css(settings.style);
			setPosition($this,settings.position);
			$(this).data("isAllowScroll",true);
			$(window).scroll(function(){
				$this.data("isAllowScroll") && setPosition($this,settings.position,true);
			});
		})	
	}else{
		var speed = arguments.length > 1 && arguments[1] || "fast"; 
		this.each(function(){		   
			if(settings == "clearOffset"){
					var _c = {};
					if($(this).data("offset")){
						 _c[$(this).data("offset")] = 0; 
						 $(this).data("isAllowScroll",false);
						 $(this).stop().animate(_c,speed);
					}
			}else if(settings == "addOffset"){
					var _c = {};
					if($(this).data("offset") && $(this).data("offsetPostion")){
						 _c[$(this).data("offset")] = $(this).data("offsetPostion"); 
						 $(this).stop().animate(_c,speed);
						 $(this).data("isAllowScroll",true);
					}
									   
			}else if(settings == "setScrollDisable"){
				$(this).data("isAllowScroll",false);
			}else if(settings == "setScrollUsable"){
				$(this).data("isAllowScroll",true);	
			}
		})
	}
}		  

jQuery(document).ready(function() {
  var winW = $(window).width();
  var w = winW/2 - 475;
  $('#fc').css({position:'absolute',top:700,left:w});
  $('#fc').hide();
  
  $('#fl').css('position','absolute');
  $('#fl').css('z-index',999999);
  my=setInterval("mm()",10);
}); 


var x=0,y=0,xpos=0,ypos=0; 
function mm(){
  if(x>=$(window).width()-$("#fl").width()){xpos=1}
  if(y>=$(window).height()-$("#fl").height()){ypos=1}
  if(x<0){xpos=0}
  if(y<0){ypos=0}
  if(xpos){x--}else{x++}
  if(ypos){y--}else{y++}
  $("#fl").animate({left:x+"px",top:y+"px"},10);
}
