$(document).ready(function(){  
    $("#question_slides").slidequestions();
});
function question_gethelppage(page){
   $("#question_mainContent_questions").hide();
   $("#question_mainContent_help").show(500);
   $.get(page,
           function(data){
             $("#question_mainContent_help").html('<input type="button" onClick="question_getquestionpage()" value="Back" style="border:solid 1px #999999"/><br>' + data);
            });
}
function question_getquestionpage(){
   $("#question_mainContent_help").hide();
   $("#question_mainContent_questions").show();
}
function question_submit(){
   if($("[name=answer4W]").val() > 0 || $("[name=answer4A]").val() > 0) //if a watt or amp is entered
      $("#question_form1").submit();
   else
      alert("Please enter a number for Watts or Amps.");
   return false;
}

(function($) {
    $.fn.slidequestions = function() {
        return this.each(function() {
            qobj = $(this);
            var st = 4; //number of questions
            var wt = qobj.width();
            var ht = qobj.height();
            var tst = st - 1;
            var tt = 0;
            $("#question_slide_holder", qobj).css('width', st * wt);
            $(".question_prev").click(function() {
                nextquestion("0");
            });
            $(".question_startover").click(function() {
                nextquestion("3");
            });
            $(".question_startover").click(function() {
                nextquestion("3");
            });                
            $(".question_answer").mouseover(function() {
                $(this).css('backgroundColor', '#EEEEEE');
                }).mouseout(function() {
                $(this).css('backgroundColor', '#FFFFFF')
                }).click(function(event) {
                if (event.target.type !== 'radio') {
                  $(':radio', this).attr('checked', true);
                }
                nextquestion("1");
                });
            
            function nextquestion(next) {
                if (next == "1"){ 
                  if(tt >= tst){ //last page
                     if($("[name=answer4W]").val() > 0 || $("[name=answer4A]").val() > 0) //if a watt or amp is entered
                        $("#question_form1").submit();
                     else
                        alert("Please enter a number for Watts or Amps.");
                  }
                  else{
                     tt++;
                     if(tt == 2){   //if page 3, cancel out same voltage as page 1
                        $("#q3_A").show();
                        $("#q3_B").show();
                        if( $("[name=answer1]:checked").val() == 'A' )
                           $("#q3_A").hide();
                        else
                           $("#q3_B").hide();
                     }
                     if(tt == 1){   //if page 2, if already has multicountry voltage, show need adapter msg
                        $("#q2_questions").show();
                        $("#q2_adapter").show();
                        if( $("[name=answer1]:checked").val() == 'C' )
                           $("#q2_questions").hide();
                        else
                           $("#q2_adapter").hide();
                        //reset page 2 to links
                        $('#question_2_A').hide();   
                        $('#question_2_B').hide();
                        $("#question_hide_itemlinks").show(); 
                     }   
                  }
                }else if(next == "3"){
                  tt = 0;
                }  
                else tt = (tt <= 0) ? tst: tt - 1;
                pt = (tt * wt * -1);
                $("#question_slide_holder", qobj).animate({
                    marginLeft: pt
                },
                600);
            };
        });

    };
})(jQuery);