// prevent javascript error before the content has loaded
var TB_zIndex = 100;
var TB_marginTop = 73;

/*
 * Smoothbox v20070814 by Boris Popoff (http://gueschla.com)
 *
 * Based on Cody Lindley's Thickbox, MIT License
 *
 * Licensed under the MIT License:
 *   http://www.opensource.org/licenses/mit-license.php
 */

// called when the user clicks on a smoothbox link
function TB_show(callback) {

	// create iframe, overlay and box if non-existent

	if ( !$("TB_overlay") )	{

//		new Element('div').setProperty('id', 'TB_overlay').injectInside(document.body);
		new Element('div').setProperty('id', 'TB_overlay').injectInside( $('map') );
		$('TB_overlay').setOpacity(0);
		$('TB_overlay').style.zIndex = TB_zIndex;
		$('TB_overlay').style.marginTop = TB_marginTop;

		if (callback) {
		  $('TB_overlay').onclick=callback;
		}

		TB_overlaySize();
		new Fx.Style('TB_overlay', 'opacity',{duration: 400, transition: Fx.Transitions.sineInOut}).start(0,0.6);

  	document.onkeyup = function(event){
  		var event = new Event(event);
  		if(event.code == 27){ // close
  			TB_remove();
  		}
  	}
    TB_overlaySize();
	}
}


// called when the user clicks on a smoothbox link
function TB_show_full(callback) {

	// create iframe, overlay and box if non-existent

	if ( !$("TB_overlay") )	{

		new Element('div').setProperty('id', 'TB_overlay').injectInside(document.body);

		$('TB_overlay').setOpacity(0);
		$('TB_overlay').style.zIndex = TB_zIndex;
		$('TB_overlay').style.marginTop = TB_marginTop;

		if (callback) {
		  $('TB_overlay').onclick=callback;
		}

		TB_overlaySize();
		new Fx.Style('TB_overlay', 'opacity',{duration: 400, transition: Fx.Transitions.sineInOut}).start(0,0.6);

  	document.onkeyup = function(event){
  		var event = new Event(event);
  		if(event.code == 27){ // close
  			TB_remove();
  		}
  	}
    TB_overlaySize();
	}
}


//helper functions below

function TB_remove() {

  if ($('TB_overlay')) {
   	$('TB_overlay').onclick=null;
  	document.onkeyup=null;

  	if ($('TB_overlay')) {
    	new Fx.Style('TB_overlay', 'opacity',{duration: 400, transition: Fx.Transitions.sineInOut, onComplete:function(){$('TB_overlay').remove();} }).start(0.6,0);
  	}
  }
	return false;
}


function TB_overlaySize(){
	// we have to set this to 0px before so we can reduce the size / width of the overflow onresize
	$("TB_overlay").setStyles({"height": '0px', "width": '0px'});
	$("TB_overlay").setStyles({"height": (window.getScrollHeight() - TB_marginTop)+'px', "width": window.getScrollWidth()+'px'});
}

