Question = Class.create();
Question.Const = {};
Question.Const.first = {
        index : "1/5",
        alt : "あなたは、女性？ 男性？",
        src : "http://i.yimg.jp/images/evt/recommend/partner/mehyou/shi_q_01.gif",
        width : "364",
        height : "40"
};
Question.Const.female = {};
Question.Const.female.images = [
    { 
        index : "2/5",
        alt : "恋と仕事なら、迷わず恋をとる!",
        src : "http://i.yimg.jp/images/evt/recommend/partner/mehyou/shi_q_f02.gif",
        width : "434",
        height : "40"
    },
    {
        index : "3/5",
        alt : "恋愛にモラルなんていらない！",
        src : "http://i.yimg.jp/images/evt/recommend/partner/mehyou/shi_q_f03a.gif",
        width : "413",
        height : "40" 
    },
    {
        index : "3/5",
        alt : "他人のことはあまり気にならない。",
        src : "http://i.yimg.jp/images/evt/recommend/partner/mehyou/shi_q_f03b.gif",
        width : "475",
        height : "40"
    },
    {
        index : "4/5",
        alt : "アクセサリーは指輪よりもネックレスが好き。",
        src : "http://i.yimg.jp/images/evt/recommend/partner/mehyou/shi_q_f04a.gif",
        width : "361",
        height : "76"
    },
    {
        index : "4/5",
        alt : "彼氏がいても、合コンに参加するのはアリ。",
        src : "http://i.yimg.jp/images/evt/recommend/partner/mehyou/shi_q_f04b.gif",
        width : "382",
        height : "76"
    },
    {
        index : "4/5",
        alt : "好きな人にはメールより電話することが多い。",
        src : "http://i.yimg.jp/images/evt/recommend/partner/mehyou/shi_q_f04c.gif",
        width : "336",
        height : "76"
    },
    {
        index : "5/5",
        alt : "恋愛にテクニックは不可欠だと思う。",
        src : "http://i.yimg.jp/images/evt/recommend/partner/mehyou/shi_q_f05a.gif",
        width : "281",
        height : "76"
    },
    {
        index : "5/5",
        alt : "片思いの状況も楽しめるほうだ。",
        src : "http://i.yimg.jp/images/evt/recommend/partner/mehyou/shi_q_f05b.gif",
        width : "444",
        height : "40"
    },
    {
        index : "5/5",
        alt : "「してあげる」よりも「してもらう」ほうが好き。",
        src : "http://i.yimg.jp/images/evt/recommend/partner/mehyou/shi_q_f05c.gif",
        width : "352",
        height : "76"
    },
    {
        index : "5/5",
        alt : "自分磨きにはお金をかけている。",
        src : "http://i.yimg.jp/images/evt/recommend/partner/mehyou/shi_q_f05d.gif",
        width : "439",
        height : "40"
    }
];
Question.Const.female.href = {
    10 : "resultf01",
    11 : "resultf02",
    12 : "resultf03",
    13 : "resultf04",
    14 : "resultf05"
};
Question.Const.male = {};
Question.Const.male.images = [
    { 
        index : "2/5",
        alt : "オシャレには気を使うほうだと思う。",
        src : "http://i.yimg.jp/images/evt/recommend/partner/mehyou/shi_q_m02.gif",
        width : "326",
        height : "76"
    },
    {
        index : "3/5",
        alt : "「カワイイ」と言われるのは結構うれしい。",
        src : "http://i.yimg.jp/images/evt/recommend/partner/mehyou/shi_q_m03a.gif",
        width : "370",
        height : "76"
    },
    {
        index : "3/5",
        alt : "熱しやすく冷めやすい傾向がある。",
        src : "http://i.yimg.jp/images/evt/recommend/partner/mehyou/shi_q_m03b.gif",
        width : "474",
        height : "40"
    },
    {
        index : "4/5",
        alt : "女友だちは結構多いほうだ。",
        src : "http://i.yimg.jp/images/evt/recommend/partner/mehyou/shi_q_m04a.gif",
        width : "414",
        height : "40"
    },
    {
        index : "4/5",
        alt : "メールや電話はマメなほうだ。",
        src : "http://i.yimg.jp/images/evt/recommend/partner/mehyou/shi_q_m04b.gif",
        width : "404",
        height : "40"
    },
    {
        index : "4/5",
        alt : "正直、女性は面倒くさいと思ってしまうことがある。",
        src : "http://i.yimg.jp/images/evt/recommend/partner/mehyou/shi_q_m04c.gif",
        width : "361",
        height : "76"
    },
    {
        index : "5/5",
        alt : "デートは相手任せのことが多い。",
        src : "http://i.yimg.jp/images/evt/recommend/partner/mehyou/shi_q_m05a.gif",
        width : "429",
        height : "40"
    },
    {
        index : "5/5",
        alt : "場の空気を読むのは結構得意なほうだ。",
        src : "http://i.yimg.jp/images/evt/recommend/partner/mehyou/shi_q_m05b.gif",
        width : "279",
        height : "76" 
    },
    {
        index : "5/5",
        alt : "人に相談されるより、相談することのほうが多い。",
        src : "http://i.yimg.jp/images/evt/recommend/partner/mehyou/shi_q_m05c.gif",
        width : "384",
        height : "76"
    },
    {
        index : "5/5",
        alt : "好きになる女性のタイプはいつもバラバラだ。",
        src : "http://i.yimg.jp/images/evt/recommend/partner/mehyou/shi_q_m05d.gif",
        width : "368",
        height : "76"
    }
];
Question.Const.root = {
    0 : {yes : 1,  no : 2},
    1 : {yes : 3,  no : 4},
    2 : {yes : 4,  no : 5},
    3 : {yes : 6,  no : 7},
    4 : {yes : 7,  no : 8},
    5 : {yes : 8,  no : 9},
    6 : {yes : 10, no : 11},
    7 : {yes : 11, no : 12},
    8 : {yes : 12, no : 13},
    9 : {yes : 13, no : 14}
};
Question.Const.male.href = {
    10 : "resultm01",
    11 : "resultm02",
    12 : "resultm03",
    13 : "resultm04",
    14 : "resultm05"
};
Question.Const.yes = {
    alt : "はい",
    src : "http://i.yimg.jp/images/evt/recommend/partner/mehyou/shi_btn_yes.gif",
    width : "193",
    height : "62"
};
Question.Const.no = {
    alt : "いいえ",
    src : "http://i.yimg.jp/images/evt/recommend/partner/mehyou/shi_btn_no.gif",
    width : "193",
    height : "62" 
};
Question.prototype = {
    initialize : function(question, yes, no, index, goFirst) {
        this.question = question;
        this.yes = yes;
        this.no = no;
        this.index = index;
        this.goFirst = goFirst;
        Element.observe(yes.link, "click", function() {
            if (this.gender === undefined) {
                this.replaceYesNoImage()
                this.gender = "female";
                this.display(0);
                Element.setStyle(this.goFirst, { 'display' : 'block' });
                return;
            } 
            if (this.current !== undefined) {
                this.display(this.current.yes);
            } 
        }.bindAsEventListener(this));
        Element.observe(no.link, "click", function() {
            if (this.gender === undefined) {
                this.replaceYesNoImage()
                this.gender = "male";
                this.display(0);
                Element.setStyle(this.goFirst, { 'display' : 'block' });
                return;
            } 
            if (this.current !== undefined) {
                this.display(this.current.no);
            }
        }.bindAsEventListener(this));
    },
    display : function(index) {
        if (this.gender == undefined) {
            return;
        }
        if (Question.Const.root[index] == undefined) {
            if (Question.Const[this.gender].href[index] != undefined) {
                location.href = Question.Const[this.gender].href[index];
                return;
            }
        }
        this.current = Question.Const.root[index];
        var image = Question.Const[this.gender].images[index];
        this.index.innerHTML = image.index;
        this.question.setAttribute('src', image.src);
        this.question.setAttribute('alt', image.alt);
        this.question.setAttribute('width', image.width);
        this.question.setAttribute('height', image.height);
    },
    replaceYesNoImage : function() {
        this.yes.img.setAttribute('src', Question.Const.yes.src);
        this.yes.img.setAttribute('alt', Question.Const.yes.alt);
        this.yes.img.setAttribute('width', Question.Const.yes.width);
        this.yes.img.setAttribute('height', Question.Const.yes.height);
        this.no.img.setAttribute('src', Question.Const.no.src);
        this.no.img.setAttribute('alt', Question.Const.no.alt);
        this.no.img.setAttribute('width', Question.Const.no.width);
        this.no.img.setAttribute('height', Question.Const.no.height);
    }
}
Element.observe(window, "load", function() {
    new Question($('question'), {link : $('yes'), img : $('yes-img')}, {link : $('no'), img : $('no-img')}, $('index'), $('go-first'));
});

