$(document).ready(function () {
    $('.tracks').tinyscrollbar();
    $('.tileCallouts .lifeStyleContainer').tsort('', { order: 'rand' });
    $('.heroContainer').tsort('', { order: 'rand' });
    $('.visionContainer').tsort('', { order: 'rand' });
    $('.productContainer').tsort('', { order: 'rand' });

    $('.homepageRight').fadeIn();
    $('.homepageLeft').fadeIn();

    if ($('.newsContent')) {
        $('.newsContent .blogEntry .blogContent div').attr('style', '');
        initNews($('.newsContent'));
    }
    if ($('.mp3Player')) {
        $('.player .currentlyPlaying:first-child').addClass('activeTrack');
        initPlayer($('.mp3Player'));
    }
       
});

function initNews(news) {
    $('.olderPosts .oldPost').click(function () {
        var neededIndex = '#' + $(this).attr('id');

        $('.postContent .activeNews').fadeOut('fast', function () {
            $(this).removeClass('activeNews');
            $('.postContent').children(neededIndex).fadeIn('fast', function () {
                $(this).addClass('activeNews');
            });
        });  
    });
}

function initPlayer(player) {
    $('.singletrack').click(function () {
        window.location.href = "/CoreSoundSystem/" + $(this).attr('id');
        return;
        var neededIndex = '#' + $(this).attr('id');
        $('.player .activeTrack').fadeOut('fast', function () {
            $('.player .activeTrack').removeClass('activeTrack');
            $('.player').find(neededIndex).fadeIn('fast', function () {
                $('.player').find(neededIndex).addClass('activeTrack');
            });
        });
    });
}

$('.tileCallouts .lifeStyleContainer').hover(
    function () {
        $(this).children('.filter').css('opacity', 0.5);
        $(this).children('.filter').fadeIn();
    },
    function () {
        $(this).children('.filter').fadeOut();
    }
);


