/*
 * 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
 */

// on page load call TB_init
window.addEvent('domready', TB_init);

// prevent javascript error before the content has loaded
TB_WIDTH = 0;
TB_HEIGHT = 0;
var TB_doneOnce = 0 ;

/*This function is a browser sniffer (yes I know this is bad and I am going to hell) to detect Firefox on the Mac.
 * There is a bug which affects firefox on the bac where flash movies with wmode="transparent" on a semi-transparent background do not appear at all. 
 */
function TB_detectMacXFF() {
	var $ = document.id;
	var userAgent = navigator.userAgent.toLowerCase();
	if (userAgent.indexOf('mac') != -1 && userAgent.indexOf('firefox') != -1) {
  		return true; 
	} 
}
var isMacAndFF = TB_detectMacXFF();

// add smoothbox to href elements that have a class of .smoothbox
function TB_init(){
	var $ = document.id;
	$$("a.smoothbox").each(function(el){el.onclick=TB_bind});
}

function TB_bind(event) {
	var $ = document.id;
	var event = new Event(event);
	// stop default behaviour
	event.preventDefault();
	// remove click border
	this.blur();
	// get caption: either title or name attribute
	var caption = this.title || this.name || "";
	// get rel attribute for image groups
	var group = this.rel || false;
	// display the box for the elements href
	TB_show(caption, this.href, group);
	this.onclick=TB_bind;
	return false;
}


