//幻灯
//UI&UE Dept. mengjia
//090106

var sina = {
	$ : function(objName){if(document.getElementById){return eval('document.getElementById("'+objName+'")')}else{return eval('document.all.'+objName)}},
	isIE : navigator.appVersion.indexOf("MSIE")!=-1?true:false,
	
	//Event
	addEvent : function(obj,eventType,func){if(obj.attachEvent){obj.attachEvent("on" + eventType,func);}else{obj.addEventListener(eventType,func,false)}},
	delEvent : function(obj,eventType,func){
		if(obj.detachEvent){obj.detachEvent("on" + eventType,func)}else{obj.removeEventListener(eventType,func,false)}
	},
	//Cookie
	readCookie : function(l){var i="",I=l+"=";if(document.cookie.length>0){var offset=document.cookie.indexOf(I);if(offset!=-1){offset+=I.length;var end=document.cookie.indexOf(";",offset);if(end==-1)end=document.cookie.length;i=document.cookie.substring(offset,end)}};return i},
	
	writeCookie : function(O,o,l,I){var i="",c="";if(l!=null){i=new Date((new Date).getTime()+l*3600000);i="; expires="+i.toGMTString()};if(I!=null){c=";domain="+I};document.cookie=O+"="+escape(o)+i+c},
	//Style
	readStyle:function(i,I){if(i.style[I]){return i.style[I]}else if(i.currentStyle){return i.currentStyle[I]}else if(document.defaultView&&document.defaultView.getComputedStyle){var l=document.defaultView.getComputedStyle(i,null);return l.getPropertyValue(I)}else{return null}}
};

var coverLayer = {
	divObj : null,
	_coverTime : null,
	_coverRe : function(){//刷新遮盖层
		if(document.body.offsetHeight < document.documentElement.clientHeight){
			this.divObj.style.width = document.body.clientWidth + "px";
			this.divObj.style.height = document.documentElement.clientHeight + "px";
		}else{
			this.divObj.style.width = document.body.clientWidth + "px";
			this.divObj.style.height = document.body.clientHeight + "px";
		}
	},
	isIE : navigator.appVersion.indexOf("MSIE")!=-1?true:false,
	on : function(noSave){ //打开遮盖层
		if(this.divObj == null){
			this.divObj = document.createElement("div");
			this.divObj.style.zIndex = 10000;
			this.divObj.style.left = '0px';;
			this.divObj.style.top = '0px';;
			this.divObj.style.position = "absolute";
			this.divObj.style.backgroundColor = "#333";
			if(this.isIE){
				var tempFrame = document.createElement("iframe");
				tempFrame.style.filter = "Alpha(Opacity=0)";
				tempFrame.frameBorder=0;
				tempFrame.scrolling="no";
				tempFrame.style.width = "100%";
				tempFrame.style.height = "100%";
				this.divObj.appendChild(tempFrame);
				this.divObj.style.filter = "Alpha(Opacity=80)";
			}else{
				this.divObj.style.opacity = 0.8
			};
			document.body.appendChild(this.divObj);
		};
		if(document.body.offsetHeight < document.documentElement.clientHeight){
			this.divObj.style.width = document.body.clientWidth + "px";
			this.divObj.style.height = document.documentElement.clientHeight + "px";
		}else{
			this.divObj.style.width = document.body.clientWidth + "px";
			this.divObj.style.height = document.body.clientHeight + "px";
		};
		this.divObj.style.display = "block";
		clearInterval(this._coverTime);
		this._coverTime = setInterval("coverLayer._coverRe()",50);
	},
	off : function(noSave){ //关闭遮盖层
		if(this.divObj){this.divObj.style.display = "none"};
		clearInterval(this._coverTime);
	}
}

