$(document).ready(function() {	
		var demo_state = GetParam('demo');
		if(demo_state == 'done'){
			demo('done');
		}
	});
var menu_state = "menu_go";
function pause_slider(){
	//alert("PAUSE!");
	user_menu=window.clearInterval(user_menu);
}

function validateForm()
		{
			var x=document.forms["form_sf1"]["email"].value;
			var atpos=x.indexOf("@");
			var dotpos=x.lastIndexOf(".");
			if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length)
			  {
			  document.getElementById('required_email').innerHTML = '<font color="red">Email:&nbsp;</font>';
			  document.getElementById('required').innerHTML = '<font color="red">*Please enter a valid email address</font>';
			  document.getElementById('email').focus();
			  return false;
			  }
		}

function validateForm2()
		{
			var x=document.forms["form_sf2"]["email"].value;
			var atpos=x.indexOf("@");
			var dotpos=x.lastIndexOf(".");
			if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length)
			  {
			  document.getElementById('required_email2').innerHTML = '<font color="red">Email:&nbsp;</font>';
			  document.getElementById('required2').innerHTML = '<font color="red">*Please enter a valid email address</font>';
			  document.getElementById('email').focus();
			  return false;
			  }
		}
		
function validateForm3()
		{
			var x=document.forms["form_sf3"]["email"].value;
			var atpos=x.indexOf("@");
			var dotpos=x.lastIndexOf(".");
			if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length)
			  {
			  document.getElementById('required_email3').innerHTML = '<font color="red">Email:&nbsp;</font>';
			  document.getElementById('required3').innerHTML = '<font color="red">*Please enter a valid email address</font>';
			  document.getElementById('email').focus();
			  return false;
			  }
		}
			
function start_slider(){
	//alert("START!");
	if(menu_state == "menu_go"){
		user_menu = window.setInterval('arrow("loop")',10000);
	}
}

function customer_link(){
	var randomnumber=Math.floor(Math.random()*11);
	if(randomnumber <4){
		switch_image('cust_3','images/customers/2.png');
		switch_image('cust_2','images/customers/3.png');
		switch_image('cust_1','images/customers/1.png');
	}
	else if(randomnumber <7){
		switch_image('cust_2','images/customers/2.png');
		switch_image('cust_1','images/customers/3.png');
		switch_image('cust_3','images/customers/1.png');
	}
	
	else if(randomnumber <10){
		switch_image('cust_1','images/customers/2.png');
		switch_image('cust_2','images/customers/3.png');
		switch_image('cust_3','images/customers/1.png');
	}

}



function GetParam(name)
{
	var start=location.search.indexOf("?"+name+"=");
	if (start<0) start=location.search.indexOf("&"+name+"=");
	if (start<0) return '';
	start += name.length+2;
	var end=location.search.indexOf("&",start)-1;
	if (end<0) end=location.search.length;
	var result=location.search.substring(start,end);
	var result='';
	for(var i=start;i<=end;i++) {
	var c=location.search.charAt(i);
	result=result+(c=='+'?' ':c);
	}
	return unescape(result);
}

var user_menu;
var gal1;
var gal2;
var gal3;
var gal4;

function menu_true(){
	user_menu=window.clearInterval(user_menu);
	menu_state = "No GO";
}

function clear_gal1(){
	gal1=window.clearInterval(gal1);
}

function clear_gal2(){
	gal2=window.clearInterval(gal2);
}

function clear_gal3(){
	gal3=window.clearInterval(gal3);
}

function clear_gal4(){
	gal4=window.clearInterval(gal4);
}

function slideShow() {
	//Set the opacity of all images to 0
	$('#gallery a').css({opacity: 0.0});
	
	//Get the first image and display it (set it to full opacity)
	$('#gallery a:first').css({opacity: 1.0});

	
	
	
	//Call the gallery function to run the slideshow, 6000 = change to next image after 6 seconds
	customer_link();
	homey('click');
	user_menu = window.setInterval('arrow("loop")',10000);
}



