//display a linked tag to the "next" semester's classes in the header
//sunny walker, university of hawaii at hilo, 2007-11-27
function currentClasses() {
	var cct = document.getElementById('current_classes_link');
	var h = document.getElementById('header');
	if (h) {
		var l = h.offsetLeft+570, t = h.offsetTop+40; //240
		var d = new Date();
		var m = d.getMonth()+1, y = d.getFullYear();
		var i = '/images/tags/', a = '', r = y*100;
		if (m==1) {
			a = 'Spring '+y;
			r += 30;
		} else if (m>9) {
			a = 'Spring '+(y+1);
			r += 130;
		} else if (m>=4) {
			a = 'Fall '+y;
			r += 110;
		}
		i += r+'_classes.gif';
		a += ' classes';
		if (!cct) {
			//tag doe
			cct = document.createElement('a');
			cct.setAttribute('href','/classes_redirect.php?url=http://www.sis.hawaii.edu/uhdad/avail.classes%3Fi%3DHIL%26t%3D'+r+'');
			cct.setAttribute('id','current_classes_link');
			cct.setAttribute('class','noprint');
			cct.style.position='absolute';
			cct.style.borderWidth=0;
			cct.style.top=t+'px';
			cct.style.left=l+'px';
			cct.style.opacity=0.8;
			var img = document.createElement('img');
			img.setAttribute('src',i);
			img.setAttribute('alt',a);
			img.setAttribute('title',a);
			img.setAttribute('border',0);
			img.setAttribute('height',28);
			img.setAttribute('width',172);
			cct.appendChild(img);
			document.body.appendChild(cct);
		}
	}
}

// following DOM ready code by Dean Edwards/Matthias Miller/John Resig

function init() {
    // quit if this function has already been called
    if (arguments.callee.done) return;

    // flag this function so we don't do the same thing twice
    arguments.callee.done = true;

    // kill the timer
    if (_timer) clearInterval(_timer);

    // do stuff
	currentClasses();
};

/* for Mozilla/Opera9 */
if (document.addEventListener) {
    document.addEventListener('DOMContentLoaded', init, false);
}

/* for Internet Explorer */
/*@cc_on @*/
/*@if (@_win32)
    document.write("<script id=__ie_onload defer src=javascript:void(0)><\/script>");
    var script = document.getElementById("__ie_onload");
    script.onreadystatechange = function() {
        if (this.readyState == "complete") {
            init(); // call the onload handler
        }
    };
/*@end @*/

/* for Safari */
if (/WebKit/i.test(navigator.userAgent)) { // sniff
    var _timer = setInterval(function() {
        if (/loaded|complete/.test(document.readyState)) {
            init(); // call the onload handler
        }
    }, 10);
}

/* for other browsers */
window.onload = init;