var epidiascope = {
	picTitleId : "PicTitle",
	picMemoId : "PicMemo",
	picListId : "picList",
	BigPicId : "BigPic",
	picArrLeftId : "picArrLeft",
	picArrRightId : "picArrRight",
	playButtonId : "playButton",
	estateId : "estate",
	mainBoxId : "Main",
	PVUrl : "http://news.sina.com.cn/pc/2008-12-24/326/1131.html",
	repetition : true, //循环播放
	prefetch : true, //预读图片
	autoPlay : true, //自动播放
	autoPlayTimeObj : null,
	timeSpeed : 5,
	maxWidth : 948,
	filmstrips : [],
	prefetchImg : [],
	selectedIndex : 0,
	previousPicList : {},
	nextPicList : {},
	add : function(s){
		this.filmstrips.push(s);
		if(this.prefetch){ //预载图片
			var tempImg = new Image();
			tempImg.src = s.src;
			this.prefetchImg.push(tempImg);
		};
	},
	initialize : function(){
		//全屏
		epidiascope.fullScreen.initialize();
		
		var tempWidth = 0;
		if(this.filmstrips.length * 110 < sina.$("picList").offsetWidth){
			tempWidth = Math.round(sina.$("picList").offsetWidth / 2 - this.filmstrips.length * 110/2);
		};
		
		
		var tempHTML = '<div class="PL_cont" style="padding-left:' + tempWidth + 'px">',i;
		for(i=0;i<this.filmstrips.length;i++){
			tempHTML += '<div class="pic'+ (i==this.selectedIndex?"On":"") +'" id="slide_' + i + '"><table cellspacing="0"><tr><td><a href="javascript:epidiascope.select(' + i + ');" onclick="this.blur();"><img src="' + this.filmstrips[i].lowsrc + '" alt="' + this.filmstrips[i].title + '"  onload="showImage(this);" oncontextmenu="event.returnValue=false;return false;" /></a></td></tr></table></div>';
		};


		sina.$(this.picListId).innerHTML = tempHTML + "</div>";
		
		//
		sina.$(this.picArrLeftId).onclick = function(){epidiascope.previous()};
		sina.$(this.picArrRightId).onclick = function(){epidiascope.next()};
		
		sina.$("commentLink").onclick = function(){epidiascope.clickComment()}; //评论
		//
		this.BigImgBox = sina.$(this.BigPicId);
		
		this.ImgObj1 = document.createElement("img");
		this.ImgObj2 = document.createElement("img");
		this.Link1 = document.createElement("a");
		this.Link2 = document.createElement("a");
		this.SpanObj1 = document.createElement("Span");
		this.SpanObj2 = document.createElement("Span");
		
		//禁止右键
		this.ImgObj1.oncontextmenu = this.ImgObj2.oncontextmenu = function(e){
			e = e?e:event;
			e.returnValue=false;
			return false;
		};
		this.ImgObj1.onmousedown = this.ImgObj2.onmousedown = function(){return false};
		
		this.ImgObj1.galleryImg = false;
		this.ImgObj2.galleryImg = false;
		
		this.ImgObj1.src = "";//空图
		
		this.ImgObj1.onload = function(){
			if(epidiascope.maxWidth == 0 ){return};
			var temp = new Image();
			temp.src = this.src;
			
			if(temp.width > epidiascope.maxWidth){
				this.width = epidiascope.maxWidth;
				this.height = Math.round(epidiascope.maxWidth * temp.height / temp.width);
			}else{
				this.width = temp.width;
				this.height = temp.height;
			};
		};
		
		
		this.BigImgBox.appendChild(this.SpanObj1);
		this.BigImgBox.appendChild(this.SpanObj2);
		this.SpanObj1.appendChild(this.Link1);
		this.SpanObj2.appendChild(this.Link2);
		this.Link1.appendChild(this.ImgObj1);
		this.Link2.appendChild(this.ImgObj2);
		
		this.Link1.target = "_blank";
		this.Link2.target = "_blank";
				
		this.select(this.selectedIndex);
		
		this.foreAndAft();
		
		if(!sina.isIE){
			this.BigImgBox.style.position = 'relative';
			this.BigImgBox.style.overflow = "hidden";
			this.SpanObj2.style.position = "absolute";
			this.SpanObj2.style.width = "100%";
			this.SpanObj2.style.top = "0px";
			this.SpanObj1.style.textAlign = this.SpanObj2.style.textAlign = "center";
			this.SpanObj1.style.display = this.SpanObj2.style.display = "block";
			this.SpanObj1.style.zIndex = 1;
			this.SpanObj2.style.zIndex = 2;
		}else{
			this.SpanObj2.style.display = 'none';
			
		};
		
		if(this.autoPlay){this.play()}else{this.stop()};
		
		if(this.onstart){this.onstart()};
	},
	select : function(num){
		if(this.endSelect.estate == 1){
			this.endSelect.close();
		};
		var i;
		if(num >= this.filmstrips.length || num < 0){return};
		
		sina.$(this.picTitleId).innerHTML = this.filmstrips[num].title;
		sina.$(this.picMemoId).innerHTML = this.filmstrips[num].text;
		
		if(this.filmstrips[num].link=="" || this.filmstrips[num].link == "javascript:void(0)"){
			this.Link1.target = "_self";
			this.Link2.target = "_self";
			this.Link1.href = "javascript:void(0)";
			this.Link2.href = "javascript:void(0)";
		}else{
			this.Link1.target = "_brank";
			this.Link2.target = "_brank";
			this.Link1.href = this.filmstrips[num].link;
			this.Link2.href = this.filmstrips[num].link;
		};
		
				
		window.TmpImgObj1 = this.ImgObj1;
		window.TmpImgObj2 = this.ImgObj2;
		window.BigImgBox = this.BigImgBox;
		
		
		if(sina.isIE){
			this.ImgObj1.filters[0].Apply();
			this.ImgObj1.lowsrc = this.filmstrips[num].lowsrc;
			this.ImgObj1.src = this.filmstrips[num].src;
			
			this.ImgObj1.filters[0].Play();
		}else{
			
			this.ImgObj2.src = this.filmstrips[num].src;
			this.ImgObj2.lowsrc = this.filmstrips[num].lowsrc;
			this.ImgObj1.style.opacity = 1;
			this.ImgObj2.style.opacity = 0;
			
			for(i = 0;i <= 10;i ++){
				setTimeout("window.TmpImgObj2.style.opacity = " + (i * 0.1),i * 60);
			};
			setTimeout("window.TmpImgObj1.width=window.TmpImgObj2.width;window.TmpImgObj1.src = window.TmpImgObj2.src;",10 * 60);
		};
		sina.$("slide_" + this.selectedIndex).className = "pic";
		sina.$("slide_" + num).className = "picOn";
		this.selectedIndex = num;
		
		this.picList.foucsTo(num + 1); //滚动
		
		sina.$("total").innerHTML = (num + 1) + "/" + this.filmstrips.length;
		if(this.autoPlay){this.play()};
		this.PVCount(); //PV统计
	},
	PVCount : function(){
		if(this.PVUrl == "" && this.PVUrl == null){return;};
		//移除iframe
		if(this.PVFrame){
			this.PVFrame.parentNode.removeChild(this.PVFrame);
		};
		//create new iframe
		this.PVFrame = document.createElement("iframe");
		//style="height:0px;width:1px;overflow:hidden;"
		this.PVFrame.style.height = "0px";
		this.PVFrame.style.width = "1px";
		this.PVFrame.style.overflow = "hidden";
		this.PVFrame.frameBorder = 0;
		sina.$(this.mainBoxId).appendChild(this.PVFrame);
		this.PVFrame.src = this.PVUrl + "?r=" + Math.random();
		
	},
	next : function(){
		var tempNum = this.selectedIndex + 1;
		if(tempNum >= this.filmstrips.length){
			if(this.repetition){ //循环播放
				tempNum = 0;
			}else{
				this.endSelect.open(); //选择
				return;
			};
		};
		this.select(tempNum);
	},
	previous : function(){
		var tempNum = this.selectedIndex - 1;
		if(tempNum < 0){ //循环播放
			if(this.repetition){
				tempNum = this.filmstrips.length - 1
			}else{
				return;
			};
		};
		this.select(tempNum);
	},
	play : function(){
		clearInterval(this.autoPlayTimeObj);
		this.autoPlayTimeObj = setInterval("epidiascope.next()",this.timeSpeed*1000);
		sina.$(this.playButtonId).onclick = function(){epidiascope.stop()};
		sina.$(this.estateId).className = "stop";
		sina.$(this.estateId).title = "暂停";
		this.autoPlay = true;
	},
	stop : function(){
		clearInterval(this.autoPlayTimeObj);
		sina.$(this.playButtonId).onclick = function(){epidiascope.play()};
		sina.$(this.estateId).className = "play";
		sina.$(this.estateId).title = "播放";
		this.autoPlay = false;
	},
	foreAndAft : function(){ //设置 前一个 后一个 图集
		var foreBoxId = "PL_Left";
		var aftBoxId = "PL_Right";
		var nextPicsButId = "nextPicsBut";
		var i;
		var links = sina.$(foreBoxId).getElementsByTagName("a");
		for(i=0;i<links.length;i++){
			links[i].href = this.previousPicList.link;
		};
		sina.$(foreBoxId).getElementsByTagName("img")[0].src = this.previousPicList.lowsrc;
		
		links = sina.$(aftBoxId).getElementsByTagName("a");
		for(i=0;i<links.length;i++){
			links[i].href = this.nextPicList.link;
		};
		sina.$(aftBoxId).getElementsByTagName("img")[0].src = this.nextPicList.lowsrc;
		
		sina.$(nextPicsButId).href = this.nextPicList.link;
	},
	rePlay : function(){ //重新播放
		if(this.endSelect.estate == 1){this.endSelect.close()};
		this.autoPlay = true;
		this.select(0);
	},
	clickComment : function(){ //评论
		var thisFilmstrip = this.filmstrips[this.selectedIndex];
		window.open(thisFilmstrip.comment,"");
	},
	downloadPic : function(){ //下载图片
		var thisFilmstrip = this.filmstrips[this.selectedIndex];
		
	},
	sendToMobile : function(){ //发送到手机
		var thisFilmstrip = this.filmstrips[this.selectedIndex];
		
	}
};