function gallery() {
	
	//if no IMGs have the show class, grab the first image
	var current = ($('#gallery a.show')?  $('#gallery a.show') : $('#gallery a:first'));

	//Get next image, if it reached the end of the slideshow, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().hasClass('caption'))? $('#gallery a:first') :current.next()) : $('#gallery a:first'));	
	
	//Get next image caption
	var caption = next.find('img').attr('rel');	
	
	//Set the fade in effect for the next image, show class has higher z-index
	next.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 1200);
	

	//Hide the current image
	current.animate({opacity: 0.0}, 1200)
	.removeClass('show');
	
	//Set the opacity to 0 and height to 1px
	$('#gallery .caption').animate({opacity: 0.0}, { queue:false, duration:0 }).animate({height: '1px'}, { queue:true, duration:300 });	
	
	//Animate the caption, opacity to 0.7 and heigth to 100px, a slide up effect
	$('#gallery .caption').animate({opacity: 0.7},100 ).animate({height: '100px'},500 );
	
	//Display the content
	$('#gallery .content').html(caption);
	
	
}

function gallery2() {
	
	//if no IMGs have the show class, grab the first image
	var current = ($('#gallery2 a.show')?  $('#gallery2 a.show') : $('#gallery2 a:first'));

	//Get next image, if it reached the end of the slideshow, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().hasClass('caption'))? $('#gallery2 a:first') :current.next()) : $('#gallery2 a:first'));	
	
	//Get next image caption
	var caption = next.find('img').attr('rel');	
	
	//Set the fade in effect for the next image, show class has higher z-index
	next.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 1200);
	

	//Hide the current image
	current.animate({opacity: 0.0}, 1200)
	.removeClass('show');
	
	//Set the opacity to 0 and height to 1px
	$('#gallery2 .caption').animate({opacity: 0.0}, { queue:false, duration:0 }).animate({height: '1px'}, { queue:true, duration:300 });	
	
	//Animate the caption, opacity to 0.7 and heigth to 100px, a slide up effect
	$('#gallery2 .caption').animate({opacity: 0.7},100 ).animate({height: '100px'},500 );
	
	//Display the content
	$('#gallery2 .content').html(caption);
	
	
}

function gallery3() {
	
	//if no IMGs have the show class, grab the first image
	var current = ($('#gallery3 a.show')?  $('#gallery3 a.show') : $('#gallery3 a:first'));

	//Get next image, if it reached the end of the slideshow, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().hasClass('caption'))? $('#gallery3 a:first') :current.next()) : $('#gallery3 a:first'));	
	
	//Get next image caption
	var caption = next.find('img').attr('rel');	
	
	//Set the fade in effect for the next image, show class has higher z-index
	next.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 1200);
	

	//Hide the current image
	current.animate({opacity: 0.0}, 1200)
	.removeClass('show');
	
	//Set the opacity to 0 and height to 1px
	$('#gallery3 .caption').animate({opacity: 0.0}, { queue:false, duration:0 }).animate({height: '1px'}, { queue:true, duration:300 });	
	
	//Animate the caption, opacity to 0.7 and heigth to 100px, a slide up effect
	$('#gallery3 .caption').animate({opacity: 0.7},100 ).animate({height: '100px'},500 );
	
	//Display the content
	$('#gallery3 .content').html(caption);
	
	
}

function gallery4() {
	
	//if no IMGs have the show class, grab the first image
	var current = ($('#gallery4 a.show')?  $('#gallery4 a.show') : $('#gallery4 a:first'));

	//Get next image, if it reached the end of the slideshow, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().hasClass('caption'))? $('#gallery4 a:first') :current.next()) : $('#gallery4 a:first'));	
	
	//Get next image caption
	var caption = next.find('img').attr('rel');	
	
	//Set the fade in effect for the next image, show class has higher z-index
	next.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 1200);
	

	//Hide the current image
	current.animate({opacity: 0.0}, 1200)
	.removeClass('show');
	
	//Set the opacity to 0 and height to 1px
	$('#gallery4 .caption').animate({opacity: 0.0}, { queue:false, duration:0 }).animate({height: '1px'}, { queue:true, duration:300 });	
	
	//Animate the caption, opacity to 0.7 and heigth to 100px, a slide up effect
	$('#gallery4 .caption').animate({opacity: 0.7},100 ).animate({height: '100px'},500 );
	
	//Display the content
	$('#gallery4 .content').html(caption);
	
	
}

