/*********************************************************************************************************
* Floatbox v2.18
*
* Image and IFrame viewer by Byron McGregor
*	Mar. 21, 2008
*   Website: http://randomous.com
* Derived from Lytebox v3.22, the original work of Markus F. Hay
*   Website: http://www.dolem.com/lytebox
* License: Creative Commons Attribution 3.0 License (http://creativecommons.org/licenses/by/3.0/)
* Onload routine modified from http://dean.edwards.name/weblog/2006/06/again/#comment5338
* Credit: Lytebox was originally derived from the Lightbox class (v2.02) that was written by Lokesh Dhakar
*   Website: http://huddletogether.com/projects/lightbox2/
**********************************************************************************************************/
Floatbox.prototype.setDefaultOptions = function() {

/***<Global Configuration>***/
  this.theme          = 'black';   // themes: black, grey, red, green, blue, gold, custom.  Custom is for defining your own styles in the css without overwriting existing themes
  this.overlayOpacity = 86;        // 0-100. Higher opacity = darker overlay
  this.padding        = 12;        // padding in pixels between the displayed item and float box edges
  this.outerBorder    = 4;         // width in pixels of the outer border around the float box
  this.innerBorder    = 1;         // width in pixels of the inner border around the image or iframe content
  this.navType        = 'both';    // 'upper', 'lower', 'both' or 'none'.  upper = "Prev/Next" image overlay, lower = "<< prev || next >>" on lower panel
  this.navOpacity     = 60;        // opacity of the upper prev and next navigation buttons
  this.upperNavWidth  = 42;        // 0-50. Percent width of each upper nav panel. 50 means prev and next nav panels meet in the middle, 40 leaves a 20% gap between panels, etc.
  this.autoResize     = true;     // resize images and iframes down to the browser window size if necessary (but are not made larger)
  this.doSlideshow    = false;     // launch a multi-item gallery as a slideshow regardless of what the rel attributes say
  this.showHints      = true;      // display mouseover hint messages for the nav and control buttons. Useful for informing users about keyboard shortcuts
  this.showCaption    = true;      // display caption pulled from the anchor's title attribute
  this.showItemNumber = true;      // display 'image/page X of Y' below the caption
  this.showClose      = true;      // display the close button
  this.showPlayPause  = true;      // display the slideshow play & pause buttons
  this.modal          = false;     // applies only to iFrame and slideshow content.  Shorthand for navType=none, showClose=false, showPlayPause=false, showCaption=false, showItemNumber=false, enableKeyboardNav=false & outsideClickCloses=false.  Modal iFrame must call parent.floatbox.end().  Modal slideshow should autoexit.
  this.hideFlash      = true;      // hide Flash objects so they don't bleed through the overlay or distract
  this.resizeDuration      = 1;    // 0-10. 0 = no resize animation, 1 is fast, 10 is slooow.  Unit-less, not seconds!
  this.imageFadeDuration   = 0;    // 0-10. 0 = no image fade-in, 1 is fast, 10 is slooow.  Unit-less, not seconds!
  this.overlayFadeDuration = 0;    // 0-10. 0 = no overlay fading in or out, 1 is fast, 10 is slooow.  Unit-less, not seconds!
  this.enableKeyboardNav   = true; // enable/disable keyboard handler for prev, next, pause/play and close (If you disable keyboard nav you should also set showHints to false or change the default text displayed in the hints)
  this.outsideClickCloses  = true; // clicking on the overlay closes floatbox
/***</Global Configuration>***/

/***<Slideshow Configuration>***/
  this.slideInterval  = 4.1;       // number of seconds to show each image during a slideshow
  this.endTask        = 'exit';    // 'halt' (default), 'exit' or 'cont'.  What to do when all the images have been shown: stop the slideshow but leave the last pic up, close the image display, or continuous looping
  this.startPaused    = false;     // true to start slideshow in paused state, false to have the slideshow auto-play on start
  this.pauseOnNext    = false;     // true to pause the slideshow when the 'Next'" button is clicked or when 'next' keyboard action is fired
  this.pauseOnPrev    = true;      // true to pause the slideshow when the 'Prev' button is clicked or when 'prev' keyboard action is fired
/*** </Slideshow Configuration> ***/

/***<String Configuration>***/
  this.hintClose      = "keybd: Esc";       // Shortcut: 'Escape' or 'X' or 'C'
  this.hintNext       = "keybd: rt.arrow";  // Shortcut: 'Right Arrow' or 'N'
  this.hintPrev       = "keybd: lt.arrow";  // Shortcut: 'Left Arrow' or 'P'
  this.hintPlayPause  = "keybd: space";     // Shortcut: 'Spacebar'
/*** </String Configuration> ***/
};

