 $(document).ready(function() {
 
		$("#nav a").attr("target","_top")



  $("#nav li a").hover(function() {
  	$(this).stop().animate({ opacity:0})
  },
  
  function() {
  $(this).stop().animate({ opacity:1})
  }
  
  	
  );
  
//survey js

  $("#survey form > div:odd").addClass("striped");
	
	$(":radio").click(function(){
		$(this).parent().parent().children('.navControl').children('.alert').fadeOut("fast")
		var answer = $(this).attr('value')
		if(answer == "Yes") {
			
			
			$(this).parent().next(".hiddenQuestion").slideDown('fast')
		} else {
		
		$(this).parent().next(".hiddenQuestion").slideUp('fast')
		}
	});	
	
	// next actions
	
   $("#survey p a.next").click(function(){
    
    
    var checkedBox = 
    $(this).parent().parent().children(":first").children(":checked").length
    
  	
    if(checkedBox > 0){
    	
    	
    	var answer = $(this).parent().parent().children(":first").children(":checked").attr('value')
    	
    	
    	if(answer == "Yes" && 	$(this).parent().parent().children(".hiddenQuestion").length == 1){
    		
    		var hq = $(this).parent().parent().children(".hiddenQuestion").find(":input")
    		
    		switch($(hq).attr("type"))
				{
					case "text":
						var inputVal = $(hq).val()
						if(!isNaN(inputVal) && inputVal.length > 0){ $("#survey").animate({"top": "-=150px"}, "slow");}
						else {
							$(hq).siblings(".alert").remove()
							$(hq).parent().append(" <strong class='alert'> Please input a number.</strong>")
						}
  						//console.log("text input")
						  break;    
					case "select-one":
						var inputVal = $(hq).val()

 						if(inputVal.length > 0){
 							$("#survey").animate({"top": "-=150px"}, "slow");}
						else {
							$(hq).siblings(".alert").remove()
							$(hq).parent().append(" <strong class='alert'> Please select a reading.</strong>")
						}
 						 break;
					case "checkbox":					
 						 
 						 var checkem = $(this).parent().parent().children(".hiddenQuestion").find(":checked");
 						 
 						 if(checkem.length > 0){
 							$("#survey").animate({"top": "-=150px"}, "slow");
 						
 							}
						else {
							//$(this).parent().siblings(".alert").remove()
							//$(this).parent().prev().append(" <strong class='alert'> Please check a box</strong>")
							//console.log($(this).parent().parent().children(":last").attr('class'))
							
							$(this).parent().parent().children(".hiddenQuestion").children(":first").children("strong").remove();
							$(this).parent().parent().children(".hiddenQuestion").children(":first").append(" <strong class='alert'> Please check a box.</strong>")
							
						}
						  break;
					default:
  						//console.log("error")
					}
				    			
    		
    		
    		
    	} else {
    		if($(this).parent().parent().parent().attr("id") == "question1" && answer == "No" ){
    			$("#survey").animate({"top": "-=1350px"}, "slow");
    		} else 	{
    		$("#survey").animate({"top": "-=150px"}, "slow");
    		}
    	}
    
    $(this).siblings(".alert").remove()
    } else {
    	requiredError(this)
    	//console.log($(this).attr('href'))
    }
	
	
	
	
      return false;
    });
    
 
 
 $("#survey p a.back").click(function(){
     $("#survey").animate({"top": "+=150px"}, "slow");
	
      return false;
    });

 //submit check
  $("form").submit(function() {
  //console.log("yes")
  	var name = $("#demographics input:eq(0)").val()
  	var phone = $("#demographics input:eq(1)").val()
  	var email = $("#demographics input:eq(2)").val()
  	var error = 0
  	
  	//name validation
  	if(name.length == 0 ){
  		$("#demographics input:eq(0)").addClass("fieldError")
  		error++
  	}
  	
  	
  	//phone validation
  	var phoneStripped = phone.replace(/[\(\)\.\-\ ]/g, '');
//strip out acceptable non-numeric characters
	if (isNaN(parseInt(phoneStripped))) {
   //	console.log("The phone number contains illegal characters.");
	}
	if (!(phoneStripped.length == 10)) {
	$("#demographics input:eq(1)").addClass("fieldError")
	 	error++
	}
  	
  	//checks email validation
  var emailCheck = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	
	if(!email.match(emailCheck)){
		$("#demographics input:eq(2)").addClass("fieldError")
		error++
		}
  	
  	
  	//remove error class
	$("#demographics input").focus(function () {
		$(this).removeClass("fieldError")
  	});

  	
     if(error > 0){
     $("#demographics p.submit strong").remove()
     $("#demographics p.submit").append("<strong> Error. Missing or invalid fields.</strong>")
      return false;
      } else {
      $("#demographics p.submit strong").remove()
          $("#demographics p.submit").append("<strong> Sending Information...</strong>")

    //   console.log("sending")
      }
    });
	
 });//end on doc ready 
 


 
 
 function showSurvey() {
 	
	jQuery.each(jQuery.browser, function(i, val) {
 		 if(i=="msie" && jQuery.browser.version.substr(0,1)=="6") {
   		 window.parent.location = "http://www.maduilaw.com/VirtCon.htm"
     
		 } else{
		 $("#surveyWrap").fadeIn("fast")
		 }
});
 }
 
 
 function requiredError(button) {
 $(button).siblings(".alert").remove()
 $(button).parent().append(" <strong class='alert'> No box checked, please check an answer.</strong>")
 //console.log(button)
 }
 
 
 function playVideo() {
 	//alert("Play the video!");
 	HtWwaitforok=1;
 
 }
 
 function callNoFlashEd() {
 	clearTimeout(noFlashEd);
 }
 
