
var isOpen = false
var lastID = null;
var orgItemHeight = 0;
var orgInhoudHeight = 0;

function openFancyContent(agendaID){
    if(isOpen){
        closeFancyContent(lastID);
        setTimeout("openFancyContent("+agendaID+");", 2000);
        return;
    }
        
    lastID = agendaID;
    orgInhoudHeight = $("#inhoud_"+agendaID).height();
    orgItemHeight = $("#agendaItem_"+agendaID).height();
    
    var newHeight = 0;
    if(orgItemHeight < orgInhoudHeight){
        newHeight = orgInhoudHeight - orgItemHeight;
    }
    newHeight += orgItemHeight + 30;
    $("#innerInhoud_"+agendaID).css('display',"none", 'padding-top',"20px");
    $("#openbtn_"+agendaID).fadeOut(250, function(){
    $("#agendaItem_"+agendaID).animate({height:newHeight+"px"}, 500, function(){
        $("#inhoud_"+agendaID).css({width:"0", height:"3px", display:"block"});
        $("#inhoud_"+agendaID).animate({width:"500px"}, 500, function(){
                $(this).animate({height:orgInhoudHeight+"px"}, 500, function(){
                    $("#innerInhoud_"+agendaID).fadeIn(250);
                    $("#closeBtn_"+agendaID).fadeIn(250);
                    isOpen = true;
                });
        });
    });
    
    
    });
}

function closeFancyContent(agendaID){
    $("#closeBtn_"+agendaID).fadeOut(250, function(){
        
        
        $("#inhoud_"+agendaID).animate({height:"3px"}, 500, function(){
            $(this).animate({width:"1px"}, 500, function(){
                $("#agendaItem_"+agendaID).animate({height:orgItemHeight+"px"});
                $(this).hide(0)
                        .css({height:orgInhoudHeight+"px"});
                $("#openbtn_"+agendaID).fadeIn(500)
                isOpen = false;
            })
        })
    });
}

function toggleWijnContent(wijnID)
{
    if(isOpen && lastID == wijnID)
    {
        closeWijnContent(wijnID);
    }else{
        openWijnContent(wijnID);
    }
}

function openWijnContent(wijnID){
    if(isOpen){
        closeWijnContent(lastID);
        setTimeout("openWijnContent("+wijnID+");", 2000);
        return;
    }
    wijnElement = $("#wijn_"+wijnID);   
    lastID = wijnID;
    orgInhoudHeight = wijnElement.children(".prijzen").height();
    orgItemHeight = wijnElement.height();
    
    var newHeight = 0;
    if(orgItemHeight < orgInhoudHeight){
        newHeight = orgInhoudHeight - orgItemHeight;
    }
    newHeight += orgItemHeight + 25;
    newButtonTop = newHeight / 2 + 12;
    
    wijnElement.children(".prijzen").children(".innerContent").css('display',"none", 'padding-top',"20px", 'margin-left',"20px");
    wijnElement.animate({height:newHeight+"px"}, 500, function(){
        wijnElement.children(".prijzen").css({width:"0", height:"3px", display:"block"});
        wijnElement.children(".prijzen").animate({width:"500px"}, 500, function(){
                wijnElement.children(".button").animate({top:newButtonTop+"px"}, 500);
                $(this).animate({height:orgInhoudHeight+"px"}, 500, function(){
                    $(this).children(".innerContent").fadeIn(250);
                    isOpen = true;
                })
        });
    });
}
function closeWijnContent(wijnID){
    wijnElement = $("#wijn_"+wijnID);   
    prijzenElement = wijnElement.children(".prijzen");
    buttonElement = wijnElement.children(".button");
    innerContent = prijzenElement.children(".innerContent");
    
    oldButtonTop = orgItemHeight / 2;

    innerContent.fadeOut(250, function(){
       buttonElement.animate({top:oldButtonTop+"px"}, 500);
       prijzenElement.animate({height:"3px"}, 500, function(){
        $(this).animate({width:"0px"}, function(){
            wijnElement.animate({height:orgItemHeight+"px"}, 500);
            $(this).css('height',orgInhoudHeight+"px", 'block',"none");
            isOpen = false;
        })
       }) 
    });
    
    
}
