var MovingBoxBehavior = Class.create();
MovingBoxBehavior.Load = function() {
    OS.RegisterBehaviour(MovingBoxBehavior.Rules);
}

//MovingBoxBehavior.Gallery = null;
MovingBoxBehavior.Rules = {
    '.movingView': function(element) {
        //Element.forceRerendering(element);
    },
    '.movingView>.content': function(element) {
        Element.show('Gallery_Albums');
        Element.identify(element);
        var oGallery = new MovingViewModel(element, MovingViewModel.Type.Box);
        Element.setStyle(element, { float: 'none' });
        element.select('.item').each(function(item) {
            Element.setStyle(item, { float: 'none' });
            if (Element.hasClassName('Body', 'viewGallery')) {

                //The following allows moving box behavior                
                Event.observe(item, 'mouseover', function() {
                    if (oGallery.currentItemId == item.id) return;
                    MovingBoxBehavior.LoadGalleryItem(oGallery, item.id);
                });
                Event.observe(item, 'click', function() {
                    //if (Element.hasClassName(item, 'active')) return;
                    MovingBoxBehavior.LoadGalleryItem(oGallery, item.id);
                });
                var eCancel = item.down('.cmdClose');
                if (eCancel) Event.observe(eCancel, 'click', function() {
                    setTimeout(function() {
                        MovingBoxBehavior.LoadGalleryItem(oGallery, item.id);
                    }, 50);
                });
            } else {
                Event.observe(item, 'click', function() {
                    oGallery.reset();
                    oGallery.update(item.id);
                });
            }
        });
    }
}
MovingBoxBehavior.LoadGalleryItem = function(gallery, itemId) {
    gallery.reset();
    gallery.update(itemId);
}
MovingBoxBehavior.Load();
