window.addEvent('domready', function(){  
	//nav
	$$('.NavMenu li').each( function( elem ){
		elem.getElements('.NavBullet').setStyles({ 
			visibility:'visible',
			'opacity': 0
		});
		
		elem.addEvents({
			'mouseenter' : function(e){
				e.stop();
				if(this.getElement('.NavBullet')) this.getElement('.NavBullet').fade(0,1);
			},
			'mouseleave' : function(e){
				e.stop();
				if(this.getElement('.NavBullet')) this.getElement('.NavBullet').fade(1,0);
			}
		});
	});
	
	// 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').each( function( elem ){
			elem.setStyles({ 
				'background': '#fff url(/images/topstorybg.gif)',
				'backgroundRepeat': 'no-repeat',
				'backgroundPosition': '0px ' + (parseInt(elem.getStyle('height')) - 0 + 31) + 'px'
			});
			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({
				'mouseenter' : function(e){
					e.stop();
					oldpos = parseInt(this.getStyle('height'));
					newpos = parseInt(this.getStyle('height')) - 13;
					this.morph({
						backgroundPosition: '0px ' + newpos + 'px',
						borderColor: '#000000'
					});
				},
				'mouseleave' : function(e){
					e.stop();
					oldpos = parseInt(this.getStyle('height'));
					newpos = parseInt(this.getStyle('height')) - 0 + 31;
					this.morph({
						backgroundPosition: '0px ' + newpos + 'px',
						borderColor: '#ededed'
					});
				},
				'mouseup' : function(e) {
					e.stop();
					if(e.control) {
						window.open("article.php?" + this.get('id'));
					} else if(e.ctrlClick) {
						window.open("article.php?" + this.get('id'));
					} else if(e.rightClick) {
						window.open("article.php?" + this.get('id'));
					} else {
						location.href = "article.php?" + this.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(icskin == true) toggle_skin();
	
	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 });
	}
	*/
});

skin = 1;

function toggle_skin() {
	hd = document.id('Head');
	if(skin == 1) {	
		if(document.id('TopStoryList')) document.id('TopStoryList').getElements('li').each( function( elem ){
			elem.removeEvents('mouseenter');
			elem.removeEvents('mouseleave');
		});
		var fx = new Fx.Tween(hd, { duration: 500,
			onComplete: function() { 
				hd.setStyle('background-image','url(images/VGOHead.gif)');
				hd.fade('in');
			}
		});
		//fx.start('opacity',1,0);
		//document.body.setStyle('background','#dbd6c5');
		//document.id('SideGutter').morph({'width':180, 'padding':0 });
		//document.id('MainAds').tween('margin-right',0 );
		//document.id('Tabs').setStyles({ 'background':'#8db2ac', 'padding':'10px 0 7px 18px', 'height':'auto','width':920,'margin':'0 0 15px 20px' });
		//document.id('Tabs').getElements('img').setStyle('display','none');
		//document.id('Tabs').getElements('a').setStyle('margin-right',95);
		//document.id('Tabs').getElement('a:last-child').setStyle('margin-right',0);
		//$$('.TabText').morph({'display':'block','opacity':1});
		//document.id('Location').setStyles({'text-shadow':'none','color':'#dbd6c5','height':50,'margin':'25px 0 5px 0' });
		//document.id('LocationBox').setStyles({'background':'transparent','height':38,'font-family':'Trajan Pro Bold, serif','font-size':'9pt','text-transform':'uppercase'});
		//document.id('WeatherBox').setStyle('width',310).getElement('img').setStyle('display','none');
		//document.id('BreadCrumbs').morph({'width':330, 'height':15});
		//$$('#MainAds img').setStyle('box-shadow','none');
		//$$('#MainAds iframe').setStyle('box-shadow','none');
		//$$('#BreadCrumbs a').setStyle('color','#5b9c92');
		//$$('#WeatherBox a').setStyle('color','#5b9c92');
		//$$('.FootToolTable').setStyles({'font-family':'Trajan Pro Regular'});
		//$$('.CrumbBullet').each(function(bul) { bul.set('html', '|');bul.setStyles({'margin':'0 6px', 'color':'#5b9c92' }); });
		//if(document.id('secondbullet')) document.id('secondbullet').empty();
		//if(document.id('Crumb2')) document.id('Crumb2').setStyle('display','none');
		//if(document.id('headline_h1')) document.id('headline_h1').setStyles({'font-family':'Times New Roman, serif','font-size':'16pt','line-height':'19pt','text-transform':'uppercase'});
		//if(document.id('NewsCopy')) document.id('NewsCopy').setStyles({'font-family':'Times New Roman, serif', 'font-size':'17px', 'color':'#474949', 'line-height':'24px'});
		//document.id('MainFrame').setStyle('background','#fff');
		//document.id('MainFrameBottom').setStyle('background-image','none');
		//$$('.TopRule').setStyle('border-top',0);
		//$$('.RssTitle img').setStyle('display','none');
		//$$('.RssTitle').setStyles({ 'font-family':'Trajan Pro Bold, serif', 'text-transform':'uppercase','font-size':'12pt', 'color':'#7a776c','text-shadow':'none','font-weight':'normal' });
		//$$('.Grade, .HomeBox').setStyles({'background':'transparent','text-shadow':'none','text-align':'left'});
		//$$('.OutsetBox').setStyle('border', 0);
		//document.id('FootMenu').setStyles({'background':'#cae3df', 'width':870,'margin':'3px auto 15px auto','padding':'15px 35px' });
		//document.id('Main').setStyle('background','#fff');
		//document.id('Main').tween('margin-left',22);
		//$$('.OutsetBox').setStyles({'font-family':'Times New Roman, serif' });
		//$$('.DateHead').setStyles({'text-transform':'uppercase','background':'#b6af96','height':27, 'font-size':'1em','padding':'8px 0 0 10px','font-family':'Trajan Pro Regular, serif','font-weight':'normal'});
		//$$('.FeedbackHead').setStyles({'text-transform':'uppercase','background':'#b6af96','height':27, 'font-size':'1em','padding':'8px 0 0 10px','font-family':'Trajan Pro Regular, serif','font-weight':'normal'});
		//document.id('NavSiteHead').setStyles({'text-transform':'uppercase','background':'#b6af96','font-family':'Trajan Pro Regular, serif'}).getElement('span').tween('opacity',1);
		//document.id('NavSiteHead').morph({ 'width':180, 'height':25, 'padding':'10px 0 0 10px'});
		//document.id('NavSectionsHead').setStyle('display','none');
		//$$('.NavFoot').setStyle('display','none');
		//$$('.NavMenu li a').setStyles({ 'background':'#fff','padding':'8px 0 0 0','text-transform':'uppercase','font-family':'Trajan Pro Regular, serif', 'color':'#336666','text-shadow':'none','font-size':'.75em' });
		//$$('.NavBullet').setStyles({'visibility':'visible','padding':'0 5px 0 0'});
		$$('.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');
				}
			});
		});
		//document.id('SearchBox').setStyles({'width':250, 'border-left':'1px solid #999','border-right':'1px solid #999','padding':'0 12px'});
		document.id('SearchInput').set('value','SEARCH');
		//.setStyles({'background':'#c9e3e0','border-radius': 0,'text-align':'left','font-size':'9pt','font-family':'Times New Roman, serif','border-style': 'none' ,'width':245,'height':22 });
		//document.id('Head').setStyles({'height':190,'background-color':'#dbd6c5' });
		//document.id('QuoteContainer').setStyles({'position':'absolute','top':0,'left':0,'width':'100%','background':'#f5f5f5','height':40 });
		//document.id('QuoteText').setStyles({'filter':'none','font-family':'Trajan Pro Regular, serif','padding':'13px 0px 0 0px','color':'#565757','width':'100%','font-size':'.7em','text-shadow': 'none','font-weight':'normal','height':40});
		//document.id('OuterContainer').setStyles({'background':'#fff'});
		skin = 2;
	}
}

