var $E = window.$E || function(selector, filter){
  return ($(filter) || document).getElement(selector);
};
var exampleFx = null;
var fxTarget = null;
var mySlider = null;
var scroller = new Fx.Scroll(window);

/*	menu code for test page	*/
var mootorial = {
	setUpScrollAnchors: function(){
		$$('ul#toc li a.toc').each(function(lnk) {
			if(lnk.href.test("#")) {
				lnk.addEvent('click', function(){
					this.scrollTo(lnk.href.split('#')[1]);
				}.bind(this));
			}
		}, this);
	},
	scrollTo: function(element){
		if(this.scrollingTo != element) {
			this.scrollTries = 0;
			this.scrollingTo = element;
		} else this.scrollTries++;
		$clear(this.scrollTimer);
		if($(element)) scroller.toElement($(element));
		else
			if(this.scrollTries < 15) this.scrollTimer = this.scrollTo.pass(element, this).delay(100);
	},
	fixMenu: function(){
		$('navigation').getChildren('ul.idx').each(function(ul){
			var levels = ul.getChildren('li.level1');
			var opens = ul.getChildren('li.open');
			var open_paths = opens.map(function(li){
				var lnk = li.getElement('div.li a.idx_dir');
				if (lnk) return lnk.get('href').replace(/\/$/,'');
			}).clean();
			var level_paths = levels.map(function(li){
				var lnk = li.getElement('div.li a.wikilink1');
				if (lnk) return lnk.get('href')
			}).clean();
			dbug.log(open_paths, level_paths);
			open_paths.each(function(op, i){
				if(level_paths.indexOf(op) >=0) {
					
				}
			});
		});
	}
};

/*	test page initiliaziation	*/
			window.addEvent('domready', function(){
					initPage.delay(300);
					try {
						dbug.enable();
						dbug.log('mootools is loaded and ready');
					}catch(e) {}
			});

			
			
/*	set's up code blocks; run after user loads new content from menu	*/
			var isInited = false;
			function initPage(){
					if(isInited) return;
					isInited = true;
					mootorial.fixMenu();
					/*	var fxTargetClone = fxTarget.clone().setProperty('id', 'fxTarget').injectInside($('rightCol'));
					fxTargetClone.setProperty('id', 'fxTargetClone');	*/
					$$('textarea.execCode').each(function(code){
						var run = code.getNext()
						run.onclick = function(){
							var source = code.innerHTML.replace("&amp;", "&", "g");
							source = source.replace("&lt;", "<", "g");
							source = source.replace("&gt;", ">", "g");
							source = source.replace("&quot;", "\"", "g");
							source = source.replace(/\/\*(.|[\r\n])*?\*\//g,'');
							dbug.log(source);
							var delayVal = 0;
							var result = null;
							if(source.test('fxTarget')) delayVal = grabFXTarget(run.getPrevious().getPrevious()); 
							try {
								if(!source.test("makeDraggable"))
									$('fxTarget').makeDraggable();
							} catch(e){}
							(function(){
								result = eval(source);
								if(typeof result != "undefined") dbug.log(result);
								else dbug.log('nothing returned');
							}).delay(delayVal);
						};
					});
					var imgExecs = $$('img.executeCode');
					if(imgExecs.length>0) {
						imgExecs.each(function(img){
							img.store("tip:title", img.get('title').split("::")[0]);
							img.store("tip:text", img.get('title').split("::")[1]);
						});
						new Tips(imgExecs, {showDelay: 750});
					}
					
					$$('form.button input').each(function(btn){
						btn.addEvent('mouseover', function(){
							this.tween('opacity', [.3, 1]);
						}).addEvent('mouseout', function(){
							this.tween('opacity', [1, .3]);
						});
					});
					$('main').getElements('h2, h3').each(function(h2){
						new Element('a').appendText('top').addClass('toTop'+h2.get('tag').toUpperCase()).setProperty('href','#top').injectBefore(h2);
					});
					new SmoothScroll();
			};
			
