/*MooTools, My Object Oriented Javascript Tools. Copyright (c) 2006-2007 Valerio Proietti, <http://mad4milk.net>, MIT Style License.||Clientcide Copyright (c) 2006-2008, http://www.clientcide.com/wiki/cnet-libraries#license*/

Fx.Elements=new Class({Extends:Fx.CSS,initialize:function(elements,options){this.elements=this.subject=$$(elements);this.parent(options)},compute:function(from,to,delta){var now={};for(var i in from){var iFrom=from[i],iTo=to[i],iNow=now[i]={};for(var p in iFrom)iNow[p]=this.parent(iFrom[p],iTo[p],delta)}return now},set:function(now){for(var i in now){var iNow=now[i];for(var p in iNow)this.render(this.elements[i],p,iNow[p],this.options.unit)}return this},start:function(obj){if(!this.check(arguments.callee,obj))return this;var from={},to={};for(var i in obj){var iProps=obj[i],iFrom=from[i]={},iTo=to[i]={};for(var p in iProps){var parsed=this.prepare(this.elements[i],p,iProps[p]);iFrom[p]=parsed.from;iTo[p]=parsed.to}}return this.parent(from,to)}});var dbug={logged:[],timers:{},firebug:false,enabled:false,log:function(){dbug.logged.push(arguments)},nolog:function(msg){dbug.logged.push(arguments)},time:function(name){dbug.timers[name]=new Date().getTime()},timeEnd:function(name){if(dbug.timers[name]){var end=new Date().getTime()-dbug.timers[name];dbug.timers[name]=false;dbug.log('%s: %s',name,end)}else dbug.log('no such timer: %s',name)},enable:function(silent){if(dbug.firebug){try{dbug.enabled=true;dbug.log=function(){(console.debug||console.log).apply(console,arguments)};dbug.time=function(){console.time.apply(console,arguments)};dbug.timeEnd=function(){console.timeEnd.apply(console,arguments)};if(!silent)dbug.log('enabling dbug');for(var i=0;i<dbug.logged.length;i++){dbug.log.apply(console,dbug.logged[i])}dbug.logged=[]}catch(e){dbug.enable.delay(400)}}},disable:function(){if(dbug.firebug)dbug.enabled=false;dbug.log=dbug.nolog;dbug.time=function(){};dbug.timeEnd=function(){}},cookie:function(set){var value=document.cookie.match('(?:^|;)\\s*jsdebug=([^;]*)');var debugCookie=value?unescape(value[1]):false;if((!$defined(set)&&debugCookie!='true')||($defined(set)&&set)){dbug.enable();dbug.log('setting debugging cookie');var date=new Date();date.setTime(date.getTime()+(24*60*60*1000));document.cookie='jsdebug=true;expires='+date.toGMTString()+';path=/;'}else dbug.disableCookie()},disableCookie:function(){dbug.log('disabling debugging cookie');document.cookie='jsdebug=false;path=/;'}};(function(){var fb=typeof console!="undefined";var debugMethods=['debug','info','warn','error','assert','dir','dirxml'];var otherMethods=['trace','group','groupEnd','profile','profileEnd','count'];function set(methodList,defaultFunction){for(var i=0;i<methodList.length;i++){dbug[methodList[i]]=(fb&&console[methodList[i]])?console[methodList[i]]:defaultFunction}};set(debugMethods,dbug.log);set(otherMethods,function(){})})();if(typeof console!="undefined"&&console.warn){dbug.firebug=true;var value=document.cookie.match('(?:^|;)\\s*jsdebug=([^;]*)');var debugCookie=value?unescape(value[1]):false;if(window.location.href.indexOf("jsdebug=true")>0||debugCookie=='true')dbug.enable();if(debugCookie=='true')dbug.log('debugging cookie enabled');if(window.location.href.indexOf("jsdebugCookie=true")>0){dbug.cookie();if(!dbug.enabled)dbug.enable()}if(window.location.href.indexOf("jsdebugCookie=false")>0)dbug.disableCookie()}var IframeShim=new Class({Implements:[Options,Events],options:{name:'',className:'iframeShim',display:false,zindex:null,margin:0,offset:{x:0,y:0},browsers:(Browser.Engine.trident4||(Browser.Engine.gecko&&!Browser.Engine.gecko19&&Browser.Platform.mac))},initialize:function(element,options){this.setOptions(options);if(this.options.offset&&this.options.offset.top)this.options.offset.y=this.options.offset.top;if(this.options.offset&&this.options.offset.left)this.options.offset.x=this.options.offset.left;this.element=$(element);this.makeShim();return},makeShim:function(){this.shim=new Element('iframe');this.id=this.options.name||new Date().getTime()+"_shim";if(this.element.getStyle('z-Index').toInt()<1||isNaN(this.element.getStyle('z-Index').toInt()))this.element.setStyle('z-Index',5);var z=this.element.getStyle('z-Index')-1;if($chk(this.options.zindex)&&this.element.getStyle('z-Index').toInt()>this.options.zindex)z=this.options.zindex;this.shim.setStyles({'position':'absolute','zIndex':z,'border':'none','filter':'progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)'}).setProperties({'src':'javascript:void(0);','frameborder':'0','scrolling':'no','id':this.id}).addClass(this.options.className);this.element.store('shim',this);var inject=function(){this.shim.inject(this.element,'after');if(this.options.display)this.show();else this.hide();this.fireEvent('onInject')};if(this.options.browsers){if(Browser.Engine.trident&&!IframeShim.ready){window.addEvent('load',inject.bind(this))}else{inject.run(null,this)}}},position:function(shim){if(!this.options.browsers||!IframeShim.ready)return this;var before=this.element.getStyles('display','visibility','position');this.element.setStyles({display:'block',position:'absolute',visibility:'hidden'});var size=this.element.getSize();this.element.setStyles(before);if($type(this.options.margin)){size.x=size.x-(this.options.margin*2);size.y=size.y-(this.options.margin*2);this.options.offset.x+=this.options.margin;this.options.offset.y+=this.options.margin}this.shim.setStyles({'width':size.x,'height':size.y}).setPosition({relativeTo:this.element,offset:this.options.offset});return this},hide:function(){if(this.options.browsers)this.shim.setStyle('display','none');return this},show:function(){if(!this.options.browsers)return this;this.shim.setStyle('display','block');return this.position()},dispose:function(){if(this.options.browsers)this.shim.dispose();return this}});window.addEvent('load',function(){IframeShim.ready=true});Element.implement({expose:function(){if(this.getStyle('display')!='none')return $empty;var before={};var styles={visibility:'hidden',display:'block',position:'absolute'};$each(styles,function(value,style){before[style]=this.style[style]||''},this);this.setStyles(styles);return(function(){this.setStyles(before)}).bind(this)},getDimensions:function(options){options=$merge({computeSize:false},options);var dim={};function getSize(el,options){return(options.computeSize)?el.getComputedSize(options):el.getSize()};if(this.getStyle('display')=='none'){var restore=this.expose();dim=getSize(this,options);restore()}else{try{dim=getSize(this,options)}catch(e){}}return $chk(dim.x)?$extend(dim,{width:dim.x,height:dim.y}):$extend(dim,{x:dim.width,y:dim.height})},getComputedSize:function(options){options=$merge({styles:['padding','border'],plains:{height:['top','bottom'],width:['left','right']},mode:'both'},options);var size={width:0,height:0};switch(options.mode){case'vertical':delete size.width;delete options.plains.width;break;case'horizontal':delete size.height;delete options.plains.height;break};var getStyles=[];$each(options.plains,function(plain,key){plain.each(function(edge){options.styles.each(function(style){getStyles.push((style=="border")?style+'-'+edge+'-'+'width':style+'-'+edge)})})});var styles=this.getStyles.apply(this,getStyles);var subtracted=[];$each(options.plains,function(plain,key){size['total'+key.capitalize()]=0;size['computed'+key.capitalize()]=0;plain.each(function(edge){size['computed'+edge.capitalize()]=0;getStyles.each(function(style,i){if(style.test(edge)){styles[style]=styles[style].toInt();if(isNaN(styles[style]))styles[style]=0;size['total'+key.capitalize()]=size['total'+key.capitalize()]+styles[style];size['computed'+edge.capitalize()]=size['computed'+edge.capitalize()]+styles[style]}if(style.test(edge)&&key!=style&&(style.test('border')||style.test('padding'))&&!subtracted.contains(style)){subtracted.push(style);size['computed'+key.capitalize()]=size['computed'+key.capitalize()]-styles[style]}})})});if($chk(size.width)){size.width=size.width+this.offsetWidth+size.computedWidth;size.totalWidth=size.width+size.totalWidth;delete size.computedWidth}if($chk(size.height)){size.height=size.height+this.offsetHeight+size.computedHeight;size.totalHeight=size.height+size.totalHeight;delete size.computedHeight}return $extend(styles,size)}});Element.implement({setPosition:function(options){$each(options||{},function(v,k){if(!$defined(v))delete options[k]});options=$merge({relativeTo:document.body,position:{x:'center',y:'center'},edge:false,offset:{x:0,y:0},returnPos:false,relFixedPosition:false,ignoreMargins:false},options);var parentOffset={x:0,y:0};var parentPositioned=false;var putItBack=this.expose();var offsetParent=$(this.getOffsetParent());putItBack();if(offsetParent&&offsetParent!=this.getDocument().body){var putItBack=offsetParent.expose();parentOffset=offsetParent.getPosition();putItBack();parentPositioned=true;options.offset.x=options.offset.x-parentOffset.x;options.offset.y=options.offset.y-parentOffset.y}function fixValue(option){if($type(option)!="string")return option;option=option.toLowerCase();var val={};if(option.test('left'))val.x='left';else if(option.test('right'))val.x='right';else val.x='center';if(option.test('upper')||option.test('top'))val.y='top';else if(option.test('bottom'))val.y='bottom';else val.y='center';return val};options.edge=fixValue(options.edge);options.position=fixValue(options.position);if(!options.edge){if(options.position.x=='center'&&options.position.y=='center')options.edge={x:'center',y:'center'};else options.edge={x:'left',y:'top'}}this.setStyle('position','absolute');var rel=$(options.relativeTo)||document.body;var top=(rel==document.body)?window.getScroll().y:rel.getPosition().y;var left=(rel==document.body)?window.getScroll().x:rel.getPosition().x;if(top<0)top=0;if(left<0)left=0;var dim=this.getDimensions({computeSize:true,styles:['padding','border','margin']});if(options.ignoreMargins){options.offset.x=options.offset.x-dim['margin-left'];options.offset.y=options.offset.y-dim['margin-top']}var pos={};var prefY=options.offset.y.toInt();var prefX=options.offset.x.toInt();switch(options.position.x){case'left':pos.x=left+prefX;break;case'right':pos.x=left+prefX+rel.offsetWidth;break;default:pos.x=left+(((rel==document.body)?window.getSize().x:rel.offsetWidth)/2)+prefX;break};switch(options.position.y){case'top':pos.y=top+prefY;break;case'bottom':pos.y=top+prefY+rel.offsetHeight;break;default:pos.y=top+(((rel==document.body)?window.getSize().y:rel.offsetHeight)/2)+prefY;break};if(options.edge){var edgeOffset={};switch(options.edge.x){case'left':edgeOffset.x=0;break;case'right':edgeOffset.x=-dim.x-dim.computedRight-dim.computedLeft;break;default:edgeOffset.x=-(dim.x/2);break};switch(options.edge.y){case'top':edgeOffset.y=0;break;case'bottom':edgeOffset.y=-dim.y-dim.computedTop-dim.computedBottom;break;default:edgeOffset.y=-(dim.y/2);break};pos.x=pos.x+edgeOffset.x;pos.y=pos.y+edgeOffset.y}pos={left:((pos.x>=0||parentPositioned)?pos.x:0).toInt(),top:((pos.y>=0||parentPositioned)?pos.y:0).toInt()};if(rel.getStyle('position')=="fixed"||options.relFixedPosition){pos.top=pos.top.toInt()+window.getScroll().y;pos.left=pos.left.toInt()+window.getScroll().x}if(options.returnPos)return pos;else this.setStyles(pos);return this}});Element.implement({isVisible:function(){return this.getStyle('display')!='none'},toggle:function(){return this[this.isVisible()?'hide':'show']()},hide:function(){var d;try{if('none'!=this.getStyle('display'))d=this.getStyle('display')}catch(e){}this.store('originalDisplay',d||'block');this.setStyle('display','none');return this},show:function(display){original=this.retrieve('originalDisplay')?this.retrieve('originalDisplay'):this.get('originalDisplay');this.setStyle('display',(display||original||'block'));return this},swapClass:function(remove,add){return this.removeClass(remove).addClass(add)},fxOpacityOk:function(){return!Browser.Engine.trident4}});var Waiter=new Class({Implements:[Options,Events,Chain],options:{baseHref:'http://www.cnet.com/html/rb/assets/global/waiter/',containerProps:{styles:{position:'absolute','text-align':'center'},'class':'waiterContainer'},containerPosition:{},msg:false,msgProps:{styles:{'text-align':'center',fontWeight:'bold'},'class':'waiterMsg'},img:{src:'waiter.gif',styles:{width:24,height:24},'class':'waiterImg'},layer:{styles:{width:0,height:0,position:'absolute',zIndex:999,display:'none',opacity:0.9,background:'#fff'},'class':'waitingDiv'},useIframeShim:true,fxOptions:{}},initialize:function(target,options){this.target=$(target)||$(document.body);this.setOptions(options);this.waiterContainer=new Element('div',this.options.containerProps).inject(document.body);if(this.options.msg){this.msgContainer=new Element('div',this.options.msgProps);this.waiterContainer.adopt(this.msgContainer);if(!$(this.options.msg))this.msg=new Element('p').appendText(this.options.msg);else this.msg=$(this.options.msg);this.msgContainer.adopt(this.msg)}if(this.options.img)this.waiterImg=$(this.options.img.id)||new Element('img').injectInside(this.waiterContainer);this.waiterOverlay=$(this.options.layer.id)||new Element('div').injectInside(document.body).adopt(this.waiterContainer);this.waiterOverlay.set(this.options.layer);try{if(this.options.useIframeShim)this.shim=new IframeShim(this.waiterOverlay,this.options.iframeShimOptions)}catch(e){dbug.log("Waiter attempting to use IframeShim but failed; did you include IframeShim? Error: ",e);this.options.useIframeShim=false}this.waiterFx=this.waiterFx||new Fx.Elements($$(this.waiterContainer,this.waiterOverlay),this.options.fxOptions)},toggle:function(element,show){element=$(element)||$(this.active)||$(this.target);if(!$(element))return this;if(this.active&&element!=this.active)return this.stop(this.start.bind(this,element));if((!this.active||show)&&show!==false)this.start(element);else if(this.active&&!show)this.stop();return this},reset:function(){this.waiterFx.cancel().set({0:{opacity:[0]},1:{opacity:[0]}})},start:function(element){this.reset();element=$(element)||$(this.target);if(this.options.img){this.waiterImg.set($merge(this.options.img,{src:this.options.baseHref+this.options.img.src}))}var start=function(){var dim=element.getComputedSize();this.active=element;this.waiterOverlay.setStyles({width:this.options.layer.width||dim.totalWidth,height:this.options.layer.height||dim.totalHeight,display:'block'}).setPosition({relativeTo:element,position:'upperLeft'});this.waiterContainer.setPosition({relativeTo:this.waiterOverlay});if(this.options.useIframeShim)this.shim.show();this.waiterFx.start({0:{opacity:[1]},1:{opacity:[this.options.layer.styles.opacity]}}).chain(function(){if(this.active==element)this.fireEvent('onShow',element);this.callChain()}.bind(this))}.bind(this);if(this.active&&this.active!=element)this.stop(start);else start();return this},stop:function(callback){if(!this.active){if($type(callback)=="function")callback.attempt();return this}this.waiterFx.cancel();this.waiterFx.clearChain();this.waiterFx.start({0:{opacity:[0]},1:{opacity:[0]}}).chain(function(){this.active=null;this.waiterOverlay.hide();if(this.options.useIframeShim)this.shim.hide();this.fireEvent('onHide',this.active);this.callChain();this.clearChain();if($type(callback)=="function")callback.attempt()}.bind(this));return this}});if(typeof Request!="undefined"&&Request.HTML){Request.HTML=new Class({Extends:Request.HTML,options:{useWaiter:false,waiterOptions:{},waiterTarget:false},initialize:function(options){this._send=this.send;this.send=function(options){if(this.waiter)this.waiter.start().chain(this._send.bind(this,options));else this._send(options);return this};this.parent(options);if(this.options.useWaiter&&($(this.options.update)||$(this.options.waiterTarget))){this.waiter=new Waiter(this.options.waiterTarget||this.options.update,this.options.waiterOptions);['onComplete','onException','onCancel'].each(function(event){this.addEvent(event,this.waiter.stop.bind(this.waiter))},this)}}})}var OverText=new Class({Implements:[Options,Events],options:{positionOptions:{position:"upperLeft",edge:"upperLeft",offset:{x:4,y:2}},poll:false,pollInterval:250},overTxtEls:[],initialize:function(inputs,options){this.setOptions(options);$$(inputs).each(this.addElement,this);OverText.instances.push(this);if(this.options.poll)this.poll()},addElement:function(el){if(this.overTxtEls.contains(el)||el.retrieve('overtext'))return;var val=this.options.textOverride||el.get('alt')||el.get('title');if(!val)return;this.overTxtEls.push(el);var txt=new Element('div',{'class':'overTxtDiv',styles:{lineHeight:'normal'},html:val,events:{click:this.hideTxt.pass([el,true],this)}}).inject(el,'after');el.addEvents({focus:this.hideTxt.pass([el,true],this),blur:this.testOverTxt.pass(el,this),change:this.testOverTxt.pass(el,this)}).store('overtext',txt);window.addEvent('resize',this.repositionAll.bind(this));this.testOverTxt(el);this.repositionOverTxt(el)},startPolling:function(){this.pollingPaused=false;return this.poll()},poll:function(stop){if(this.poller&&!stop)return this;var test=function(){if(this.pollingPaused==true)return;this.overTxtEls.each(function(el){if(el.retrieve('ot_paused'))return;this.testOverTxt(el)},this)}.bind(this);if(stop)$clear(this.poller);else this.poller=test.periodical(this.options.pollInterval,this);return this},stopPolling:function(){this.pollingPaused=true;return this.poll(true)},hideTxt:function(el,focus){var txt=el.retrieve('overtext');if(txt&&txt.isVisible()&&!el.get('disabled')){txt.hide();try{if(focus)el.fireEvent('focus').focus()}catch(e){}this.fireEvent('onTextHide',[txt,el]);el.store('ot_paused',true)}return this},showTxt:function(el){var txt=el.retrieve('overtext');if(txt&&!txt.isVisible()){txt.show();this.fireEvent('onTextShow',[txt,el]);el.store('ot_paused',false)}return this},testOverTxt:function(el){if(el.get('value'))this.hideTxt(el);else this.showTxt(el)},repositionAll:function(){this.overTxtEls.each(this.repositionOverTxt.bind(this));return this},repositionOverTxt:function(el){if(!el)return;try{var txt=el.retrieve('overtext');if(!txt||!el.getParent())return;this.testOverTxt(el);txt.setPosition($merge(this.options.positionOptions,{relativeTo:el}));if(el.offsetHeight)this.testOverTxt(el);else this.hideTxt(el)}catch(e){dbug.log('overTxt error: ',e)}return this}});OverText.instances=[];OverText.update=function(){return OverText.instances.map(function(ot){return ot.repositionAll()})};