﻿$(document).ready(function(){
    // Tick the medium (index 2) on each panel. Also (just in case) untick them all first.
    $("div.AspNet-CheckBoxList").each(function(){
        $(this).children("ul.AspNet-CheckBoxList-RepeatDirection-Vertical").each(function(){
            $(this).children("li.AspNet-CheckBoxList-Item").each(function(){ 
                $(this).children("input").each(function(){
                    $(this).attr('checked', false); 
                });
            });
            $($(this).children("li.AspNet-CheckBoxList-Item")[1]).children("input").attr('checked', true);
        });
    });
    
    // Set each 'out of stock' element to reflect that status...
    $("div.AspNet-CheckBoxList").each(function(){
        $(this).children("ul.AspNet-CheckBoxList-RepeatDirection-Vertical").each(function(){
            $(this).children("li.AspNet-CheckBoxList-Disabled").each(function(){ 
                $(this).children("label").each(function(){
                    $(this).html($(this).text() + "&nbsp;&nbsp;<img src=\"../App_Themes/trionz/images/red-q.gif\" title=\"Sorry, this product is out of stock\" />"); 
                });
            });
        });
    });

    // Make an event for each checkbox...
    $("li.AspNet-CheckBoxList-Item").click(function(){  
        var index = $(this).index();
        
        $($(this).closest('ul')).children("li.AspNet-CheckBoxList-Item").each(function(){
            $(this).children("input").attr('checked', false);
        });
        $($($(this).closest('div.AspNet-CheckBoxList')).children("ul.AspNet-CheckBoxList-RepeatDirection-Vertical").children("li.AspNet-CheckBoxList-Item")[index]).children("input").attr('checked', true);
    });

});
