﻿window.addEvent('domready', function() {
	initTabs();
	initLibGuides();
});
function initTabs() {
	$$('div#tabMenu a').each(function(el) {
		el.addEvent('click',function(e) {
			var ev = new Event(e).stop();
			tabState(el);
		});
	});
}

function tabState(ael) {
	$$('div#tabMenu a').each(function(el) {
		if(el.hasClass('active')) {
			el.removeClass('active');
		}
	});
	ael.addClass('active');
	$$('#searchContent div.tabContent').each(function(el) {
		if(el.hasClass('active')) {
			el.removeClass('active');
		}
	});
	var acu = ael.getProperty('href');
	var ac = acu.replace(/#/,'');
	$(ac).addClass('active');
}

function initLibGuides()
{
    var s = $('subjects');
    var sel = document.getElementById('selSubjects');

    if (s)
    {
    var links = s.getElements('a');
    links.each(function(link){
        //  alert(link.get('text') + ': ' + link.get('href'));
        // sel.inject(new Element('option', {value : link.get('href'), text : link.get('text')}));
        sel.options[sel.options.length] = new Option(link.get('text'), link.get('href').replace('browse.php','cat.php'));
    });
    }
    var g = $('getGuides');
    var gSel = document.getElementById('selGuides');
    if (g)
    {
        var links = g.getElements('a');
        links.each(function(link){
        gSel.options[gSel.options.length] = new Option(link.get('text'), link.get('href'));
        });
    }
}

function openPage(s)
     {
        window.open(s.value,"newWin");
     }