/*
 * carousel
 */
 
function setChoice(value) {
    $.ajax({
        async: false,
        cache: false,
        data: {
            action: "chooseitem",
            itemvalue: value
        },
        dataType: "json",
        success: function(response, textStatus, jqXHR) {
            if(response.result) {
                document.location.href = response.data.urllocation;
            }
        },
        url: "/?format=json"
    });
}

$(document).ready(function(){

    var start = 1;
    var item_total = $("input[name=item]").size();
    
    if(chosen_item > 0) {
    
        var $choosen = $("#page_inschrijven input[value="+chosen_item+"]");
        
        var index = $("#carousel input").index($choosen);
        
        $choosen.attr("checked", "checked");
        
        if(index > 5) {
            start = item_total - index + 6;
        }
        
    }
    
    $("#carousel").tinycarousel({
        start: start,
        display: 1,
        axis: "x",
        controls: true,
        duration: 300
    });
    
    /*
    $(".item img").click(function(){
        $(this).next().find("input").click();
    });
    
    $(".item input").click(function(){
        $("li.item img.selected").removeClass("selected");
        $(this).parent().prev().addClass("selected");
    });
    
    $(".item input:first").attr("checked", "checked");
    */
    
    $("#carousel img").attr("draggable", false).mousedown(function(e){
        e.preventDefault();
        return false;
    });
    
    $("#page_home input[name=item]").change(function(e){
        var value = $("input:checked").val();
        setChoice(value);
    });
    
});
