window.addEvent('domready', function(){  
	//nav
	$$('.NavMenu li').each( function( elem ){
			//elem.setStyle('height',26);
			elem.getElements('.NavBullet').morph({ 
				visibility:'visible', 
				color: '#dbd6c5',
				'opacity': 1
			});
			//elem.removeEvents('mouseenter');elem.removeEvents('mouseleave');
			elem.addEvents({
				'mouseenter' : function(e){
					e.stop();
					if(this.getElement('.NavBullet')) this.getElement('.NavBullet').setStyle('color','maroon');
				},
				'mouseleave' : function(e){
					e.stop();
					if(this.getElement('.NavBullet')) this.getElement('.NavBullet').setStyle('color','#dbd6c5');
				}
			});
		});
	
	// articles
	if( $('font_size_toggler') != null ) {
		
		$('font_size_toggler').addEvent('click', function(e) {
			e.stop();
			switch ( $('NewsCopy').getStyle('fontSize')) {
				case "14px":
					newSize = "17px";
					newLineHeight = "24px";
					break;
				case "17px":
					newSize = "20px";
					newLineHeight = "26px";
					break;
				default:
					newSize = "14px";
					newLineHeight = "18px";
			}
			$('NewsCopy').morph({
				fontSize: newSize,
				lineHeight: newLineHeight
			});
		});
	}
	//news index
	if($$('.NewsIndex')) {
		$$('.NewsIndex').each(function (NI) {
			if(NI.get('html').trim() == '') NI.destroy();
		});
	}
	//calendar
	if( $('eventchecktoggle') != null ) {
		$('eventchecktoggle').addEvent('click', function(e){
			if($('eventchecktoggle').checked) {				
				$$('.eventcheck').each(function(c) { c.checked = true; });
			} else {
				$$('.eventcheck').each(function(c) { c.checked = false; });
			}			
		});
	}
	
	//home page
	if($('TopStoryList')!=null) {
		/* click - control event */
		Event.implement({
			uberControlPressed: function() {
				return Browser.Platform.mac ? this.meta : this.control;
			}
		});
		/* click - control event */
		Element.Events.altClick = {
			base: 'click',
			condition: function(event) {
				return event.alt;
			}
		};
		Element.Events.ctrlClick = {
			base: 'click',
			condition: function(event) {
				return event.control;
			}
		};
		
		$('TopStoryList').getElements('li span.TopStoryIndent').each( function( elem ){
			if(elem.getElement('div[class^=comments]')!=null){
				elem.getElement('div[class^=comments]').addEvents({
						'mousedown': function(e) {
							e.stop();
							location.href = this.getElement('a').get('href');
						}
				});
			}
			
			elem.addEvents({
				'mouseup' : function(e) {
					e.stop();
					if(e.control) {
						window.open("article.php?" + this.getParent().get('id'));
					} else if(e.ctrlClick) {
						window.open("article.php?" + this.getParent().get('id'));
					} else if(e.rightClick) {
						window.open("article.php?" + this.getParent().get('id'));
					} else {
						location.href = "article.php?" + this.getParent().get('id');
					}
				}
			});
		})
	}
	//newsletter
	if(signup = document.id('NewsletterSignup')) {
		signup.addEvent('change', function(inp) {
			signup.fade(.3).blur();
			new Request.JSON({
				url: 'library/signup.php',
				method: 'post',
				data: {'email': signup.get('value')},
				onSuccess: function(signup_json) {
					if(signup_json.status == 'bad_email') {
						signup.fade(1).set('placeholder', 'PLEASE ENTER A VALID EMAIL').set('value','');
					} else if(signup_json.status == 'OK') {
						signup.fade(1).set('placeholder', 'THANK YOU!').set('value','');
						document.id('newsletter_confirmation').set('html', "An email confirmation has been sent.");
															  
					} else {
						signup.fade(1).set('placeholder', 'ERROR: PLEASE TRY AGAIN').set('value','');
					}
				}
			}).send();
		});
	}
	
	
	if($$('.SubscribeChoice')!=null) {
		$$('.SubscribeChoice').each( function( elem ) {
			elem.setStyles({ 
				'background': '#fff url(https://secure.mvgazette.com/images/subscribe_bg.gif)',
				'backgroundRepeat': 'repeat-x',
				'backgroundPosition': '0px ' + (parseInt(elem.getStyle('height')) - 0 + 33) + 'px'
			});
			
			elem.addEvents({
				'mouseenter' : function(e){
					e.stop();
					newpos = parseInt(this.getStyle('height')) - 16;
					if(this.getElement('input').checked!=true){
						this.morph({
							backgroundPosition: '0px ' + newpos + 'px',
							borderColor: '#000000'
						});
					}
				},
				'mouseleave' : function(e){
					e.stop();
					//oldpos = parseInt(this.getStyle('height'));
					newpos = parseInt(this.getStyle('height')) - 0 + 33;
					if(this.getElement('input').checked!=true){
						this.morph({
							backgroundPosition: '0px ' + newpos + 'px',
							borderColor: '#ededed'
						});
					}
				},
				'click' : function(e) {
					newpos = parseInt(this.getStyle('height')) - 0 + 33;
					$seldiv = this.id;
					$$('.SubscribeChoice').each( function( eleme ){
						if(eleme.id != $seldiv){
							eleme.morph({
								backgroundPosition: '0px ' + newpos + 'px',
								borderColor: '#ededed'
							});
						}
					})
					if(!this.getElement('input').checked==true) this.getElement('input').checked=true;
					subscribe_update(this.get('rel'));
				}
			});
		})
	}
	function reveal_news() { //prevents Safari from enabling Reader button
		document.id('NewsCopy').setStyles({'opacity':0,'display':'block'}).fade('in');
		document.id('Main').setStyle('height', document.id('MainFrame').getStyle('height'));
	}
	if( document.id('NewsCopy') != null ) {
		//reveal_news.delay(110);
	}
	/*Subscription special
	if(!Cookie.read('subdeal')) {
		var subdeal = new Element('div');
			subdeal.set('html', "<br><b>Mother's Day Special</b><br/><br/>For a limited time,<br/>get half-off a subscription<br />to the Gazette.").set('id',"subdeal").setStyles({ 
				'opacity': 0,
				'top': 20,
				'left': document.id('subscribe_tab').getLeft() - 7
			});
																				 
		subdeal.inject(document.body).morph({'opacity':.9, 'top':53 });
		
		var myCookie = Cookie.write('subdeal', 'seen', { duration: 1 });
	}
	*/
});

