document.observe("dom:loaded",function(){	
	if($$('.scroll_to_top').length > 0){
		var scrollToTop = $$('.scroll_to_top')
		for (var i=0; i< scrollToTop.length ; i++) {
			scrollToTop[i].observe('click', function(event){
				event.stop();
				new Effect.ScrollTo('master_container', { duration: 0.5, queue: 'end' });
			}).onclick = function(){ return false }
		};
	}
		
	// XHTML 1.0 Strict work around for external links
	$$('a[rel*="external"]').each(function(e){
		e.writeAttribute("target","_blank");
	});

	// Automatic text clear
	$$('input.clearField').each(function(e){
		e.observe('focus',function(){
			this.value = "";
		}).observe('blur',function(){
			if(this.value == "") {
				this.value = this.defaultValue;
			}
		});
	});

	// Image roll-over setup
	$$('img.rollOver, input[type="image"].rollOver').each(function(e){
		e.observe('mouseover',function(){
			if (this.src.indexOf("_i.") != -1) {
				this.src = this.src.replace("_i.", "_o.");
			}
		}).observe('mouseout',function(){
			if (this.src.indexOf("_o.") != -1) {
				this.src = this.src.replace("_o.", "_i.");
			}
			if(this.src.indexOf("_a.")) {
				this.src = this.src.replace("_a.","_i.");
			}
		})
		if(e.match("input")) {
			e.observe('mousedown',function(){
				this.src = this.src.replace("_o.","_a.");
			}).observe('mouseup',function(){
				this.src = this.src.replace("_a.","_i.");
			});
		}
	});

	if($('btn_features_next')){
		$('btn_features_next').observe('click',function(e){
			if(!$('features').hasClassName('animating')){
				$('features').addClassName('animating');
				featureNext();
			}
		});
	}
	if($('btn_features_next')){
		$('btn_features_previous').observe('click',function(e){
			if (!$('features').hasClassName('animating')) {
				$('features').addClassName('animating');
				featurePrev();
			}
		});
	}
	if($('feature_nav')){
		$$('#feature_nav li a').each(function(e){
			e.observe('click',function(){
				var navIndex = ($(this).up().id.split('_')[1])-1;
				moveFeatures((0-(navIndex*($('feature_wrapper').getDimensions().width))));
			});
		});
	}
	if($('demo_whatischamp')){
		$('vid_play').writeAttribute("href","javascript:void(null);");
		videoHTML = $('vid_holder').innerHTML;
		$('vid_play').observe('click', function(){
			//$('demo_whatischamp').update(videoHTML);
			$('demo_whatischamp').insert({bottom : videoHTML});
			$('vid_play').slideUp({duration: 2.0});
		});
	}




/* Homepage Slider */
$$('#slidedeck_and_promo #slidedeck #tab li').each(function(e,i){
	
	var arrowOffsetTop = parseInt($('arrow').getStyle('top').gsub('px',''));
	var myDuration = 0.25;
	
	e.observe('mouseover', function(event){ e.addClassName('hover'); });
	e.observe('mouseout', function(event){ e.removeClassName('hover'); });
	
	e.observe('click',function(event){
		new Effect.Morph('slides', { 
			style: 'top:' + (-342 * i) + "px",
			duration: myDuration,
			queue: {
				position: 'end',
				scope: 'slider'
			}
		});
		$$('#slidedeck_and_promo #slidedeck #tab li').each(function(li){
			li.removeClassName('active');
		});
		e.addClassName('active');
		new Effect.Morph('arrow', {
			style: "top: " + (arrowOffsetTop + (48 * i)) + "px",
			duration: myDuration,
			queue: {
				position: 'end',
				scope: 'arrow'
			}
		});
	});
});

});
function featureNext(){
	leftPos = $('features').positionedOffset().left;
	if(leftPos > -4300){
		newLeftPos = leftPos - 860;
		moveFeatures(newLeftPos);
	} else {
		newLeftPost = 0;
		moveFeatures(0);
	}
}
function featurePrev(){
	leftPos = $('features').positionedOffset().left;
	if(leftPos < 0){
		newLeftPos = leftPos + 860;
		moveFeatures(newLeftPos);
	} else {
		newLeftPost = 0;
		moveFeatures(-4300);
	}
}
function moveFeatures(leftVal){
	var navIndex = ((0-leftVal)/($('feature_wrapper').getDimensions().width))+1;
	$$('#feature_nav li').each(function(e){
		if(e.id == "nav_"+navIndex){
			e.select('a')[0].addClassName('active');
		}else{
			e.select('a')[0].removeClassName('active');
		}
		$('feature_nav').className = 'active_'+navIndex;
	});
	new Effect.Morph('features',{style:{left: leftVal+'px'},duration: 0.5,transition: Effect.Transitions.sinoidal, afterFinish: function(){
		$('features').removeClassName('animating');
	}});
}

function featureScroll(featureID){
	new Effect.ScrollTo(featureID, { duration: 1.0 });
}