function load_ss(page){
	switch(page){
		
		case "fh":
				fh1 = new Image();
				fh2 = new Image();
				fh3 = new Image();
				fh4 = new Image();
				fh5 = new Image();
				fh6 = new Image();
				fh7 = new Image();
				fh8 = new Image();
				adv3 = new Image();
				adv5 = new Image();

			    fh1.src = "../images/screen_shots/fh_admin1.jpg";
			    fh2.src = "../images/screen_shots/fh_config1.jpg";
			    fh3.src = "../images/screen_shots/fh_editcheck1.jpg";
			    fh4.src = "../images/screen_shots/fh_partial1.jpg";
			    fh5.src = "../images/screen_shots/fh_skip1.jpg";
			    fh6.src = "../images/screen_shots/fh_variables1.jpg";
			    fh7.src = "../images/screen_shots/fh_query1.jpg";
			    fh8.src = "../images/screen_shots/fh_deploy1.jpg";
			    adv3.src = "../images/screen_shots/adv_eclinical3.jpg";
			    adv5.src = "../images/screen_shots/adv_eclinical5.jpg";
			break;
			
		case "adv":
				adv1 = new Image();
				adv2 = new Image();
				adv3 = new Image();
				adv4 = new Image();
				adv5 = new Image();
				
			    adv1.src = "../images/screen_shots/adv_eclinical1.jpg";
			    adv2.src = "../images/screen_shots/adv_eclinical2.jpg";
			    adv3.src = "../images/screen_shots/adv_eclinical3.jpg";
			    adv4.src = "../images/screen_shots/adv_eclinical4.jpg";
			    adv5.src = "../images/screen_shots/adv_eclinical5.jpg";
			break;
			
		case "gen":
				gen1 = new Image();
				gen2 = new Image();
				gen3 = new Image();
							
			    gen1.src = "../images/screen_shots/gen_saas1.jpg";
			    gen2.src = "../images/screen_shots/gen_saas2.jpg";
			    gen3.src = "../images/screen_shots/gen_saas3.jpg";
				break;
	}
	
		   
	
}

