var chosenPet = 0; var pet4Points = 0; var pet3Points = 0; var pet2Points = 0; var pet1Points = 0;

var total_questions = 6; var max_score = 100; var finalPet = 0;

var pets = Array();

var petsArray = Array();

pets[0] = "Talking Dog";
pets[1] = "Psychic Cat";
pets[2] = "Phoenix";
pets[3] = "Baby Dragon";

var sidebarContent = new Array(); 

sidebarContent[0] = "<a href=\"http://www.angiefox.com\"><img width=\"150\" src=\"http://angiefox.files.wordpress.com/2008/02/midt2ds2.jpg\" alt=\"A Tale of Two Demon Slayers\" border=\"0\" /></a><br><br>\"Fabulously Fun\"<br>-Chicago Tribune";

sidebarContent[1] = "<a href=\"http://www.angiefox.com\"><img width=\"150\" src=\"http://angiefox.files.wordpress.com/2008/02/midt2ds2.jpg\" alt=\"A Tale of Two Demon Slayers\" border=\"0\" /></a><br><br />\"A rollicking paranormal comedy.\"<br>- Booklist<br><br>\"With dogs!\"<br>- Added by Pirate the dog, who doesn't always know when to hush up";

sidebarContent[2] = "<a href=\"http://www.angiefox.com\"><img width=\"150\" src=\"http://angiefox.files.wordpress.com/2008/02/midt2ds2.jpg\" alt=\"A Tale of Two Demon Slayers\" border=\"0\" /></a><br><br>\"A new talent just hit the urban fantasy genre, and she has a genuine gift for creating dangerously hilarious drama.\"<br>- RT Book Reviews";

sidebarContent[3] = "<a href=\"http://www.angiefox.com\"><img width=\"150\" src=\"http://angiefox.files.wordpress.com/2008/02/midt2ds2.jpg\" alt=\"A Tale of Two Demon Slayers\" border=\"0\" /></a><br><br>\"Why does everyone look at me when they talk about the neighbor's cat? I like cats. Especially with a little BBQ sauce.\"<br>- Unauthorized quote by Pirate. Sorry. We gave him his squeaky toy, we gave him a Pup-per-roni treat. He's more interested in this.";

sidebarContent[4] = "<a href=\"http://www.angiefox.com\"><img width=\"150\" src=\"http://angiefox.files.wordpress.com/2008/02/midt2ds2.jpg\" alt=\"A Tale of Two Demon Slayers\" border=\"0\" /></a><br><br>\"You know I think more books should have talking dogs. I can sniff out trouble. I'm always up for a tummy rub. And I even know where to find the fettuccine from last week - Back of the fridge, to the left of the lettuce crisper, behind the mustard.\"<br>- Pirate, the dog (who is not getting any fettuccine)";

sidebarContent[5] = "<a href=\"http://www.angiefox.com\"><img width=\"150\" src=\"http://angiefox.files.wordpress.com/2008/02/midt2ds2.jpg\" alt=\"A Tale of Two Demon Slayers\" border=\"0\" /></a><br><br>\"Ohh...what kind of supernatural pet are you gonna get? Can I see?\"<br>- Pirate, who just danced across the author's laptop cord and unplugged it.";

function begin() {
  if ($('score')) {
    new Ajax.Updater('question','processQuiz.asp?score='+$('score').value + '&random=' + random_int());
  } else {
    new Ajax.Updater('question','processQuiz.asp?question=0&random='+random_int());
  } 
}



