//popwindow.js
var isIE=(navigator.appVersion.indexOf('MSIE')>0)?true:false;
SWODE.newWindows={};SWODE.openNewWindow=function(url,win,options){var m_options=Object.extend({'width':screen.availWidth,'height':screen.availHeight,'scroll':'no','resize':'no'},options||{});var mx=m_options.left||(screen.availWidth-m_options.width)/2;var my=m_options.top||(screen.availHeight-m_options.height)/2;var features='width='+m_options.width+',height='+m_options.height+',left='+mx+',top='+my+',scrollbars='+m_options.scroll+',resizable='+m_options.resize;SWODE.newWindows[win]=window.open(url,win,features);}
SWODE.showPopWindow=function(options){var container=document.getElementsByTagName('body').item(0);var m_this=this;var instance_id=(new Date()).getTime()+'_'+(Math.floor((Math.random()*10)+1));var m_options=Object.extend({'head':'yes','top':0,'left':0,'width':300,'height':100,'overlap':false,'onClose':function(){}},options||{});var m_deltaPos=[];this.init=function(){Position.prepare();m_deltaPos=[Position.deltaX,Position.deltaY];m_this.main=Builder.node('div',{className:'module popwindow',style:'display:none;width:'+m_options.width+'px',id:'window'+instance_id});container.appendChild(m_this.main);m_this.main.appendChild(Builder.node('div',{className:'popwindow_frame'}));if(m_options.head!='no'){m_this.header=Builder.node('div',{className:'moduleHeader header',style:'height:18px'});m_this.main.firstChild.appendChild(m_this.header);m_this.txtTitle=Builder.node('b',{style:'cursor:default'});m_this.btnClose=Builder.node('img',{src:SWODE.formatLink('images/closeWin.gif',true),className:'fr pointer',title:'关闭窗口'});m_this.btnClose.onclick=function(){if(m_this.confirmCall)m_this.confirmCall();if(m_this.confirmMode){if(confirm(m_this.confirmText)==m_this.confirmValue){if(m_this.confirmCallBack)m_this.confirmCallBack();return;}else{if(m_this.confirmCancelCallBack)m_this.confirmCancelCallBack();}}
if(!m_this.cancelMode)m_this.onCloseWindow();}
m_this.header.appendChild(m_this.btnClose);m_this.header.appendChild(m_this.txtTitle);m_this.header.onmousedown=this.startDrag.bindAsEventListener(this);m_this.header.onmouseover=function(){this.style.cursor='move';}
m_this.header.onmouseout=function(){this.style.cursor='default';}}
m_this.body=Builder.node('div',{className:'moduleContent body',style:'background-image:none;background-color:#ffffff;height:'+m_options.height+'px'});m_this.main.firstChild.appendChild(m_this.body);m_this.showWindow();m_this.onShowWindow();};this.initTitle=function(title){m_this.txtTitle.innerHTML=title;};this.initContent=function(content){m_this.body.innerHTML='';m_this.body.appendChild(content);};this.showWindow=function(){var innerWidth=document.documentElement.clientWidth||document.body.clientWidth;var innerHeight=document.documentElement.clientHeight||document.body.clientHeight;if(!isIE){innerWidth=window.innerWidth;innerHeight=window.innerHeight;}
var m_left=m_options.left||(innerWidth-m_options.width-20)/2;var m_top=m_options.top||(innerHeight-m_options.height-80)/2;m_top=(m_top>10)?m_top:10;m_top+=m_deltaPos[1];m_this.moveTo(m_left,m_top);};this.onShowWindow=function(){$(m_this.main).show();if(isIE)SWODE.hideElements('select',m_this.main);if(!isIE)SWODE.hideElements('object',m_this.main);if(!isIE)SWODE.hideElements('embed',m_this.main);if(m_options.overlap)SWODE.disableScreen(m_options.opacity);};this.closeWindow=function(options){if(options&&options.reload)m_options.onClose=function(){document.location.reload();};if(options&&options.callback)m_options.onClose=callback;m_this.onCloseWindow();};this.onCloseWindow=function(){$(m_this.main).remove();if(m_options.overlap)SWODE.enableScreen();if(isIE)SWODE.showElements('select');if(!isIE)SWODE.showElements('object',m_this.main);if(!isIE)SWODE.showElements('embed',m_this.main);m_options.onClose();};this.moveTo=function(x,y){m_this.main.style.left=x+'px';m_this.main.style.top=y+'px';};this.resizeTo=function(w,h){m_options.width=w;m_options.height=h;m_this.main.style.width=m_options.width+'px';m_this.body.style.height=m_options.height+'px';m_this.body.firstChild.style.height=m_options.height+'px';m_this.showWindow();};this.startDrag=function(e){var evt=e?e:(window.event?window.event:null);var src=evt.srcElement||evt.target;if(src!=$(m_this.header)&&src.className!='header')return;m_this.startX=evt.clientX-parseInt(m_this.main.style.left);m_this.startY=evt.clientY-parseInt(m_this.main.style.top);m_this.shader=Builder.node('div',{style:'position:absolute;left:0px;cursor:move;background:#fff;filter:alpha(opacity=0);-moz-opacity:0;opacity:0;'});m_this.shader.style.width=m_this.main.offsetWidth+'px';m_this.shader.style.height=(m_this.main.offsetHeight-m_this.header.offsetHeight)+'px';m_this.shader.style.top=m_this.header.offsetHeight+'px';m_this.main.appendChild(m_this.shader);this.dragMode=true;document.onmousemove=this.moveDrag.bindAsEventListener(this);document.onmouseup=this.endDrag.bindAsEventListener(this);document.body.onselectstart=function(){return false;}};this.moveDrag=function(e){if(this.dragMode){var evt=e?e:(window.event?window.event:null);m_this.main.style.left=(evt.clientX-m_this.startX)+"px";m_this.main.style.top=(evt.clientY-m_this.startY)+"px";}};this.endDrag=function(e){if(!this.dragMode)return;this.dragMode=false;document.body.onselectstart=function(){return true;}
m_this.main.removeChild(m_this.shader);if(isIE){SWODE.showElements('select');SWODE.hideElements('select',m_this.main);}
if(!isIE)SWODE.showElements('object');if(!isIE)SWODE.showElements('embed');if(!isIE)SWODE.hideElements('object',m_this.main);if(!isIE)SWODE.hideElements('embed',m_this.main);};this.init();}
SWODE.popEditBox=function(title,apiurl,options){if(SWODE.popEditBoxWin&&SWODE.popEditBoxWin.closeWindow){SWODE.popEditBoxWin.closeWindow();}
var boxOptions=Object.extend({top:0,left:0,width:600,height:400,overlap:true,callback:function(){}},options||{});SWODE.popEditBoxWin=new SWODE.showPopWindow({top:boxOptions.top,left:boxOptions.left,width:boxOptions.width,height:boxOptions.height,overlap:boxOptions.overlap,onClose:function(){SWODE.popEditBoxWin=null;setTimeout(function(){boxOptions.callback();},100);}});SWODE.popEditBoxWin.initTitle(title);var contentNode=Builder.node('div',{style:'height:'+boxOptions.height+'px'});contentNode.miframe=Builder.node('iframe',{width:'100%',height:'100%',frameborder:'0',border:'0'});contentNode.appendChild(contentNode.miframe);setTimeout(function(){contentNode.miframe.src=apiurl;},0);contentNode.loading=Builder.node('div',{style:'padding-top:'+(boxOptions.height-20)/2+'px;font-size:14px;color:#000000;text-align:center;'});contentNode.loading.innerHTML='<img src="'+SWODE.formatLink('images/spinner.gif',true)+'" border="0" align="absmiddle" /> 正在加载页面……';contentNode.appendChild(contentNode.loading);contentNode.loaded=false;contentNode.loadPage=function(){if(this.loaded)return;this.loaded=true;$(this.loading).remove();this.miframe.style.display='';}
contentNode.miframe.style.display='none';if(isIE){contentNode.miframe.onreadystatechange=function(){contentNode.loadPage();}}else{contentNode.miframe.onload=function(){contentNode.loadPage();}}
setTimeout(function(){contentNode.loadPage();},5000);SWODE.popEditBoxWin.initContent(contentNode);};SWODE.resizeEditBox=function(w,h){if(SWODE.popEditBoxWin){SWODE.popEditBoxWin.resizeTo(w,h);}}
SWODE.showElements=function(tag){var elms=$$(tag);elms.each(function(elm){if(elm._hide){$(elm).style.visibility='visible';elm._hide=false;}});}
SWODE.hideElements=function(tag,overElement){var elms=$$(tag);var ox=parseInt(overElement.style.left);var oy=parseInt(overElement.style.top);var ow=parseInt(overElement.offsetWidth);var oh=parseInt(overElement.offsetHeight);elms.each(function(elm){var pos=Position.cumulativeOffset(elm);if(!(ox>(pos[0]+elm.offsetWidth)||pos[0]>(ox+ow)||pos[1]>(oy+oh)||oy>(pos[1]+elm.offsetHeight))){$(elm).style.visibility='hidden';elm._hide=true;}});}
SWODE.disableScreen=function(opacity){if(SWODE.screenDisabled)return;var overlayElement=$('nv-overlay');if(!overlayElement){var bodyElement=document.getElementsByTagName('body').item(0);overlayElement=document.createElement('div');overlayElement.setAttribute('id','nv-overlay');overlayElement.style.position='absolute';overlayElement.style.top='0px';overlayElement.style.left='0px';overlayElement.style.width='100%';bodyElement.appendChild(overlayElement);}
var clientHeight=document.documentElement.clientHeight||document.body.clientHeight||window.innerHeight;var scrollHeight=document.documentElement.scrollHeight||document.body.scrollHeight;overlayElement.className='op'+(opacity||'3');overlayElement.style.height=((clientHeight>scrollHeight)?clientHeight:scrollHeight)+'px';var fun=function(){};Event.observe(overlayElement,'click',fun,true);$(overlayElement).show();SWODE.screenDisabled=true;Event.observe(window,'resize',SWODE.resizeScreen.bindAsEventListener());}
SWODE.enableScreen=function(){var overlayElement=$('nv-overlay');if(overlayElement){$(overlayElement).hide();Event.stopObserving(overlayElement,'click',SWODE.enableScreen);$(overlayElement).remove();}
SWODE.screenDisabled=false;Event.stopObserving(window,'resize',SWODE.resizeScreen.bindAsEventListener());}
SWODE.resizeScreen=function(){if(SWODE.screenDisabled&&$('nv-overlay')){var clientHeight=document.documentElement.clientHeight||document.body.clientHeight||window.innerHeight;var scrollHeight=document.documentElement.scrollHeight||document.body.scrollHeight;$('nv-overlay').style.height=((clientHeight>scrollHeight)?clientHeight:scrollHeight)+'px';}}

