/* Standard Macromedia functions for rollovers */

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
	var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
	if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
	d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

/* At a regular interval, pick a quote and overwrite the img src tag */
function HF_header_quote() {
	var images = quotes.split(",");
	var imageCount = images.length;
	var i = Math.round(imageCount*Math.random());
	var thisImage = images[i].split("|");
	var imagePath = "/Filestore/_quotes/"+thisImage[0];
	var el = document.getElementById('quote_image');
	el.src = imagePath;
	el.width = thisImage[1];
	el.height = thisImage[2];
	
	var timer = setTimeout("HF_header_quote()", 10000);
}

// MooTools setup function
function windowDomReady() {
	//var tooltips = new Tips($$('.toolTipElement'),{ fixed:true });
			
	//$('ftci_window_bg').effect('opacity', {duration: 500}).hide();
	//$('ftci_window_bg').setStyles({'top': window.getScrollTop(), 'height': window.getHeight()});
	//HFoverlay.init();

}

// ======================================================
var HFoverlay = {
	// ---------------------------
	init:	function() {
				
				// scan anchors for those with rel="hfoverlay"
				// add onclick event to call our 'show' function
				this.anchors = [];
				$A($$('a')).each(function(el){
					// we use a regexp to check for links that
					// have a rel attribute starting with "moodalbox"
					if(el.rel && el.href && el.rel.test('^hfoverlay', 'i')) {
						el.onclick = this.show.pass(el, this);
						this.anchors.push(el);
					}
				}, this);


				// add event listener
				this.eventKeyDown = this.keyboardListener.bindWithEvent(this);
				
				// Setup our overlay (dark background) element and inject it into the body of the page
				this.overlay = new Element('div', {'id': 'lbOverlay'}).injectInside(document.body);
				this.overlay.setStyles({'top': window.getScrollTop(), 'height': window.getHeight()});
				this.overlay.onclick = this.hide.bind(this);

				// Setup our content div within the overlay div and inject this into the body too
				var center = new Element('div', {'id': 'lbCenter', 'styles': {'width': 250, 'height': 250, 'marginLeft': -(125), 'display': 'none'}}).injectInside(document.body);

				// define the effect for our overlay, in this case we're messing with the
				// opacity. Define here as an object because we call it within our show()
				// and hide() functions and we don't want to create new effect instance there 
				// as this is wasteful. (Thanks to digitarald for the heads-up!)
				this.overlayFX = this.overlay.effect('opacity', {duration: 500}).hide();
			},
	
	// What do we need to have in place when the overlay is functional?
	// Currently we inject an event (keydown) to look for the ESC being pressed
	// We need to remove this when the overlay is put away.
	setup: function(open){
				var fn = open ? 'addEvent' : 'removeEvent';
				//window[fn]('scroll', this.eventPosition)[fn]('resize', this.eventPosition);
				document[fn]('keydown', this.eventKeyDown);
			},
			
	// ---------------------------
	show:	function(url) {
				this.setup(true);
				this.overlayFX.start(0.8);
				this.getContent(url);
			},
			
	// ---------------------------
	hide:	function() {
				this.overlayFX.start(0.0);
				this.setup(false);
			},

	// Get the html content for our Centre div
	getContent:	function(url) {
				var content = "<h3>Here we are</h3><p>Just chillin'</p>";
				$('lbCenter').setHTML(content);
				//$('lbCenter').setStyle('height','100%');
			},

	// Looking for key presses...
	keyboardListener: function(event) {
			if (event.key == 'esc') {
				this.hide();
			}
			event.stop();
	}

};
// ======================================================

//window.addEvent('domready',HFoverlay.init.bind(HFoverlay));