function answer(question_id,answer) {
  
  $('question').innerHTML = 'Loading Next Question...';
  
  new Ajax.Request('processQuiz.asp',
    {
      method:'get',
      parameters: { question: question_id, answer: answer, random: random_int() },
      onSuccess: function(transport){
        
        var response = transport.responseText || "no response text";
        
        if (response.match(/PET(\d+)/)) {

          //1. Add up numbers for each pet
        
          chosenPet = parseFloat(RegExp.$1);
          switch(chosenPet){

            case 1: //Dog
               pet1Points = pet1Points + 1;
               break;

            case 2: //cat
               pet2Points = pet2Points + 1;
               break;

            case 3: //dragon
               pet3Points = pet3Points + 1;
               break;

            case 4: //dragon
               pet4Points = pet4Points + 1;
               break;

          }
         
                  
          
          percentage = (question_id / (total_questions)) * 100;
          
          $('progress').style.width = Math.floor((percentage * 4.5)) + 'px';
          
          percentage = Math.floor(percentage);
          
        }
        
        question_id++;
        
        if (question_id >= total_questions) {


        petsArray = [pet1Points,pet2Points,pet3Points,pet4Points];

        finalPet = returnMax(petsArray);

        finalPet = pets[finalPet]; 

         //Pet Window

switch(finalPet){

case "Talking Dog":

petText = "<h2>Your ideal pet is Frodo, the talking dog!</h2><br>He's charming at chatty. He'll be your best friend for a tummy rub - or that pork chop from last night. Just don't let him hop on a motorcycle with the biker witches or you'll be in for a wild ride.";
petImage = "talking_dog.jpg";
petBG = "#789D02";
petBorder = "#485F00";
break;

case "Psychic Cat":

petText = "<h2>Your ideal pet is Nostra, the psychic cat!</h2><br>Sure, cats are smart, but yours can see the future. Literally. Treat her to some cat nip, or perhaps a nice scratch behind the ears...and maybe she'll let you know what else is in store.";
petImage = "psychic_cat.jpg";
petBG = "#3B85AF";
petBorder = "#27607F";
break;

case "Phoenix":
petText = "<h2>Your ideal pet is Smoky, the phoenix!</h2><br>Regal and inquisitive, the phoenix is one of the oldest and most exotic birds. Let her sit on your shoulder and you'll both be a hit around town."
petImage = "phoenix.jpg";
petBG = "#DF0D2E";
petBorder = "#7F0717";
break;

case "Baby Dragon":
petText = "<h2>Your ideal pet is Zippy, the three-headed dragon!</h2><br>He may not be the most handsome creature on Earth, but who else can fly you to work? Or start up the barbecue grill in a single breath? Just make sure you have plenty of room in your bed - dragons like to cuddle.";
petImage = "dragon.gif";
petBG = "#7F3F58";
petBorder = "#2F1721";
break;
}

        partOne = "<table width='90%' cellpadding=2 cellspacing=2 style='border:solid 1px "+petBorder+"; background:"+petBG+"'><tr><td valign='top'><img style='border:solid 1px #000' width='175' src='images/"+petImage+"' /></td><td>"+petText+"</td></tr></table><br><br>";
            
         // Twitter
         partTwo = "<table width='90%' cellpadding=2 cellspacing=2 style='border:solid 1px #858484; background:#e0e0e0'><tr><td valign='top' align='center'><a href=\"http://twitter.com/home/?status=I+just+adopted+a+" + finalPet + ".Get+your+own+supernatural+pet+at+http%3A%2F%2Fwww.angiefox.com\" border=\"0\"> <img src=\"images/tweet.jpg\" border=\"0\"><br>Tweet your Supernatural Pet Quiz Results!</a>";

        partThree = "<br><br>Or <a href=\"http://quiz.angiefox.com/supernatural-pet/tellafriend.asp?finalpet=" + finalPet + "\" target=\"_blank\">Spread the Word and Email a Fellow Biker Chick/Dude</a><br><br><a href=\"http://apps.facebook.com/pirates-journey/\" target=\"_blank\"><img src=\"http://angiefox.files.wordpress.com/2010/02/facebookgame_ad.jpg\" /></a></td>";
       
        partFour = "<td align='center'><img src='images/getwidget.gif' alt='Get the official widget' title='Get the official widget'><div id=\"slayerwidget\" style=\"background-image:url(http://quiz.angiefox.com/supernatural-pet/supernatural-pet-widget.jpg);width:175px; height:220px;\"><div id=\"finalPet\" style=\"margin-left:10px; padding-top:25px; color:white;font-size:20px;\">" + finalPet + "</div></div><br>Copy the code below and paste into your website:<br><textarea cols=30 rows=10><div id=\"slayerwidget\" style=\"background-image:url(http://quiz.angiefox.com/supernatural-pet/supernatural-pet-widget.jpg);width:175px; height:220px;\"><div id=\"finalPet\" style=\"margin-left:10px; padding-top:25px; color:white;font-size:20px;\">" +finalPet + "</div></div></textarea></td></tr></table>";

        partFive = "</center>";

		$('question').innerHTML = partOne + partTwo + partThree + partFour + partFive;

        } else {
          new Ajax.Updater('question','processQuiz.asp?question='+question_id+'&random='+random_int());
		  $('textwidget').innerHTML = sidebarContent[question_id];
        }
        
      },
      onFailure: function(){ alert('Something went wrong...') }
    });
}


function random_int() {
 return Math.floor(Math.random()*100000);
}

  function returnMax( arrayValue ){
                     var max = arrayValue[0]; var maxIndex = 0;
                     var len = arrayValue.length;
                     for (var i = 1; i < len; i++) if (arrayValue[i] > max){ max = arrayValue[i]; maxIndex = i;}
                     return maxIndex;
              }
