var Site = {
	start: function(){
		MooTools.lang.setLanguage("en-US");
		// Launch-in-new-window links automagically created
		var extLinks = $$('a.external');
		if ( extLinks.length ) {
			extLinks.each(function(elem, idx) {
				elem.setProperty('target', '_blank');
			});
		}
		// Form validation automagic
		var valForms = $$('form.validate-form');
		if ( valForms.length ) {
			valForms.each(function(elem, idx) {
				new FormValidator.Inline(elem, {
					onFormValidate: Site.formHandler
				});
			});
		}
		if ($('member-login-content')) Site._memberLoginSetup();
		if ($('accordion')) Site._accordionSetup();
		if ($('text-decrease-top')) {
			$('text-decrease-top').addEvent('click', Site.scaleDown);
			$('text-increase-top').addEvent('click', Site.scaleUp);
            $('print-page').addEvent('click', Site.printPage);
		}
	},

	openPopup: function(node_id) {
		// Create the overlay
		$(document.body).adopt(new Element('div',{id:'popup-overlay'}));

		// Create the popup
		var popup = new Element('div', {id:'popup'});

		var popup_close = new Element('a', {id:'popup-close',href:'javascript:Site.closePopup();'});

		var popup_top = new Element('div', {id:'popup-top'});
		var popup_middle = new Element('div', {id:'popup-middle'});
		var popup_bottom = new Element('div', {id:'popup-bottom'});

		popup.adopt(popup_close).adopt(popup_top).adopt(popup_middle).adopt(popup_bottom);
		$(document.body).adopt(popup);

		// Create the iframe
		var iframe = new Element('iframe', {
			frameborder: 0
		});

		popup_middle.adopt(iframe);
		iframe.setProperty('src', '/?action=view&view='+node_id+'&rtemplate=3504');
	},

	closePopup: function() {
		$('popup').dispose();
		$('popup-overlay').dispose();
	},

	closePopupAndLoad: function(url) {
		Site.closePopup();
		document.location = url;
	},

    printPage: function(url)
    {
        window.open("&rtemplate=2441", 'PrintPage', 'width=680,height=740,location=no,toolbars=no,status=no, scrollbars=yes');
    },


	formHandler: function(pass, form, submitEvent) {
		// Do anything necessary here
	},
	_memberLoginSetup: function() {

		var slidey = new Fx.Slide('member-login-content').hide();

		$('member-login-btn').addEvent('click', function(e){
			e.stop();
			slidey.toggle();
		});

	},
	_accordionSetup: function() {

		var myAccordion = new Accordion($('accordion'), 'h3.toggler', 'div.stretcher', {
			opacity: false,
			onActive: function(toggler, element){
				toggler.setStyle('background-position', 'left bottom');
			},
			onBackground: function(toggler, element){
				toggler.setStyle('background-position', 'left top');
			}
		});

	},
	currentFontSize: 100,
	scaleDown: function() {
		Site.currentFontSize -= 10;
		Site.updateFontSize();
	},
	scaleUp: function() {
		Site.currentFontSize += 10;
		Site.updateFontSize();
	},
	updateFontSize: function() {
		$('content-main-inner').style.fontSize = Site.currentFontSize+"%";
		$('content-main-inner').style.lineHeight = (Site.currentFontSize * 1.5)+"%"; // * 1.5 'cause lineheight should already be 150%
		Cufon.replace('#member-login h3, #content-main-inner h1, #content-main h2, #content-main h3, #footer h5, #top-logged-in h1', { fontFamily: 'Myriad Pro' });
	}

};
window.addEvent('domready', Site.start);