epidiascope.speedBar = { //速度条

	slideId : "slide",
	slideButtonId : "slideButton",
	grades : 10, //等级数
	grade : 1, //等级
	_slideWidth : 0,
	_slideButtonWidth : 0,
	_marginLeft : 0,
	_mouseDisparity : 0,
	initialize : function(){
		this._slideWidth = sina.$(this.slideId).offsetWidth;
		this._slideButtonWidth = sina.$(this.slideButtonId).offsetWidth;
		this._marginLeft = Math.round(this._slideWidth/this.grades * (this.grade - 1));
		
		sina.$(this.slideButtonId).style.marginLeft = this._marginLeft + "px";
		sina.$("speedCall").innerHTML = this.grade + "秒";
		
		
		sina.$(this.slideId).onselectstart = function(){return false};
		sina.$(this.slideButtonId).onmousedown = function(e){epidiascope.speedBar.mouseDown(e);return false};
	},
	mouseDown : function(e){
		e = window.event?window.event:e;
		this._mouseDisparity = (e.pageX?e.pageX:e.clientX) - this._marginLeft;
		document.onmousemove = function(e){epidiascope.speedBar.mouseOver(e)};
		document.onmouseup = function(){epidiascope.speedBar.mouseEnd()};
	},
	mouseOver : function(e){
		e = window.event?window.event:e;
		this._marginLeft = (e.pageX?e.pageX:e.clientX) - this._mouseDisparity;
		if(this._marginLeft > (this._slideWidth - this._slideButtonWidth)){this._marginLeft = this._slideWidth - this._slideButtonWidth};
		if(this._marginLeft < 0){this._marginLeft = 0;};
		sina.$(this.slideButtonId).style.marginLeft = this._marginLeft + "px";
		
		this.grade = Math.round(this._marginLeft/(this._slideWidth/this.grades) + 1);
		
		if(this.onmover){this.onmover()};
	},
	mouseEnd : function(){
		if(this.onend){this.onend()};
		
		sina.writeCookie("eSp",this.grade,720);
		document.onmousemove = null;
		document.onmouseup = null;
	},
	onmover : function(){
		sina.$("speedCall").innerHTML = this.grade + "秒";
	},
	onend : function(){
		epidiascope.timeSpeed = this.grade;
		if(epidiascope.autoPlay){epidiascope.play()};
	}
};

