var Site = {
	
	
	start: function(){
		MooTools.lang.setLanguage("en-US");
		
		Site.attachPageActions();
		
		if ($('username'))
			$('username').focus();

	},
	attachPageActions: function(){

		// Launch-in-new-window links automagically created
		var extLinks = $$('a.external');
		if ( extLinks.length ) {
			extLinks.each(function(elem, idx) { 
				elem.setProperty('target', '_blank');
			});
		}
		
		
		// Safari Suckerfish 'fix'
		if ( navigator.appVersion.toLowerCase().indexOf('safari') != -1 ) {
			$$('#navigation li a').each(function(elem, idx) {
				elem.set('title', '');
			});
		}
		
		if ( $('text_smaller_link') ) {
			$('text_smaller_link').addEvent('click', function() {
				scaleDown();
				return false;
			});
		}
		if ( $('text_bigger_link') ) {
			$('text_bigger_link').addEvent('click', function() {
				scaleUp();
				return false;
			});
		}
		
		if ($$('.forgot_password')[0]) {
			$$('.forgot_password').each(function(elem, idx) {
				elem.href += "&rtemplate=8?height=300&width=400";
			});
		}
		
		
		// Form validation automagic
		var valForms = $$('form.validate-form');
		if ( valForms.length ) {
			valForms.each(function(elem, idx) { 
				new FormValidator.Inline(elem, {
					onFormValidate: Site.formHandler
				});
			});
		}
		
		if ( $('query') ) {
			$('query').addEvent('focus', function() {
				if ($('query').value == 'Search') {
					$('query').value = '';
				}
			});
			$('query').addEvent('blur', function() {
				if ($('query').value == '') {
					$('query').value = 'Search';
				}
			});
		}
		
		if ( $('accordion') ) {
			
			//create our Accordion instance
			var myAccordion = new Accordion($('accordion'), 'h3.toggler', 'div.element', {
				alwaysHide: true,
				display: -1,
				opacity: false,

				onActive: function(toggler, element){
					toggler.addClass('toggler_active');
				},
				onBackground: function(toggler, element){
					toggler.removeClass('toggler_active');
				}
			});
			
			// Change the cursor to a hand-pointer
			$$('h3.toggler').each(function(elem, idx) {
				elem.addEvent('mouseenter', function() {
					this.style.cursor = 'pointer';
				});
			});
		}
		
		// Adding bookmarks
		if ( $('bookmark_link') ) {
			
			if (window.opera) {
				$('bookmark_link').rel = 'sidebar'; // this makes it work in Opera 7+
				$('bookmark_link').title = "Bookmark: " + document.title;
				$('bookmark_link').href = $('bookmark_link').href.substring(0, $('bookmark_link').href.indexOf("#"));
			} else {
				$('bookmark_link').addEvent('click', function() {
					var ua = navigator.userAgent.toLowerCase();
					var isKonq = (ua.indexOf('konqueror') != -1);
					var isSafari = (ua.indexOf('webkit') != -1);
					var isMac = (ua.indexOf('mac') != -1);
					var buttonStr = isMac ? 'Command/Cmd' : 'CTRL';
					try {
						if(window.external && (!document.createTextNode ||
							(typeof(window.external.AddFavorite)=='unknown'))) {
							window.external.AddFavorite(window.location, document.title); // IE/Win
						} else if(isKonq) {
							alert('Please press CTRL + B to bookmark this page.');
						} else if(window.opera) {
							void(0); // do nothing here (Opera 7+)
						} else if(window.home || isSafari || !window.print || isMac) { // Firefox, Netscape, Safari, iCab, IE5/Mac and Safari 1.0
							alert('Please press ' + buttonStr + ' + D to bookmark this page.');
						} else {
							alert('In order to bookmark this page you need to do so manually through your browser.');
						}
					} catch(err) {
						// IE might error out
						alert("Error: " + err.description);
					}
					return false;
					
				});	
			}
		}
		
	},
	
	
	formHandler: function(pass, form, submitEvent) {
		// Do anything necessary here
	}
	
};


// Do stuff on load
window.addEvent('load', Site.start);