var selected;

(function(){

	window.addEvent('domready', function(){


		
		$$("html, body").setStyle("height", "100%");
		$$("body, html").setStyle("overflow-y", "hidden");

	}).addEvent('load', function(){

		$("loading").set("tween", { duration: 1000, transition: Fx.Transitions.Quint.easeInOut, unit: "%", onComplete: function(){
			$$("html, body").setStyle("height", "");
			$$("body, html").setStyle("overflow-y", "");
		}}).tween.delay(100, $("loading"), ["top", -100]);


		if(Browser.ie)
			return;

		scrollSpyElements = $$('').fade('hide');
	});

	
	

	function scrollSpy(){

		var windowScroll;
		var windowScrollY = win.getScroll().y;
		var windowSizeY = win.getSize().y;

		if(!scrollSpyElements.length)
			window.removeEvent('scroll', scrollSpy);

		var elements = new Array();

		Array.clone(scrollSpyElements).each(function(item, index) {

			windowScroll = windowScrollY + windowSizeY - (item.scrollSpyOffset ? item.scrollSpyOffset : 300);

			if(windowScroll >= item.getPosition().y) {

				elements.push(item);
				scrollSpyElements = scrollSpyElements.erase(item);
			}
		});

		elements.each(function(item, index){

			if(typeof item.scrollSpyShow == "function")
				item.scrollSpyShow.delay(index * 200, item);
			else
				(function(){ item.morph({ 'opacity': 1 }); }).delay(index * 300);
		});
	};

	function configureCustomScrollSpyCallBack() {

		$$("hr").scrollSpyOffset = 100;
		$$("hr").each(function(item){
		
			item.scrollSpyShow = function() {

				this.setStyle('width', 0);
				this.setStyle('opacity', 1);
				new Fx.Tween(this, { duration: 1000, transition: Fx.Transitions.Back.easeInOut }).start('width', 950);
			};
		});
	}

})();


