// <![CDATA[
			
var News = {
	init:function() {
		News.linksetup();
	},
	linksetup:function() {
		// this adds events to each of the
		// available links written to the
		// DOM by Smarty and PHP:
		var newslinks = $$('.newslink');
		newslinks.each(function(el) {
			if (!el.get('isideations')) {
				el.addEvents({
					'mouseenter':function() {
						el.setStyle('cursor', 'pointer');
						el.tween ('background-color', el.getStyle('background-color'), '#E9E9E9');
						
						// add events to children, actually:
						var currElChildren = el.getChildren();
						
						// find the headlines and subheadlines:
						$$(currElChildren).each(function(el) {
							if (el.hasClass('newsheadline')) {
								el.setStyle('color', '#A80C1A');
							}
						});
					},
					'mouseleave':function() {
						el.setStyle('cursor', 'normal');
						el.tween ('background-color', el.getStyle('background-color'), '#FFFFFF');
						
						var currElChildren = el.getChildren();
						
						$$(currElChildren).each(function(el) {
							if (el.hasClass('newsheadline')) {
								el.setStyle('color', '#444');
							}
						});
					},
					'click':function() {
						if (el.getProperty('hasblurb') !== 'true') {
							News.showStory(el.get('storyID'));
						}
					}
				 });
			} else {
				el.addEvents({
					'mouseenter':function() {
						el.setStyle('cursor', 'pointer');
						el.tween ('background-color', el.getStyle('background-color'), '#E9E9E9');
						
						// add events to children, actually:
						var currElChildren = el.getChildren();
						
						// find the headlines and subheadlines:
						$$(currElChildren).each(function(el) {
							if (el.hasClass('newsdate')) {
								el.getFirst().setStyle('color', '#A80C1A');
							} else {
								el.setStyle('color', '#A80C1A');
							}
						});
					},
					'mouseleave':function() {
						el.setStyle('cursor', 'normal');
						el.tween ('background-color', el.getStyle('background-color'), '#FFFFFF');
						
						var currElChildren = el.getChildren();
						
						$$(currElChildren).each(function(el) {
							if (el.hasClass('newsdate')) {
								el.getFirst().setStyle('color', '#000000');
							} else {
								el.setStyle('color', '#666');
							}
						});
					},
					'click':function() {
						// load the ipaper document:
						Site.loadiPaper(this.get('docID'), this.get('access_key'));						
					}
				});
			}
		});
		var segmentlinks = $$('.segment');
		segmentlinks.each(function(el) {
			if (!el.get('isideations')) {
				el.addEvents({
					'mouseenter':function() {
						el.setStyle('cursor', 'pointer');
						el.tween ('background-color', el.getStyle('background-color'), '#E9E9E9');
						
						// add events to children, actually:
						var currElChildren = el.getChildren();
						
						// find the headlines and subheadlines:
						$$(currElChildren).each(function(el) {
							if (el.hasClass('newsheadline')) {
								el.setStyle('color', '#A80C1A');
							}
						});
					},
					'mouseleave':function() {
						el.setStyle('cursor', 'normal');
						el.tween ('background-color', el.getStyle('background-color'), '#FFFFFF');
						
						var currElChildren = el.getChildren();
						
						$$(currElChildren).each(function(el) {
							if (el.hasClass('newsheadline')) {
								el.setStyle('color', '#444');
							}
						});
					},
					'click':function() {
						if (el.getProperty('hasblurb') !== 'true') {
							News.showStory(el.get('storyID'));
						}
					}
				 });
			} else {
				el.addEvents({
					'mouseenter':function() {
						el.setStyle('cursor', 'pointer');
						el.tween ('background-color', el.getStyle('background-color'), '#E9E9E9');
						
						// add events to children, actually:
						var currElChildren = el.getChildren();
						
						// find the headlines and subheadlines:
						$$(currElChildren).each(function(el) {
							if (el.hasClass('newsdate')) {
								el.getFirst().setStyle('color', '#A80C1A');
							} else {
								el.setStyle('color', '#A80C1A');
							}
						});
					},
					'mouseleave':function() {
						el.setStyle('cursor', 'normal');
						el.tween ('background-color', el.getStyle('background-color'), '#FFFFFF');
						
						var currElChildren = el.getChildren();
						
						$$(currElChildren).each(function(el) {
							if (el.hasClass('newsdate')) {
								el.getFirst().setStyle('color', '#000000');
							} else {
								el.setStyle('color', '#666');
							}
						});
					},
					'click':function() {
						// load the ipaper document:
						Site.loadiPaper(this.get('docID'), this.get('access_key'));						
					}
				});
			}
		});
	},
	showStory:function(storyID) {
		if (!$('document_viewer')) {
			if (Site.doMask()) {
				if ($('redsquare')) $('redsquare').fade('out');
				
				// create container for news stories:
				var documentviewer = new Element('div', {
					'id':'document_viewer',
					'class':'document_viewer',
					'styles':{
						'top':$$('.smallimgRow')[0].getPosition().y,
						'left':$$('.smallimgRow')[0].getPosition().x,
						'z-index':'10000',
						'border':'2px solid #181818'
					}
				}).inject(document.body, 'bottom');
				
				var documentviewer_closebutton = new Element('img', {
					'id':'document_viewer_close_button',
					'src':'../../img/buttons/closebox.png',
					'alt':'Close this Document',
					'width':'30',
					'height':'30',
					'styles':{
						'position':'absolute',
						'top':documentviewer.getPosition().y - 10,
						'left':documentviewer.getPosition().x - 10,
						'z-index':'10001',
						'width':'30px',
						'height':'30px'
					},
					'events':{
						'mouseenter':function() {
							this.setStyle('cursor', 'pointer');
									  
						},
						'mouseleave':function() {
							this.setStyle('cursor', 'default');						
						},
						'click':function() {
							// find any object or embed elements:
							if (Browser.Engine.trident) {
								try {
									if (document.getElementById('document_viewer').children.length > 0) {
										var iPaperViewer = document.getElementById('document_viewer').children(0);
										document.getElementById('document_viewer').removeChild(iPaperViewer);
									}
									
									try {
										$('document_viewer').destroy();
										$('document_viewer_close_button').destroy();
									} catch (ex) {
										if (console) console.log ('couldn\'t remove viewer: ' + ex.message);
										return;
									}
									
								} catch (ex) {
									if (console) console.log ('couldn\'t remove viewer: ' + ex.message);
									return;
								}
							} else {
								try {
									documentviewer.destroy();
									documentviewer_closebutton.destroy();
									
								} catch (ex) {
									if (console) console.error ('couldn\'t remove viewer: ' + ex.message);
									return;
								}							
							}
							
							if (Site.undoMask()) {							
								if ($('redsquare')) $('redsquare').fade('in');
							}
						}
					}
				}).inject(document.body, 'bottom');
				
				// populate #document_viewer with content gotten from database:
				var getStory = new Request.HTML({
					method:'post',
					url:'/include/getNewsItems.php',
					async:true,
					update:$('document_viewer')
				}).send('storyID=' + storyID);
			}
		} else {
			alert ('You are already viewing a news item.\nPlease close the viewer to read a different news item.');
			return;
		}
	}	
};

window.addEvent('domready', News.init);

// ]]>