jQuery(document).ready(function () {

    jQuery(".toggle-element").click(function () {
        var switchID = jQuery(this).attr("id");
        if (jQuery("#" + switchID + "-content").hasClass("hide") || jQuery("#" + switchID + "-content").attr("style").indexOf("none;") != -1) {
            jQuery("#" + switchID + "-content").slideDown("slow");
            jQuery("#" + switchID + "-content").removeClass("hide");
            jQuery("#" + switchID).toggleClass("onClickLinkOff");
            jQuery("#" + switchID).toggleClass("onClickLinkOn");
        }
        else {
            jQuery("#" + switchID + "-content").slideUp("slow");
            jQuery("#" + switchID).toggleClass("onClickLinkOff");
            jQuery("#" + switchID).toggleClass("onClickLinkOn");
        }
    });

    jQuery(".small-preview").each(function () {
        var itemWidth = parseInt(jQuery(this).attr("width"));
        var itemHeight = parseInt(jQuery(this).attr("height"));

        var smallItemWidth = parseInt(itemWidth * 0.25);
        var smallItemHeight = parseInt(itemHeight * 0.25);

        jQuery(this).attr("width", smallItemWidth);
        jQuery(this).attr("height", smallItemHeight);

    });

    jQuery(".small-preview").click(function () {

        var itemWidth = parseInt(jQuery(this).attr("width"));
        var itemHeight = parseInt(jQuery(this).attr("height"));

        if (jQuery(this).hasClass("big-picture")) {

            var smallItemWidth = parseInt(itemWidth * 0.25);
            var smallItemHeight = parseInt(itemHeight * 0.25);

            jQuery(this).attr("width", smallItemWidth);
            jQuery(this).attr("height", smallItemHeight);

            jQuery(this).removeClass("big-picture");
        }
        else {

            var bigItemWidth = parseInt(itemWidth * 4);
            var bigItemHeight = parseInt(itemHeight * 4);

            jQuery(this).attr("width", bigItemWidth);
            jQuery(this).attr("height", bigItemHeight);

            jQuery(this).addClass("big-picture");
        }
    });

    jQuery(".colorbox").colorbox();

    jQuery("#search-input").autocomplete({source:availableTags});
    jQuery("#search-input").autocomplete({select:function (event, ui) {
        jQuery("#searchform").submit();
    }    });

    jQuery('.js-tr-expand-trigger').each(function () {
        if (!jQuery(this).next('tr').hasClass('js-tr-expand-trigger')) {
            if (!jQuery(this).children('td').hasClass('week-indicator-active')) {
                jQuery(this).next('tr').css('display', 'none');
            }
        }
    });

    jQuery('.js-tr-expand-trigger').click(function () {
        if (jQuery(this).children('td').hasClass('week-indicator')) {
            jQuery(this).children('td').removeClass('week-indicator').addClass('week-indicator-active');
            jQuery(this).next('tr').show();
        } else {
            jQuery(this).children('td').removeClass('week-indicator-active').addClass('week-indicator');
            jQuery(this).next('tr').hide();
        }
    });

});

