﻿$().ready(function() {
    // simple accordion
    $('#list1a').accordion();
    $('#list1b').accordion({
        autoheight: false
    });

    // second simple accordion with special markup
    $('#navigation').accordion({
        active: false,
        header: '.head',
        navigation: true,
        event: 'mouseover',
        fillSpace: true,
        animated: 'easeslide'
    });

    // highly customized accordion
    $('#list2').accordion({
        event: 'mouseover',
        active: '.selected',
        selectedClass: 'active',
        animated: "bounceslide",
        header: "dt"
    }).bind("change.ui-accordion", function(event, ui) {
        $('<div>' + ui.oldHeader.text() + ' hidden, ' + ui.newHeader.text() + ' shown</div>').appendTo('#log');
    });

    // first simple accordion with special markup
    $('#list3').accordion({
        header: 'div.title',
        active: false,
        alwaysOpen: false,
        animated: false,
        autoheight: false
    });

    var wizard = $("#wizard").accordion({
        header: '.title',
        event: false
    });

    var wizardButtons = $([]);
    $("div.title", wizard).each(function(index) {
        wizardButtons = wizardButtons.add($(this)
			.next()
			.children(":button")
			.filter(".next, .previous")
			.click(function() {
			    wizard.accordion("activate", index + ($(this).is(".next") ? 1 : -1))
			}));
    });

    // bind to change event of select to control first and seconds accordion
    // similar to tab's plugin triggerTab(), without an extra method
    var accordions = $('#list1a, #list1b, #list2, #list3, #navigation, #wizard');

    $('#switch select').change(function() {
        accordions.accordion("activate", this.selectedIndex - 1);
    });
    $('#close').click(function() {
        accordions.accordion("activate", -1);
    });
    $('#switch2').change(function() {
        accordions.accordion("activate", this.value);
    });
    $('#enable').click(function() {
        accordions.accordion("enable");
    });
    $('#disable').click(function() {
        accordions.accordion("disable");
    });
    $('#remove').click(function() {
        accordions.accordion("destroy");
        wizardButtons.unbind("click");
    });
});