//gadgets.js
SWODE.Gadgets.RSS=function(module){var container=module.body;var m_this=this;var m_feedurl=module.getPreference('feedUrl')||module.feed;var m_listnum=module.getPreference('listnum')||10;var m_showdate=module.getPreference('showdate')||false;var m_thepage=1;var m_RSS_PROXY=SWODE.Config.ContextPath+'/rss_proxy';var m_API_TOPICURL_RSS='http://rss.swode.com/read.wo?rss={%rss}&t={%title}&u=';this.init=function(){container.innerHTML='<div class="loading"><span class="loadbg">正在加载RSS...</span></div>';m_this.initRssData();};this.formatRssData=function(data){m_this.rssdata=[];if(data.rss&&data.rss.channel&&data.rss.channel.item){$arr(data.rss.channel.item).each(function(item){var newitem={'title':$str(item.title),'pubDate':$str(item.pubDate),'link':$str(item.link)};m_this.rssdata._add(newitem);});}
data.rss.channel.item=null;delete data.rss.channel.item;};this.initRssData=function(){module.showLoading();var rss_url=m_feedurl+((m_feedurl.indexOf('?')>0)?'&dev':'?dev');new Ajax.Request(m_RSS_PROXY,{method:'get',parameters:'force=true&url='+encodeURIComponent(rss_url),onSuccess:function(req){var data=eval('('+req.responseText+')');if(data&&data.rss&&data.rss.channel){module.title=module.title||data.rss.channel.title||'';if((!module.link||module.link=='')&&data.rss.channel.link){module.link=data.rss.channel.link;}
module.initModuleTitle();m_this.formatRssData(data);setTimeout(function(){m_this.initRssList();module.hideLoading();},1000);}else{if(module.edit){m_this.initInvalidRssUrl();}else{container.innerHTML='<div class="nodata">RSS读取失败！</div>';}
module.hideLoading();}},onFailure:function(){container.innerHTML='<div class="nodata">RSS读取失败！</div>';module.hideLoading();}});};this.initInvalidRssUrl=function(){container.innerHTML='<div class="nodata">RSS读取失败！请检查RSS地址：</div>';var apiLink=Builder.node('a',{href:m_feedurl,target:'_blank'},m_feedurl);var btnReload=Builder.node('a',{className:'uline pointer'},'重新加载');btnReload.onclick=function(){container.innerHTML='<div class="loading"><span class="loadbg">正在加载RSS...</span></div>';setTimeout(function(){m_this.initRssData();},1000);return false;}
var btnModify=Builder.node('a',{className:'uline pointer'},'修改RSS地址');btnModify.onclick=function(){m_this.editRssUrl();return false;}
container.firstChild.appendChild(Builder.node('br'));container.firstChild.appendChild(apiLink);container.firstChild.appendChild(Builder.node('br'));container.firstChild.appendChild(Builder.node('br'));container.firstChild.appendChild(btnReload);container.firstChild.appendChild(Builder.node('font',' | '));container.firstChild.appendChild(btnModify);};this.editRssUrl=function(){container.innerHTML='<div style="padding:20px 10px;">请输入有效的博客RSS地址：<br></div>';var txtRssUrl=Builder.node('input',{type:'text',style:'width:80%',value:m_feedurl});var btnUpdate=Builder.node('input',{type:'button',value:'读取内容'});var btnReset=Builder.node('a',{className:'uline pointer op3'},'恢复原地址');btnUpdate.onclick=function(){var url=txtRssUrl.value.strip();if(url==''){alert('请输入有效的博客RSS地址');txtRssUrl.focus();return;}
this.value='读取中...';this.disabled=true;m_feedurl=url;module.setPreference('feedUrl',url);m_this.saveData();m_this.initRssData();}
btnReset.onclick=function(){txtRssUrl.value=module.feed;this.className='uline pointer op3';}
txtRssUrl.onkeyup=function(){if(this.value!=_url)btnReset.className='uline pointer';}
container.firstChild.appendChild(txtRssUrl);container.firstChild.appendChild(Builder.node('br'));container.firstChild.appendChild(btnUpdate);container.firstChild.appendChild(btnReset);};this.initRssList=function(){if(m_this.rssdata.length==0){container.innerHTML='<div class="nodata">没有文章记录！</div>';return;}
container.innerHTML='<div class="contentBox"><ul class="listStyle1"></ul></div>';var stpage=m_this.rssdata._getpage(m_listnum,m_thepage);for(var i=stpage.begin-1;i<stpage.end;i++){var item=m_this.rssdata[i];var itemLink=module.link;if(item.link){itemLink=m_API_TOPICURL_RSS.replace('{%rss}',encodeURIComponent(m_feedurl)).replace('{%title}',encodeURIComponent(item.title))+encodeURIComponent(item.link);}
var itemNode=Builder.node('li');itemNode.innerHTML='<a href="'+itemLink+'" target="_blank">'+item.title+'</a>';container.firstChild.firstChild.appendChild(itemNode);if(m_showdate&&item.pubDate){var txtDate=Builder.node('font',{className:'distext'},' '+(new Date()).setMyDate(item.pubDate).format('yyyy-mm-dd'));itemNode.appendChild(txtDate);}}
if(stpage.allnum>0){var pageDiv=Builder.node('div',{className:'pageNum'});container.appendChild(pageDiv);m_this.initPageList(pageDiv,stpage);}};this.initPageList=function(pageDiv,stpage){pageDiv.innerHTML='<b class="red">'+stpage.thepage+'</b>/<b>'+stpage.allpage+'</b>页，共'+stpage.allnum+'条';if(stpage.last>0){pageDiv.appendChild(Builder.node('font',' '));var prevNode=Builder.node('a','上一页');prevNode.id=stpage.last;prevNode.href='#';prevNode.onclick=function(){m_thepage=this.id;m_this.initRssList();return false;}
pageDiv.appendChild(prevNode);}
if(stpage.next>0){pageDiv.appendChild(Builder.node('font',' '));var nextNode=Builder.node('a','下一页');nextNode.id=stpage.next;nextNode.href='#';nextNode.onclick=function(){m_thepage=this.id;m_this.initRssList();return false;}
pageDiv.appendChild(nextNode);}};this.initOptions=function(parent){parent.innerHTML='<div class="editArea"><div>标　题：</div><div>列表数：</div></div>';var txtTitle=Builder.node('input',{type:'text',value:module.title});txtTitle.style.width='60%';var selNumber=Builder.node('select');for(i=0;i<20;i++){selNumber.options[i]=new Option(i+1,i+1);}
selNumber.selectedIndex=m_listnum-1;selNumber.onchange=function(){m_listnum=this.value;m_this.initRssList();}
var chkShowDate=Builder.node('input',{type:'checkbox'});chkShowDate.onclick=function(){m_showdate=this.checked;m_this.initRssList();}
var btnResetTxt=Builder.node('a',{className:'uline',title:'取回博客原先标题'},'重置');btnResetTxt.href="#";btnResetTxt.onclick=function(){txtTitle.value=module._obj.rss.channel.title;return false;}
var btnUpdate=Builder.node('input',{type:'button',value:'保存'});btnUpdate.onclick=function(){var _title=txtTitle.value.strip();if(_title==''){alert('请输入标题名称。');txtTitle.focus();return;}
if(module.title!=_title){module.title=_title;module.initModuleTitle();}
module.setPreference('listnum',m_listnum);module.setPreference('showdate',m_showdate);m_this.saveData();module.hideOptions();}
parent.firstChild.firstChild.appendChild(txtTitle);parent.firstChild.firstChild.appendChild(Builder.node('font',' '));parent.firstChild.firstChild.appendChild(btnResetTxt);parent.firstChild.lastChild.appendChild(selNumber);parent.firstChild.lastChild.appendChild(Builder.node('font','条 '));parent.firstChild.lastChild.appendChild(chkShowDate);parent.firstChild.lastChild.appendChild(Builder.node('font','显示时间 '));parent.firstChild.lastChild.appendChild(btnUpdate);if(m_showdate)chkShowDate.checked=true;};this.saveData=function(onSuccess,onFailure){SWODE.UserData.saveModule(module,onSuccess,onFailure);};}
SWODE.Gadgets.Space=function(module){var container=module.body;var m_type=module.name;var m_this=this;this.init=function(){if(module.title==''){module.title=SWODE.PageData.GadgetTitle[m_type];module.initModuleTitle();}
container.innerHTML='<div class="editBox" style="display:none"></div><div class="contentBox"><div class="loading"><span class="loadbg">正在加载内容...</span></div></div>';container.lastChild.id='moduleContainer_'+module.mid;this.params=module.getPreference("params")||{};if(m_type=='princess'){container.innerHTML='<div class="nodata">活动已经结束。</div>';return;}
var params={'width':container.lastChild.offsetWidth,'moduleId':module.mid,'containerId':container.lastChild.id};if(m_type=='article'){params.articleId=this.params.id||'';params.showtype=this.params.showtype||'';}else if(m_type=='friend'){var m_width=container.lastChild.offsetWidth-10;var b_width=80;if(m_width>0){b_width=Math.floor(m_width/Math.floor(m_width/((this.params.isShowBuddyIcon)?70:85)));}
Object.extend(params,this.params);params.width=b_width-((this.params.isShowBuddyIcon)?4:26);params.groupId=this.params.groupId||'';}else if(m_type=='visitor'){var m_width=container.lastChild.offsetWidth-10;var b_width=80;if(m_width>0){b_width=Math.floor(m_width/Math.floor(m_width/((this.params.isShowBuddyIcon)?70:85)));}
Object.extend(params,this.params);params.width=b_width-((this.params.isShowBuddyIcon)?4:26);}else{Object.extend(params,this.params);}
var urlStr=SWODE.Config.ContextPath+(module.view.content||('/mod'+m_type+'index.wo'));var paramStr=(params)?$H(params).toQueryString():'';this.loadModuleHtml(urlStr,paramStr);this.initEditActions(container.firstChild);};this.loadModuleHtml=function(url,param){module.showLoading();new Ajax.Request(url,{method:'get',parameters:param,onSuccess:function(req){var ww=container.lastChild.offsetWidth-20;container.lastChild.innerHTML=req.responseText;if(m_type=='article'&&m_this.params.id!=''){module.link=SWODE.Config.ContextPath+'/article/view_'+m_this.params.id+'.jhtml';module.initModuleTitle();m_this.initImageResize(ww);if(container.lastChild.innerHTML.indexOf('_NOEDITLINK_')>0){m_this.params.id='';m_this.initEditActions(container.firstChild);}}
if(m_type=='update'||m_type=='account'){m_this.initImageResize(ww);}
if(m_type=='account'&&module.edit){setTimeout(function(){m_this.initAccountEvent();},500);}
module.hideLoading();},onFailure:function(){container.lastChild.innerHTML='<div class="nodata">内容载入失败</div>';module.hideLoading();}});};this.initImageResize=function(ww){var images=container.lastChild.getElementsByTagName('IMG');for(var i=0;i<images.length;i++){var image=images[i];image.onload=function(){var ow=parseInt(this.width);var oh=parseInt(this.height);if(ow>=ww){this.style.width=ww+'px';this.style.height=parseInt(ww*oh/ow)+'px';}}}};var m_editAPIs={"article":{"选择文章":"js:chooseArticle","撰写文章":"pw:article/owner/edit.wo"},"article2":{"修改文章":"js:editArticle","选择文章":"js:chooseArticle","撰写文章":"pw:article/owner/edit.wo"},"video":{"选择视频":"js:chooseVideo","上传视频":"video/owner/upload.wo","录制视频":"video/owner/record.wo"},"update":{"撰写文章":"pw:article/owner/edit.wo","上传照片":"photo/owner/upload.wo","上传视频":"video/owner/upload.wo","录制视频":"video/owner/record.wo"},"article/type":{"编辑分类":"pw:article/owner/admin_type.wo"},"photofolder":{"创建目录":"pw:photo/owner/create_folder.wo"},"videofolder":{"创建专辑":"pw:video/owner/edit_special.wo"},"visitstat":{"修改设置":"js:editVisitStatSetting"},"account":{"编辑个人资料":"account/edit.wo","设置关键信息":"pw:account/key_info.wo"},"link":{"编辑列表":"pw:mod/link/manage.wo"},"game":{"修改游戏信息":"js:editGame"}};this.initEditActions=function(parent){parent.innerHTML='';if(module.edit){this.editAPI=m_editAPIs[m_type]||false;if(m_type=='article'&&this.params.id!=''){this.editAPI=m_editAPIs['article2'];}
if(!this.editAPI)return;function getLinkIcon(item){if(item.indexOf('设置')>=0)return'icon/cog.gif';if(item.indexOf('照片')>=0)return'icon/picture.gif';if(item.indexOf('选择')>=0)return'icon/mouse.gif';if(item.indexOf('撰写')>=0)return'icon/ico_write.gif';return'icon/ico_edit.gif';}
for(var item in this.editAPI){var api_type=this.editAPI[item].substring(0,3);if(api_type!='js:'&&api_type!='pw:'){var linkIcon=Builder.node('img',{src:SWODE.formatImageLink('images/'+getLinkIcon(item)),align:'absmiddle',style:'margin-right:3px'});var linkItem=Builder.node('a',item);linkItem.href=this.editAPI[item];linkItem.target='_blank';parent.appendChild(linkIcon);parent.appendChild(linkItem);parent.appendChild(Builder.node('font',' '));}else{var linkIcon=Builder.node('img',{src:SWODE.formatImageLink('images/'+getLinkIcon(item)),align:'absmiddle',style:'margin-right:3px'});var linkItem=Builder.node('a',item);linkItem.href='#';linkItem.apiType=api_type;linkItem.apiLink=this.editAPI[item].substring(3,this.editAPI[item].length);linkItem.onclick=function(){if(this.apiType=='js:'){eval('m_this.'+this.apiLink+'()');}else{var title=this.innerHTML;var apiurl=SWODE.formatLink(this.apiLink);if(apiurl.indexOf('?')==-1){apiurl+='?';}else{apiurl+='&';}
apiurl+='moduleId='+module.mid;m_this.popEditWindow(title,apiurl);}
return false;}
parent.appendChild(linkIcon);parent.appendChild(linkItem);parent.appendChild(Builder.node('font',' '));}}
$(parent).show();}else{$(parent).hide();}};this.popEditWindow=function(title,apiurl,width,height){apiurl+=(apiurl.right(4)=='mid=')?module.mid:'';var width=width||600;var height=height||400;if(m_type=='article'||(m_type=='update'&&title=='撰写文章')){width=800;height=500;}else if(m_type=='account'&&title=='设置关键信息'){width=800;height=560;}
SWODE.popEditBox(title,apiurl,{width:width,height:height,callback:function(){m_this.init();}});};this.initOptions=function(parent){parent.innerHTML='<div class="editArea">标题：</div>';var txtTitle=Builder.node('input',{type:'text',size:'15',value:module.title});parent.firstChild.appendChild(txtTitle);parent.titleElement=txtTitle;if(SWODE.PageData.GadgetTitle[m_type]){var btnResetTxt=Builder.node('img',{src:SWODE.formatImageLink('images/module/reset.gif'),style:'margin:0px 3px;cursor:pointer',title:'恢复模块默认名称'});btnResetTxt.onclick=function(){txtTitle.value=SWODE.PageData.GadgetTitle[m_type]||'';return false;}
parent.firstChild.appendChild(btnResetTxt);}
if(m_this.params){if(m_type=='game'){m_this.initOptionsElement(parent,'checkbox','showcomment','是否显示留言内容 ');m_this.initOptionsElement(parent,'select','pageSize','每页显示数量：');}
if(m_type=='comment'||m_type=='game')m_this.initOptionsElement(parent,'checkbox','openSend','是否显示留言框 ');if(m_type=='rnd'||m_type=='comment')m_this.initOptionsElement(parent,'checkbox','showicon','是否显示头像 ');if(m_type=='link'||m_type=='photofolder'||m_type=='videofolder')m_this.initOptionsElement(parent,'select','pageSize','每页显示数量：');if(m_type=='link'||m_type=='rnd')m_this.initOptionsElement(parent,'checkbox','showdesc','是否显示描述 ');if(m_type=='update')m_this.initOptionsElement(parent,'checkboxs','type','类型：',{'article':'文章','photo':'相册','video':'视频','module':'模块','friend':'交友','comment':'留言','game':'游戏','datou':'大头贴','zipai':'自拍','page':'页面'});if(m_type=='update')m_this.initOptionsElement(parent,'select','view','视图：',{'title':'只显示标题','titles':'显示标题和时间','summary':'显示首篇摘要','summarys':'显示所有摘要','fulltext':'显示所有全文'});if(m_type=='article')m_this.initOptionsElement(parent,'select','showtype','显示：',{'summary':'文章摘要','full':'文章全文'});if(m_type=='rnd'||m_type=='update'||m_type=='comment')m_this.initOptionsElement(parent,'select','max','显示数量：');if(m_type=='friend'){m_this.initFriendGroupListOptionElement(parent);m_this.initOptionsElement(parent,'checkbox','isShowBuddyIcon','是否显示头像：');m_this.initOptionsElement(parent,'checkbox','isShowDescription','是否显示批注：');m_this.initOptionsElement(parent,'select','pageSize','每页显示：');}
if(m_type=='visitor'){m_this.initOptionsElement(parent,'checkbox','isShowBuddyIcon','是否显示头像：');m_this.initOptionsElement(parent,'checkbox','isShowVisitTime','是否显示访问时间：');m_this.initOptionsElement(parent,'select','pageSize','显示最新：');}}
var btnUpdate=Builder.node('input',{type:'button',value:'保存'});btnUpdate.onclick=function(){var _title=txtTitle.value.strip();if(_title==''){alert('请输入标题名称。');txtTitle.focus();return;}
var _updated=false;if(module.title!=_title){module.title=_title;module.initModuleTitle();_updated=true;}
if(m_this.params){module.setPreference('params',m_this.params);m_this.init();_updated=true;}
if(_updated)m_this.saveData();module.hideOptions();}
parent.firstChild.appendChild(btnUpdate);Event.observe(txtTitle,'keydown',function(e){if(e.keyCode==13)btnUpdate.onclick();},false);};this.initOptionsElement=function(parent,type,item,title,data){parent.firstChild.appendChild(Builder.node('br'));if(type=='checkbox'){var chkElement=Builder.node('input',{type:'checkbox'});chkElement.item=item;chkElement.onclick=function(){m_this.params[this.item]=this.checked;}
parent.firstChild.appendChild(chkElement);parent.firstChild.appendChild(Builder.node('font',title));chkElement.checked=m_this.params[item]||false;}else if(type=='checkboxs'){var chk_arr=(m_this.params[item])?m_this.params[item].split(','):[];parent.firstChild.appendChild(Builder.node('font',title));m_this['chk'+item]=[];for(var key in data){var chkInput=Builder.node('input',{'type':'checkbox',value:key});chkInput.item=item;chkInput.onclick=function(){var chk_arr=[];for(var i=0;i<m_this['chk'+this.item].length;i++){if(m_this['chk'+this.item][i].checked)chk_arr.push(m_this['chk'+this.item][i].value);}
m_this.params[this.item]=chk_arr._str();}
parent.firstChild.appendChild(chkInput);parent.firstChild.appendChild(Builder.node('font',data[key]));chkInput.checked=chk_arr._find(key);m_this['chk'+item].push(chkInput);}}else if(type=='select'){var selElement=Builder.node('select');var selElementIndex=0;if(data){for(var key in data){if(m_this.params[item]==key)selElementIndex=selElement.length;selElement.options[selElement.length]=new Option(data[key],key);}}else{for(i=2;i<=20;i++){selElement.options[selElement.length]=new Option(i,i);}
if(m_this.params[item])selElementIndex=m_this.params[item]-2;}
selElement.item=item;selElement.onchange=function(){m_this.params[this.item]=this.value;}
selElement.selectedIndex=selElementIndex;parent.firstChild.appendChild(Builder.node('font',title));parent.firstChild.appendChild(selElement);if(!data)parent.firstChild.appendChild(Builder.node('font','条 '));}};this.initFriendGroupListOptionElement=function(parent){parent.firstChild.appendChild(Builder.node('br'));var selElement=Builder.node('select');selElement.options[0]=new Option('所有分组','');selElement.onchange=function(){m_this.params.groupId=this.value;}
parent.firstChild.appendChild(Builder.node('font','选择分组：'));parent.firstChild.appendChild(selElement);module.groupListOptionElement=selElement;new Ajax.Request(SWODE.Config.ContextPath+'/mod/friend/groups.wo',{method:'get',onComplete:function(transport){var groups=transport.responseText.parseJSON();if(!groups['error']){for(var n=0;n<groups.length;n++){module.groupListOptionElement.options[n+1]=new Option(groups[n].name,groups[n].id);if(m_this.params.groupId==groups[n].id){module.groupListOptionElement.selectedIndex=n+1;}}}}});};this.saveData=function(onSuccess,onFailure){SWODE.UserData.saveModule(module,onSuccess,onFailure);};this.resize=function(){if(m_type=='video'||m_type=='article')this.init();};if(module.edit&&m_type!='article')module.initModuleTitleEdit();this.initAccountEvent=function(){if(!$('uols_desc_'+module.mid))return;this.uolsElements={'txtDesc':$('uols_desc_'+module.mid),'selButton':$('uols_selbutton_'+module.mid),'btnEditer':$('uols_btnedit_'+module.mid),'txtStatus':$('uols_txtstatus_'+module.mid),'selStatus':$('uols_selstatus_'+module.mid)};this.uols={'status':'','statusDesc':this.uolsElements.txtDesc.innerHTML};this.uolsElements.txtDesc.onmouseover=function(){m_this.uolsElements.btnEditer.isView=true;m_this.uolsElements.btnEditer.style.display='';}
this.uolsElements.txtDesc.onmouseout=function(){m_this.uolsElements.btnEditer.isView=false;setTimeout(function(){if(m_this.uolsElements.btnEditer.isView==true)return;m_this.uolsElements.btnEditer.style.display='none';},500);}
this.uolsElements.selButton.onclick=function(){if(m_this.uolsElements.selStatus.isOpen){m_this.uolsElements.selStatus.onHide();}else{m_this.uolsElements.selStatus.onShow();}}
this.uolsElements.btnEditer.onclick=function(){m_this.uolsElements.selStatus.onHide();$(m_this.uolsElements.txtDesc).hide();$(this.parentNode).hide();$(m_this.uolsElements.txtStatus.parentNode).show();m_this.uolsElements.txtStatus.value=m_this.uols.statusDesc;m_this.uolsElements.txtStatus.select();m_this.uolsElements.txtStatus.focus();}
this.uolsElements.txtStatus.onblur=function(){if(this.value.strip()=='')return;m_this.uols.status='CUSTOM';m_this.uols.statusDesc=this.value;m_this.uolsElements.txtDesc.innerHTML=this.value;$(this.parentNode).hide();$(m_this.uolsElements.txtDesc).show();$(m_this.uolsElements.selButton.parentNode).show();m_this.saveUolStatus();}
this.uolStatus={'ONLINE':'在线','OFFLINE':'不在线','BUSY':'忙碌','LEAVING':'离开','DINING':'外出用餐','CUSTOM':'自定义'};this.uolsElements.selStatus.innerHTML='';for(var item in this.uolStatus){var statusItem=Builder.node('div',this.uolStatus[item]);statusItem.status=item;statusItem.onmouseover=function(){this.style.backgroundColor='#ddeeff';}
statusItem.onmouseout=function(){this.style.backgroundColor='';}
statusItem.onclick=function(){m_this.uols.status=this.status;m_this.uols.statusDesc=this.innerHTML;m_this.uolsElements.selStatus.onHide();if(this.status=='CUSTOM'){m_this.uolsElements.btnEditer.onclick();}else{m_this.uolsElements.txtDesc.innerHTML=this.innerHTML;m_this.saveUolStatus();}}
this.uolsElements.selStatus.appendChild(statusItem);}
this.uolsElements.selStatus.isOpen=false;this.uolsElements.selStatus.onShow=function(){this.isOpen=true;var pos=Position.cumulativeOffset(m_this.uolsElements.txtDesc);this.style.left=pos[0]+'px';this.style.top=(pos[1]+16)+'px';}
this.uolsElements.selStatus.onHide=function(){this.isOpen=false;this.style.left='-100px';this.style.top='0px';}};this.saveUolStatus=function(){if(this.uols.status=='')return;var url=SWODE.Config.ContextPath+'/api/change_status.wo';var param=$H(this.uols).toQueryString();new Ajax.Request(url,{method:'post',postBody:param,onComplete:function(){}});};this.popVideoProof=function(){SWODE.popEditBox('会员认证',SWODE.Config.ContextPath+'/proof.wo',{width:700,height:470,callback:function(){m_this.init();}});};this.chooseArticle=function(tid,title){if(!tid){var src=SWODE.Config.ContextPath+'/mod/article/choose_article.wo?moduleId='+module.mid+'&articleId='+this.params.id;SWODE.popEditBox('选择文章',src,{callback:function(){m_this.init();}});}else{if(tid!=this.params.id){this.params.id=tid;module.title=title||'文章';module.link=SWODE.Config.ContextPath+'/article/view_'+tid+'.jhtml';module.initModuleTitle();module.setPreference('params',this.params);this.saveData();}else if(module.title!=title){module.title=title||'文章';module.link=SWODE.Config.ContextPath+'/article/view_'+tid+'.jhtml';module.initModuleTitle();this.saveData();}
SWODE.popEditBoxWin.btnClose.onclick();}};this.editArticle=function(){var apiurl=SWODE.formatLink('article/owner/edit.wo?isForArticleModule=true&articleId='+this.params.id+'&moduleId='+module.mid);this.popEditWindow('修改文章',apiurl);};this.chooseVideo=function(tid,title){if(!tid){var src=SWODE.Config.ContextPath+'/mod/video/specials.wo?moduleId='+module.mid;SWODE.popEditBox('选择视频',src,{callback:function(){m_this.init();}});}else{if(tid!=this.params.id){this.params.videoId=tid;module.title=title||'视频';module.initModuleTitle();module.setPreference('params',this.params);this.saveData();}else if(module.title!=title){module.title=title||'视频';module.initModuleTitle();this.saveData();}
SWODE.popEditBoxWin.btnClose.onclick();}};this.auditionMusic=function(musicId){var mw=350;var mh=200;var mx=(screen.availWidth-mw)/2;var my=(screen.availHeight-mh)/2;var features='width='+mw+',height='+mh+',left='+mx+',top='+my+',scrollbars=no,resizable=no';window.open(SWODE.Config.ContextPath+'/music/audition.wo?type=musics&musicIds='+musicId,'musicplayerWin',features);};this.editGame=function(){var apiurl=SWODE.formatLink('mod/game/edit.wo?gameId='+this.params.gameId+'&moduleId='+module.mid);this.popEditWindow('修改游戏信息',apiurl,450,250);}
this.editVisitStatSetting=function(){var apiurl=SWODE.formatLink('mod/visitstat/setting.wo');this.popEditWindow('访问统计设置',apiurl,300,120);};this.sendMessage=function(content,options){if(content.strip()==''){alert('请输入留言内容!');return;}
if(content.length>300){alert('留言内容不能超过300个字符!');return;}
var url=SWODE.Config.ContextPath+'/comment/post.wo';var param='content='+encodeURIComponent(content);if(options)param+=('&'+$H(options).toQueryString());container.innerHTML='<div class="editBox" style="display:none"></div><div class="contentBox"><div class="loading"><span class="loadbg">正在发送留言...</span></div></div>';new Ajax.Request(url,{method:'post',postBody:param,onComplete:function(){m_this.init();}});};}
SWODE.App={};SWODE.App.ScriptsLoader={};SWODE.App.Callback=function(data){if(data&&data.moduleId){var mdl=SWODE.UserModules.modules._getitemby('id',data.moduleId);if(mdl&&mdl.obj){var module=mdl.obj;if(module.title==''){module.title=data.title;module.header.mtitle.innerHTML=data.title;}
if(!data.error){module.body.innerHTML='<div class="contentBox">'+data.content+'</div>';}else{module.body.innerHTML='<div class="nodata">内容载入失败。</div>';}}}
try{SWODE.App.ScriptsLoader[data.moduleId].removeScriptTag();}catch(e){}
delete SWODE.App.ScriptsLoader[data.moduleId];}
SWODE.App.Popwin=function(title,apiurl,width,height){var width=width||600;var height=height||400;SWODE.popEditBox(title,apiurl,{width:width,height:height,callback:function(){}});};SWODE.Gadgets.APP=function(module){var container=module.body;var m_type=module.name;var m_this=this;var m_APP_PATH='http://apps.swode.com/';this.params=module.getPreference("params")||{};this.init=function(){container.innerHTML='<div class="loading"><span class="loadbg">正在加载内容...</span></div>';this.initModuleParams();this.loadModuleHtml();};this.initModuleParams=function(){var paramstr=$H(this.params).toQueryString();if(paramstr==''&&module.view.pref){$arr(module.view.pref).each(function(pref){pref.datatype=pref.datatype||'string';m_this.params[pref.name]=pref['default_value']||((pref.datatype=='bool')?false:'')});}};this.loadModuleHtml=function(){var contentUrl=module.view.content||'';if(contentUrl==''){container.innerHTML='<div class="nodata">内容为空</div>';return;}
var paramstr=$H(this.params).toQueryString();paramstr+=((paramstr!='')?'&':'')+'swodeOwner='+SWODE.Config.isOwner;paramstr+='&swodeUid='+(SWODE.Config.spaceOwnUid||'');var request=m_APP_PATH+'api_render_gadget.wo?gadget_id='+module.gid+'&gadget_content='+contentUrl;request+='&params='+encodeURIComponent(paramstr);request+='&module_id='+module.mid+'&callback=SWODE.App.Callback';var loadJsonDataRequest=new JSONscriptRequest(request);loadJsonDataRequest.buildScriptTag();loadJsonDataRequest.addScriptTag();SWODE.App.ScriptsLoader[module.mid]=loadJsonDataRequest;};this.initOptions=function(parent){this.elements=[];parent.innerHTML='<div class="editArea">标题：</div>';var txtTitle=Builder.node('input',{type:'text',size:'15',value:module.title});parent.firstChild.appendChild(txtTitle);parent.titleElement=txtTitle;var btnUpdate=Builder.node('input',{type:'button',value:'保存'});btnUpdate.onclick=function(){var _title=txtTitle.value.strip();if(_title==''){alert('请输入标题名称。');txtTitle.focus();return;}
if(module.title!=_title){module.title=_title;module.initModuleTitle();}
module.setPreference('params',m_this.params);m_this.saveData();module.hideOptions();m_this.init();}
if(module.view.pref){$arr(module.view.pref).each(function(pref){m_this.initOptionsElement(parent,pref);});}
parent.firstChild.appendChild(btnUpdate);Event.observe(txtTitle,'keydown',function(e){if(e.keyCode==13)btnUpdate.onclick();},false);};this.initOptionsElement=function(parent,pref){parent.firstChild.appendChild(Builder.node('br'));pref.datatype=pref.datatype||'string';var item=pref.name;if(pref.datatype=='string'){var txtElement=Builder.node('input',{type:'text',style:'width:60%'});txtElement.item=item;txtElement.required=pref.required;txtElement.value=this.params[item]||pref['default_value']||'';txtElement.onblur=function(){m_this.params[this.item]=this.value;}
parent.firstChild.appendChild(Builder.node('font',pref['display_name']+'：'));parent.firstChild.appendChild(txtElement);this.elements[item]=txtElement;}else if(pref.datatype=='bool'){var chkElement=Builder.node('input',{type:'checkbox'});chkElement.item=item;chkElement.onclick=function(){m_this.params[this.item]=this.checked;}
parent.firstChild.appendChild(chkElement);parent.firstChild.appendChild(Builder.node('font',pref['display_name']));chkElement.checked=this.params[item]||(pref['default_value']=='true')||false;}else if(pref.datatype=='enum'){var selElement=Builder.node('select');var selElementIndex=0;var data=pref.EnumValue;for(var i=0;i<data.length;i++){if((this.params[item]||pref['default_value']||'')==data[i].value)selElementIndex=selElement.length;selElement.options[selElement.length]=new Option(data[i]['display_value']||data[i].value,data[i].value);}
selElement.item=item;selElement.onchange=function(){m_this.params[this.item]=this.value;}
selElement.selectedIndex=selElementIndex;parent.firstChild.appendChild(Builder.node('font',pref['display_name']+'：'));parent.firstChild.appendChild(selElement);}else if(pref.datatype=='enums'){var chk_arr=(m_this.params[item])?m_this.params[item].split(','):((pref['default_value'])?pref['default_value'].split('|'):[]);parent.firstChild.appendChild(Builder.node('font',pref['display_name']+'：'));this['chk'+item]=[];var data=pref.EnumValue;for(var i=0;i<data.length;i++){var chkInput=Builder.node('input',{'type':'checkbox',value:data[i].value});chkInput.item=item;chkInput.onclick=function(){var chk_arr=[];for(var i=0;i<m_this['chk'+this.item].length;i++){if(m_this['chk'+this.item][i].checked)chk_arr.push(m_this['chk'+this.item][i].value);}
m_this.params[this.item]=chk_arr._str();}
parent.firstChild.appendChild(chkInput);parent.firstChild.appendChild(Builder.node('font',data[i]['display_value']||data[i].value));chkInput.checked=chk_arr._find(data[i].value);this['chk'+item].push(chkInput);}}};this.saveData=function(onSuccess,onFailure){SWODE.UserData.saveModule(module,onSuccess,onFailure);};if(module.edit) module.initModuleTitleEdit();}
SWODE.Gadgets.GTL=function(module){}
SWODE.Gadgets.UWA=function(module){}
SWODE.PhotoUtility=function(module,source){var container=module.body;var m_this=this;var m_RSS_PROXY=SWODE.Config.ContextPath+'/rss_proxy';this.init=function(gallery){this.source=source||'';this.photos=[];this.thepage=1;this.player={playstatus:true};this.gallery=gallery;this.loadedPhoto=null;this.loadedError=0;this.imgObjects=null;this.closeImagePreloadTimer();};this.loadPhotoData=function(url,cbkSuccess){url+=((url.indexOf('?')>0)?'&dev':'?dev');new Ajax.Request(m_RSS_PROXY,{method:'get',parameters:'url='+encodeURIComponent(url),onSuccess:function(req){var rssdata=eval('('+req.responseText+')');if(rssdata.rss&&rssdata.rss.channel&&rssdata.rss.channel.item){var p_data=rssdata.rss.channel;m_this.moreurl=p_data.link;m_this.photos=m_this.formatPhotoRss(p_data.item);if(m_this.photos.length==0){container.firstChild.innerHTML='<div class="nodata">图片列表为空。</div>';module.hideLoading();return;}
setTimeout(function(){if(cbkSuccess)cbkSuccess();module.hideLoading();},1000);}else{container.firstChild.innerHTML='<div class="nodata">图片数据载入失败！</div>';module.hideLoading();return;}},onFailure:function(){container.firstChild.innerHTML='<div class="nodata">图片数据载入失败！</div>';module.hideLoading();}});module.showLoading();};this.formatPhotoRss=function(data){var newdata=[];if(!data.length)data=$arr(data);data.each(function(item){var thumb=item['media:thumbnail']||{};var medium=item['media:content']||{};if(m_this.source=='picasa'){var mediagroup=item['media:group']||{};var thumb=mediagroup['media:thumbnail']||{};var medium=mediagroup['media:content']||{};if(thumb.length)thumb=thumb[0];}
newdata[newdata.length]={'title':$str(item.title),'content':$str(item.content),'thumbnail':$str(thumb.url),'medium':$str(medium.url),'width':$str(medium.width),'height':$str(medium.height),'link':$str(item.link)}});return newdata;};this.initPhotoData=function(photos){if(photos)this.photos=photos;if(this.gallery.type=='slideshow'){this.initSlideShow();}else if(this.gallery.type=='thumbnail'){this.initThumbnail();}else{this.initLoopShow();}};this.setContainer=function(node){container=node;};this.resize=function(){if(this.photos.length>0){if(this.gallery.type=='thumbnail'){this.initThumbnail();}else if(this.gallery.type=='photoloop'){this.closeMarquee();this.initLoopShow();}}};this.pointer=-1;this.opacitysetting=0.1;this.opacitystring='width:100%; filter:progid:DXImageTransform.Microsoft.alpha(opacity=100); -moz-opacity:1';this.initSlideShow=function(){if(this.photos.length==0)return;var strHtml='<div style="overflow:hidden;text-align:center;'+this.opacitystring+'">';strHtml+='<div class="loading"><span class="loadbg">正在加载图片...</span></div>';strHtml+='</div>';strHtml+='<div style="padding:2px 0px; text-align:center;"></div>';var viewNode=container.firstChild;viewNode.innerHTML=strHtml;if(this.loadedPhoto&&this.loadedPhoto.length>0){this.playNextShow(true);this.initPlayControl();return;}
this.loadedPhoto=[];this.loadedError=0;this.imgObjects=[];SWODE.ImagePreloader[module.mid]=function(i){if(m_this.photos.length==0)return;var item=m_this.photos[i];if(!item)return;m_this.imgObjects[i]=new SWODE.ImageLoader({src:item.medium});m_this.imgObjects[i].title=item.title;m_this.imgObjects[i].content=item.content;m_this.imgObjects[i].link=item.link;m_this.imgObjects[i].onLoad=function(){if(!m_this.loadedPhoto)return;this.width=this.element.width;this.height=this.element.height;m_this.loadedPhoto.push(this);if(m_this.loadedPhoto.length==1){m_this.playNextShow(true);m_this.initPlayControl();}}
m_this.imgObjects[i].onError=function(){if(!m_this.loadedPhoto)return;m_this.loadedError++;if(m_this.loadedError==m_this.photos.length&&m_this.gallery.type=='slideshow'){container.firstChild.innerHTML='<div class="nodata">图片载入失败。</div>';}}}
this.imagePreloadTimer=[];for(var i=0;i<this.photos.length;i++){this.imagePreloadTimer[i]=setTimeout('SWODE.ImagePreloader[\''+module.mid+'\']('+i+')',2000*i);}};this.closeImagePreloadTimer=function(){if(!this.imagePreloadTimer)return;for(var i=0;i<this.imagePreloadTimer.length;i++){clearInterval(this.imagePreloadTimer[i]);}
this.imagePreloadTimer=null;};this.fitPhotoSize=function(imgObj){var mW=(container.firstChild.offsetWidth>0)?(container.firstChild.offsetWidth-10):200;var mH=Math.floor(mW*3/4);var w=imgObj.width;var h=imgObj.height;if(imgObj.width>mW||imgObj.height>mH){var a=imgObj.width/mW;var b=imgObj.height/mH;if(b>a)a=b;w=imgObj.width/a;h=imgObj.height/a;}
if(w>0&&h>0){imgObj.element.width=w;imgObj.element.height=h;}};this.playNextShow=function(next){if(this.gallery.type!='slideshow')return;if(next){this.pointer++;if(this.pointer>=this.loadedPhoto.length)this.pointer=0;}else{this.pointer--;if(this.pointer<0)this.pointer=this.loadedPhoto.length-1;}
var imgObj=this.loadedPhoto[this.pointer];this.fitPhotoSize(imgObj);this.fadeTransition("reset");container.firstChild.firstChild.innerHTML='<a href="'+imgObj.link+'" target="_blank"></a>';container.firstChild.firstChild.firstChild.appendChild(imgObj.element);container.firstChild.lastChild.innerHTML='<b>'+imgObj.title+'</b>'+((imgObj.content)?('<br>'+imgObj.content):'');this.fadeTimer=setInterval(function(){m_this.fadeTransition('up');},100);if(this.gallery.type=='slideshow'&&this.player.playstatus){this.slideTimer=setTimeout(function(){m_this.playNextShow(next);},this.gallery.speed);}};this.initPlayControl=function(){var pageNode=container.lastChild;pageNode.innerHTML='<div align="center" style="padding-top:6px;padding-bottom:3px;"></div>';pageNode.className='';$(pageNode).show();var btnPrev=Builder.node('span',{style:'margin:2px; padding:2px 2px 1px 2px; border-style:solid; border-width:1px;',className:'greyborder backcolor pointer'});btnPrev.innerHTML='上一张';btnPrev.onclick=function(){if(m_this.player.playstatus)btnPlay.onclick();m_this.playNextShow(false);}
btnPrev.onmouseover=function(){this.style.borderWidth='2px';this.style.margin='1px';}
btnPrev.onmouseout=function(){this.style.borderWidth='1px';this.style.margin='2px';}
var btnNext=Builder.node('span',{style:'margin:2px; padding:2px 2px 1px 2px; border-style:solid; border-width:1px;',className:'greyborder backcolor pointer'});btnNext.innerHTML='下一张';btnNext.onclick=function(){if(m_this.player.playstatus)btnPlay.onclick();m_this.playNextShow(true);}
btnNext.onmouseover=function(){this.style.borderWidth='2px';this.style.margin='1px';}
btnNext.onmouseout=function(){this.style.borderWidth='1px';this.style.margin='2px';}
var btnPlay=Builder.node('span',{style:'margin:2px; padding:2px 2px 1px 2px; border-style:solid; border-width:1px;',className:'greyborder backcolor pointer'});btnPlay.innerHTML=(this.player.playstatus)?'＝暂停':'＞播放';btnPlay.onclick=function(){m_this.player.playstatus=!m_this.player.playstatus;if(m_this.player.playstatus){this.innerHTML='＝暂停';m_this.playNextShow(true);}else{this.innerHTML='＞播放';if(m_this.slideTimer){clearInterval(m_this.slideTimer);m_this.slideTimer=null;}}}
btnPlay.onmouseover=function(){this.style.borderWidth='2px';this.style.margin='1px';}
btnPlay.onmouseout=function(){this.style.borderWidth='1px';this.style.margin='2px';}
pageNode.firstChild.appendChild(btnPrev);pageNode.firstChild.appendChild(btnPlay);pageNode.firstChild.appendChild(btnNext);var moreNode=Builder.node('a','查看列表页面');moreNode.className='pointer uline';moreNode.href=this.moreurl;moreNode.target='_blank';pageNode.firstChild.appendChild(Builder.node('font',' '));pageNode.firstChild.appendChild(moreNode);};this.fadeTransition=function(fadetype){var fadeNode=container.firstChild.firstChild;if(fadetype=="reset")this.opacitysetting=0.1;if(fadeNode.filters&&fadeNode.filters[0]){if(typeof fadeNode.filters[0].opacity=="number"){fadeNode.filters[0].opacity=this.opacitysetting*100;}else{fadeNode.firstChild.style.filter="alpha(opacity="+this.opacitysetting*100+")";}}else if(typeof fadeNode.style.MozOpacity!="undefined"&&this.opacitystring!=""){fadeNode.style.MozOpacity=this.opacitysetting;}else{this.opacitysetting=1;}
if(fadetype=="up")this.opacitysetting+=0.1;if(fadetype=="up"&&this.opacitysetting>=1)clearInterval(this.fadeTimer);};this.initThumbnail=function(){var viewNode=container.firstChild;var table_width=['100%',(Math.floor(100/this.gallery.width)+'%'),'100%',0];if((viewNode.offsetWidth-10)>(83*this.gallery.width)){table_width=[this.gallery.width*75,'75','75',1];}
viewNode.innerHTML='<table width="'+table_width[0]+'" border="0" cellspacing="0" cellpadding="0" align="center" style="margin:auto;"></table>';var stpage=this.photos._getpage(this.gallery.width*this.gallery.height,this.thepage);var tmp=0;for(var i=stpage.begin-1;i<stpage.end;i++){var item=this.photos[i];if(tmp%this.gallery.width==0){var newRow=viewNode.firstChild.insertRow(viewNode.firstChild.rows.length);newRow.setAttribute('valign','top');}else{var newRow=viewNode.firstChild.rows[viewNode.firstChild.rows.length-1];}
var newCell=newRow.insertCell(tmp%this.gallery.width);newCell.setAttribute('width',table_width[1]);newCell.setAttribute('height',table_width[1]);if(table_width[3]==0&&newCell.offsetWidth>0){table_width[2]=Math.floor(viewNode.firstChild.offsetWidth/this.gallery.width)-8;table_width[3]=1;}
newCell.innerHTML='<a href="'+item.link+'" target="_blank"><img src="'+item.thumbnail+'" width="'+table_width[2]+'" height="'+table_width[2]+'" border="0" onerror="this.src=\'http://space.swode.com/images/nopic2_75.v0.5.28.gif\';" /></a>';newCell.title=item.title;tmp++;}
var pageNode=container.lastChild;$(pageNode).show();this.initPageList(pageNode,stpage);};this.initPageList=function(pageDiv,stpage){pageDiv.innerHTML='<div align="center" style="padding-top:6px;padding-bottom:3px;"></div>';if(stpage.last>0){pageDiv.appendChild(Builder.node('font',' '));var prevNode=Builder.node('span',{style:'margin:2px; padding:2px 2px 1px 2px; border-style:solid; border-width:1px;',className:'greyborder backcolor pointer'});prevNode.innerHTML='上一页';prevNode.id=stpage.last;prevNode.onclick=function(){m_this.thepage=this.id;m_this.initThumbnail();}
prevNode.onmouseover=function(){this.style.borderWidth='2px';this.style.margin='1px';}
prevNode.onmouseout=function(){this.style.borderWidth='1px';this.style.margin='2px';}
pageDiv.firstChild.appendChild(prevNode);}
if(stpage.next>0){pageDiv.appendChild(Builder.node('font',' '));var nextNode=Builder.node('span',{style:'margin:2px; padding:2px 2px 1px 2px; border-style:solid; border-width:1px;',className:'greyborder backcolor pointer'});nextNode.innerHTML='下一页';nextNode.id=stpage.next;nextNode.onclick=function(){m_this.thepage=this.id;m_this.initThumbnail();}
nextNode.onmouseover=function(){this.style.borderWidth='2px';this.style.margin='1px';}
nextNode.onmouseout=function(){this.style.borderWidth='1px';this.style.margin='2px';}
pageDiv.firstChild.appendChild(nextNode);}
var moreNode=Builder.node('a','查看列表页面');moreNode.className='pointer uline';moreNode.href=this.moreurl;moreNode.target='_blank';pageDiv.firstChild.appendChild(Builder.node('font',' '));pageDiv.firstChild.appendChild(moreNode);};this.initLoopShow=function(){var viewNode=container.firstChild;var pageNode=container.lastChild;viewNode.innerHTML='<div style="overflow:hidden; width:'+(viewNode.offsetWidth-10)+'px"></div>';pageNode.innerHTML='';$(pageNode).hide();var loopHtml='';for(var i=0;i<this.photos.length;i++){loopHtml+='<td><a href="'+this.photos[i].link+'" target="_blank" title="'+this.photos[i].title+'"><img height="'+this.gallery.lheight+'" src="'+this.photos[i].medium+'" border="0"></a></td>';}
var tableHtml='<table border="0" cellspacing="0" cellpadding="0" style="padding:0px;border:none;"><tr>';tableHtml+='<td><table border="0" cellspacing="0" cellpadding="0" style="padding:0px;border:none;"><tr>'+loopHtml+'</tr></table></td>';tableHtml+='<td><table border="0" cellspacing="0" cellpadding="0" style="padding:0px;border:none;"><tr>'+loopHtml+'</tr></table></td>';tableHtml+='</tr></table>';viewNode.firstChild.innerHTML=tableHtml;viewNode.firstChild.onmouseover=function(){m_this.closeMarquee();}
viewNode.firstChild.onmouseout=function(){if(m_this.loopTimer)return;m_this.startMarquee();}
setTimeout(function(){m_this.startMarquee();},100);};this.startMarquee=function(){this.loopTimer=setInterval(function(){m_this.initMarquee();},this.gallery.lspeed);};this.closeMarquee=function(){if(this.loopTimer){clearInterval(this.loopTimer);this.loopTimer=null;}
if(this.slideTimer){clearInterval(this.slideTimer);this.slideTimer=null;}};this.initMarquee=function(){if(!this.loopTimer)return;var viewNode=container.firstChild;if(this.gallery.type!='photoloop'){this.closeMarquee();return;}
var demo=viewNode.firstChild;var demo1=demo.firstChild.rows[0].cells[0];var demo2=demo.firstChild.rows[0].cells[1];if(demo2.offsetWidth-demo.scrollLeft<=0){demo.scrollLeft-=demo1.offsetWidth;}else{demo.scrollLeft++;}};this.initPlayOptions=function(parent,gallery,onSave){this.gallery=gallery;var thtml='<div></div><table width="90%" border="0" cellspacing="0" cellpadding="2">';thtml+='<tr><td nowrap>显示：</td><td width="100%"></td></tr>';thtml+='<tr><td>速度：</td><td></td></tr>';thtml+='<tr><td>排列：</td><td></td></tr>';thtml+='<tr><td>高度：</td><td></td></tr>';thtml+='<tr><td></td><td></td></tr>';thtml+='</table>';parent.innerHTML=thtml;var editDiv=parent.lastChild;var selType=Builder.node('select');var selSpeed=Builder.node('select');var selWidth=Builder.node('select');var selHeight=Builder.node('select');var txtLHeight=Builder.node('input',{type:'text',value:this.gallery.lheight,size:4});var selLSpeed=Builder.node('select');var btnUpdate=Builder.node('input',{type:'button',value:'保存'});var selTypeIndex=0;var viewerTypes={'slideshow':'幻灯片','thumbnail':'缩略图','photoloop':'横向滚动'};for(var item in viewerTypes){if(this.gallery.type==item)selTypeIndex=selType.length;selType.options[selType.length]=new Option(viewerTypes[item],item);}
selType.selectedIndex=selTypeIndex;for(i=3;i<13;i++){selSpeed[selSpeed.length]=new Option(i,i);}
selSpeed.selectedIndex=(this.gallery.speed/1000)-3;for(i=1;i<9;i++){selWidth[selWidth.length]=new Option(i,i);}
selWidth.selectedIndex=this.gallery.width-1;for(i=1;i<9;i++){selHeight[selHeight.length]=new Option(i,i);}
selHeight.selectedIndex=this.gallery.height-1;var selLSpeedIndex=0;[5,10,15,20,25,30,40,50].each(function(val){if(val==m_this.gallery.lspeed)selLSpeedIndex=selLSpeed.length;selLSpeed[selLSpeed.length]=new Option(val,val);});selLSpeed.selectedIndex=selLSpeedIndex;editDiv.rows[0].cells[1].appendChild(selType);editDiv.rows[1].cells[1].appendChild(selSpeed);editDiv.rows[1].cells[1].appendChild(Builder.node('font','秒/张'));editDiv.rows[2].cells[1].appendChild(selWidth);editDiv.rows[2].cells[1].appendChild(Builder.node('b','×'));editDiv.rows[2].cells[1].appendChild(selHeight);editDiv.rows[3].cells[1].appendChild(txtLHeight);editDiv.rows[3].cells[1].appendChild(Builder.node('font','像素 速度：'));editDiv.rows[3].cells[1].appendChild(selLSpeed);editDiv.rows[4].cells[1].appendChild(btnUpdate);if(this.gallery.type=='slideshow'){editDiv.rows[2].style.display='none';editDiv.rows[3].style.display='none';}else if(this.gallery.type=='thumbnail'){editDiv.rows[1].style.display='none';editDiv.rows[3].style.display='none';}else{editDiv.rows[1].style.display='none';editDiv.rows[2].style.display='none';}
selType.onchange=function(){m_this.gallery.type=this.value;m_this.closeMarquee();if(m_this.gallery.type=='slideshow'){editDiv.rows[1].style.display='';editDiv.rows[2].style.display='none';editDiv.rows[3].style.display='none';m_this.initSlideShow();}else if(m_this.gallery.type=='thumbnail'){editDiv.rows[1].style.display='none';editDiv.rows[2].style.display='';editDiv.rows[3].style.display='none';m_this.initThumbnail();}else{editDiv.rows[1].style.display='none';editDiv.rows[2].style.display='none';editDiv.rows[3].style.display='';m_this.initLoopShow();}}
selSpeed.onchange=function(){m_this.gallery.speed=this.value*1000;}
selWidth.onchange=function(){m_this.gallery.width=this.value;if(m_this.gallery.type=='thumbnail'){m_this.initThumbnail();}}
selHeight.onchange=function(){m_this.gallery.height=this.value;if(m_this.gallery.type=='thumbnail'){m_this.initThumbnail();}}
txtLHeight.onblur=function(){if(m_this.gallery.lheight!=this.value){m_this.gallery.lheight=this.value;if(m_this.gallery.type=='photoloop'){m_this.closeMarquee();m_this.initLoopShow();}}}
selLSpeed.onchange=function(){m_this.gallery.lspeed=this.value;if(m_this.gallery.type=='photoloop'){m_this.closeMarquee();m_this.startMarquee();}}
btnUpdate.onclick=function(){onSave(m_this.gallery);}};}
SWODE.ImagePreloader={};SWODE.ImageLoader=Class.create();SWODE.ImageLoader.prototype={initialize:function(options){this.options=Object.extend({src:'',min:3,max:30},options||{});this.minTimeout=this.options.min*1000;this.maxTimeout=this.options.max*1000;this.theTimeout=0;this.loadStatus=0;var self=this;this.element=new Image();this.element.src=this.options.src;this.element.border=0;this.element.onload=function(){self.loadStatus=1;if(self.onLoad)self.onLoad();}
this.element.onerror=function(){self.loadStatus=-1;if(self.onError)self.onError();}
this.startMonitor();},startMonitor:function(){var self=this;setTimeout(function(){self.checkMonitor();},this.minTimeout);},checkMonitor:function(){if(this.loadStatus!=0)return;var self=this;this.theTimeout=this.minTimeout;this._monitor=setInterval(function(){self.theTimeout+=50;if(self.loadStatus!=0){clearInterval(self._monitor);}else if(self.element.complete){clearInterval(self._monitor);self.loadStatus=1;if(self.onLoad)self.onLoad();}else if(self.theTimeout>=self.maxTimeout){clearInterval(self._monitor);self.loadStatus=-1;if(self.onError)self.onError();}},50);}}