

/**
 * 
 * Functions
 * 
 * 
 */

var moopop = {
    width: 400,
    height: 400,
    
	captureByRel: function(attrVal, parent){
        this.capture((parent || document).getElements('a[rel*=' + (attrVal || 'popup') + ']'));
    },
    
    capture: function(el, width, height){
        if ($defined(width) && $defined(height)) {
            this.width = width;
            this.height = height;
        }
        
        switch ($type(el)) {
            case 'string':
                el = $$(el);
            case 'element':
            case 'array':
                $splat(el).each(this.add_pop_to, this);
        }
        
        this.width = null;
        this.height = null;
    },
    
	add_pop_to: function(el){
        el.addEvent('click', function(e){
            e.stop();
            this.popup(el);
        }.bind(this));
        
        var size = el.get('rel').match(/\[(\d+),?\s*(\d+)/) || ['', this.width, this.height];
        var resizable = el.get('rel').match(/,(r)/) || [];
		
		var chasm = screen.availWidth;
		var mount = screen.availHeight;
		var attribs = 'toolbar=no,location=no,directories=no,scrollbars=yes,' 
			+ 'width='+size[1]+',height='+size[2]+',left=' 
			+ ((chasm - size[1] - 10) * .5) + ',top=' + ((mount - size[2] - 30) * .5 ) 			
			+ ',status=no,menubar=no';
			+ (resizable[1] ? ',resizable=yes' : ',resizable=no');

        
        if (size[1]) 
            el.store('popupprops', attribs);
    },
    
	popup: function(el){
        window.open(el.get('href'), el.get('name') || 'popup', el.retrieve('popupprops') || '');
    }
};

sfHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
//if (window.attachEvent) window.attachEvent("onload", sfHover);

window.addEvent('domready', function(){
	var menu = new Openmoomenu('#nav ul', {
		delay: 0,
		animate: {
			props: ['width', 'height'],
			options: {
				duration: 400,
				fps: 100,
				transition: 'expo:out'
			}
		}
	});
	/* process all links with rel="popup" by default. */
	window.addEvent('domready', function () {
		moopop.captureByRel('popup');
	});
});	