Floatbox.prototype.parseOptions = function(qs) {
	if (!qs) return;
	qs = qs.replace(/\s*[:=]\s*/g, ':')
	qs = qs.replace(/\s*[;&]\s*/g, ' ')
	qs = qs.replace(/^\s+|\s+$/g, '')
	var aVars = qs.toLowerCase().split(/\s+/);
	var i = aVars.length;  while (i--) {
		var aThisVar = aVars[i].split(':');
		if      (aThisVar[0] == 'theme') this.theme = aThisVar[1];
		else if (aThisVar[0] == 'overlayopacity') this.overlayOpacity = parseInt(aThisVar[1]);
		else if (aThisVar[0] == 'padding') this.padding = parseInt(aThisVar[1]);
		else if (aThisVar[0] == 'outerborder') this.outerBorder = parseInt(aThisVar[1]);
		else if (aThisVar[0] == 'innerborder') this.innerBorder = parseInt(aThisVar[1]);
		else if (aThisVar[0] == 'navtype') this.navType = aThisVar[1];
		else if (aThisVar[0] == 'navopacity') this.navOpacity = parseInt(aThisVar[1]);
		else if (aThisVar[0] == 'uppernavwidth') this.upperNavWidth = parseInt(aThisVar[1]);
		else if (aThisVar[0] == 'autoresize') this.autoResize = (aThisVar[1] == 'true');
		else if (aThisVar[0] == 'doslideshow') this.doSlideshow = (aThisVar[1] == 'true');
		else if (aThisVar[0] == 'showhints') this.showHints = (aThisVar[1] == 'true');
		else if (aThisVar[0] == 'showcaption') this.showCaption = (aThisVar[1] == 'true');
		else if (aThisVar[0] == 'showitemnumber') this.showItemNumber = (aThisVar[1] == 'true');
		else if (aThisVar[0] == 'showclose') this.showClose = (aThisVar[1] == 'true');
		else if (aThisVar[0] == 'showplaypause') this.showPlayPause = (aThisVar[1] == 'true');
		else if (aThisVar[0] == 'modal') this.modal = (aThisVar[1] == 'true');
		else if (aThisVar[0] == 'hideflash') this.hideFlash = (aThisVar[1] == 'true');
		else if (aThisVar[0] == 'resizeduration') this.resizeDuration = parseFloat(aThisVar[1]);
		else if (aThisVar[0] == 'imagefadeduration') this.imageFadeDuration = parseFloat(aThisVar[1]);
		else if (aThisVar[0] == 'overlayfadeduration') this.overlayFadeDuration = parseFloat(aThisVar[1]);
		else if (aThisVar[0] == 'enablekeyboardnav') this.enableKeyboardNav = (aThisVar[1] == 'true');
		else if (aThisVar[0] == 'outsideclickcloses') this.outsideClickCloses = (aThisVar[1] == 'true');
		else if (aThisVar[0] == 'slideinterval') this.slideInterval = parseFloat(aThisVar[1]);
		else if (aThisVar[0] == 'endtask') this.endTask = aThisVar[1];
		else if (aThisVar[0] == 'startpaused') this.startPaused = (aThisVar[1] == 'true');
		else if (aThisVar[0] == 'pauseonnext') this.pauseOnNext = (aThisVar[1] == 'true');
		else if (aThisVar[0] == 'pauseonprev') this.pauseOnPrev = (aThisVar[1] == 'true');
	}
};
function Floatbox() {
	this.bottomPadding = 8;
	this.infoPanelHeight = 40;
	this.doc = top.document;
	this.body = this.doc.body;
  	this.arrItems = new Array();
	this.arrResizeGroup	= new Array();
	this.objSetSizeGroup = new Object();
	this.objTimeouts = new Object();
	this.ie6 = ((document.all && !window.opera && !window.XMLHttpRequest) === true);
	this.quirksMode = ((this.doc.compatMode && this.doc.compatMode == "BackCompat") === true);
	this.ff2 = /firefox\/[12]/i.test(navigator.userAgent);
	this.nextImageLoader = new Image();
	this.prevImageLoader = new Image();
	this.fbIFrameLoader = this.doc.createElement('iframe');
	this.fbIFrameLoader.setAttribute('name', 'fbIFrameLoader');
	this.fbIFrameLoader.style.display = 'none';
	this.body.appendChild(this.fbIFrameLoader);
	this.sourceFolder = document.getElementsByTagName('html').item(0).innerHTML.match(/src=[\"'](.*)floatbox\.js[\"']/i)[1];
	var autoStart = null;
	var anchors = document.getElementsByTagName('a');
	for ( var i = 0, len = anchors.length; i < len; i++) {
		var anchor = anchors[i];
		var href = anchor.getAttribute('href');
		var rel = anchor.getAttribute('rel');
		var rev = anchor.getAttribute('rev');
		if (/^(gallery|slideshow|lytebox|lyteshow|lightbox)/i.test(rel)) {
			anchor.onclick = function () { floatbox.start(this); return false; }
			if (!this.nextImageLoader.src) this.nextImageLoader.src = href;
			if (!autoStart && /autoStart:true/i.test(rev)) autoStart = anchor;
		}
		if (/^(iframe|lyteframe)/i.test(rel)) {
			anchor.onclick = function () { floatbox.start(this); return false; }
			if (!this.fbIFrameLoader.src) this.fbIFrameLoader.src = href;
			if (!autoStart && /autoStart:true/i.test(rev)) autoStart = anchor;
		}
	}
	if (autoStart) this.start(autoStart);
};
Floatbox.prototype.buildDOM = function() {
	var doc = this.doc;
	function setNode(nodeType, id, parentNode, className, title) {
		var node = doc.getElementById(id);
  		if (!node) {
			node = doc.createElement(nodeType);
			if (id) node.id = id;
			if (nodeType == 'a' && !window.opera) node.setAttribute('href', '#');
			if (nodeType == 'iframe') node.setAttribute('name', id);
			if (title) node.setAttribute('title', title);
			parentNode.appendChild(node);
		}
		if (className) node.className = id.replace('_ie6', '') + '_' + className;
		node.style.display = 'none';
		return node;
	};
	this.fbOverlay		= setNode('div', 'fbOverlay', this.body, this.theme);
	this.fbPositioner	= setNode('div', 'fbPositioner', this.body);
	this.fbFloatbox		= setNode('div', 'fbFloatbox', this.fbPositioner, this.theme);
	this.fbLoader		= setNode('div', 'fbLoader' + ((this.ie6 || this.quirksMode) ? '_ie6' : ''), this.fbFloatbox, this.theme);
	this.fbContentPanel	= setNode('div', 'fbContentPanel', this.fbFloatbox);
	if (this.isIFrame) {
		this.fbIFrame	= setNode('iframe', 'fbIFrame', this.fbContentPanel, this.theme);
	} else {
		this.fbImage	= setNode('img', 'fbImage', this.fbContentPanel, this.theme);
	}
	if (this.upperNav) {
		this.fbLeftNav	= setNode('a', 'fbLeftNav', this.fbContentPanel, this.theme);
		this.fbPrev		= setNode('a', 'fbPrev', this.fbLeftNav, this.theme, (this.showHints ? this.hintPrev : ''));
		this.fbRightNav	= setNode('a', 'fbRightNav', this.fbContentPanel, this.theme);
		this.fbNext		= setNode('a', 'fbNext', this.fbRightNav, this.theme, (this.showHints ? this.hintNext : ''));
	}
	this.fbInfoPanel	= setNode('div', 'fbInfoPanel', this.fbContentPanel, this.theme);
	this.fbCaption		= setNode('span', 'fbCaption', this.fbInfoPanel);
	this.fbItemNumber	= setNode('span', 'fbItemNumber', this.fbInfoPanel);
	this.fbControlPanel	= setNode('div', 'fbControlPanel', this.fbContentPanel, this.theme);
	this.fbLowerNav		= setNode('div', 'fbLowerNav', this.fbControlPanel);
	this.fbLowerPrev	= setNode('a', 'fbLowerPrev', this.fbLowerNav, this.theme, (this.showHints ? this.hintPrev : ''));
	this.fbLowerNext	= setNode('a', 'fbLowerNext', this.fbLowerNav, this.theme, (this.showHints ? this.hintNext : '' ));
	this.fbControls		= setNode('div', 'fbControls', this.fbControlPanel);
	this.fbClose		= setNode('a', 'fbClose', this.fbControls, this.theme, (this.showHints ? this.hintClose : '' ));
	this.fbPlay			= setNode('a', 'fbPlay', this.fbControls, this.theme, (this.showHints ? this.hintPlayPause : '' ));
	this.fbPause		= setNode('a', 'fbPause', this.fbControls, this.theme, (this.showHints ? this.hintPlayPause : '' ));
};
Floatbox.prototype.start = function(itemLink) {
	this.arrItems.length = 0;
	this.itemsShown = 0;
	var href = itemLink.getAttribute('href');
	var rel = itemLink.getAttribute('rel');
	var rev = itemLink.getAttribute('rev');
	rev = (rev ? rev.toLowerCase() : '');
	this.isIFrame = /^(iframe|lyteframe)/i.test(rel);
	if (/^(gallery|iframe|lytebox|lyteframe|lightbox)$/i.test(rel)) {
		this.arrItems.push( {'href': href, 'title': itemLink.getAttribute('title'), 'rev': rev, 'seen': false} );
	} else {
		var anchors = document.getElementsByTagName('a');
		var href_i, rel_i, rev_i;
		for (var i = 0, len = anchors.length; i < len; i++) {
			href_i = anchors[i].getAttribute('href');
			rel_i = anchors[i].getAttribute('rel');
			rev_i = anchors[i].getAttribute('rev');
			rev_i = (rev_i ? rev_i.toLowerCase() : '');
			if (rel_i == rel && rev_i.indexOf('showthis:false') == -1) {
				this.arrItems.push( {'href': href_i, 'title': anchors[i].getAttribute('title'), 'rev': rev_i, 'seen': false} );
			}
		}
	}
	this.itemCount = this.arrItems.length;
	this.setDefaultOptions();
	this.parseOptions(window.location.search.substring(1));
	this.parseOptions(rev);
	this.theme = this.theme.toLowerCase();
	if (!/^(black|grey|red|green|blue|gold|custom)$/.test(this.theme)) this.theme='black';
	this.isSlideshow = this.itemCount > 1 && (/^(slideshow|lyteshow)/i.test(rel) || this.doSlideshow);
	if (this.modal && (this.isSlideshow || this.isIFrame)) {
		this.navType = 'none';
		this.showClose = false;
		this.showPlayPause = false;
		this.showCaption = false;
		this.showItemNumber = false;
		this.enableKeyboardNav = false;
		this.outsideClickCloses = false;
	}
	this.navType = this.navType.toLowerCase();
	if (!/^(upper|lower|both|none)$/.test(this.navType)) this.navType = 'both';
	if (this.itemCount <= 1) {
		this.navType = 'none';
		this.showItemNumber = false;
	} else if (this.isIFrame && (this.navType == 'upper' || this.navType == 'both')) {
		this.navType = 'lower';
	}
	this.upperNav = (this.navType == 'upper' || this.navType == 'both');
	this.lowerNav = (this.navType == 'lower' || this.navType == 'both');
	if (this.upperNav) {
		if (this.upperNavWidth < 0) this.upperNavWidth = 0;
		if (this.upperNavWidth > 50) this.upperNavWidth = 50;
	}
	this.buildDOM();
	this.fbItem = (this.isIFrame ? this.fbIFrame : this.fbImage);
	this.fbPlay.onclick = function() { floatbox.setPause(false); return false; }
	this.fbPause.onclick = function() { floatbox.setPause(true); return false; }
	this.fbClose.onclick = function() { floatbox.end(); return false; }
	if (this.outsideClickCloses) {
		this.fbOverlay.onclick = function() { floatbox.end(); return false; }
		this.fbPositioner.onclick = function(e) {
			if (!e) var e = top.event;
			var target = (e.target ? e.target : e.srcElement);
			if (target.id == 'fbPositioner') {
				floatbox.end();
				return false;
			}
		}
	}
	if (this.ie6 || this.quirksMode) {
		this.setVisibility('select', 'hidden');
		this.fbOverlay.style.position = 'absolute';
		top.attachEvent('onresize', floatbox.stretchOverlay);
	}
	if (this.ie6 && this.isIFrame) this.innerBorder = 0;
	if (this.hideFlash) {
		this.setVisibility('object', 'hidden');
		this.setVisibility('embed', 'hidden');
	}
	this.fade(this.fbOverlay, 10, this.overlayOpacity);
	this.fbPositioner.style.top = (this.getViewPortSize()[1] / 16) + 'px';
	this.fbFloatbox.style.width = this.fbFloatbox.style.height = '0';
	this.fbFloatbox.style.borderWidth = this.outerBorder + 'px';
	this.fbItem.style.left = this.fbItem.style.top = this.padding + 'px';
	this.fbItem.style.borderWidth = this.innerBorder + 'px';
	this.fbFloatbox.style.visibility = this.fbContentPanel.style.visibility = 'hidden';
	this.fbPositioner.style.display = '';
	this.fbFloatbox.style.display = '';
	this.fbContentPanel.style.display = '';
	if (this.upperNav) {
		this.fbLeftNav.style.display = this.fbRightNav.style.display = '';
		this.fbLeftNav.style.top = this.fbRightNav.style.top = (this.padding + this.innerBorder) + 'px';
		this.fbLeftNav.style.left = this.fbRightNav.style.right = (this.padding + this.innerBorder) + 'px';
		if (this.navOpacity < 100) {
			this.fade(this.fbPrev, this.navOpacity);
			this.fade(this.fbNext, this.navOpacity);
		} else {
			this.fbPrev.style.display = this.fbNext.style.display = '';
		}
	}
	if (this.lowerNav) {
		this.fbLowerNav.style.display = this.fbLowerPrev.style.display = this.fbLowerNext.style.display = '';
	}
	if (this.upperNav || this.lowerNav) this.setNavActions();
	if (this.showCaption) this.fbCaption.style.display = '';
	if (this.showItemNumber) {
		this.fbItemNumber.style.display = '';
		this.fbItemNumber.style.paddingBottom = '7px';
	}
	if (this.showCaption || this.showItemNumber) {
		this.fbInfoPanel.style.display = '';
		this.fbInfoPanel.style.left = Math.max(this.padding, 8) + 'px';
		this.fbInfoPanel.style.height = this.infoPanelHeight + 'px';
		this.fbCaption.style.paddingBottom = (this.showItemNumber ? '0' : '7px');
	}
	if (!this.isSlideshow) this.showPlayPause = false; 
	if (this.showClose || this.showPlayPause || this.lowerNav) {
		this.fbControlPanel.style.display = '';
		this.fbControlPanel.style.right = Math.max(this.padding, 8) + 'px';
	} else if (!(this.showCaption || this.showItemNumber)) {
		this.bottomPadding = this.padding;
	}
    var controlsWidth = 0;
	if (this.showClose || this.showPlayPause ) this.fbControls.style.display = '';
	if (this.showClose) {
		this.fbClose.style.display = '';
		controlsWidth = this.fbClose.offsetWidth;
	}
	if (this.showPlayPause) {
		this.isPaused = this.startPaused;
		if (this.isPaused) {
			this.fbPlay.style.display = '';
			controlsWidth += this.fbPlay.offsetWidth + (this.showClose ? 10 : 0);
		} else {
			this.fbPause.style.display = '';
			controlsWidth += this.fbPause.offsetWidth + (this.showClose ? 10 : 0);
		}
	}
	this.fbControls.style.width = controlsWidth + 'px';
	this.fbControlPanel.style.width = (this.fbLowerNav.offsetWidth + this.fbControls.offsetWidth) + 'px';
	this.xFramework = 2*(this.outerBorder + this.innerBorder + this.padding);
	this.yFramework = 2*(this.outerBorder + this.innerBorder) + this.padding + this.bottomPadding;
	if (this.enableKeyboardNav) {
		this.priorOnkeydown = document.onkeydown;
		document.onkeydown = this.keyboardAction;
	}
	for (i = this.itemCount - 1; i > 0 ; i--) if (this.arrItems[i].href == href) break;
	this.loadItem(i);
};
Floatbox.prototype.loadItem = function(newItem) {
	this.clearTimeout('slideshow');
	this.activeItem = newItem;
	self.focus();
	var callee = arguments.callee;
	callee.loader = (this.isIFrame ? this.fbIFrameLoader : new Image());
	var width = height = 0;
	var options = this.arrItems[this.activeItem].rev;
	if (options) {
		options = options.replace(/\s*[:=]\s*/g, ':')
		options = options.replace(/\s*[;&]\s*/g, ' ')
		options = options.replace(/^\s+|\s+$/g, '')
		var aOptions = options.toLowerCase().split(/\s+/);
		var i = aOptions.length;  while (i--) {
			var aThisOption = aOptions[i].split(':');
			if (aThisOption[1]) {
				if (aThisOption[0] == 'width') {
					width = aThisOption[1];
					if (width != 'max') width = parseInt(width);
				} else if (aThisOption[0] == 'height') {
					height = aThisOption[1];
					if (height != 'max') height = parseInt(height);
				}
			}
		}
	}
	var viewPortSize = this.getViewPortSize();
	var maxWidth = viewPortSize[0] - this.xFramework - 12;
	if (width == 'max') width = maxWidth;
	var maxHeight = viewPortSize[1] - this.yFramework - Math.max(this.fbInfoPanel.offsetHeight, this.fbControlPanel.offsetHeight) - 8;
	if (height == 'max') height = maxHeight;
	this.objTimeouts.loader = setTimeout('floatbox.fbLoader.style.display = ""', 250);
	this.fbContentPanel.style.visibility = 'hidden';
	this.fbItem.style.display = 'none';
	if (!(this.isIFrame && this.ff2)) this.fbInfoPanel.style.top = this.fbControlPanel.style.top = '0';
	if (this.upperNav) {
		this.fbPrev.style.visibility = this.fbNext.style.visibility = 'hidden';
		this.fbLeftNav.style.height = this.fbRightNav.style.height = '0';
	}
	var that = this;
	callee.loader.loaded = function() {
		if (!width) width = parseInt(this.width ? this.width : 500);
		if (!height) height = parseInt(this.height ? this.height: 300);
		if (that.autoResize && width > maxWidth) {
			height = Math.round(height * (maxWidth/width));
			width = maxWidth;
		}
		if (that.autoResize && height > maxHeight) {
			width = Math.round(width * (maxHeight/height));
			height = maxHeight;
		}
		this.width = width;
		this.height = height;
		that.fbItem.src = this.src;
		that.resize(width, height);
	};
	if (!this.isIFrame) callee.loader.onload = callee.loader.loaded;
	callee.loader.src = this.arrItems[this.activeItem].href;
	if (this.isIFrame) {
		this.fbItem.src = this.sourceFolder + 'floatbox_ifload.html';
		setTimeout('floatbox.loadItem.loader.loaded()', 100);
	}
};
Floatbox.prototype.resize = function(itemWidth, itemHeight) {
	this.fbItem.width = itemWidth;
	this.fbItem.height = itemHeight;
 	var newWidth = itemWidth + this.xFramework;
	if (this.showCaption || this.showItemNumber) {
		this.fbInfoPanel.style.height = '';
		this.fbInfoPanel.style.width = (newWidth - 2*(this.outerBorder + Math.max(this.padding, 8)) - 30 - this.fbControlPanel.offsetWidth) + 'px';
		if (this.showCaption) {
			var sCaption = this.arrItems[this.activeItem].title;
			if (sCaption == 'href') sCaption = this.arrItems[this.activeItem].href;
			this.fbCaption.innerHTML = (sCaption) ? sCaption : '';
		}
		if (this.showItemNumber) {
			this.fbItemNumber.innerHTML = (this.isIFrame ? 'Page ' : 'Image ') + eval(this.activeItem + 1) + ' of ' + this.itemCount;
		} else {
			this.fbItemNumber.innerHTML = '';
		}
	}
	this.infoPanelHeight = this.fbInfoPanel.offsetHeight;
	var newHeight = itemHeight + this.yFramework + Math.max(this.infoPanelHeight, this.fbControlPanel.offsetHeight, this.padding - this.bottomPadding);
	var viewPortHeight = this.getViewPortSize()[1];
	var newTop = viewPortHeight / 16;
	if ((viewPortHeight - newHeight) < (viewPortHeight / 8)) {
		newTop = Math.max (4, (viewPortHeight - newHeight) / 2);
	}
	if (this.isIFrame && this.ff2 && newHeight < parent.innerHeight) {
		this.fbPositioner.style.position = 'fixed';
		this.fbFloatbox.style.marginLeft = 'auto';
	} else {
		this.fbPositioner.style.position = 'absolute';
		var pageScroll = this.getPageScroll();
		this.fbFloatbox.style.marginLeft = (pageScroll[0] ? (pageScroll[0] + 6) + 'px' : 'auto');
		newTop += pageScroll[1];
	}
	var oldWidth = this.fbFloatbox.offsetWidth;
	var oldHeight = this.fbFloatbox.offsetHeight;
	var oldTop = this.getTopLeft(this.fbPositioner)[0];
	if (oldWidth != newWidth) this.arrResizeGroup.push([this.fbFloatbox, 'width', oldWidth, newWidth - (this.quirksMode ? 0 : 2*this.outerBorder)]);
	if (oldHeight != newHeight) this.arrResizeGroup.push([this.fbFloatbox, 'height', oldHeight, newHeight - (this.quirksMode ? 0 : 2*this.outerBorder)]);
	if (oldTop != Math.round(newTop)) this.arrResizeGroup.push([this.fbPositioner, 'top', oldTop, newTop]);
	this.fbFloatbox.style.visibility = 'visible';
	if (this.arrResizeGroup.length) {
		this.resizeGroup();
	} else {
		this.showContent();
	}
};
Floatbox.prototype.showContent = function() {
	if (this.ie6 || this.quirksMode) {
		this.fbOverlay.style.width = this.fbOverlay.style.height = '100%';
		this.stretchOverlay();
	}
	this.fbItem.style.display = '';
	var itemWidth = parseInt(this.fbItem.width);
	var itemHeight = parseInt(this.fbItem.height);
	if (this.upperNav) {
		this.fbLeftNav.style.width = this.fbRightNav.style.width = Math.max(this.upperNavWidth/100 * itemWidth, this.fbPrev.offsetWidth) + 'px';
		this.fbLeftNav.style.height = this.fbRightNav.style.height = itemHeight + 'px';
	}
	var panelTop = itemHeight + 2*this.innerBorder + this.padding + this.bottomPadding;
	if (this.showCaption || this.showItemNumber) {
		this.fbInfoPanel.style.top = panelTop + 'px';
		var pad = (this.fbInfoPanel.offsetHeight - 32) / 2;
		if (pad > 0) panelTop += pad;
	}
	if (this.showClose || this.showPlayPause || this.lowerNav) {
		this.fbControlPanel.style.top = panelTop + 'px';
	}
	setTimeout('floatbox.showContent2()', 10);
};
Floatbox.prototype.showContent2 = function() {
	this.fade(this.fbContentPanel, 10, 100);
	this.clearTimeout('loader');
	this.fbLoader.style.display = 'none';
	if (!this.arrItems[this.activeItem].seen) {
		this.arrItems[this.activeItem].seen = true;
		this.itemsShown++;
	}
	this.nextImageLoader.src = (this.activeItem + 1 < this.itemCount ? this.arrItems[this.activeItem + 1].href : this.arrItems[0].href);
	this.prevImageLoader.src = (this.activeItem > 0 ? this.arrItems[this.activeItem - 1].href : this.arrItems[this.itemCount - 1].href);
	if (this.isSlideshow && !this.isPaused) {
		if (this.endTask == 'cont' || this.itemsShown < this.itemCount) {
			var nextItem = (this.activeItem < this.itemCount - 1) ? this.activeItem + 1 : 0;
			this.objTimeouts.slideshow = setTimeout('floatbox.loadItem(' + nextItem + ')', this.slideInterval*1000);
		} else if (this.endTask == 'exit')  {
			this.objTimeouts.slideshow = setTimeout('floatbox.end()', this.slideInterval*1000);
		} else {
			this.objTimeouts.slideshow = setTimeout('floatbox.setPause(true)', this.slideInterval*1000);
			var i = this.itemCount;
			while (i--) this.arrItems[i].seen = false;
			this.itemsShown = 0;
		}
	}
};
Floatbox.prototype.end = function() {
	for (var key in this.objTimeouts) {
		this.clearTimeout(key);
	}
	if (this.enableKeyboardNav) document.onkeydown = this.priorOnkeydown;
	this.fbOverlay.onclick = this.fbPositioner.onclick = null;
	this.fbPositioner.style.display = 'none';
	this.fade(this.fbOverlay, this.overlayOpacity, 0);
	if (this.ie6 || this.quirksMode) {
		this.setVisibility('select', '');
		top.detachEvent('onresize', floatbox.stretchOverlay);
	}
	if (this.hideFlash) {
		this.setVisibility('object', '');
		this.setVisibility('embed', '');
	}
	function remove(el) { el.parentNode.removeChild(el); }
	if (this.isIFrame) {
		remove (this.fbIFrame); delete this.fbIFrame;
	} else {
		remove (this.fbImage); delete this.fbImage;
	}
	if (this.upperNav) {
		remove(this.fbPrev); delete this.fbPrev;
		remove(this.fbNext); delete this.fbNext;
		remove(this.fbLeftNav); delete this.fbLeftNav;
		remove (this.fbRightNav); delete this.fbRightNav;
	}
	remove (this.fbCaption); delete this.fbCaption;
	remove (this.fbItemNumber); delete this.fbItemNumber;
	remove (this.fbInfoPanel); delete this.fbInfoPanel;
};
Floatbox.prototype.setNavActions = function() {
	var prev = function() {
		floatbox.loadItem(floatbox.activeItem == 0 ? floatbox.itemCount - 1 : floatbox.activeItem - 1);
		if (floatbox.isSlideshow  && floatbox.pauseOnPrev && !floatbox.isPaused && floatbox.showPlayPause) {
			floatbox.setPause(true);
		}
		return false;
	}
	var next = function() {
		floatbox.loadItem(floatbox.activeItem == floatbox.itemCount - 1? 0 : floatbox.activeItem + 1);
		if (floatbox.isSlideshow && floatbox.pauseOnNext && !floatbox.isPaused && floatbox.showPlayPause) {
			floatbox.setPause(true);
		}
		return false;
	}
	if (this.upperNav) {
		this.fbLeftNav.onclick = prev;
		this.fbRightNav.onclick = next;
		this.fbLeftNav.onmouseover = this.fbLeftNav.onmousemove = function() {
			if (!floatbox.objTimeouts['fbContentPanel']) floatbox.fbPrev.style.visibility = 'visible';
		}
		this.fbRightNav.onmouseover = this.fbRightNav.onmousemove = function() {
			if (!floatbox.objTimeouts['fbContentPanel']) floatbox.fbNext.style.visibility = 'visible';
		}
		this.fbLeftNav.onmouseout = function() { floatbox.fbPrev.style.visibility = 'hidden'; }
		this.fbRightNav.onmouseout = function() { floatbox.fbNext.style.visibility = 'hidden'; }
	}
	if (this.lowerNav) {
		this.fbLowerPrev.onclick = prev;
		this.fbLowerNext.onclick = next;
	}
};
Floatbox.prototype.keyboardAction = function(e) {
	if (!e) var e = window.event;
	switch(e.which ? e.which : e.keyCode) {
		case 88: case 67: case 27: {
			floatbox.end();
			break;
		}
		case 78: case 39: {
			if (floatbox.itemCount > 1) {
				floatbox.loadItem(floatbox.activeItem == floatbox.itemCount - 1 ? 0 : floatbox.activeItem + 1);
				if (floatbox.isSlideshow && floatbox.pauseOnNext && !floatbox.isPaused && floatbox.showPlayPause) {
					floatbox.setPause(true);
				}
			}
			if (e.returnValue) e.returnValue = false;
			return false;
		}
		case 80: case 37: case 8: {
			if (floatbox.itemCount > 1) {
				floatbox.loadItem(floatbox.activeItem == 0 ? floatbox.itemCount - 1 : floatbox.activeItem - 1);
				if (floatbox.isSlideshow && floatbox.pauseOnPrev && !floatbox.isPaused && floatbox.showPlayPause) {
					floatbox.setPause(true);
				}
			}
			if (e.returnValue) e.returnValue = false;
			return false;
		}
		case 32: {
			if (floatbox.isSlideshow) floatbox.setPause(!floatbox.isPaused);
		}
		case 13: {
			if (e.returnValue) e.returnValue = false;
			return false;
		}
	}
};
Floatbox.prototype.setPause = function(bPause) {
	this.isPaused = bPause;
	if (bPause) {
		this.clearTimeout('slideshow');
	} else {
		this.loadItem(this.activeItem < this.itemCount - 1 ? this.activeItem + 1 : 0);
	}
	if (this.showPlayPause) {
		this.fbPause.style.display = (bPause ? 'none' : '');
		this.fbPlay.style.display = (bPause ? '' : 'none');
	}
};
Floatbox.prototype.fade = function(obj, startOp, finishOp) {
	if (typeof(finishOp) == 'undefined') finishOp = startOp;
	var fadeIn = (startOp <= finishOp && finishOp > 0);
	this.clearTimeout(obj.id);
	var duration = (obj.id == 'fbOverlay' ? this.overlayFadeDuration : this.imageFadeDuration);
	if (duration > 10) duration = 10;
	if (duration < 0) duration = 0;
	if (duration == 0) {
		startOp = finishOp;
		var incr = 100;
	} else {
		var root = Math.pow(100, .1);
		var power = duration + ((10 - duration)/9) * (Math.log(2)/Math.log(root) - 1);
		var incr = Math.round(100/Math.pow(root, power));
	}
	if (!fadeIn) incr = -incr;
	this.setOpacity(obj, startOp, finishOp, incr, fadeIn);
	if (fadeIn) {
		obj.style.display = '';
		obj.style.visibility = 'visible';
	}
};
Floatbox.prototype.setOpacity = function(obj, thisOp, finishOp, incr, fadeIn) {
	if ((fadeIn && thisOp >= finishOp) || (!fadeIn && thisOp <= finishOp)) thisOp = finishOp;
	obj.style.opacity = (thisOp / 100);
	obj.style.MozOpacity = (thisOp / 100);
	obj.style.KhtmlOpacity = (thisOp / 100);
	obj.style.filter = 'alpha(opacity=' + thisOp + ')';
	if (thisOp == finishOp) {
		this.objTimeouts[obj.id] = null;
		if (finishOp >= 100) {
			try { obj.style.removeAttribute('filter'); } catch(e) {/*ignore*/}
		} else if (finishOp <= 0 && obj.id == 'fbOverlay') {
			this.fbOverlay.style.display = this.fbPositioner.style.display = 'none';
		}
	} else {
		this.objTimeouts[obj.id] = setTimeout('floatbox.setOpacity(floatbox.' + obj.id + ', ' + (thisOp + incr) + ', ' + finishOp + ', ' + incr + ', ' + fadeIn + ')', 20);
	}
};
Floatbox.prototype.resizeGroup = function() {
	var diff = 0;
	var idx = '';
	var i = this.arrResizeGroup.length;
	while (i--) {
		if (typeof(this.arrResizeGroup[i][3]) == 'undefined') {
			this.arrResizeGroup[i][3] = this.arrResizeGroup[i][2];
		}
  		diff = Math.max(diff, Math.abs(this.arrResizeGroup[i][3] - this.arrResizeGroup[i][2]));
  		idx += this.arrResizeGroup[i][0].id + this.arrResizeGroup[i][1];
	}
	if (idx) {
		this.clearTimeout(idx);
		if (typeof(this.objSetSizeGroup[idx]) == 'undefined') {
			this.objSetSizeGroup[idx] = new Array();
		} else {
			this.objSetSizeGroup[idx].length = 0;
		}
		var rate = (diff == 0 || this.resizeDuration == 0) ? 1 : Math.pow(Math.max(1, 2.2 - this.resizeDuration/10), (Math.log(diff))) / diff;
		i = this.arrResizeGroup.length;
		while (i--) {
			this.objSetSizeGroup[idx][i] = [
				this.arrResizeGroup[i][0],
				this.arrResizeGroup[i][1],
				this.arrResizeGroup[i][2],
				this.arrResizeGroup[i][3] - this.arrResizeGroup[i][2]
			];
		}
		this.setSize(idx, rate, 1);
	}
	this.arrResizeGroup.length = 0;
};
Floatbox.prototype.setSize = function(idx, rate, count) {
	var increment = rate * count;
	if (increment > 1) increment = 1;
	var i = this.objSetSizeGroup[idx].length;
	while (i--) {
		var obj = this.objSetSizeGroup[idx][i][0];
		var prop = this.objSetSizeGroup[idx][i][1];
		var startPx = this.objSetSizeGroup[idx][i][2];
		var diff = this.objSetSizeGroup[idx][i][3];
		obj.style[prop] = Math.round(startPx + (diff * increment)) + 'px';
	}
	if (increment >= 1) {
		this.objTimeouts[idx] = null;
		this.objSetSizeGroup[idx].length = 0;
		this.showContent();
	} else {
		this.objTimeouts[idx] = setTimeout("floatbox.setSize('" + idx + "', " + rate + ", " + (count + 1) + ")", 20);
	}
};
Floatbox.prototype.getPageScroll = function() {
	var x=0, y=0;
	if (typeof(top.pageXOffset) != 'undefined') {
		x = top.pageXOffset;
		y = top.pageYOffset;
	} else if (this.doc.documentElement && this.doc.documentElement.scrollLeft != 'undefined') {
		x = this.doc.documentElement.scrollLeft;
		y = this.doc.documentElement.scrollTop;
	}
	if (typeof(this.body.scrollLeft) != 'undefined') {
		x = Math.max(x, this.body.scrollLeft);
		y = Math.max(y, this.body.scrollTop);
	}
	return [x, y];
};
Floatbox.prototype.getViewPortSize = function() {	
	var x=999999, y=999999, t;
	if (top.innerWidth) x = top.innerWidth;
	if (top.innerHeight) y = top.innerHeight;
	if (this.doc.documentElement) {
		t = this.doc.documentElement.clientWidth;
		if (t && t < x) x = t;
		t = this.doc.documentElement.clientHeight;
		if (t && t < y) y = t;
	}
	t = this.body.clientWidth;
	if (t && t < x) x = t;
	t = this.body.clientHeight;
	if (t && t < y) y = t;
	return [(x == 999999) ? 0 : x, (y == 999999) ? 0 : y];
};
Floatbox.prototype.getTopLeft = function(el) {
	var top = (el.offsetTop) ? el.offsetTop : 0;
	var left = (el.offsetLeft) ? el.offsetLeft : 0;
	var parent = el;
	while (parent = parent.offsetParent) {
		top += parent.offsetTop;
		left += parent.offsetLeft;
	}
	return [top, left];
};
Floatbox.prototype.setVisibility = function(tagName, state, thisWindow) {
	if (!thisWindow) {
		arguments.callee(tagName, state, top)
	} else {
		try {
			var els = thisWindow.document.getElementsByTagName(tagName);
			var i = els.length; while (i--) {
				els[i].style.visibility = state;
			}
		} catch(e) {}
		var frames = thisWindow.frames;
		i = frames.length; while (i--) {
			arguments.callee(tagName, state, frames[i].window);
		}
	}
};
Floatbox.prototype.clearTimeout = function(key) {
	if (this.objTimeouts[key]) {
		clearTimeout(this.objTimeouts[key]);
		this.objTimeouts[key] = null;
	}
};
Floatbox.prototype.stretchOverlay = function() {
	if (arguments.length == 1) {
		floatbox.clearTimeout('onresize');
		floatbox.objTimeouts.onresize = setTimeout('floatbox.stretchOverlay()', 100);
	} else {
		floatbox.objTimeouts.onresize = null;
		topLeft = floatbox.getTopLeft(floatbox.fbFloatbox);
		var width = topLeft[1] + floatbox.fbFloatbox.offsetWidth;
		var height = topLeft[0] + floatbox.fbFloatbox.offsetHeight;
		var style = floatbox.fbOverlay.style;
		style.width = style.height = '0';
		style.width = Math.max(width, floatbox.body.scrollWidth, floatbox.body.clientWidth) + 'px';
		style.height = Math.max(height, floatbox.body.scrollHeight, floatbox.body.clientHeight) + 'px';
	}
};
function initfb() {
	floatbox = new Floatbox();
};
fb_isIE = false;
/*@cc_on @*/
/*@if (@_win32)
	fb_isIE = true;
	document.write('<script type="text/javascript" src="//:" defer="defer" onreadystatechange="if(this.readyState == \'complete\') initfb();"></script>');
/*@end @*/
if (!fb_isIE) {
	if (/KHTML|WebKit/i.test(navigator.userAgent)) {
		var fb_timer = setInterval(function() {
			if (/loaded|complete/.test(document.readyState)) {
				clearInterval(fb_timer);
				initfb();
			}
		}, 50);
	} else if (document.addEventListener) {
		document.addEventListener("DOMContentLoaded", initfb, false);
	} else {
		var prevOnload = window.onload;
		if (prevOnload) {
			window.onload = function() {
				initfb();
				prevOnload();
			};
		} else {
			window.onload = initfb;
		}
	}
}