epidiascope.background = {
	estate : 1,
	initialize : function(){
		sina.$("color_01").onclick = function(){epidiascope.background.select(1)};
		sina.$("color_02").onclick = function(){epidiascope.background.select(2)};
		//sina.$("color_03").onclick = function(){epidiascope.background.select(3)};
		this.select(this.estate);
	},
	select : function(num){
		var className = "";
		
		switch(num){
			case 2:
				className = "bS_02";
				this.labelClass(2);
				break;
			case 3:
				className = "bS_03";
				this.labelClass(3);
				break;
			default :
				num = 1;
				className = "";
				this.labelClass(1);
		};
		document.body.className = className;
		sina.writeCookie("eBg",num,720);
	},
	labelClass : function(num){
		sina.$("color_01").className = "";
		sina.$("color_02").className = "";
		//sina.$("color_03").className = "";
		sina.$("color_0" + num).className = "selected";
	}
};

epidiascope.picList = { //列表滚动
	leftArrId : "leftArr",
	rightArrId : "rightArr",
	picListId : "picList",
	timeoutObj : null,
	pageWidth : 110,
	totalWidth : 0,
	offsetWidth : 0,
	lock : false,
	initialize : function(){
		sina.$(this.rightArrId).onmousedown = function(){epidiascope.picList.leftMouseDown()};
		sina.$(this.rightArrId).onmouseout = function(){epidiascope.picList.leftEnd("out");this.className='';};
		sina.$(this.rightArrId).onmouseup = function(){epidiascope.picList.leftEnd("up")};
		sina.$(this.leftArrId).onmousedown = function(){epidiascope.picList.rightMouseDown()};
		sina.$(this.leftArrId).onmouseout = function(){epidiascope.picList.rightEnd("out");this.className='';};
		sina.$(this.leftArrId).onmouseup = function(){epidiascope.picList.rightEnd("up")};
		this.totalWidth = epidiascope.filmstrips.length * this.pageWidth;
		this.offsetWidth = sina.$(this.picListId).offsetWidth;
		
		
	},
	leftMouseDown : function(){
		if(this.lock){return};
		this.lock = true;
		this.timeoutObj = setInterval("epidiascope.picList.moveLeft()",10);
	},
	rightMouseDown : function(){
		if(this.lock){return};
		this.lock = true;
		this.timeoutObj = setInterval("epidiascope.picList.moveRight()",10);
	},
	moveLeft : function(){
		if(sina.$(this.picListId).scrollLeft + 10 > this.totalWidth - this.offsetWidth){
			sina.$(this.picListId).scrollLeft = this.totalWidth - this.offsetWidth;
			this.leftEnd();
		}else{
			sina.$(this.picListId).scrollLeft += 10;
		};
	},
	moveRight : function(){
		sina.$(this.picListId).scrollLeft -= 10;
		if(sina.$(this.picListId).scrollLeft == 0){this.rightEnd()};
	},
	leftEnd : function(type){
		if(type=="out"){if(!this.lock){return}};
		clearInterval(this.timeoutObj);
		this.lock = false;
		this.move(30);
	},
	rightEnd : function(type){
		if(type=="out"){if(!this.lock){return}};
		clearInterval(this.timeoutObj);
		this.lock = false;
		this.move(-30);
	},
	foucsTo : function(num){
		if(this.lock){return};
		this.lock = true;
		
		var _moveWidth = Math.round(num * this.pageWidth - this.offsetWidth / 2) - 33;
		_moveWidth -= sina.$(this.picListId).scrollLeft;
		
		if(sina.$(this.picListId).scrollLeft + _moveWidth < 0){
			_moveWidth = - sina.$(this.picListId).scrollLeft;
		};
		if(sina.$(this.picListId).scrollLeft + _moveWidth >= this.totalWidth - this.offsetWidth){
			_moveWidth = this.totalWidth - this.offsetWidth - sina.$(this.picListId).scrollLeft;
		};
		
		this.move(_moveWidth);
	},
	move : function(num){
		
		var thisMove = num/4;
		if(Math.abs(thisMove)<1 && thisMove!=0){
			thisMove = (thisMove>=0?1:-1)*1;
		}else{
			thisMove = Math.round(thisMove);
		};
		
		var temp = sina.$(this.picListId).scrollLeft + thisMove;
		if(temp <= 0){sina.$(this.picListId).scrollLeft = 0;this.lock = false;return;}
		if(temp >= this.totalWidth - this.offsetWidth){sina.$(this.picListId).scrollLeft = this.totalWidth - this.offsetWidth;this.lock = false;return;}
		sina.$(this.picListId).scrollLeft += thisMove;
		num -= thisMove;
		if(Math.abs(num) <= 1){this.lock = false;return;}else{
			setTimeout("epidiascope.picList.move(" + num + ")",10)
		}
		
	}
};

