var floatTip = {
    //浮动对象
	blockId:'sleekBlock',
	//限制数量
	len:4,
        tipStr:'对不起！',
	//始终离上边距
	theTop:150,
	//记录旧值
	old:this.theTop,
   //传递checkbox对象和ID值
   check:function(obj,id) {
     var panel = HX.$(floatTip.blockId);
	 if(obj.checked) {
	    if(panel.style.display == 'none') panel.style.display = '';
		if(floatTip.getLen()>=floatTip.len){
		 obj.checked = '';
		 alert(floatTip.tipStr);
		 }
		else {
		obj.checked = 'checked';
		floatTip.addLi(id,obj.value);
		}
	 }
	 else {
	    obj.checked = '';
		floatTip.deleteLi(id);		
	 }
	 floatTip.saveCookie();
   },
   //获取li数组
   getLi:function() {
     var ul = HX.$(floatTip.blockId).getElementsByTagName('ul')[0];
	 HX.$E.clearWhite(ul);
	 if(ul.childNodes.length!=0)
      return ul.getElementsByTagName('li');
	 else return null;
   },
   //获取li的个数
   getLen:function() {
     return (floatTip.getLi()==null)?0:floatTip.getLi().length;
   },
   //获取载入父节点对象
   getUl:function() {
      return  HX.$(floatTip.blockId).getElementsByTagName('ul')[0];
   },
   //添加Li
   addLi:function(id,value) {
      var li = HX.$E.create('li',floatTip.getUl());
	  li.id = 'li_'+id;
	  li.innerHTML = '<a href=javascript:floatTip.removeLi("'+id+'")></a><p>'+value+'</p>';
   },
   //关闭控制删除Li
   removeLi:function(id) {
      floatTip.deleteLi(id);
	  if(HX.$(id)) HX.$(id).checked='';
	  floatTip.saveCookie();
   },
   //多选框控制删除Li
   deleteLi:function(id) {
     try{
	   HX.$E.remove(HX.$('li_'+id));
	   floatTip.saveCookie();
	   if(floatTip.getLi()==null) floatTip.close();
	   }
	 catch(e) {}
   },
   //获取li的值
   gain:function() {
	 var res  = [];
     if(floatTip.getLi()!=null) {
		 var arr = floatTip.getLi();
		 for(var i=0;i<arr.length;i++) {
			   var m = {id:'',value:''};
			   m.id = arr[i].id.split('_')[1];
			   m.value = arr[i].getElementsByTagName('p')[0].innerHTML;
			   res.push(m);
			 }
		 }
	  return res;
   },
   //清空
   clear:function() {
   if(floatTip.getLi()!=null) {
     var arr = floatTip.getLi();
	 var res = [];
     for(var i=0;i<arr.length;i++) {
	   res.push(arr[i].id.split('_')[1]);
	 }
	 for(var i=0;i<res.length;i++) {
	   if(HX.$(res[i])) HX.$(res[i]).checked = '';
	 }
	 floatTip.getUl().innerHTML = '';
	 }
     floatTip.close();
	 floatTip.saveCookie();
   },
   //关闭浮动窗口
   close:function() {
     HX.$(floatTip.blockId).style.display = 'none';
   },
   //保存cookie
   saveCookie:function() {
	  var arr = floatTip.gain();
	  trustCookie.save(arr);
   },
   //读取cookie
   readCookie:function() {
      if(trustCookie.has()) {
		  HX.$(floatTip.blockId).style.display = '';
		  var arr = trustCookie.read();
		  for(var i=0;i<arr.length;i++) {
			  floatTip.addLi(arr[i].id,arr[i].value);
			  if(HX.$(arr[i].id)) HX.$(arr[i].id).checked = 'checked';
			  }
	  }
   },
   //浮动效果
   moveTips:function() {
     var tt=1;
	 var tips = HX.$(floatTip.blockId);
     pos = document.body.scrollTop||document.documentElement.scrollTop;
     pos=pos-tips.offsetTop+floatTip.theTop;
     pos=tips.offsetTop+pos/10;
     if (pos < floatTip.theTop) pos = floatTip.theTop;
     if (pos != floatTip.old) {
     tips.style.top = pos+"px";
     tt=10;
     }
     if(pos >= pageHeight){
     tips.style.top = pageHeight+"px";
     clearInterval(oo);
     }
     old = pos;
     var oo = setTimeout(floatTip.moveTips,tt);
    },
	//浮动效果开启
    initFloatTips:function(){
	 var tips = HX.$(floatTip.blockId);
     pageHeight = document.body.scrollHeight + floatTip.theTop;
	 floatTip.readCookie();
     floatTip.moveTips();
    }  
};
floatTip.initFloatTips();