/*
 * Menu according
 */
function initMenu() {
    $('.sidebar ul ul').hide();
    $('.sidebar li a').click(function() {
            var checkElement = $(this).next();
            if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
                return false;
            }
            if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
                $('.sidebar ul ul:visible').slideUp('slow');
                $('.sidebar ul ul').removeClass("active");
                $('.sidebar li').removeClass("active-li");
                checkElement.slideDown('slow');
                checkElement.addClass("active");
                checkElement.parent().addClass('active-li');
                return false;
            }
        });
}
$(document).ready(function() {
    initMenu();
});


/*
 * "Colums-Content"
 */
$.fn.columContent = function(options) {
        var options = $.extend({
            parrent_el: 'div.container-entry',
            el: 'div.container-entry >*'
        },options);

        var y_coord = 0;
        var x_coord = 0;
        var wrap_div = 210;
        var width_sum = 0;
        var height_container = parseInt($(options['parrent_el']).height());
        var width_el = parseInt($(options['el']).css('width'));
        var padding_l_el = parseInt($(options['el']).css('padding-left'));
        var padding_r_el = parseInt($(options['el']).css('padding-right'));
   
        var shift = parseInt(width_el + padding_l_el + padding_r_el + 1);
	var difference = 0;


        $(options['el']).css('position','absolute');


        $(options['el']).each(function(){
            var height = parseInt($(this).height());
            var padding_bottom = parseInt($(this).css('padding-bottom'));
            var padding_top = parseInt($(this).css('padding-top'));
            var height_sum = parseInt(y_coord + height + padding_top);

            if( height_container < height_sum ) {
                x_coord = x_coord + shift;
                y_coord = 0;
                width_sum = width_sum + shift;
            }

            if(y_coord == 0){
                $(this).css('padding-top', 0);
                padding_top = 0;
            }

            $(this).css({
                top:y_coord,
                left:x_coord
            });

            y_coord = parseInt(y_coord + height + padding_bottom + padding_top);
        });

        difference = wrap_div - width_sum - shift;

};

$(document).ready(function(){
    $('div.container-entry').columContent();
});

