$(document).ready(function() {
    
    /* Videos */
    $('#mmpr-video-slider').easySlider({
        auto: false,
        continuous: true,
        nextId: "mmpr-video-slider-next",
        prevId: "mmpr-video-slider-prev"
    });
    
    $('#mmpr-video-slider a').bind('click', function (event) {
        var target = $(this),
            listItem = target.closest('li'),
            embedCode = listItem.find('.embed').html(),
            modal = $('#mmpr-video-lb');
            
        modal.find('#mmprlb-vidcontent').html(embedCode);
        $.fn.colorbox({width: '598px', inline: true, href: '#mmpr-video-lb'});
        
        return false;
    });
    
    /* Wallpaper */
    $('#mmpr-wallpaper-slider').easySlider({
        auto: false,
        continuous: true,
        nextId: "mmpr-wallpaper-slider-next",
        prevId: "mmpr-wallpaper-slider-prev"
    });
    
    $('#wallpaper-size').change(function (event) {
        var selector = $(this),
            size = $(this).find(':selected').val(),
            currentLocation = window.location.pathname,
            wallpaperLocation = null,
            wallpaperPopup = null,
            wallpaperIndex = $('#mmpr-wallpaper-slider').data('current'),
            wallpaper = $('#mmpr-wallpaper-slider').find('li img:eq(' + wallpaperIndex + ')'),
            wallpaperId = wallpaper.attr('id').match(/^wallpaper-([\d]+)$/)[1];
        
        if (!size) { return; }
        
        if (currentLocation.substr(-1, 1) != '/') {
            currentLocation += '/';
        }
        wallpaperLocation = currentLocation + 'wallpaper/?' + $.param({
            'id': wallpaperId,
            'size': size
        });
        
        wallpaperPopup = window.open(wallpaperLocation, '_blank');
        wallpaperPopup.focus();
    });
    
    /* Avatars */
    $('#mmpr-avatars-slider').easySlider({
        auto: false,
        continuous: true,
        nextId: "mmpr-avatars-slider-next",
        prevId: "mmpr-avatars-slider-prev"
    });
    
});