window.addEvent('domready', function() {
	var contentScroller, links, initial, initialHeight, search, innerHeight, getMinHeight, toggles;
	
	// Returns 680px, or height+20 if height is larger than 680
	getMinHeight = function(height) {
		height = height.toInt();
		
		return ((height < 860) ? 860 : height + 20);
	};
	
	if ($('faq_sec')){
		var accordion = new Fx.Accordion($$('.toggler'),$$('.element'), {
				opacity: 0,
				onActive: function(toggler, element) { 
					toggler.setStyle('color', '#333');
					element.setStyle('width', '399px');
				},
				onBackground: function(toggler) { 
					toggler.setStyle('color', '#000');
				},
				alwaysHide: true
		});
	}
	
	// Set up the scroller for the content area
	if ($('scroller')) {
		
		contentScroller = new Fx.Scroll2('scroller', {
	        wait: false,
	        duration: 2000,
	        transition: Fx.Transitions.Linear,
	        overflow: 'hidden',
	        wheelStops: false,
	        
	        // Dynamically modifies the size of the scroll area based on height
	        // of the content being scrolled to
	        onStart: function () {
	    		$('scroller').setStyle('height', innerHeight + 'px');
	    		$('right-content').setStyle('height', innerHeight + 'px');    	
	    	} 

	
	    });
		
		
	    links = $('left-content').getElements('.scroll_link');
	    
	    links.each(function(el){
	    	var divID, path, current, myHeight;
	        divID = el.get('id') + '_sec';
	                
	        path = el.get('href').split('#')[0];
	        current = window.location.pathname.substr(1);
	
	        el.addEvent('click', function(event) {
	        	if (path !== current){
	        		return true;
	        	}
	        	
	        	event = new Event(event).stop();
	        	innerHeight = getMinHeight($(divID).getStyle('height'));
	            contentScroller.toElement(divID);
	            var scrolllinks = $$('.scroll_link');
	            scrolllinks.each(function(elm){
	                elm.removeClass('selected');
	            });
	            this.addClass('selected');
	        });
	    });
	    
	    initial = window.location.hash.substr(1).split('_');
	    initial = initial[0];
	    
	    initial = $(initial + '_sec') || $('scroller').getChildren()[0];
	    
	    innerHeight = getMinHeight(initial.getStyle('height'));
	        
	    if (initial){
	    	contentScroller.toElement(initial); 
	    }
	    
	}
	
    
			
	getInitial = function(toggles) {
		search = window.location.pathname.substr(1).split('.')[0];;
		search = search + '_toggle';
			
		return toggles.get('id').indexOf(search) || 0;
	};
	
	toggles = $$('#left-content dt');		
	// Set up accordion behavior for left nav
	leftNavSetup = function() {
		var accordion;
		
		accordion = new Fx.Accordion(toggles, $$('#left-content dd'), {
			alwaysHide : true,
			initialDisplayFx : false,
			display : getInitial(toggles),
			onActive: function (toggler, el) {
				toggler.setStyles({
					'background': "#000000 url('../images/arrow.png') 3px -40px no-repeat",
					'border-bottom': '0 none',
					'margin-bottom': '0'
				});
			},
			onBackground: function (toggler) {
				toggler.setStyles({
					'background': "url('../images/arrow.png') top left no-repeat",
					'margin-bottom': '1px',
					'border-bottom': '1px solid black'
				});
			}
		});
	}();
	
	if ($('carousel')){
		var texts = $$('#image-rotate p');
		
		function hideTexts(){
			texts.setStyles({
				'visibility': 'hidden',
				'opacity': 0
			});
		}
		
		hideTexts();
		
		new SimpleCarousel($('carousel'), $$('#carousel img'), $$('#carousel_buttons a'), {
			slideInterval: 8000,
			rotateAction: 'click',
			onShowSlide: function (index) {
				hideTexts();
				texts[index].setStyles({
					'visibility': 'visible',
					'opacity': 1
				});
			}
		});
	}
	
	//new Fx.Scroll(window).set(0,0);
}); 

window.addEvent('domready', function() {
	var myFx = new Fx.Scroll(window);
	myFx.toTop();
	// var t=setTimeout(window.scrollTo(0, 0),1000);
    // clearTimeout();
}); 
