	/**
	 * JavaScript Library http://www.newsnet.com.au/
	 * Initialises start up scripts
	 * @required MooTools v1.2
	 * @author Haruki Takechi
	 * @since 14/07/2008
	 */	
	var NewsNet = {
		Init : function() {
			NewsNet.Login.Init();
			NewsNet.Rotate.Init();
			NewsNet.Partners.Init();
			NewsNet.Lists.Init();
		}
	};
	
	/**
	 * Menu functions for http://www.newsnet.com.au/
	 * @required MooTools v1.2
	 * @author Haruki Takechi
	 * @since 14/07/2008
	 */	
	NewsNet.Menu = {
		Bar : null,
		Init : function() {
			$$('#menu ul li').each(function(el){
				if (NewsNet.Menu.Bar.has(el.getElement('a').get('text'))) { // check for menu
					var items = NewsNet.Menu.Bar.get(el.getElement('a').get('text'));
					if (items) { // check for sub-menu
						el.addEvents({
							'mouseenter': function(){
								if (!this.getElement('ul')) {
									NewsNet.Menu.Generate(this,new Hash(items));
								} else if (this.getElement('ul').hasClass('sub-menu-off')) {								
									var sm = this.getElement('ul');
									sm.removeClass('sub-menu-off');
									sm.set('styles',{'display':'block'});
									sm.set('tween',{duration: 500,transition: Fx.Transitions.Bounce.easeOut}).tween('line-height', [5,21]);
								}
							},
							'mouseleave': function(){
								//el.getElement('ul').set('tween',{
								//	duration: 250
								//}).tween('line-height', [21,0]);
								var sm = this.getElement('ul');
								sm.addClass('sub-menu-off');
								sm.set('styles',{'display':'none','line-height':'0'});
							}
						});
					}
				}				
			});					
		},
		Generate : function(el,items) {
			//ul
			var ul = new Element('ul', {
				'class': 'sub-menu',
				'styles': {
					'top': el.getPosition().y + el.getSize().y,
					'left': el.getPosition().x - 1
				}
			});
			
			//li
			var li = new Element('li');

			//a
			var a = new Element('a', {
				'styles': {
					'opacity': '0.7'
				}
			});
			
			// attach anchor
			li.adopt(a);				

			// sub-menu items
			var tmp;
			items.each(function(v,k){
				tmp = li.clone();
				tmp.getElement('a').set({
					'href': v,
					'html': k
				});					
				ul.adopt(tmp);
			});
			
			// inject sub-menu into li
			el.adopt(ul);
			ul.set('tween',{duration: 500,transition: Fx.Transitions.Bounce.easeOut}).tween('line-height', [5,21]);
				
			a.dispose();
			li.dispose();
		}
	};
	
	/**
	 * Rotating Panel functions for http://www.newsnet.com.au/
	 * @required MooTools v1.2
	 * @author Haruki Takechi
	 * @since 09/08/2008
	 */
	NewsNet.Rotate = {
		Init : function() {
			if ($('news-container')) {
				var slideIt = null;
				var slideTimer = null;
				var items_category = $$('.news-category a');
				var items = $$('.news');
				items.each(function(el,index) {
					if (index !== 0) {
						el.setStyle('opacity',0);
						// items_category[index].setStyles({'text-decoration':'none','background-color':'none','color':'#fff'});
					} else {
						items_category[index].addClass('hover');
					}
					el.addEvents({
						'mouseenter': function(){
							slideTimer = $clear(slideTimer);
						},
						'mouseleave': function(){
							if (!slideTimer) {
								slideTimer = slideIt.periodical(5000,slideIt);
							}
						}
					});
				});
				
				var items_length = items.length;
				var i = 0;				
				slideIt = function() { 
					var curItem = items[i]; 
					var curCategoryItem = items_category[i];
					i = (i < (items_length - 1)) ? i + 1 : 0;
					var newItem = items[i];
					var newCategoryItem = items_category[i];
					
					newItem.morph({'opacity':1});
					curItem.morph({'opacity':0});
					newCategoryItem.addClass('hover');
					curCategoryItem.removeClass('hover');
				};				
				slideTimer = slideIt.periodical(10000,this); 
			}
		}
	};
	
	/**
	 * Newsnet Partners functions for http://www.newsnet.com.au/
	 * @required MooTools v1.2
	 * @author Haruki Takechi
	 * @since 12/09/2008
	 */
	NewsNet.Partners = {
		Init : function() {
			if ($('partners')) {
				$('partners').setStyle('display','block');
				$('partners').innerHTML = '<div class="top"><h4>Feedback</h4></div><div class="bottom"><p>We would love to hear your comments and suggestions on our services or website. Please click here to contact us.</p><span class="link"><a href="/contact-us/" rel="nofollow" title="Contact Us"><img src="/images/Contact-Us.gif" width="158" height="106" alt="Contact Us" class="photo" /></a></span></div>';
			}
		}
	};
	
	/**
	 * Newsnet Login functions for http://www.newsnet.com.au/
	 * @required MooTools v1.2
	 * @author Haruki Takechi
	 * @since 25/09/2008
	 */
	NewsNet.Login = {
		Target : 'NewsnetWebAccess',
		URL : "http://portal.newsnet.com.au/Main.asp?MainType=1",
		Init : function() {
			var html = '<form id="login" method="POST" name="LoginForm" action="'+this.URL+'" target="'+this.Target+'"  onsubmit="return NewsNet.Login.Process(this);">';
			html += '<fieldset>';
			html += '<label for="username">user:</label>';
			html += '<input type="text" id="username" />';
			html += '<label for="password">pass:</label>';
			html += '<input type="password" id="password" />';
			html += '<input type="text" id="tmp_username" name="txt_UserId" />'; // Following legacy code
			html += '<input type="password" id="tmp_password" name="txt_Password" />';
			html += '<input type="image" src="/images/login.gif" id="login-button" name="imageField" value="Login" title="Login" />';
			html += '</fieldset>';
			html += '</form>';			
			$('header').innerHTML += html;
		},
		Process : function(f) {
			// @TODO: Trim input values
			if ($('username').value.length < 1 && $('password').value.length < 1) {
				return false;	
			}
			
			$('tmp_username').value = $('username').value;
			$('tmp_password').value = $('password').value;
			$('username').value = "";
			$('password').value = "";
			
			// @TODO: Clean up!
			var height, width;			
			if ((screen.Height >= 0) && (screen.Width >= 0)) {
				height = screen.Height - 90;
				width = screen.Width - 10;
			} else if ((screen.availHeight >= 0) && (screen.availWidth >= 0)) {
				height = screen.availHeight - 90;
				width = screen.availWidth - 10;
			}
			var msg = window.open(this.URL,this.Target,"toolbar=0,status=0,location=no,menubar=no,directories=no,scrollbars=yes,resizable=yes,screenX=0,screenY=0,left=0,top=0,width="+width+",height="+height);	

			f.submit();			
			return true;
		}
	};
		
	/**
	 * Newsnet Makerting Lists functions for http://www.newsnet.com.au/
	 * @required MooTools v1.2
	 * @author Haruki Takechi
	 * @since 01/10/2008
	 */
	NewsNet.Lists = {
		Library : null,
		Init : function() {			
			if ($('lists')) {		
				this.Library = new Hash();
				var links = $$('.list-header a');
				$$('.list').each(function(el,i){					
					NewsNet.Lists.Library.set(i,new Fx.Slide(el));
					NewsNet.Lists.Library.get(i).hide();
					NewsNet.Lists.Library.get(i).addEvent('complete', function() {																			   
						if (!this.open) {
							links[i].removeClass('open');
							links[i].addClass('close');
						} else {
							links[i].removeClass('close');
							links[i].addClass('open');
						}
					});
				});
				$$('.list-header a').each(function(el,i){
					el.addEvent('click', function(e){
						e.stop();
						NewsNet.Lists.Library.get(i).toggle();					
					});
				});
			}			
		}
	};
	