var OverOpacity = Class.create({
	initialize : function(menu_element) {
		this.menu_element = $(menu_element); //make sure you have an extended element
		this.state = 0; // the state of the menu
		this.mouseover_callback =  this.mouseOver.bindAsEventListener(this); //callbacks
		this.mouseout_callback = this.mouseOut.bindAsEventListener(this);
		this.menu_element.observe('mouseover', this.mouseover_callback);
		this.menu_element.observe('mouseout', this.mouseout_callback);
		this.queue = Effect.Queues.get(this.menu_element.identify() + '-scope'); //create a queue with a unique name
	},
	mouseOver : function() {
		this.queue.each(function(ev) { ev.cancel(); });
		opacity = $(this.menu_element).getOpacity();
		new Effect.Opacity(this.menu_element, {duration: 0.4,from:opacity, to:0,
			queue : {scope : this.menu_element.identify() + '-scope',  
			limit : 1},
			afterFinish : function() { // using an effect callback to  make sure state is changes _after_ the last frame was renderd
				this.state = 1;
			}.bind(this)
		});
	},
	mouseOut : function() {
		this.queue.each(function(ev) { ev.cancel(); });
		opacity = $(this.menu_element).getOpacity();
		new Effect.Opacity(this.menu_element, {duration: 0.4,from:opacity, to:1,
			queue : {scope :  this.menu_element.identify() + '-scope',  
			limit : 1},
			afterFinish : function() {
				this.state = 0;
			}.bind(this)
		});
	}
});
function changeIndexPage(numToShow,setTime){
	if(stop == false){
		stop = true;
		clearTimeout(timeOutVar);
		selPosition = new Array("0","318","590");
		left = -(numToShow-1)*950;
		leftSel = selPosition[(numToShow-1)];
		new Effect.Move("indexFrameInner", { y: 0, x:left, mode: 'absolute',duration:.7,queue : {scope :  "menuOver-scope", limit : 1},afterFinish:function(){
			$$(".indexTabSel").each(function(element){element.removeClassName("indexTabSel")});
			if(setTime=="true")
				timeOutVar = setTimeout("startSlideShow()",timeOutDuration,"JavaScript");
			stop = false;
		}});
		new Effect.Move("tabSelContainer", { y: 0, x:leftSel, mode: 'absolute',duration:0.7});
	}
}
function startSlideShow(){
	switch(currentSlideNum){
		case 3:
			currentSlideNum = 2;
			currentSlideType = "backward";
			break;
		case 2:
			if(currentSlideType=="forward"){
				currentSlideNum = 3;
				currentSlideType = "forward";
			}
			else{
				currentSlideNum = 1;
				currentSlideType = "backward";
			}
			break;
		case 1:
			currentSlideNum = 2;
			currentSlideType = "forward";
			break;
	}
	changeIndexPage(currentSlideNum,"true");
}
function onYouTubePlayerReady(playerId) {
	ytplayer = $(playerId);
	ytplayer.playVideo();
	ytplayer.pauseVideo();
}
function changeLearMore(action){
	if(action  == "close"){
		$("appLearnMore").style.display = "none";
		$("appBg").style.display = "block";
	}
	else{
		$("appBg").style.display = "none";
		if(typeof(ytplayer) != 'undefined')
			ytplayer.pauseVideo();
		$("appVideo").style.visibility = "hidden";
		$("appLearnMore").style.display = "block";
	}
}
function changeVideo(action){
	if(action  == "close"){
		if(typeof(ytplayer) != 'undefined')
			ytplayer.pauseVideo();
		$("appVideo").style.visibility = "hidden";
		$("appBg").style.display = "block";
	}
	else{
		appTitle = $("appTextContainer").select(".appTitle")[0].innerHTML;
		pageTracker._trackEvent('App_Video', 'Play', appTitle);
		$("appBg").style.display = "none";
		$("appLearnMore").style.display = "none";
		if(typeof(ytplayer) != 'undefined')
			ytplayer.playVideo();
		$("appVideo").style.visibility = "visible";
	}
}
function sendDownloadForm(evt){
	Event.stop(evt);
	formData = $('downloadFormData').serialize();
	new Ajax.Request($('downloadFormData').action, {
		method: 'post',
		postBody: formData,
		onComplete: function(resp) {
			txt = resp.responseText;
			switch(txt){
				case "Error Email":
					$('formError').innerHTML = "Please enter a valid email address";
				break;
				case "Fine":
					$('formError').innerHTML = "";
					$('emailhere').innerHTML = $("downloadEmail").value;
					$("downloadWayEmail").style.display = "none";
					$("downloadWayEmailConfirm").style.display = "block";
					$("downloadFormData").reset();
				break;
			}
		}
	});
}
function returnEmail(){
	$("downloadFormData").reset();
	$("downloadWayEmailConfirm").style.display = "none";
	$("downloadWayEmail").style.display = "block";
	$('emailhere').innerHTML = "";
}
function changeLegal(type){
	$$(".legalText").invoke("hide");
	$$(".legalTitle").invoke("hide");
	$$(".legalBtnSel").each(function(ele){ele.removeClassName("legalBtnSel")});
	$(type+"Title").style.display = "block";
	$(type+"Content").style.display = "block";
	$(type+"Btn").addClassName("legalBtnSel");
	pageTracker._trackEvent('Legal', 'change', type);
}
function initGetBtn(){
	$$("div.hasover").each(
		function(element){
			new OverOpacity(element);
		}
	);
}
function createFlashPlayer(file,placeHolder,width,height){
	var params = {"allowfullscreen": "true","allowScriptAccess": "always","wmode": "transparent"};
	swfobject.embedSWF(file+".swf",placeHolder, width, height, "8", null, null, params, null);
}
function initIndex(){
	currentSlideNum = 1;
	currentSlideType = "forward";
	timeOutDuration = 30000
	timeOutVar = setTimeout("startSlideShow()",timeOutDuration,"JavaScript");
	stop = false;
	createFlashPlayer("anim","step1flash","140","187");
}