// called when the user clicks on a smoothbox link
function TB_show(caption, url, rel) {
	var $ = document.id;
	// create iframe, overlay and box if non-existent

	if ( !$("TB_overlay") )
	{	/* set src property to actual file, to avoid secure/non-secure dialog in ie over https */
		new Element('iframe').setProperty('id', 'TB_HideSelect').setProperty('src',staticRoot+'img/blank.gif').injectInside(document.body);
		$('TB_HideSelect').set('opacity', 0);
		new Element('div').setProperty('id', 'TB_overlay').injectInside(document.body);
		$('TB_overlay').set('opacity', 0);
		TB_overlaySize();
		new Element('div').setProperty('id', 'TB_load').injectInside(document.body);
		$('TB_load').innerHTML = "<img src='"+staticRoot+"/img/loading.gif' />";
		TB_load_position();
		if (isMacAndFF) {
			$('TB_overlay').set('opacity', 1);
			$('TB_overlay').style.visibility = "visible";
			$('TB_overlay').style.backgroundColor = "transparent";
			$('TB_overlay').style.backgroundImage = 
			"url(data:image/png;base64,"+
			'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAACXBIWXMAAAsTAAALEwEAmpwYAAAK'+
			'T2lDQ1BQaG90b3Nob3AgSUNDIHByb2ZpbGUAAHjanVNnVFPpFj333vRCS4iAlEtvUhUIIFJCi4AU'+
			'kSYqIQkQSoghodkVUcERRUUEG8igiAOOjoCMFVEsDIoK2AfkIaKOg6OIisr74Xuja9a89+bN/rXX'+
			'Pues852zzwfACAyWSDNRNYAMqUIeEeCDx8TG4eQuQIEKJHAAEAizZCFz/SMBAPh+PDwrIsAHvgAB'+
			'eNMLCADATZvAMByH/w/qQplcAYCEAcB0kThLCIAUAEB6jkKmAEBGAYCdmCZTAKAEAGDLY2LjAFAt'+
			'AGAnf+bTAICd+Jl7AQBblCEVAaCRACATZYhEAGg7AKzPVopFAFgwABRmS8Q5ANgtADBJV2ZIALC3'+
			'AMDOEAuyAAgMADBRiIUpAAR7AGDIIyN4AISZABRG8lc88SuuEOcqAAB4mbI8uSQ5RYFbCC1xB1dX'+
			'Lh4ozkkXKxQ2YQJhmkAuwnmZGTKBNA/g88wAAKCRFRHgg/P9eM4Ors7ONo62Dl8t6r8G/yJiYuP+'+
			'5c+rcEAAAOF0ftH+LC+zGoA7BoBt/qIl7gRoXgugdfeLZrIPQLUAoOnaV/Nw+H48PEWhkLnZ2eXk'+
			'5NhKxEJbYcpXff5nwl/AV/1s+X48/Pf14L7iJIEyXYFHBPjgwsz0TKUcz5IJhGLc5o9H/LcL//wd'+
			'0yLESWK5WCoU41EScY5EmozzMqUiiUKSKcUl0v9k4t8s+wM+3zUAsGo+AXuRLahdYwP2SycQWHTA'+
			'4vcAAPK7b8HUKAgDgGiD4c93/+8//UegJQCAZkmScQAAXkQkLlTKsz/HCAAARKCBKrBBG/TBGCzA'+
			'BhzBBdzBC/xgNoRC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jlG4dvyr+Z3JS0qavEuWTPZtJm6ebeLZ5bDpaql+aX'+
			'Dm4N2dq0Dd9WtO319kXbL5fNKNu7g7ZDuaO/PLi8ZafJzs07P1SkVPRU+lQ27tLdtWHX+G7R7ht7'+
			'vPY07NXbW7z3/T7JvttVAVVN1WbVZftJ+7P3P66Jqun4lvttXa1ObXHtxwPSA/0HIw6217nU1R3S'+
			'PVRSj9Yr60cOxx++/p3vdy0NNg1VjZzG4iNwRHnk6fcJ3/ceDTradox7rOEH0x92HWcdL2pCmvKa'+
			'RptTmvtbYlu6T8w+0dbq3nr8R9sfD5w0PFl5SvNUyWna6YLTk2fyz4ydlZ19fi753GDborZ752PO'+
			'32oPb++6EHTh0kX/i+c7vDvOXPK4dPKy2+UTV7hXmq86X23qdOo8/pPTT8e7nLuarrlca7nuer21'+
			'e2b36RueN87d9L158Rb/1tWeOT3dvfN6b/fF9/XfFt1+cif9zsu72Xcn7q28T7xf9EDtQdlD3YfV'+
			'P1v+3Njv3H9qwHeg89HcR/cGhYPP/pH1jw9DBY+Zj8uGDYbrnjg+OTniP3L96fynQ89kzyaeF/6i'+
			'/suuFxYvfvjV69fO0ZjRoZfyl5O/bXyl/erA6xmv28bCxh6+yXgzMV70VvvtwXfcdx3vo98PT+R8'+
			'IH8o/2j5sfVT0Kf7kxmTk/8EA5jz/GMzLdsAAAAgY0hSTQAAeiUAAICDAAD5/wAAgOkAAHUwAADq'+
			'YAAAOpgAABdvkl/FRgAAABNJREFUeNpiYGBgmAkAAAD//wMAAJ4AmoUKguwAAAAASUVORK5CYII=)';
			$('TB_overlay').style.backgroundRepeat ="repeat";
			$('TB_HideSelect').style.backgroundColor ="transparent";
			//this was the problem in FF on Mac
			//$('flash_enhancement_movie').style.visibility = "hidden";
			for (var i=0; i<($$('.sIFR-flash').length); i++) {
				$$('.sIFR-flash')[i].style.cssText = "visibility: hidden !important;";					
			}
		}
		else {
			new Fx.Tween('TB_overlay', {property: 'opacity', duration: 400, transition: Fx.Transitions.sineInOut}).start(0,0.6);
		}
	}
	
	if ( !$("TB_load") )
	{		
		new Element('div').setProperty('id', 'TB_load').injectInside(document.body);
		$('TB_load').innerHTML = "<img src='"+staticRoot+"/img/loading.gif' />";
		TB_load_position();
	}
	
	if ( !$("TB_window") )
	{
		new Element('div').setProperty('id', 'TB_window').injectInside(document.body);
		$('TB_window').set('opacity', 0);
	}
	
	$("TB_overlay").onclick=TB_remove;
	window.onscroll=TB_positionEffect;

	// check if a query string is involved
	var baseURL = url.match(/(.+)?/)[1] || url;

	// regex to check if a href refers to an image
	var imageURL = /\.(jpe?g|png|gif|bmp)/gi;

	// check for images
	if ( baseURL.match(imageURL) ) {
		var dummy = { caption: "", url: "", html: "" };
		
		var prev = dummy,
			next = dummy,
			imageCount = "";
			
		// if an image group is given
		if ( rel ) {
			function getInfo(imageTag, id, label) {
				return {
					caption: imageTag.title,
					url: imageTag.href,
					html: "<span id='TB_" + id + "'>&nbsp;&nbsp;<a href='#'>" + label + "</a></span>"
				}
			}
		
			// find the anchors that point to the group
			var imageGroup = [] ;
			$$("a.smoothbox").each(function(el){
				if (el.rel==rel) {imageGroup[imageGroup.length] = el ;}
			})

			var foundSelf = false;
			
			// loop through the anchors, looking for ourself, saving information about previous and next image
			for (var i = 0; i < imageGroup.length; i++) {
				var imageTag = imageGroup[i];
				var urlTypeTemp = imageTag.href.match(imageURL);
				
				// look for ourself
				if ( imageTag.href == url ) {
					foundSelf = true;
					imageCount = "Image " + (i + 1) + " of "+ (imageGroup.length);
				} else {
					// when we found ourself, the current is the next image
					if ( foundSelf ) {
						next = getInfo(imageTag, "next", "Next &gt;");
						// stop searching
						break;
					} else {
						// didn't find ourself yet, so this may be the one before ourself
						prev = getInfo(imageTag, "prev", "&lt; Prev");
					}
				}
			}
		}
		
		imgPreloader = new Image();
		imgPreloader.onload = function() {
			imgPreloader.onload = null;

			// Resizing large images
			var x = window.getWidth() - 150;
			var y = window.getHeight() - 150;
			var imageWidth = imgPreloader.width;
			var imageHeight = imgPreloader.height;
			if (imageWidth > x) {
				imageHeight = imageHeight * (x / imageWidth); 
				imageWidth = x; 
				if (imageHeight > y) { 
					imageWidth = imageWidth * (y / imageHeight); 
					imageHeight = y; 
				}
			} else if (imageHeight > y) { 
				imageWidth = imageWidth * (y / imageHeight); 
				imageHeight = y; 
				if (imageWidth > x) { 
					imageHeight = imageHeight * (x / imageWidth); 
					imageWidth = x;
				}
			}
			// End Resizing
			
			// TODO don't use globals
			TB_WIDTH = imageWidth + 30;
			TB_HEIGHT = imageHeight + 60;
			
			// TODO empty window content instead
			$("TB_window").innerHTML += "<a href='' id='TB_ImageOff' title='Close'><img id='TB_Image' src='"+url+"' width='"+imageWidth+"' height='"+imageHeight+"' alt='"+caption+"'/></a>" + "<div id='TB_caption'>"+caption+"<div id='TB_secondLine'>" + imageCount + prev.html + next.html + "</div></div><div id='TB_closeWindow'><a href='#' id='TB_closeWindowButton' title='Close'>close</a></div>";
			
			$("TB_closeWindowButton").onclick = TB_remove;
			
			function buildClickHandler(imageTag) {
				return function() {
					$("TB_window").dispose();
					new Element('div').setProperty('id', 'TB_window').injectInside(document.body);
					
					TB_show(imageTag.caption, imageTag.url, rel);
					return false;
				};
			}
			var goPrev = buildClickHandler(prev);
			var goNext = buildClickHandler(next);
			if ( $('TB_prev') ) {
				$("TB_prev").onclick = goPrev;
			}
			
			if ( $('TB_next') ) {		
				$("TB_next").onclick = goNext;
			}
			
			document.onkeydown = function(event) {
				var event = new Event(event);
				switch(event.code) {
				case 27:
					TB_remove();
					break;
				case 190:
					if( $('TB_next') ) {
						document.onkeydown = null;
						goNext();
					}
					break;
				case 188:
					if( $('TB_prev') ) {
						document.onkeydown = null;
						goPrev();
					}
					break;
				}
			}
			
			// TODO don't remove loader etc., just hide and show later
			$("TB_ImageOff").onclick = TB_remove;
			TB_position();
			TB_showWindow();
		}
		imgPreloader.src = url;
		
	} else { //code to show html pages
		//alert(url)
		var queryString = url.match(/\?(.+)/)[1];
		var params = TB_parseQuery( queryString );
		
		if (!params['width']) {
			TB_WIDTH = (TB_getMaxChildDimensions('width')*1) + 110;
		} else {
			TB_WIDTH = (params['width']*1) + 110;
		}
		if (!params['height']) {
			TB_HEIGHT = (TB_getMaxChildDimensions('height')*1) + 40;
		} else {
			TB_HEIGHT = (params['height']*1) + 40;
		}

		var ajaxContentW = TB_WIDTH - 30,
			ajaxContentH = TB_HEIGHT - 45;
			
		var showTitle = '';
		if (params['showTitle'] && params['showTitle'] == "true") {
			showTitle = ' class="showTitle"'
		}
		
		
		if(url.indexOf('TB_iframe') != -1){				
			urlNoQuery = url.split('TB_');		
			$("TB_window").innerHTML += "<div id='TB_title'"+showTitle+"><div id='TB_ajaxWindowTitle'>"+caption+"</div><div id='TB_closeAjaxWindow'><a href='#' id='TB_closeWindowButton' title='Close'>close</a></div></div><iframe frameborder='0' hspace='0' src='"+urlNoQuery[0]+"' id='TB_iframeContent' name='TB_iframeContent' style='width:"+(ajaxContentW + 29)+"px;height:"+(ajaxContentH + 17)+"px;' onload='TB_showWindow()'> </iframe>";
		} else {
			var sizeAddition = -25;
			var browser = navigator.appName;
			if (browser=="Microsoft Internet Explorer"){
				sizeAddition = 8;
			}
			
			$("TB_window").innerHTML += "<div id='TB_title'"+showTitle+"><div id='TB_ajaxWindowTitle'>"+caption+"</div><div id='TB_closeAjaxWindow'><a href='#' id='TB_closeWindowButton' title='Close'>close</a></div></div><div id='TB_ajaxContent' style='width:"+ajaxContentW+"px;height:"+(ajaxContentH + sizeAddition)+"px;'></div>";
		}
				
		$("TB_closeWindowButton").onclick = TB_remove;
		
			if(url.indexOf('TB_inline') != -1){	
				$("TB_ajaxContent").innerHTML = ($(params['inlineid']).innerHTML);
				TB_position();
				TB_showWindow();
			}else if(url.indexOf('TB_iframe') != -1){
				TB_position();
				if(frames['TB_iframeContent'] == undefined){//be nice to safari
					$(document).keyup( function(e){ var key = e.keyCode; if(key == 27){TB_remove()} });
					TB_showWindow();
				}
			}else{
				var handlerFunc = function(){
					TB_position();
					TB_showWindow();
				};
				var myRequest = new Request.HTML({url: url, method: 'get', update: $("TB_ajaxContent"), onSuccess: handlerFunc}).send();
			}
	}

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

//helper functions below

function TB_showWindow(){
	var $ = document.id;
	//$("TB_load").dispose();
	//$("TB_window").setStyles({display:"block",opacity:'0'});
	
	if (TB_doneOnce==0) {
		TB_doneOnce = 1;
		var myFX = new Fx.Tween('TB_window', {property: 'opacity', duration: 250, transition: Fx.Transitions.sineInOut, onComplete:function(){if ($('TB_load')) { $('TB_load').dispose();}} }).start(0,1);
	} else {
		$('TB_window').setStyle('opacity',1);
		if ($('TB_load')) { $('TB_load').dispose();}
	}
}

function TB_remove() {
	var $ = document.id;
 	$("TB_overlay").onclick=null;
	document.onkeyup=null;
	document.onkeydown=null;
	
	if ($('TB_imageOff')) $("TB_imageOff").onclick=null;
	if ($('TB_closeWindowButton')) $("TB_closeWindowButton").onclick=null;
	if ( $('TB_prev') ) { $("TB_prev").onclick = null; }
	if ( $('TB_next') ) { $("TB_next").onclick = null; }

	if (isMacAndFF) {
		//this was the problem in FF on Mac
		//$('flash_enhancement_movie').style.visibility = "visible";
		//for (var i=0; i<($$('.sIFR-flash').length); i++) {
		//	$$('.sIFR-flash')[i].style.cssText = "visibility: visible !important;";					
		//}
		new Fx.Tween('TB_window', {property: 'opacity', duration: 250, transition: Fx.Transitions.sineInOut, onComplete:function(){$('TB_window').dispose();} }).start(1,0);
		new Fx.Tween('TB_overlay', {property: 'opacity', duration: 400, transition: Fx.Transitions.sineInOut, onComplete:function(){$('TB_overlay').dispose();} }).start(0.6,0);
	}
	else {
		new Fx.Tween('TB_window', {property: 'opacity',duration: 250, transition: Fx.Transitions.sineInOut, onComplete:function(){$('TB_window').dispose();} }).start(1,0);
		new Fx.Tween('TB_overlay', {property: 'opacity',duration: 400, transition: Fx.Transitions.sineInOut, onComplete:function(){$('TB_overlay').dispose();} }).start(0.6,0);
	}

	window.onscroll=null;
	window.onresize=null;	
	
	$('TB_HideSelect').dispose();
	TB_init();
	TB_doneOnce = 0;
	return false;
}

function TB_position() {
	var $ = document.id;
	$("TB_window").setStyles({width: TB_WIDTH+'px', 
				 left: (window.getScrollLeft() + (window.getWidth() - TB_WIDTH)/2)+'px',
				 top: (window.getScrollTop() + (window.getHeight() - TB_HEIGHT)/2)+'px'});
}

function TB_positionEffect() {
	var $ = document.id;
	
	var myFx = new Fx.Tween($("TB_window"), {duration: 75, transition: Fx.Transitions.sineInOut});
	myFx.set('left', (window.getScrollLeft() + (window.getWidth() - TB_WIDTH)/2)+'px');
	myFx.set('top', (window.getScrollTop() + (window.getHeight() - TB_HEIGHT)/2)+'px');
}

function TB_overlaySize(){
	var $ = document.id;
	// 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_HideSelect").setStyles({"height": '0px', "width": '0px'});
	var exactWidth = (window.getWidth() == 0) ? window.getScrollWidth()-22 : window.getWidth();
	$("TB_overlay").setStyles({"height": window.getScrollHeight()+'px', "width": exactWidth+'px'});
	$("TB_HideSelect").setStyles({"height": window.getScrollHeight()+'px',"width": exactWidth+'px'});
}

function TB_load_position() {
	var $ = document.id;
	if ($("TB_load")) { $("TB_load").setStyles({left: (window.getScrollLeft() + (window.getWidth() - 56)/2)+'px', top: (window.getScrollTop() + ((window.getHeight()-20)/2))+'px',display:"block"}); }
}

function TB_parseQuery ( query ) {
	var $ = document.id;
	
	// return empty object
	if( !query )
		return {};
	var params = {};
	
	// parse query
	var pairs = query.split(/[;&]/);
	for ( var i = 0; i < pairs.length; i++ ) {
		var pair = pairs[i].split('=');
		if ( !pair || pair.length != 2 )
			continue;
		// unescape both key and value, replace "+" with spaces in value
		params[unescape(pair[0])] = unescape(pair[1]).replace(/\+/g, ' ');
   }
   return params;
}

function TB_getMaxChildDimensions(dim) {
	var $ = document.id;

	var maxCalculatedDim = 0;
	if ($('sizingGuide')) {
		var children = $('sizingGuide').getChildren();
		$$(children).each(function(el) {
			switch (dim) {
				case 'width':
					maxCalculatedDim = (maxCalculatedDim < parseInt($(el).getStyle(dim))) ? parseInt($(el).getStyle(dim)) : maxCalculatedDim;
					break;
				case 'height':
					maxCalculatedDim = maxCalculatedDim+parseInt($(el).getStyle(dim));
					break;
			}
			
		});	
	}	
	return maxCalculatedDim;
}

