﻿
$(document).ready(function() {



    //$("table tbody tr td").find("table#changeContestImg tbody tr.visibleTr").show();


    //  $("tr.rowgrid").find("table#changeContestImg.vera").show();
    //$("tr.rowgrid").find("table#changeContestImg.vera tr.visibleTr").show();



    //$("tr.rowgrid").find("table#changeContestImg.vera").css("visibility", "visible");

    //$("tr.rowgrid").find("table#changeContestImg.vera tr").css("display", "none");


    $(".defaultContest").each(function() {
        var thh = $(this).parent().find("table thead tr").height();
        var trh = $(this).parent().find("tr.visibleTr").height();
        var tot = thh + trh + 5;

        //        if (/msie 9\.0/i.test(navigator.userAgent)) {
        //            tot += 15;
        //        }

        //        if (/msie 8\.0/i.test(navigator.userAgent)) {
        //            tot += 12;
        //        }

        if (/msie 7\.0/i.test(navigator.userAgent)) {
            tot += 22;
        }
        $(this).css({ height: tot + "px" });
    });

    $(".redContest").each(function() {
        var thh = $(this).parent().find("table thead tr").height();
        var trh = $(this).parent().find("tr.visibleTr").height();
        var tot = thh + trh + 5;

        //        if (/msie 9\.0/i.test(navigator.userAgent)) {
        //            tot += 15;
        //        }

        //        if (/msie 8\.0/i.test(navigator.userAgent)) {
        //            tot += 12;
        //        }

        if (/msie 7\.0/i.test(navigator.userAgent)) {
            tot += 22;
        }
        $(this).css({ height: tot + "px" });
    });

    $(".blueContest").each(function() {
        var thh = $(this).parent().find("table thead tr").height();
        var trh = $(this).parent().find("tr.visibleTr").height();
        var tot = thh + trh + 5;

        //        if (/msie 9\.0/i.test(navigator.userAgent)) {
        //            tot += 15;
        //        }

        //        if (/msie 8\.0/i.test(navigator.userAgent)) {
        //            tot += 12;
        //        }

        if (/msie 7\.0/i.test(navigator.userAgent)) {
            tot += 22;
        }
        $(this).css({ height: tot + "px" });
    });

    $(".orangeContest").each(function() {
        var thh = $(this).parent().find("table thead tr").height();
        var trh = $(this).parent().find("tr.visibleTr").height();
        var tot = thh + trh + 5;

        //        if (/msie 9\.0/i.test(navigator.userAgent)) {
        //            tot += 15;
        //        }

        //        if (/msie 8\.0/i.test(navigator.userAgent)) {
        //            tot += 12;
        //        }

        if (/msie 7\.0/i.test(navigator.userAgent)) {
            tot += 22;
        }
        $(this).css({ height: tot + "px" });
    });



    /*CUSTOM*/

    //var toggleMinus = 'Assets/Images/attachIcon.gif'

    var toggleMinus = 'Assets/Images/minusNew.gif'

    var togglePlus = 'Assets/Images/plusNew.gif'

    var $subHead = $('table tbody tr td table tbody th:first-child p.item_news3')

    $subHead.prepend('<img src="' + togglePlus + '" alt="collapse this section" />')
        .parents('table tbody tr td table tbody tr').siblings().hide()

    $('img', $subHead).addClass('clickable')

.click(function() {

    var toggleSrc = $(this).attr('src')

    if (toggleSrc == toggleMinus) {
        $(this).attr('src', togglePlus)

        .parents('table tbody tr td table tbody tr').siblings().hide()
    }
    else {
        $(this).attr('src', toggleMinus)

        .parents('table tbody tr td table tbody tr').siblings().show()

    }

})

    /*END CUSTOM*/



    $('img', $subHead).addClass('clickable').click(function() {

        var table = $(this).parents(".vera");

        table.parent().find(".defaultContest").css({ height: table.height() + "px" });
    });


    $('img', $subHead).addClass('clickable').click(function() {

        var table = $(this).parents(".vera");

        table.parent().find(".redContest").css({ height: table.height() + "px" });
    });


    $('img', $subHead).addClass('clickable').click(function() {

        var table = $(this).parents(".vera");

        table.parent().find(".blueContest").css({ height: table.height() + "px" });
    });


    $('img', $subHead).addClass('clickable').click(function() {

        var table = $(this).parents(".vera");

        table.parent().find(".orangeContest").css({ height: table.height() + "px" });
    });


    //        $("img.clickable").toggle(
    //            function() {
    //                alert("click function called");
    //                var table = $(this).parents(".vera");
    //                
    //                table.parent().find(".defaultContest").css({ height: table.height() + "px" });

    //            }, 
    //            function() {
    //                alert('Second handler for .toggle() called.');
    //            }
    //        );

});




