// This function will either resize the parent iframe (if class of
// 'resize-me'), or redirect the browser if the document if not part of an
// iframe.
//
// Tested on: Gecko (Firefox 3.0.5)
window.addEvent('domready', 
		function (){
		    var frameElement = $(window.frameElement);
		    if(frameElement){
			if(frameElement.hasClass('resize-me')){
			    frameElement.setStyle('height', $E('html').scrollHeight);
			    $E('body').setStyle('backgroundImage', 'none');
			}
			frameElement.setProperty('frameborder','0');
		    }
		    else{
			var body = $E('body', document);
			var location = window.location.toString();
			if(location.match('noreroute')){
			    return;
			}
			var divMessage = $E('div#lce-messages');
			if(!divMessage){
			    var html = 
				'<dl id="system-message">' +
				'<dt class="notice">Notice' +
				'</dt>' +
				'<dd class="notice message fade"><ul />' +
				'</dd>' +
				'</dl>';
			    divMessage = new Element('div', {'id': 'lce-messages'}).setHTML(html);
			    divMessage.inject(body, 'top');
			}
			var li = new Element('li');
			var location = window.location.toString().replace(/\/database.*$/, '/index.htm');
			li.countDown = {'string': '<span>You will be redirected in %s seconds or ' + 
					'click <a href="' + location + '">here</a>.</span>', 
					'count': 15};
			li.addEvent('reduceNotice', function(){
				var text = this.countDown.string.replace(/%s/, this.countDown.count);
				if(this.countDown.count == 1){
				    text = text.replace(/seconds/, 'second');
				}
				this.setHTML(text);
				if(this.countDown.count){
				    this.countDown.count--;
				    this.fireEvent('reduceNotice', null, 1000);
				}
				else{
				    window.location = location;
				}
			    });
			li.fireEvent('reduceNotice', null, 1000);
			$E('dd.notice ul', divMessage).adopt(li);
		    }
		});

// This function will ensure that the links in the iframe #event-calendar will reload in the ifram #component
//
// Tested on: Gecko (Firefox 3.0.5)
window.addEvent('domready', 
		function (){
		    var frameElement = $(window.frameElement);
		    if(frameElement){
			if(frameElement.getProperty('id') != 'event-calendar'){
			    return;
			}
			var component = frameElement.ownerDocument.getElementById('component');
			var location = frameElement.ownerDocument.location.toString();
			if(!location.match(/events.htm[?]?.*$/i)){
			    var doc = frameElement.ownerDocument;
			    $$('tbody a').forEach(function(el){
				    var href = el.getAttribute('href');
				    el.removeAttribute('href');
				    el.onclick = function(){
					doc.location = location.replace(/[/][^/]*$/,'/events.htm')+'?href='+href;};
				});
			    return;
			}
			else if(location.match(/href=.*/i) && component){
			    if(!component.lce_href){
				component.src = location.match(/href=(.*)$/i)[1]; 
			    }
			    component.lce_href = true;
			}
			$$('tbody a').forEach(function(el){
				var href = el.getAttribute('href');
				el.removeAttribute('href');
				el.onclick = function(){component.src = href;};
			});
		    }
		});

/*window.addEvent('domready', 
		function()
		{ 
		    var JTooltips = new LCETips($$('.hasTip'), 
						{ 
						    maxTitleChars: 50, 
						    fixed: false
						}); 
						});*/
