/**
 * Main app
 */

/**
 * Set the scroller on the thumbnails and images list
 */
var setScroller = function() {
    setScrollerForContent();
    // vertical categories scroller
    $('#mainContent .sections .thumbs').jScrollPane();
    $('#mainContent .sections .jspVerticalBar').css({'display':'none'});

    // attach events to up/down buttons
    var verticalScrollApi = $('#mainContent .sections .thumbs').data('jsp');
    $('#mainContent .sections .downButton').bind('click',function(){
        verticalScrollApi.scrollByY(444, true);
        return false;
    });
    $('#mainContent .sections .upButton').bind('click',function(){
        verticalScrollApi.scrollByY(-444, true);
        return false;
    });
}

var setScrollerForContent = function() {
    // main content scroller
    $('#mainContent .contentWrapper').css('width',$('body').width() - 218)
                                     .jScrollPane();
    $('#mainContent .contentWrapper .jspDrag').css({
        'height'    : '14px',
        'margin-top': '3px'
    });
}

/*
 * Get a category content and display it
 */
var getCategoryContent = function(id) {
    $.get("/categorycontent/id/" + id +"/format/json/", function(response){
        if (response.data.status == "success") {
            // inject it
            $("#categoryContent").html(response.data.html);
            setScrollerForContent();
            // fade out all the others
            $('.sections .thumbs img').each(function(index, item){
                if ($(item).attr('class') != 'category_' + id) {
                    $(item).css('opacity',0.5);
                } else {
                    $(item).css('opacity',1);
                }
            });
        }
    });
    return false;
}


$(document).ready(function(){
    // set the main content to be in the middle
    var aValue = ($(window).height() / 2) - 300;
    if (aValue < 130) {
        aValue = 140;
    }
    $('#mainContent').css({'margin-top':aValue});
    // set scrollers
    setScroller();
    // fade out categories
    $('.sections .thumbs img').each(function(index, item){
        if (index > 0) {
            $(item).css('opacity',0.5);
        }
    });
});
