// helper function for loading JS scripts
function staticLoadScript(url) {
    document.write('<script src="', url, '" type="text/javascript"><\/script>');
}
function staticLoadCss(url) {
    document.write('<link rel="stylesheet" href="',url,'" type="text/css" />');
}

// load ie6 message
window.addEvent('domready', function() {
	if (Browser.Engine.name == 'trident' && Browser.Engine.version <= 4) {
		var msg  = new Element('div', {'id':"msg-ie6", 'class':"notice"});
		msg.set('html', 'It appears as though you are trying to view this site using Internet Explorer 6. Internet Explorer 6 is unable to correctly render and display this site. You will need to either upgrade to <a href="http://microsoft.com/ie">Internet Explorer 8</a>  or install <a href="http://www.mozilla.com/firefox/">Firefox</a> to properly view this site.');
		msg.inject($(document.getElementsByTagName('body')[0]), "top");
	}
});

// load the tabs 
staticLoadScript("/js/tabs.js");
window.addEvent('domready', function() {	
	
	if ($('home-rankings')) {
		var home_articles_tabs = new Tabs(
			$('home-rankings').getElements('.tabs li'), 
			$('home-rankings').getElements('.top-10'), 
			{
				btn_active_class:'active'
			}
		);
	}
	
	if ($('home-articles')) {
		var home_articles_tabs = new Tabs(
			$('home-articles').getElements('.tabs li'), 
			$('home-articles').getElements('.cat-items'), 
			{
				btn_active_class:'active'
			}
		);
	}
	
});

// sub form
staticLoadScript("/js/quick-subform.js");
window.addEvent('domready', function() {	
	var subform_container = document.getElement('#right-column #email-signup-form');
	if (subform_container) {
		var subform = new QuickForm(subform_container);
	}
});

// autocomplete
staticLoadCss("/css/autocompleter.css");
staticLoadScript("/js/autocompleter.js");
staticLoadScript("/js/autocompleter.local.js");
staticLoadScript("/js/autocompleter.request.js");
staticLoadScript("/js/observer.js");

window.addEvent('domready', function() {	
	$$('input[name=hs_school]').each(function(elem){
		new Autocompleter.Request.JSON(elem, '/xhr/auto-hs-school', {
			'postVar': 'search',
			'minLength': 3,
			'delay': 400,
			'filterSubset': true,
			'overflow': true
		});
	});	
	
	$$('input[name=school]').each(function(elem){
		new Autocompleter.Request.JSON(elem, '/xhr/auto-college-school', {
			'postVar': 'search',
			'minLength': 3,
			'delay': 400,
			'filterSubset': true,
			'overflow': true
		});
	});	
	
	// get state list
	var jsonRequest = new Request.JSON({
		url: '/xhr/get-states', 
		onRequest: function() {},
		onComplete: function(states, text) {			
			if (states.length) {				
				$$('input[name=state]').each(function(elem){
					new Autocompleter.Local(elem, states, {
						'minLength': 1,
						'forceSelect': true,
						'selectMode': 'type-ahead',
						'width': '175px'
					});					
				});
			}		
		}
	}).get();
	
	
	// get conferences list
	var jsonRequest = new Request.JSON({
		url: '/xhr/get-conferences', 
		onRequest: function() {},
		onComplete: function(conferences, text) {			
			if (conferences.length) {				
				$$('input[name=conference]').each(function(elem){
					new Autocompleter.Local(elem, conferences, {
						'minLength': 1,
						'forceSelect': true,
						'selectMode': 'type-ahead'
					});					
				});
			}		
		}
	}).get();
});
