
	
		$(document).ready(function(){
		
			$(".answer").prepend('<div class="emailLink"><a href="#?w=500" rel="emailform" class="poplight">Still havent found the answer to your question?  Click here to e-mail us.<\/a><\/div>');
			
			
			function scroller()	{
				$('html, body').animate({

                        scrollTop: $("#answersblock").offset().top

                    }, 1500);
            };
			
			
			
			
		
			//Define Colors
			var $cSelectedLabel = "#FCE4A2";
			var $cHighlightedLabel = "#EBCB75";
			var $cLabelColor = $("label").css("background-color");
			var $cFadeAmount = 0.3;
			
			var $labelColor;
			var $skipNext = false;
			var $clickedQuestion = '';
			var $queryString;
			var $customerData = '';
		
			//Hide everything to begin
			$("#platformblock").hide();
			$("#brandblock").hide();
			$("#problemblock").hide();
			$("#thankyou").hide();
			$(".question").hide();
			$(".answer").hide();
			$(".emailLink").hide();
			$(".error").hide();
			
						
			
			//Fade in Driller DIVs on hover
			$(".driller").hover(function(){
					$(this).fadeTo("fast", 1); // This sets the opacity back to 60% on mouseout
				},function(){
					if ($(this).next("div").is(":visible")) {
						$(this).fadeTo("fast", $cFadeAmount); // This sets the opacity back to 60% on mouseout
				}
			});
			
			
			
			//Handle label hovers
			$(".drillerButton").hover(function(){
					$labelColor = $(this).css("background-color");
					$(this).css("background-color", $cHighlightedLabel); 
				},function(){
						$(this).css("background-color", $labelColor); 
			});
			
			
			
			//Handle question hovers
			$(".question").hover(function(){
					$(this).css("border", "2px solid #CC8323"); 
					$(this).css("text-shadow: #777777 2px 2px 2px");

				},function(){
						$(this).css("border", "2px solid #D9AE64");
						$(this).css("text-shadow: none");
			});
			

			
			//All the logic happens here
			$("input:radio").change(function()	{

				//$(this).parent("div").nextAll("div").slideUp();
				
				
				if ($('input:radio[name=prepostselect]:checked').val() == "Pre" )
				{
					//$("input:radio[name=problemselect]").click();
					//$("#problemblock").children("label").css("background-color",$cLabelColor);
					$("#problemblock").slideUp();
				}


				//If user switches to Post after filling out other fields...
				if ( ($(this).attr("name") == "prepostselect") && $('input:radio[name=platformselect]:checked').val() != "Dummy" && $('input:radio[name=brandselect]:checked').val() != "Dummy")
				{
					if ($(this).attr("id") == "Post")
					{
						$("#problemblock").slideDown();
						$("#thankyou").fadeOut();
						$(".question").fadeOut();
						$(".answer").fadeOut();
					}
					else  //pre
					{
						$("#problemblock").slideUp();
					}
				}
				
				
				if ( $('input:radio[name=prepostselect]:checked').val() != "Dummy" && $('input:radio[name=platformselect]:checked').val() != "Dummy" && $('input:radio[name=brandselect]:checked').val() != "Dummy" && $('input:radio[name=problemselect]:checked').val() != "Dummy")
				{
					$("#thankyou").fadeTo("fast",1);
				}
				
				
				
				//Make sure we should display the block...
				if ( !   (   ($(this).parent("div").next("div").attr("id") == "problemblock")    &&    ($('input:radio[name=prepostselect]:checked').val() == "Pre" )   )   )  
				{
					//alert($(this).parent("div").next("div").attr("id") + " " + $('input:radio[name=prepostselect]:checked').val());
					$(this).parent("div").next("div").slideDown();
					$(this).parent("div").next("div").fadeTo("fast", 1);
				};
								
				//Fade out clicked drilldown step
				$(this).parent("div").fadeTo("slow", $cFadeAmount);
				
				//change color of labels
				$(this).parent("div").children("label.drillerbutton").css("background-color",$cLabelColor);
				$(this).next("label.drillerbutton").css("background-color",$cSelectedLabel);
				$labelColor = $cSelectedLabel;
				
				
				
				////////  Filter Results
				if ( ( ( $('input:radio[name=prepostselect]:checked').val() == 'Pre' ) && $('input:radio[name=brandselect]:checked').val() != "Dummy" ) || $('input:radio[name=problemselect]:checked').val() != "Dummy" )
				{
					//Hide all questions and answers
					$(".question").hide();
					$(".answer").hide();
					
					//Create filter query string
					$queryString = '[name~="'+$('input:radio[name=prepostselect]:checked').val()+'"][name~="'+$('input:radio[name=platformselect]:checked').val()+'"][name~="'+$('input:radio[name=brandselect]:checked').val()+'"]';
					
					if ( $('input:radio[name=prepostselect]:checked').val() == 'Post' )	{
					
						$queryString = $queryString + '[name~="'+$('input:radio[name=problemselect]:checked').val()+'"]';
					}
					
					$("#thankyou").fadeTo("fast",1);
					
					$($queryString).show();
					
					scroller();
					
					

				};
				
				
			});	
			

			//Display answers
			$(".question").click(function()   {
					
					$(".emailLink").stop();
					
					$("input[name=subject]:hidden").val($(this).html());
										
					$(".emailLink").fadeTo('fast', 0);
					$(".answer").slideUp();
					$(this).next(".answer").slideDown("slow", scroller());
					
					
					
					$(".emailLink").fadeTo(2000,1);
			});
			
			
			
			
			
			
			
			
			
			
			
			///////////  E-mail Modal Form
			
			//When you click on a link with class of poplight and the href starts with a # 
			$('.poplight').click(function() {
				var popID = $(this).attr('rel'); //Get Popup Name
				var popURL = $(this).attr('href'); //Get Popup href to define size
			
				//Pull Query & Variables from href URL
				var query= popURL.split('?');
				var dim= query[1].split('&');
				var popWidth = dim[0].split('=')[1]; //Gets the first query string value

				//Fade in the Popup and add close button
				$('#' + popID).fadeIn().css({ 'width': Number( popWidth ) });
				
				$("input#name").focus();  //RYAN ADDED THIS
			
				//Define margin for center alignment (vertical   horizontal) - we add 80px to the height/width to accomodate for the padding  and border width defined in the css
				var popMargTop = ($('#' + popID).height() + 80) / 2;
				var popMargLeft = ($('#' + popID).width() + 80) / 2;
			
				//Apply Margin to Popup
				$('#' + popID).css({
					'margin-top' : -popMargTop,
					'margin-left' : -popMargLeft
				});
			
				//Fade in Background
				$('body').append('<div id="fade"><\/div>'); //Add the fade layer to bottom of the body tag.
				$('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn(); //Fade in the fade layer - .css({'filter' : 'alpha(opacity=80)'}) is used to fix the IE Bug on fading transparencies 
			
				return false;
			});
			
			//Close Popups and Fade Layer
			$('a.close, #fade').live('click', function() { //When clicking on the close or fade layer...
				$('#fade , .popup_block').fadeOut(function() {
					//$('#fade, a.close').remove();  //fade them both out
				});
				return false;
			});
			
			
			
			
			
			
			
			
			
			
			////////////////////////  Form Handler
			
			
			$(".button").click(function() {
				// validate and process form
				// first hide any error messages
			$('.error').hide();
				
			  var name = $("input#name").val();
				if (name == "") {
			  $("label#name_error").show();
			  $('input[name="name"]').css("background","#E8C166");
			  $("input#name").focus();
			  return false;
			}
				var email = $("input#email").val();
				if (email == "") {
			  $("label#email_error").show();
			  $('input[name="email"]').css("background","#E8C166");
			  $("input#email").focus();
			  return false;
			}
				var message = $("textarea#message").val();
				if (message == "") {
			  $("label#message_error").show();
			  $('input[name="message"]').css("background","#E8C166");
			  $("input#message").focus();
			  return false;
			}
				
				/*$.get('/h/contact_form.php?email=rezankaduncan@gmail.com', function(data) {
				  //$('.result').html(data);
				  //alert(data);
				  $customerData = data;
				});*/
				
				var emailToCheck = "email=" + email;
				
				
				var dataString = 'name='+ name + '&email=' + email + '&message=' + message;
				
				dataString = dataString + "&customerInfo=" + $('input:radio[name=prepostselect]:checked').val() + "-purchase " + $('input:radio[name=platformselect]:checked').val() + " " + $('input:radio[name=brandselect]:checked').val() + " " + $('input:radio[name=problemselect]:checked').val();
				
			
			//Get info from database based on e-mail address
			$.ajax({
			  type: "POST",
			  url: "/h/contact_form.php",
			  data: emailToCheck,
			  async: false,
			  success: function(data) {
			  dataString = dataString + "\n" + data;
               
			  }
			 });
			 
			 
			 
			 dataString = dataString + '&subject=' + $("input[name=subject]:hidden").val();
			 dataString = dataString + '&topicId=' + $("input[name=topicId]:hidden").val();
			 dataString = dataString + '&emailId=' + $("input[name=emailId]:hidden").val();
			 dataString = dataString + '&deptId=' + $("input[name=deptId]:hidden").val();
				
	
				
			$.ajax({
			  type: "POST",
			  url: "/s/open.php",
			  data: dataString,
			  success: function() {
				$('#contact_form').html("<div id='confirmation'><\/div>");
				$('#confirmation').html("<h2>Your message has been received.<\/h2>")
				.append("<p>We will get back to you shortly. Please continue looking at our tech support topics below.  Many common questions are answered there.  <\/p>")
				.hide()
				.fadeIn(2000, function() {
				  $('#confirmation').append('<center><a href="#" class="close">Click here to close.<\/a><\/center>');
				});
			  }
			 });
			 
			return false;
			});
			
	
		});