//结束选择
epidiascope.endSelect = {
	endSelectId : "endSelect",
	closeId : "endSelClose",
	rePlayButId : "rePlayBut",
	estate : 0, //1:open  0:close
	open : function(){
		this.estate = 1;
		sina.$(this.endSelectId).style.display = "block";

		sina.$(this.endSelectId).style.left = Math.round((sina.$(epidiascope.mainBoxId).offsetWidth - sina.$(this.endSelectId).offsetWidth)/2) + "px";
		epidiascope.stop();
		sina.$(epidiascope.playButtonId).onclick = function(){epidiascope.rePlay()};
		sina.$(epidiascope.estateId).title = "重新播放";
		sina.$(this.closeId).onclick = function(){epidiascope.endSelect.close()};
		sina.$(this.rePlayButId).onclick = function(){epidiascope.rePlay()};
	},
	close : function(){
		this.estate = 0;
		//sina.$(epidiascope.playButtonId).onclick = function(){epidiascope.play()};
		sina.$(this.endSelectId).style.display = "none";
	}
};

//全屏
epidiascope.fullScreen = {
	fullScreenButId : "fullScreen",
	estate : 0,//1:full 0:close
	fullWin : null,
	timeObj : null,
	initialize : function(){
		try{
			if(window.opener){
				if(window.opener.epidiascope.fullScreen.estate == 1){
					this.setFull();
				}
			}else{
				sina.$(this.fullScreenButId).onclick = function(){epidiascope.fullScreen.full()};
			}
		}catch(e){sina.$(this.fullScreenButId).onclick = function(){epidiascope.fullScreen.full()}};
	},
	full : function(){
		this.fullWin = window.open(window.location.href,"fullWin","scrollbars")
		this.fullWin.moveTo(0,0)
		this.fullWin.resizeTo(screen.width,screen.height);
		this.estate = 1;
		epidiascope.stop();
		
		sina.$("fullClew").style.display = "block";
		coverLayer.on();
		this.timeObj = setInterval("epidiascope.fullScreen.scoutFullWin()",100);
		sina.$("fullClose").onclick = function(){epidiascope.fullScreen.fullWin.close()};
		sina.$("fullCloseBut").onclick = function(){epidiascope.fullScreen.fullWin.close()};
	},
	scoutFullWin : function(){
		if(this.fullWin.closed){
			coverLayer.off();
			sina.$("fullClew").style.display = "none";
			clearInterval(this.timeObj);
			epidiascope.onstart();
			epidiascope.play();
		}else{
			sina.$("fullClew").style.left = Math.round((document.body.offsetWidth - 230)/2) + "px";
			sina.$("fullClew").style.top = Math.round((document.documentElement.scrollTop==0?document.body.scrollTop:document.documentElement.scrollTop) + document.documentElement.clientHeight * 0.3) + "px";
		};
	},
	close : function(){
		window.close();
	},
	setFull : function(){
		sina.$(this.fullScreenButId).onclick = function(){epidiascope.fullScreen.close()};
		sina.$("wrap").style.width = "auto";
		sina.$("wrap").style.padding = "5px";
		sina.$(this.fullScreenButId).innerHTML = "返回";
		sina.$(this.fullScreenButId).className = "close";
		sina.$(epidiascope.picList.picListId).style.width = sina.$("wrap").offsetWidth - 270 + "px";
	}
}

