/**
 * RTv2 Scripts
 * 
 * @version		1.4
 * 
 * @author		Djamil Legato <djamil [at] djamil.it>
 * @copyright	Author
 */

var isIE8=function(){return(Browser.Engine.trident&&navigator.userAgent.test(/MSIE 8\.0/))};
window.addEvent('domready',function(){
	$$('.external').setProperty('target','_blank');
	var f=['h1.componentheading'];
	RokBuildSpans(f);
	var g=$$('#page #details-toolbar div.button a'),panes=$$('#page .details-pane'),detailsContent=$('details-content');
	var h=[],heightsClub=[],detailsFx;
	if(detailsContent&&g.length&&panes.length&&g.length==panes.length){
		detailsContent.setStyle('position','relative');
		var k=window.location.href;k=k.split('#');
		if(k.length==2)k=k[1]; else k=false; 
		var l=0,firing=null;
		g.setStyle('outline','none').each(function(a,i){
			heightsClub.push(panes[i].getCoordinates().height);
			panes[i].setStyles({'position':'absolute','top':0,'left':0,'z-index':100});
			if(a.get('href').contains('#'+k)||(!k&&!i)){firing=a;a.addClass('active');l=i}else l=false;
			h.push(new Fx.Tween(panes[i],'opacity',{wait:false}).set('opacity',(i==l)?1:0))});
		detailsFx=new Fx.Tween(detailsContent,'height',{wait:false}).set('opacity',heightsClub[l]);
		var m=g;
		g.each(function(b,i){
						b.addEvent('click',function(){
													m.removeClass('active');
													b.addClass('active');
													h.each(function(a,j){if(i==j){a.start('opacity',1);detailsFx.start('height',heightsClub[j])}else a.start('opacity',0)})})});
		if(firing)firing.fireEvent('click')};
		var n=$$('div.entitlements .entitlements-number');
		if(n.length){
			var o=new Tips(n,{className:'rt-entitlements',offsets:{x:-10,y:-140}})};
			var p=$$('#form-login .subscriptions a span.Expires');
			var q=$$('#form-login .subscriptions a span.Expired');
			if(p)p=p.getParent();
			if(q)q=q.getParent();
			var r=new Tips(p,{className:'substips-expires',offsets:{x:-10,y:20}});
			var s=new Tips(q,{className:'substips-expired',offsets:{x:-10,y:20}});
			var t=$('fader-container'),fxs=[],heights=[];
			if(t){var u=window.location.href;u=u.split('#');
			if(u.length==2)u=u[1];else u=false;
			var v=t.getChildren(),menufader=$$('.club-nav');
			if(!menufader||!menufader.length)menufader=$$('.menu-sidemenu');
			if(menufader)menufader=menufader[0];
			var w=0;
			if(v.length&&menufader){
				var x=menufader;menufader=menufader.getElements('a');
				var y=x.getElements('li');
				y.each(function(a,i){if(a.hasClass('active'))w=i});
				menufader.setStyle('outline','none');
				var z=0;
				firing=null;
				var A=new Fx.Tween(t,'height');
				A.addEvent('onComplete',function(){
	window.fireEvent('scroll')});
				v.each(function(b,i){
								heights.push(b.getCoordinates().height);
								if(i==w)b.setStyle('opacity',1);else b.setStyles('opacity',0);
								b.setStyles({'position':'absolute','width':'100%'});
								fxs.push(new Fx.Tween(b,'opacity',{wait:false}).set('opacity',(i==w)?1:0));
								menufader[i].addEvent('click',function(e){if(e)new Event(e).stop();
									fxs.each(function(a,j){
										if(i==j)a.start('opacity',1);else a.start('opacity',0)});
									A.start('height',b.getCoordinates().height);
									y.removeClass('active');
									y[i].addClass('active')});
								if(menufader[i].getProperty('href').contains('#'+u))firing=menufader[i]});
				y[w].addClass('active');
				A.set('height',v[w].getCoordinates().height);
				t.setStyles({'height':v[w].getCoordinates().height,'position':'relative'});
				
				
		window.addEvent('load',function(){if(firing)(function(){firing.fireEvent('click')}).delay(100)})}}g=$$('.fp-club-toolbar')[0];
				allpanes=$$('.fp-content')[0];
				var pan=$$('.fp-content');
				
				var B=function(b){b.each(function(a,i){a.removeClass('fp-option-'+(i+1)+'-active')})};
				var C=function(b,c){b.each(function(a,i){if(i!=c)a.start('opacity',0); else a.start('opacity',1)})};
				if(g&&allpanes){var D=g.getChildren();
				panes=allpanes.getChildren();
				pan.setStyle('height',panes[0].getCoordinates().height);
				if(D.length!=panes.length)throw new Error("Tabs and Panes don't match in numbers.");
				else{B(D);
				fxs=[];
				panes.each(function(a,i){
						heights.push(a.getCoordinates().height);
						fxs.push(new Fx.Tween(a,{'link':'cancel','duration':400}).set('opacity',(!i)?1:0));
						if(!i)D[i].addClass('fp-option-'+(i+1)+'-active');
						
						D[i].addEvent('click',function(e){pan.setStyle('height',a.getCoordinates().height); e.stop(); C(fxs,i); B(D); D[i].addClass('fp-option-'+(i+1)+'-active')})})}}
				
				var E=new Featured('featured-showcase');				
				var F=$('demo-tab');
				if(F){F=F.getElement('.demotab-1');
				var G=$('demo-tab-drop');
				if(G){G.store('top',G.getStyle('top').toInt());
				G.store('open',false);
				G.store('demofx',new Fx.Morph(G,{duration:200,link:'cancel',onComplete:function(){if(G.retrieve('open',false))G.store('open',false);else G.store('open',true)}}).set({'opacity':0,'top':G.retrieve('top')+10}));
				F.addEvents({'mouseenter':function(e){e.stop();G.retrieve('demofx').start({'opacity':1,'top':G.retrieve('top')})},'mouseleave':function(e){e.stop();G.retrieve('demofx').start({'opacity':0,'top':G.retrieve('top')+10})}})}};
				var H=$('sidebar'),mainbody=$('mainbody'),wrapper=$('mainbody-surround');
				var I=$('fader-container');
				if(H&&wrapper&&!Browser.Platform.ipod&&(!Browser.Engine.trident4||(Browser.Engine.trident5&&isIE8()))){(function(){var c=H.getCoordinates(),wCoords=mainbody.getCoordinates();
																																															
																																															window.addEvent('scroll',function(){if(I&&Browser.Engine.webkit)return;wCoords=mainbody.getSize();																																																																							var a=window.getScroll().y,sizey=H.getSize().y;var b={'ref':(a+sizey),'bar':(mainbody.getCoordinates().top+wCoords.y)};																																																																							if(sizey<wCoords.y){if(a+12>c.top&&b.ref<b.bar)H.removeClass('top').removeClass('bottom').addClass('float');else if(b.ref>=b.bar)H.removeClass('float').removeClass('top').addClass('bottom');else H.removeClass('float').removeClass('bottom').addClass('top');																																																																							H.setStyle('margin-top',0);if(Browser.Engine.webkit)H.inject(mainbody,'after')}else{H.removeClass('float').removeClass('bottom').removeClass('top').setStyle('margin-top',mainbody.getStyle('margin-top'))}});
																																															window.fireEvent('scroll')}).delay(1)}var J=$('astroboy');
					if(J){J.setStyle('z-index',60000);
					J.addEvent('click',function(e){e.stop();K()});
					var K=function(){J.removeEvents();
					var b=window.getSize().x;
					var c=new Fx.Morph(J,{duration:600,transition:'linear'}).set({'right':20,'top':40});
					var d=b/6;
					var e={'n':65,'p':15};
					c.start({'right':20+(d*1),'top':e.n}).chain(function(){this.start({'right':20+(d*2),'top':e.p})}).chain(function(){this.start({'right':20+(d*3),'top':e.n})}).chain(function(){this.start({'right':20+(d*4),'top':e.p})}).chain(function(){this.start({'right':20+(d*5),'top':e.n})}).chain(function(){this.start({'right':20+(d*6),'top':e.n})}).chain(function(){var a=this;this.set({'right':20,'top':-600});(function(){a.options.duration=3000;a.options.transition='elastic:out';a.start({'top':40}).chain(function(){J.addEvent('click',K)})}).delay(3000)})}}});
