/*
*表示必须,非必须项的第一个选项选项为默认选项
url(*)				Flash或图片的地址
type:flash/image	类型
href				图片的目标链接，只有当type为image时才有效
width:80/任意数字	宽度
height:80/任意数字	高度
x:right/left		水平位置
xPx:1/任意数字		水平方向上Logo左边(右边)到浏览窗口左边（右边）的像素值
y:bottom/top		垂直位置
yPx:10/任意数字		垂直方向上Logo顶边(底边)到浏览窗口顶边（底边）的像素值
id:''/任意合法ID	flash的id
*/
var nadFloatLogo = function(url,options){
	if(nadIsLtIE5_5()){return;}
	this.url = url;
	this.options = {
		type	:	'flash',
		width	:	110,
		height	:	145,
		x		:	'right',
		xPx		:	1,
		y		:	'top',
		yPx		:	455,
		id		:	''
	}
	Object.nadExtend(this.options,options||{});
	this.create();
	nadAddEventListener(window,'resize',this.float.nadBind(this));
	nadAddEventListener(window,'scroll',this.float.nadBind(this));
}
nadFloatLogo.prototype={
	create:function(){
		var oA = document.createElement('a');
		this.ad = oA;
		var _url = this.url;
		var _opt = this.options;
		var _width = _opt.width;
		var _height = _opt.height;
		oA.style.position = 'absolute';
		oA.style.border = '0';
		oA.target = '_blank';
		oA.style[_opt.x] = _opt.xPx + 'px';
		var _ch = nadClientHeight();
		this.positionY(0,_ch,_height,_opt.yPx);
		this.initSt = 0;
		this.initCh = _ch;
		if(_opt.href){oA.href = _opt.href;}
		if(_opt.type=='flash'){oA.innerHTML = nadCreateSwfHtml(_url,_opt.id,{
			width	: _width,
			height	: _height,
			wmode	: 'window'
		});}
		if(_opt.type=='image'){
		oA.innerHTML = '<img src="'+ _url +'" width="'+ _width +'" height="'+ _height +'" alt="" border="0" usemap="#Map1"/>'
		}
		document.getElementById("ssid1").appendChild(oA);
	},
	positionY:function(st,ch,height,yPx){
		var _ad = this.ad;
		if(this.options.y == 'bottom'){
			_ad.style.top = st + ch - height - yPx + 'px';		
		}else{
			_ad.style.top = st + yPx + 'px';
		} 		
	},
	move:function(){
		var _initSt = this.initSt;
		var _initCh = this.initCh;
		var _ad = this.ad;
		var _opt = this.options;
		var _st = nadScrollTop();
		var _ch = nadClientHeight();
		
		if(_initSt!=_st||_initCh!=_ch){
			if(_initSt!=_st){
				_st = _initSt + (_st -_initSt)/2;
				this.initSt = _st;
			}
			if(_initCh!=_ch){this.initCh = _ch;}
			this.positionY(_st,_ch,_opt.height,_opt.yPx);	
		}else{clearInterval(this.intervalId);}

	},
	float:function(){
		clearInterval(this.intervalId);
		this.intervalId = setInterval(this.move.nadBind(this),100)
	}
}
/*==common function begin==*/
var nadUserAgent = navigator.userAgent;
var nadIsOpera = nadUserAgent.indexOf('Opera')>-1
var nadIsIE = nadUserAgent.indexOf('MSIE')>-1 && !nadIsOpera;
var nadIsLtIE5_5 = function(){
	if(nadIsIE){
		var reIE = new RegExp('MSIE (\\d+\\.\\d+);');
		reIE.test(nadUserAgent);
		var IeVersion = parseFloat(RegExp["$1"]);
		return IeVersion <5.5;
	}
}
nadScrollTop = function(){
	return document.documentElement.scrollTop?document.documentElement.scrollTop:document.body.scrollTop;
}
nadClientHeight = function(){
	return (document.body.clientHeight>document.documentElement.clientHeight)&&(document.documentElement.clientHeight!=0)?document.documentElement.clientHeight:document.body.clientHeight;
}
Object.nadExtend = function(destination, source) {
  for (var property in source) {
    destination[property] = source[property];
  }
  return destination;
}
Function.prototype.nadBind = function() {
  var __method = this, args = $nadA(arguments), object = args.shift();
  return function() {
    return __method.apply(object, args.concat($nadA(arguments)));
  }
}
var $nadA = function(iterable) {
  if (!iterable) return [];
  if (iterable.toArray) {
    return iterable.toArray();
  } else {
    var results = [];
    for (var i = 0, length = iterable.length; i < length; i++)
      results.push(iterable[i]);
    return results;
  }
}
var nadAddEventListener= function(obj,e,f){
	if(document.addEventListener){obj.addEventListener(e,f,false);}
	else{
		e = 'on' + e;
		obj.attachEvent(e,f);
	}
}
var nadCreateSwfHtml = function(url,id,options){
	var swfHtml='';
	if(!url){return;}
	_opt = options;
	if(nadIsIE){
		swfHtml += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="'+ _opt.width +'" height="'+ _opt.height +'" id="'+ id +'">';
		swfHtml += '<param name="movie" value="'+ url +'" />';
		swfHtml += '<param name="quality" value="high" />';
		swfHtml += '<param name="wmode" value="'+ _opt.wmode +'" />';
		swfHtml += '</object>';
	}
	else{
		swfHtml += '<embed src="'+ url +'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+ _opt.width +'" height="'+ _opt.height +'" wmode="'+ _opt.wmode +'" id="'+ id +'" name="'+ id +'" swliveconnect="true"></embed>'
	}
	return swfHtml;
}
/*==common function end==*/