//Prepared by Discovery Creative Resources' Webworks -- http://dcrwebworks.com

var GTBinfo = new Hash({
    Question1: {
        hint: 'Caught chasing its tail? Not likely for this breed.',
        choices: {
            a: 'Dachshund',
            b: 'Welsh Springer Terrier',
            c: 'Pembroke Welsh Corgi',
            d: 'Yorkshire Terrier'
        },
        correct: 'c',
        answer: 'The Pembroke Welsh Corgi has little or no tail.'
    },
    Question2: {
        hint: "This breed's name is no exaggeration, though it bears no direct connection to Denmark.",
        choices: {
            a: 'Giant Schnauzer',
            b: 'Chinese Shar-Pei',
            c: 'Great Dane',
            d: 'Weimaraner'
        },
        correct: 'c',
        answer: "Great Dane is the English translation of the breed's" + ' name in French, grand Danois, or "big Danish."'
    },
    Question3: {
        hint: 'Don&#39;t even think of badgering this breed.',
        choices: {
            a: 'Dachshund',
            b: 'Brittany Spaniel',
            c: 'Old English Sheepdog',
            d: 'Weimaraner'
        },
        correct: 'a',
        answer: 'The Dachshund. Developed in Germany over 300 years ago, it was bred to hunt badgers.'
    },
    Question4: {
        hint: 'Famed for its tireless work enforcing the law.',
        choices: {
            a: 'Bloodhound',
            b: 'Whippet',
            c: 'French Bulldog',
            d: 'Airedale Terrier'
        },
        correct: 'a',
        answer: 'The Bloodhound. Evidence gathered by this breed is acceptable in almost any court of law.'
    },
    Question5: {
        hint: 'It wont hang upside down but has the ears of a bat.',
        choices: {
            a: 'French Poodle',
            b: 'French Bulldog',
            c: 'Irish Setter',
            d: 'Newfoundland'
        },
        correct: 'b',
        answer: 'French Bulldog. If not for objections by American dog lovers, the bat ears would have been bred out.'
    },
    Question6: {
        hint: '60 - 70% of all guide dogs are this breed.',
        choices: {
            a: 'Golden Retriever',
            b: 'Labrador Retriever',
            c: 'Long-haired Akita',
            d: 'Great Dane'
        },
        correct: 'b',
        answer: "Labrador Retriever. Easy to train and eager to work, it's the world's most popular breed."
    },
    Question7: {
        hint: "Translated, this breed's name means"+ '"sand skin."',
        choices: {
            a: 'Rhodesian Ridgeback',
            b: 'Chinese Shar-Pei',
            c: 'Brittany Spaniel',
            d: 'Boston Terrier'
        },
        correct: 'b',
        answer: 'Chinese Shar-Pei.  The name translates even more loosely as "rough, sandy coat," a unique feature in the dog world.'
    },
    Question8: {
        hint: 'Its ancestors hunted otters around the English valley that bears its name.',
        choices: {
            a: 'Airedale Terrier',
            b: 'Beagle',
            c: 'Vizsla',
            d: 'Scottish Terrier'
        },
        correct: 'a',
        answer: 'Airedale Terrier. Originating from the valley of Airedale in Yorkshire England, the Airedale is often called the King of Terriers.'
    },
    Question9: {
        hint: 'Nicknamed the American Gentleman.',
        choices: {
            a: 'Great Dane',
            b: 'Old English Sheepdog',
            c: 'Boston Terrier',
            d: 'Papillon'
        },
        correct: 'c',
        answer: 'Boston Terrier. A gentleman among dogs thanks to its gentle disposition.'
    },
    Question10: {
        hint: 'Tiny in stature but big on personality.',
        choices: {
            a: 'Yorkshire Terrier',
            b: 'Welsh Springer Spaniel',
            c: 'Miniature Pinscher',
            d: 'Standard Poodle'
        },
        correct: 'a',
        answer: 'Yorkshire Terrier. Called Yorkies, these diminutive pooches weigh as little as four pounds.'
    }
});
var score = 0;
var hashIndex = 0;
var currQ = 0;
var questions = [];
var answersActive = false;
var questionBuilder = function(hint, choices, correct, answer){
    this.hint = hint;
    this.choices = choices;
    this.correct = correct;
    this.answer = answer;
    this.open = true;
}
window.addEvent('domready', function(){
    GTBinfo.each(function(value, key){
        questions[hashIndex] = new questionBuilder(value.hint, value.choices, value.correct, value.answer);
        hashIndex++;
    });
    var populateQuestion = function(){
		$('GTB-next').removeClass('active');
		$('GTB-back').removeClass('active');
        $('GTB-question').innerHTML = '<p><strong>Hint</strong>' + questions[currQ].hint + '</p>';
        $('GTB-opt-a').innerHTML = questions[currQ].choices.a;
        $('GTB-opt-b').innerHTML = questions[currQ].choices.b;
        $('GTB-opt-c').innerHTML = questions[currQ].choices.c;
        $('GTB-opt-d').innerHTML = questions[currQ].choices.d;
        var imgPath = 'url(media/images/photos/' + (currQ + 1) + '.jpg)';
        $('GTB-photo').setStyle('background-image', imgPath);
        answersActive = true;
    }
    $$('#GTB-answer ul li').addEvents({
        'mouseover': function(){
            if (answersActive === true) {
                this.addClass('hover');
            }
        },
        'mouseout': function(){
            if (answersActive === true) {
                this.removeClass('hover');
            }
        },
        'click': function(){
            if (answersActive === true) {
                var title = this.getProperty('title');
                this.removeClass('hover');
                answersActive = false;
                checkResponse(title, this);
            }
        }
    });
    var checkResponse = function(a, el){
		$('GTB-next').addClass('active');
		$('GTB-back').addClass('active');
        var imgPath = 'url(media/images/photos/a' + (currQ + 1) + '.jpg)';
        $('GTB-photo').setStyle('background-image', imgPath);
        if (a == questions[currQ].correct) {
            el.addClass('correct');
            $('GTB-question').innerHTML = '<p><strong>Correct</strong>' + questions[currQ].answer + '</p>'
            if (questions[currQ].open === true) 
                score++;
            questions[currQ].open = false;
        }
        else {
            var correctChoice = '#GTB-answer ul li[title=' + questions[currQ].correct + ']';
            $(document.body).getElements(correctChoice).addClass('correct');
            $('GTB-question').innerHTML = '<p><strong>Incorrect</strong>' + questions[currQ].answer + '</p>';
        }
    }
    $('GTB-next').addEvent('click', function(){
		if (answersActive == true) return
        $$('#GTB-answer ul li').removeClass('correct');
        currQ++;
        if (currQ < questions.length) {
            populateQuestion();
        }
        else {
            $('GTB-photo').setStyle('background-image', 'url(media/images/photos/dogs-101.jpg)');
            $('GTB-content').innerHTML = '<h4>Guess the Breed</h4>\n<div id="GTB-question">\n<p style="font-size: 13px"><strong>THANKS FOR PLAYING!</strong>You answered ' + score + ' out of ' + questions.length + ' questions</p><p>Challenge your friends to Guess the Breed!</p><p><a href="form.html"><img src="media/images/headers/send-to-a-friend.png" alt="Send to a friend" /></a></p>\n</div>'
        }
    });
    $('GTB-back').addEvent('click', function(){
		if (answersActive == true) return
        $$('#GTB-answer ul li').removeClass('correct');
        if (currQ > 0) {
            currQ--;
            populateQuestion();
            answersActive = true;
        }
        else 
            if (currQ == 0) {
                populateQuestion();
                answersActive = true;
            }
    });
	$$('.page').setStyle('display', 'block');
    populateQuestion();
});
