$.playception = {
    init: function()
    {

    },
    dynamicView: {
        switchViewMode: function(view, mode)
        {
            var $view = $(view);
            
            if($view.hasClass(mode)) return;
            
            $('.icon.current').removeClass('current');
            $('.' + mode).addClass('current');
            if(mode == 'grid')
            {
                $view.find('div.news-item-introduction').hide().delay(700).css('width', '375').slideDown(200);
                $view.find('div.news-item').animate({ width: '375', marginLeft: '4', marginRight: '4', marginTop: '4', marginBottom: '4' }, 400);
                $view.find('div.news-info, img.news-thumb').animate({ width: '375' }, 400);
                $view.find('div.info-box').animate({ width: '363' }, 400);
            }
            else if(mode == 'list')
            {
                $view.find('div.news-item-introduction').hide().delay(500).css('width', '508').fadeIn(200);
                $view.find('div.news-info, img.news-thumb').animate({ width: '250' }, 400);
                $view.find('div.news-item').animate({ width: '759',  marginLeft: '4', marginRight: '4', marginTop: '4', marginBottom: '4' }, 400);
                $view.find('div.info-box').animate({ width: '238' }, 400);
            }
            $view.delay(1000).removeClass(mode == 'grid' ? 'list' : 'grid').addClass(mode); // choppy bug
            $.cookie("view_mode", mode);
        }
    }
};
/*
 * Other events
 */
$(function()
{
    // News request
    $('div.dynamic-view div.controls div.categories > a').click(function()
    {
        // Variables
        var $e = $(this);
        var $id = $e.attr("id");
        var $view = $e.closest('div.dynamic-view');
        
        // Load and do animation
        $.get('/news.php', { category: $id}, function(data)
        {
            if(data.length <= 1) return; // if data is not an error code
            // Fade out and remove news items
            $('div.news-item', $view).fadeOut(400, function()
            {
                $(this).remove();
            });
            
            // Apend new *hidden* news items to the view and fade in
            $view.append($(data).hide().delay(400).fadeIn(400));
        });
        
        // Change current
        $('div.dynamic-view div.controls div.categories > a.current').removeClass('current');
        $e.addClass('current');
        
        // Set cookie
        $.cookie("view_category", $id);
    });
});
