window.addEvent('domready', function(){
	$$('.top-nav-box .top-navigation-content').each(function(el){
        if (el.hasClass('selected')){
            return;
        }
        el.set('morph',{
            duration:200
        });
        el.addEvents({
                mouseenter: function(){
                    this.morph({
                        'background-position': '0px 0px'
                    });
                },
                mouseleave: function(){
                    //alert(position);
                    this.morph({
                        'background-position': '0px 20px'
                    });
                }
            });        
    });
    Galleries.start();
    fitColHeight();
    var scanPage = function() {
        $$("a").filter(function(el) {
            return el.rel && el.rel.test(/^lightbox/i);
        }).slimbox({/* Put custom options here */}, null, function(el) {
            return (this == el) || ((this.rel.length > 8) && (this.rel == el.rel));
        });
    };
    if (!/android|iphone|ipod|series60|symbian|windows ce|blackberry/i.test(navigator.userAgent)) {
        scanPage();
    }
});

function fitColHeight() {
    var cols = $$('#col1','#col2','#col3');
    var height = 0;
    cols.each(function(col){
        var el = $(col);
        height = Math.max(height, el.clientHeight, el.offsetHeight);
    });
    if (!height){
        return;
    }
    cols.each(function(col){
        var h, id = col.get('id');
        if (id == 'col3') return;
        if (['col1','col2'].contains(id)){
            h = (height+15)+'px';
        }
        else {
            h = (height)+'px';
        }
        col.setStyle('height',h);
    });
};
var Galleries = {
    start: function() {
        $$('.mooflow').each(function(gallery){
            Galleries.init(gallery)
        });   
    },
    init: function(container){

        var mf = new MooFlow($(container), {
            startIndex: 5,
            useSlider: true,
            useAutoPlay: true,
            useCaption: true,
            useResize: true,
            useMouseWheel: true,
            useKeyInput: true,
            useViewer:true,
            onClickView: function(obj){
                var img = new Element('img',{src:obj.src, title:obj.title, alt:obj.alt, styles:obj.coords}).setStyles({'position':'absolute','border':'none'});
                var title = (obj.title || '')+(obj.title && obj.alt ? ' - ' : '')+(obj.alt || '');
                var link = new Element('a',{'class':'remooz-element','href':obj.href,'title':title, styles:{'border':'none'}});
                $(document.body).adopt(link.adopt(img));
                var remooz = new ReMooz(link, {
                    centered: true,
                    resizeFactor: 0.8,
                    origin: link.getElement('img'),
                    onCloseEnd: function(){link.destroy()}
                });
                remooz.open();
            }
        });
        
    }
    
};