var Featured=new Class({Implements:[Options],options:{'duration':900,'delay':5000,'autoplay':true,'transition':Fx.Transitions.Cubic.easeOut},initialize:function(b,c){this.container=$(b);
																																													   if(!this.container)return;																																													   this.setOptions(c);																																													   this.list=this.container.getElements('.showcase-module .module')[0].getChildren();																																													   this.controls=this.list[this.list.length-1];																																													   this.list=this.list.slice(0,this.list.length-1);																																													   this.controls.getElement('div').setStyle('position','relative').getChildren().setStyles({'position':'relative','z-index':100});																																													   this.scrollDiv=new Element('div',{'class':'scroller-div-left'}).inject(this.controls.getElement('div'));this.scrollDiv2=new Element('div',{'class':'scroller-div-right'}).inject(this.scrollDiv);var d=this.position(this.controls.getElement('span'));this.scroll=new Fx.Tween(this.scrollDiv,'left',{wait:false}).set('left',d.left);this.scroll2=new Fx.Tween(this.scrollDiv2,'width',{wait:false}).set('width',d.width);this.panes=this.list;this.fxs=[];this.active=0;this.panes.each(function(a,i){if(!i)a.setStyles({'opacity':1,'visibility':'visible'});else a.setStyles({'opacity':0,'visibility':'hidden'});this.fxs[i]=new Fx.Tween(a,'opacity',{'wait':false,'duration':this.options.duration,'transition':this.options.transition})},this);this.doControls();this.doArrows();if(this.options.autoplay){this.controls.getParent().getParent().addEvents({'mouseenter':function(){this.pause()}.bind(this),'mouseleave':function(){this.start()}.bind(this)});var e=this;
																																													   window.addEvent('load',e.start.bind(e))}},doControls:function(){this.controlsLinks=this.controls.getElements('.options a');this.controlsLinks.each(function(c,i){c.addEvent('click',function(e){new Event(e).stop();this.fxs.each(function(a,j){if(j==i){this.controlsLinks.removeClass('active');active=j;this.active=j;c.addClass('active');var b=this.position(c.getParent());this.scroll.start('left',b.left);this.scroll2.start('width',b.width);a.start('opacity',1)}else a.start('opacity',0)},this)}.bind(this))},this)},start:function(){$clear(this.timer);this.timer=this.next.periodical(this.options.delay,this)},pause:function(){return $clear(this.timer)},doArrows:function(){this.arrows=this.controls.getChildren('a').splice(0,2);this.arrows.each(function(a){if(a.getProperty('class').test('left')){a.addEvent('click',this.previous.bindWithEvent(this))}if(a.getProperty('class').test('right')){a.addEvent('click',this.next.bindWithEvent(this))}},this)},previous:function(e){if(e)new Event(e).stop();if((this.active-1)<0)this.active=this.controlsLinks.length-1;else this.active--;this.fade()},next:function(e){if(e)new Event(e).stop();if((this.active+1)>this.controlsLinks.length-1)this.active=0;else this.active++;this.fade()},fade:function(){this.fxs.each(function(a,j){if(j==this.active){this.controlsLinks.removeClass('active');active=j;var b=this.position(this.controlsLinks[j].getParent());this.scroll.start('left',b.left);this.scroll2.start('width',b.width);this.controlsLinks[j].addClass('active');a.start('opacity',1)}else a.start('opacity',0)},this)},position:function(a){var b=(Browser.Engine.trident4)?61:3;return{'left':a.getPosition().x-this.controls.getPosition().x-b,'width':a.getSize().x}}});var RokBuildSpans=function(e){(e.length).times(function(i){var d=e[i];$$(d).each(function(a){a.setStyle('visibility','visible');var b=a.get('text').trim(),temp=b.split(" ");first=temp[0];rest=temp.slice(1).join(" ");html=a.innerHTML;var c=a.clone().set('text',first+' '),span=new Element('span').set('text',rest);span.inject(c,'bottom');c.replaces(a)})})};
	window.addEvent('domready',function(){$$('.external').setProperty('target','_blank')});