﻿var customSize = new Array(11);
var customVote = new Array(11);

$(function () {
    SetCustomData();

});

function SetCustomData() {
    for(i=1; i<11; i++){
        if($(".customdatabox"+i)){
            customSize[i] = $(".customdatabox" + i).height();
            $(".customdatabox" + i).css({ 'height': '100px' });
            $(".customdatabox" + i).css({ 'overflow': 'hidden' });
            $(".custombutton" + i).attr({ 'tag': i });
            $(".voteoptiona" + i).attr({ 'tag': i });
            $(".voteoptionb" + i).attr({ 'tag': i });
            $(".voteoptionc" + i).attr({ 'tag': i });
            $(".voteoptiond" + i).attr({ 'tag': i });
            $(".voteoptione" + i).attr({ 'tag': i });
            $(".votebutton" + i).attr({ 'tag': i });

            customVote[i] = 1;

            $(".custombutton" + i).click(function () {
                var i = parseInt($(this).attr('tag'));

                if ($(".customdatabox" + i).height() < customSize[i]) {
                    //$(".customdatabox" + i).css({ 'height': customSize[i] + 'px' });

                    $(".customdatabox" + i).animate({
                        height: customSize[i]
                    }, 500, function () {
                        // Animation complete.
                    });

                    $(".custombutton" + i).css({ 'background': 'url(/resource/images/customless_m.png) no-repeat' });
                } else {
                    //$(".customdatabox" + i).css({ 'height': '150px' });
                    $(".customdatabox" + i).animate({
                        height: '100'
                    }, 500, function () {
                        // Animation complete.
                    });
                    $(".customdatabox" + i).css({ 'overflow': 'hidden' });
                    $(".custombutton" + i).css({ 'background': 'url(/resource/images/custommore_m.png) no-repeat' });
                }
            });

            $(".voteoptiona" + i).click(function () {
                var i = parseInt($(this).attr('tag'));
                customVote[i] = 1;
                $(this).css({ 'background': 'url(/resource/images/voteyes_m.png) no-repeat' });
                $(".voteoptionb" + i).css({ 'background': 'url(/resource/images/voteno_m.png) no-repeat' });
                $(".voteoptionc" + i).css({ 'background': 'url(/resource/images/voteno_m.png) no-repeat' });
                $(".voteoptiond" + i).css({ 'background': 'url(/resource/images/voteno_m.png) no-repeat' });
                $(".voteoptione" + i).css({ 'background': 'url(/resource/images/voteno_m.png) no-repeat' });
            });

            $(".voteoptionb" + i).click(function () {
                var i = parseInt($(this).attr('tag'));
                customVote[i] = 2;
                $(this).css({ 'background': 'url(/resource/images/voteyes_m.png) no-repeat' });
                $(".voteoptiona" + i).css({ 'background': 'url(/resource/images/voteno_m.png) no-repeat' });
                $(".voteoptionc" + i).css({ 'background': 'url(/resource/images/voteno_m.png) no-repeat' });
                $(".voteoptiond" + i).css({ 'background': 'url(/resource/images/voteno_m.png) no-repeat' });
                $(".voteoptione" + i).css({ 'background': 'url(/resource/images/voteno_m.png) no-repeat' });
            });

            $(".voteoptionc" + i).click(function () {
                var i = parseInt($(this).attr('tag'));
                customVote[i] = 3;
                $(this).css({ 'background': 'url(/resource/images/voteyes_m.png) no-repeat' });
                $(".voteoptiona" + i).css({ 'background': 'url(/resource/images/voteno_m.png) no-repeat' });
                $(".voteoptionb" + i).css({ 'background': 'url(/resource/images/voteno_m.png) no-repeat' });
                $(".voteoptiond" + i).css({ 'background': 'url(/resource/images/voteno_m.png) no-repeat' });
                $(".voteoptione" + i).css({ 'background': 'url(/resource/images/voteno_m.png) no-repeat' });
            });

            $(".voteoptiond" + i).click(function () {
                var i = parseInt($(this).attr('tag'));
                customVote[i] = 4;
                $(this).css({ 'background': 'url(/resource/images/voteyes_m.png) no-repeat' });
                $(".voteoptiona" + i).css({ 'background': 'url(/resource/images/voteno_m.png) no-repeat' });
                $(".voteoptionc" + i).css({ 'background': 'url(/resource/images/voteno_m.png) no-repeat' });
                $(".voteoptionb" + i).css({ 'background': 'url(/resource/images/voteno_m.png) no-repeat' });
                $(".voteoptione" + i).css({ 'background': 'url(/resource/images/voteno_m.png) no-repeat' });
            });
            $(".voteoptione" + i).click(function () {
                var i = parseInt($(this).attr('tag'));
                customVote[i] = 5;
                $(this).css({ 'background': 'url(/resource/images/voteyes_m.png) no-repeat' });
                $(".voteoptiona" + i).css({ 'background': 'url(/resource/images/voteno_m.png) no-repeat' });
                $(".voteoptionc" + i).css({ 'background': 'url(/resource/images/voteno_m.png) no-repeat' });
                $(".voteoptionb" + i).css({ 'background': 'url(/resource/images/voteno_m.png) no-repeat' });
                $(".voteoptiond" + i).css({ 'background': 'url(/resource/images/voteno_m.png) no-repeat' });
            });

            $(".votebutton" + i).click(function () {
                var i = parseInt($(this).attr('tag'));
                var yes = parseInt($("#CustomYes" + i).val());
                var no = parseInt($("#CustomNo" + i).val());
                var oc = parseInt($("#CustomC" + i).val());
                var od = parseInt($("#CustomD" + i).val());
                var oe = parseInt($("#CustomE" + i).val());

                if (customVote[i] == 1) {
                    yes += 1;
                }
                if (customVote[i] == 2) {
                    no += 1;
                }
                if (customVote[i] == 3) {
                    oc += 1;
                }
                if (customVote[i] == 4) {
                    od += 1;
                }
                if (customVote[i] == 5) {
                    oe += 1;
                }
                $(".voteoptiona" + i).css({ 'background-image': 'none' });
                $(".voteoptionb" + i).css({ 'background-image': 'none' });
                $(".voteoptionc" + i).css({ 'background-image': 'none' });
                $(".voteoptiond" + i).css({ 'background-image': 'none' });
                $(".voteoptiona" + i).html(yes);
                $(".voteoptionb" + i).html(no);
                $(".voteoptionc" + i).html(oc);
                $(".voteoptiond" + i).html(od);
                $(".voteoptionE" + i).html(oe);
                $(".votebutton" + i).hide();

                var params = "assembly=ImageStrip&Command=updatecustomvote&Data=" + $("#CustomID" + i).val() + "|" + customVote[i] + "|" + i;

                $.ajax({url: 'ajax.ajax?' + params, success: function (data) {} });

            });

        }
    }
}

