$(document).ready(function(){
    $('a.mmi').each(function(){
        var $mi = $(this);
        $mi.on('click', function(ev){
            ev.preventDefault();
            var ax = $mi.data('rel').split("|");
            var axmc = ax[0];
            var axim = ax[1];
            var axurl = "index.php";
            $.ajax({
                url: axurl,
                data: {media_ajax:'1',mc:axmc,im:axim, req:'images', module_page:'im_cinemas'},
                type: 'POST',
                cache: false,
                dataType: 'json',
                success: function(data){
                    var group = data['group'];
                    var pos = data['pos'];
                    var gallery = [];
                    for(var i=0; i<data['media'].length; i++) {
                        var media = data['media'][i];

                        var json = {
                            href: media.url,
                            title: media.title
                        };

                        gallery.push(json);
                    }

                    $.swipebox(gallery, {
                        beforeOpen: function() {
                            $('#header').addClass('hidden');
                        },
                        afterClose: function() {
                            $('#header').removeClass('hidden');
                        }
                    });
                }
            });
            return false;
        });
    });

    $('a.mmv').each(function(){
        var $trailer = $(this);
        $trailer.on('click', function(ev){
            ev.preventDefault();


            var axmc = $trailer.data('rel');
            var axurl = baseurl + '/';
            $.ajax({
                url: axurl,
                data: {media_ajax:'1',mc:axmc,req:'trailers', module_page:'im_cinemas'},
                type: 'POST',
                cache: false,
                dataType: 'json',
                success: function(data){
                    var group = data['group'];
                    var trailers = [];

                    var images = [];
                    var titles = [];
                    var descs = [];
                    for(var i=0; i<data['media'].length; i++) {
                        var media = data['media'][i];

                        trailers.push({
                            href: media.url,
                            title: media.title
                        });
                    }

                    $.swipebox(trailers, {
                        beforeOpen: function() {
                            $('#header').addClass('hidden');
                        },
                        afterClose: function() {
                            $('#header').removeClass('hidden');
                        }
                    });
                }
            });

            return false;
        });
    });

});
