
dojo.require("dojo.lang.declare");
dojo.declare('navbar', null, {
	button: null,
	dir: null,
	adrect: null,
	hidetime: 700,
	hidden: true,
	
	init: function() {
		this.button = dojo.byId('directory_button');
		this.dir = dojo.byId('site_directory');
		this.adrect = dojo.html.getElementsByClass('ad_mrect')[0];
		if(!this.button || !this.dir) return;
		dojo.event.connect(this.button, 'onmouseover', dojo.lang.hitch(this, 'handler_button'));
		dojo.event.connect(this.dir, 'onmouseover', dojo.lang.hitch(this, 'handler_button'));
		dojo.event.connect(this.button, 'onmouseout', dojo.lang.hitch(this, 'handler_out'));
		dojo.event.connect(this.dir, 'onmouseout', dojo.lang.hitch(this, 'handler_out'));
		dojo.html.setShowing(this.dir, false);
		this.dir.style.right = '0';
	},

	handler_button: function(e) {
		this.show_dir();
		this.hidden = false;
	},

	handler_out: function(e) {
		if(dojo.html.isShowing(this.dir)) {
			if(e.currentTarget == this.button.id || !dojo.dom.isDescendantOf(e.relatedTarget, this.dir)) {
				this.hidden = true;
				this.count_hide();
			}
		}
	},

	/* hide via positioning because of safari weirdness */
	hide_dir: function() { if(this.hidden) dojo.html.hide(this.dir), this.adrect.style.right = '0'; },
	show_dir: function() { dojo.html.show(this.dir), this.adrect.style.right = '7000px'; },
	count_hide: function() { dojo.lang.setTimeout(dojo.lang.hitch(this, 'hide_dir'), this.hidetime); }
});

dojo.declare('adloader', null, {
	iframes: null,

	load_all: function() {
		this.iframes = dojo.html.getElementsByClass('adframe');
		for(i = 0; i < this.iframes.length; i++) {
			iframe = this.iframes[i];
			if(m = iframe.className.match(/adzone(\d+)/)) {
				iframe.zone_id = m[1];
				iframe.src = '/include/ads/r.php?z=' + iframe.zone_id;
			}
		}
	},

	make_frame: function(zone, w, h) {
		document.write('<iframe frameborder="no" scrolling="no" width="' + w + '" height="' + h + '" class="adframe adzone' + zone + '"></iframe>');
	}
});
dojo.event.connect('after', window, 'onload', function() {
	al = new adloader;
	al.load_all();
});

dojo.addOnLoad( function() {
	var pt = dojo.byId('promo_top');
	if(!pt) return;
	var h2 = pt.getElementsByTagName('h2')[0];
	if(dojo.dom.textContent(h2).length > 75) h2.style.fontSize = '18px';
});