epidiascope.onstart = function(){
	try{document.execCommand('BackgroundImageCache', false, true);}catch(e){};
	
	
	//速度条
	epidiascope.speedBar.grade = parseInt(sina.readCookie("eSp"));
	if(isNaN(epidiascope.speedBar.grade)){epidiascope.speedBar.grade = 5};
	epidiascope.speedBar.initialize();
	epidiascope.speedBar.onend();
	
	//背景
	epidiascope.background.estate = parseInt(sina.readCookie("eBg"));
	if(isNaN(epidiascope.background.estate)){epidiascope.background.estate = 1};
	epidiascope.background.initialize();
		
	//图片列表滚动
	epidiascope.picList.initialize();
};

// -------------------------------------------------------------------------------------

//登录
String.prototype.substr2=function(a,b){a=this.getStartPst(a);var c=this.substr(a,b);var d=c.replace(/[^\x00-\xff]/g,"aa").length;var e=d-b;var f;var g=b;var i=0;while(e>0){c=this.substr(a,g);d=c.replace(/[^\x00-\xff]/g,"aa").length;e=d-b;if(e<=0){break}f=Math.floor(e/2);if(f>1){g=b-f}else{i++;g=b-i}}return this.substr(a,g)};String.prototype.getStartPst=function(a){var b=this.substr(0,a);var c=b.replace(/[^\x00-\xff]/g,"aa").length;var d=c-a;var e;var f=a;var i=0;while(d>0){b=this.substr(0,f);c=b.replace(/[^\x00-\xff]/g,"aa").length;d=c-a;if(d<=0){break}e=Math.floor(d/2);if(e>1){f=a-e}else{i++;f=a-i}}return f};
var sinaLogin = {
	quit : function() {
		sina.writeCookie("SE","",1,"sina.com.cn;path=/");
		sina.writeCookie("SCT","",1,"sina.com.cn;path=/");
		sina.writeCookie("SU","",1,"sina.com.cn;path=/");
		sina.writeCookie("SA","",1,"sina.com.cn;path=/");
		sina.writeCookie("PS","",1,"sina.com.cn;path=/");
		window.location.reload();
	},
	show : function(){
		var a=sina.readCookie("SU");
		var b=a.split(":");
		var c;
		if(b.length>1){
			a=decodeURI(b[3]);
		};
		c = "";
		if(a!=""&&a!="null"&&a!=null&&a!="undefined"){
			if(a.length>6){
				c=a;
				a=a.substr2(0,6);
				a+=".."
			};
			sina.$("uq_username").innerHTML=a;
			sina.$("uq_username").title = c;
		}else{
			return;
		};
		sina.$("userInfo").style.display = "block";
		sina.$("loginBut").style.display = "none";
	}
};


function DrawImage(ImgD,iwidth,iheight){
	var image=new Image();
	if(!iwidth)iwidth = 90;
	if(!iheight)iheight = 90; //定义允许高度，当宽度大于这个值时等比例缩小
	image.src=ImgD.src;
	if(image.width>0 && image.height>0){
		flag=true;
		if(image.width/image.height>= iwidth/iheight){
			if(image.width>iwidth){ 
				ImgD.width=iwidth;
				ImgD.height=(image.height*iwidth)/image.width;
			}else{
				ImgD.width=image.width; 
				ImgD.height=image.height;
			}
		}else{
			if(image.height>iheight){ 
				ImgD.height=iheight;
				ImgD.width=(image.width*iheight)/image.height; 
			}else{
				ImgD.width=image.width; 
				ImgD.height=image.height;
			}
		}
	}
} 