if (document.images) {
		   img1 = new Image();
		   img2 = new Image();
		   img3 = new Image();
		   img4 = new Image();
		   img5 = new Image();
		   img6 = new Image();
		   img7 = new Image();
		   
		   img1.src = "../images/nav/about_over.jpg";
		   img2.src = "../images/nav/contact_over.jpg";
		   img3.src = "../images/nav/login_over.jpg";
		   img4.src = "../images/nav/customers_over.jpg";
		   img5.src = "../images/nav/software_over.jpg";
		   img6.src = "../images/nav/t_top_over.jpg";
		   img7.src = "../images/side_over.png";

		   

		   
		}

			function switch_image(old_image, new_image) {
				document[old_image].src = new_image;
			}
			
			function fade_image(image, direction) {
				switch(image){
						case "house":
								if(direction == "in"){
									//alert('watch in');
									$("#homey")
									.animate({opacity: 1.0}, 1000);
								}
								else if(direction =="over"){
									$("#homey")
									.animate({opacity: 1.0}, 150);
								}
								else if(direction =="over_out"){
									$("#homey")
									.animate({opacity: 0.4}, 150);
								}
								else{
									//alert('watch out');
									$("#homey")
									.animate({opacity: 0.4}, 1000);
								}
								break;
						case "watch":
								if(direction == "in"){
									//alert('watch in');
									$("#fast")
									.animate({opacity: 1.0}, 1000);
								}
								else if(direction =="over"){
									$("#fast")
									.animate({opacity: 1.0}, 150);
								}
								else if(direction =="over_out"){
									$("#fast")
									.animate({opacity: 0.4}, 150);
								}
								else{
									//alert('watch out');
									$("#fast")
									.animate({opacity: 0.4}, 1000);
								}
								break;
						case "change":
								if(direction == "in"){
									//alert('watch in');
									$("#low")
									.animate({opacity: 1.0}, 1000);
								}
								else if(direction =="over"){
									$("#low")
									.animate({opacity: 1.0}, 150);
								}
								else if(direction =="over_out"){
									$("#low")
									.animate({opacity: 0.4}, 150);
								}
								else{
									//alert('watch out');
									$("#low")
									.animate({opacity: 0.4}, 1000);
								}
								break;
						case "wheel":
								if(direction == "in"){
									$("#control")
									.animate({opacity: 1.0}, 1000);
								}
								else if(direction =="over"){
									$("#control")
									.animate({opacity: 1.0}, 150);
								}
								else if(direction =="over_out"){
									$("#control")
									.animate({opacity: 0.4}, 150);
								}
								else{
									$("#control")
									.animate({opacity: 0.4}, 1000);
								}
								break;
				}
			}
				
			var which = "homey";
			
			
			function arrow(way){
				switch(which){
						case "homey":
								if(way != "left"){
									fast("click");
								}
								else{
								}
								break;
						case "fast":
								if(way != "left"){
									low("click");
								}
								else{
									homey("click");
								}
								break;
						case "low":
								if(way != "left"){
									control("click");
								}
								else{
									fast("click");
								}
								break;
						case "control":
								if(way != "left"){
									if(way == "loop"){
										homey("click");
									}
								}
								else{
									low("click");
								}
								break;
				}
			}
										
			function control(what){
				switch(what){
					case "click":
							$("#img_control").fadeIn(1200);
							//$("#gallery").css({opacity: 0.0});
							//$("#gallery3").css({opacity: 0.0});
							//$("#gallery2").css({opacity: 0.0});
							$("#gallery2").fadeOut(0);
							$("#gallery3").fadeOut(0);
							$("#gallery").fadeOut(0);
							clear_gal1();
							clear_gal2();
							clear_gal3();
							$("#gallery4").fadeIn(0);
							$("#gallery4").css({opacity: 1.0});
							$('#gallery4 a').css({opacity: 0.0});
							$('#gallery4 a:first').animate({opacity: 1.0}, 1200);
							gal4 = setInterval('gallery4()',10000);							
							control_clear();
							fade_image('wheel','in');
							switch(which){
								case "homey":
										which = "control";
										homey("out");
										break;
								case "low":
										which = "control";
										low("out");
										break;
								case "fast":
										which = "control";
										fast("out");
										break;
							}
							break;
							
					case "over":
							fade_image('wheel','over');
							break;
							
					case "over_out":
							if(which != "control"){
								fade_image('wheel','over_out');
							}
							break;
							
					case "out":
							if(which != "control"){
								fade_image('wheel','out');
							}
							break;
				}

			}
			
				
			function control_clear(){
				$("#img_low").fadeOut(1200);
				$("#img_fast").fadeOut(1200);
				$("#img_home").fadeOut(1200);
      		}
			
			function homey(what){
				switch(what){
					case "click":
							$("#img_home").fadeIn(1200);
							$("#gallery2").fadeOut(0);
							$("#gallery3").fadeOut(0);
							$("#gallery4").fadeOut(0);
							clear_gal2();
							clear_gal3();
							clear_gal4();
							$("#gallery").fadeIn(0);
							//$("#gallery3").css({opacity: 0.0});
							//$("#gallery2").css({opacity: 0.0});
							//$("#gallery4").css({opacity: 0.0});
							$("#gallery").css({opacity: 1.0});
							//$('#gallery a').css({opacity: 0.0});
							$('#gallery a:first').animate({opacity: 1.0}, 1200)
							gal1 = setInterval('gallery()',10000);
							homey_clear();
							fade_image('house','in');
							switch(which){
								case "fast":
										which = "homey";
										fast("out");
										break;
								case "low":
										which = "homey";
										low("out");
										break;
								case "control":
										which = "homey";
										control("out");
										break;
							}
							break;
							
					case "over":
							fade_image('house','over');
							break;
							
					case "over_out":
							if(which != "homey"){
								fade_image('house','over_out');
							}
							break;
							
					case "out":
							if(which != "homey"){
								fade_image('house','out');
							}
							break;
				}

			}
				
			function homey_clear(){
				$("#img_low").fadeOut(1200);
				$("#img_fast").fadeOut(1200);
				$("#img_control").fadeOut(1200);
      		}
			
			function fast(what){
				switch(what){
					case "click":
							$("#img_fast").fadeIn(1200);
							//$("#gallery").css({opacity: 0.0});
							//$("#gallery3").css({opacity: 0.0});
							//$("#gallery4").css({opacity: 0.0});
							$("#gallery").fadeOut(0);
							$("#gallery3").fadeOut(0);
							$("#gallery4").fadeOut(0);
							clear_gal1();
							clear_gal3();
							clear_gal4();
							$("#gallery2").fadeIn(0);
							$("#gallery2").css({opacity: 1.0});
							$('#gallery2 a').css({opacity: 0.0});
							$('#gallery2 a:first').animate({opacity: 1.0}, 1200);
							gal2 = setInterval('gallery2()',10000);

							fast_clear();
							fade_image('watch','in');
							switch(which){
								case "homey":
										which = "fast";
										homey("out");
										break;
								case "low":
										which = "fast";
										low("out");
										break;
								case "control":
										which = "fast";
										control("out");
										break;
							}
							break;
							
					case "over":
							fade_image('watch','over');
							break;
							
					case "over_out":
							if(which != "fast"){
								fade_image('watch','over_out');
							}
							break;
							
					case "out":
							if(which != "fast"){
								fade_image('watch','out');
							}
							break;
				}

			}
				
			function fast_clear(){
				$("#img_home").fadeOut(1200);
				$("#img_low").fadeOut(1200);
				$("#img_control").fadeOut(1200);
      		}
				
			function low(what){
				switch(what){
					case "click":
							$("#img_low").fadeIn(1200);
							//$("#gallery").css({opacity: 0.0});
							//$("#gallery2").css({opacity: 0.0});
							//$("#gallery4").css({opacity: 0.0});
							$("#gallery2").fadeOut(0);
							$("#gallery").fadeOut(0);
							$("#gallery4").fadeOut(0);
							clear_gal1();
							clear_gal4();
							clear_gal2();
							$("#gallery3").fadeIn(0);
							$("#gallery3").css({opacity: 1.0});
							$('#gallery3 a').css({opacity: 0.0});
							$('#gallery3 a:first').animate({opacity: 1.0}, 1200);
							gal3 = setInterval('gallery3()',10000);							
							low_clear();
							fade_image('change','in');
							switch(which){
								case "homey":
										which = "low";
										homey("out");
										break;
								case "fast":
										which = "low";
										fast("out");
										break;
								case "control":
										which = "low";
										control("out");
										break;
							}
							break;
							
					case "over":
							fade_image('change','over');
							break;
							
					case "over_out":
							if(which != "low"){
								fade_image('change','over_out');
							}
							break;
							
					case "out":
							if(which != "low"){
								fade_image('change','out');
							}
							break;
				}

			}
			
			function low_clear(){
				$("#img_home").fadeOut(1200);
				$("#img_fast").fadeOut(1200);
				$("#img_control").fadeOut(1200);
      		}
			
			function hide_demo(){
				document.getElementById('required_email').innerHTML = "Email:&nbsp;";
			  	document.getElementById('required').innerHTML = "&nbsp;";
				
				$("#sign_back").fadeOut("fast");
				$("#outer_form").fadeOut("fast");
				$("#outer_form_comp").fadeOut("fast");
				$("#outer_form_sales").fadeOut("fast");
				$("#outer_form_support").fadeOut("fast");
				$("#outer_form_ss1").fadeOut("fast");
				clear_ss();
				
				
			}
			function demo(what){
				switch(what){
					case "click":
							$("#sign_back").fadeIn("fast");
							$("#outer_form").fadeIn("fast");
							break;
							
					case "done":
							$("#sign_back").fadeIn("fast");
							$("#outer_form_comp").fadeIn("fast");
							break;
							
					case "sales":
							$("#sign_back").fadeIn("fast");
							$("#outer_form_sales").fadeIn("fast");
							break;
							
					case "support":
							$("#sign_back").fadeIn("fast");
							$("#outer_form_support").fadeIn("fast");
							break;
												
					case "screenshot":
							$("#sign_back").fadeIn("fast");
							$("#outer_form_ss1").fadeIn("fast");
							break;
																		
					case "over":
							switch_image('demo_pic','http://medrio.com/images/side_over.png');
							break;
							
					case "out":
							switch_image('demo_pic','http://medrio.com/images/side_reg.png');
							break;
				}

			}
			
			function demo_sub(what){
				switch(what){
					case "click":
							$("#sign_back").fadeIn("fast");
							$("#outer_form").fadeIn("fast");
							break;
							
					case "over":
							switch_image('demo_pic','../images/side_over.png');
							break;
							
					case "out":
							switch_image('demo_pic','../images/side_reg.png');
							break;
				}

			}
			
			
			function escapes(event){
				var keyCode = ('which' in event) ? event.which : event.keyCode;
				if(keyCode == 27){
					hide_demo();
				}
			}
			
			
			function s_shot(ss_caption, pic_source) {
				document.getElementById('screenshot_pic').src = pic_source;		
				document.getElementById('screenshot_caption').innerHTML = ss_caption;		
				demo('screenshot');
			}
			
			function clear_ss() {
				document.getElementById('screenshot_pic').src = "";		
				document.getElementById('screenshot_caption').innerHTML = "";		
			}
			
